protected boolean writeToDB(
      ItemBean ib,
      ItemFormMetadataBean ifm,
      ItemDataBean idb,
      String exp,
      String value,
      StringBuffer err) {
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    NumberFormat nf = NumberFormat.getInstance();

    if (idb == null) {
      idb = new ItemDataBean();
    }

    ItemDataType idt = ib.getDataType();
    if (value == null || value.length() == 0) {
      if (idb.isActive() && !"".equals(idb.getValue())) {
        idb.setValue("<erased>");
      } else {
        idb.setValue("");
      }
      err.append("Result is empty in" + " " + exp + "; ");
    } else {
      idb.setValue(this.getMathContextValue(value, ifm, idt, err));
    }

    idb.setStatus(Status.UNAVAILABLE);
    // idb.setNeedsRecalc(false);
    if (!idb.isActive()) {
      // will this need to change for double data entry?
      idb.setCreatedDate(new Date());
      idb.setOwner(ub);
      idb.setItemId(ib.getId());
      idb.setEventCRFId(ecb.getId());

      idb = (ItemDataBean) iddao.create(idb);
    } else {
      idb = (ItemDataBean) iddao.update(idb);
    }

    return idb.isActive();
  }
  @Override
  @SuppressWarnings(value = "unchecked")
  public void processRequest() throws Exception {
    ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
    EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
    CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(sm.getDataSource());
    String action = request.getParameter("action");

    FormProcessor fp = new FormProcessor(request);

    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);

    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);

    setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));

    setToPanel(
        resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
    setToPanel(
        resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
    setToPanel(
        resword.getString("CRF_spreadsheet_template"),
        respage.getString("br_download_blank_CRF_spreadsheet_from"));
    setToPanel(
        resword.getString("example_CRF_br_spreadsheets"),
        respage.getString("br_download_example_CRF_instructions_from"));

    if ("confirm".equalsIgnoreCase(action)) {
      List<DisplayItemBeanWrapper> displayItemBeanWrappers =
          (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
      logger.info("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());
      forwardPage(Page.VERIFY_IMPORT_CRF_DATA);
    }

    if ("save".equalsIgnoreCase(action)) {
      List<DisplayItemBeanWrapper> displayItemBeanWrappers =
          (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
      // System.out.println("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());

      for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {

        int eventCrfBeanId = -1;
        EventCRFBean eventCrfBean = new EventCRFBean();

        // TODO : tom , the wrapper object has all the necessary data -
        // as you see we check the
        // is to see if this data is Savable if it is then we go ahead
        // and save it. if not we discard.
        // So the change needs to happen here , instead of discarding we
        // need to file discrepancy notes
        // and save the data. If you look in the
        // Page.VERIFY_IMPORT_CRF_DATA jsp file you can see how I am
        // pulling the errors. and use that in the same way.

        logger.info("right before we check to make sure it is savable: " + wrapper.isSavable());
        if (wrapper.isSavable()) {
          ArrayList<Integer> eventCrfInts = new ArrayList<Integer>();
          // based on the use case: "If any of the data does not meet
          // validations specified in the CRF
          // Template, a discrepancy note is automatically logged.
          // The DN will have a type of Failed Validation Check, and
          // a message of Failed Validation check."
          // System.out.println("wrapper problems found : " +
          // wrapper.getValidationErrors().toString());
          for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
            eventCrfBeanId = displayItemBean.getData().getEventCRFId();
            eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
            logger.info("found value here: " + displayItemBean.getData().getValue());
            logger.info("found status here: " + eventCrfBean.getStatus().getName());
            // System.out.println("found event crf bean name here: "
            // +
            // eventCrfBean.getEventName()+" id "+eventCrfBean.getId
            // ());
            // SO, items can be created in a wrapper which is set to
            // overwrite
            // we get around this by checking the bean first, to
            // make sure it's not null
            ItemDataBean itemDataBean = new ItemDataBean();
            itemDataBean =
                itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(
                    displayItemBean.getItem().getId(),
                    eventCrfBean.getId(),
                    displayItemBean.getData().getOrdinal());
            if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
              // ItemDataBean itemDataBean = new ItemDataBean();
              // itemDataBean =
              // itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(
              // displayItemBean.getItem().getId(),
              // eventCrfBean.getId(), displayItemBean
              // .getData().getOrdinal());
              // itemDataBean =
              // itemDataDao.findByEventCRFIdAndItemName(
              // eventCrfBean,
              // displayItemBean.getItem().getName());
              logger.info(
                  "just tried to find item data bean on item name "
                      + displayItemBean.getItem().getName());
              itemDataBean.setUpdatedDate(new Date());
              itemDataBean.setUpdater(ub);
              itemDataBean.setValue(displayItemBean.getData().getValue());
              // set status?
              itemDataDao.update(itemDataBean);
              logger.info("updated: " + itemDataBean.getItemId());
              // need to set pk here in order to create dn
              displayItemBean.getData().setId(itemDataBean.getId());
            } else {
              itemDataDao.create(displayItemBean.getData());
              logger.info(
                  "created: "
                      + displayItemBean.getData().getItemId()
                      + "event CRF ID = "
                      + eventCrfBean.getId()
                      + "CRF VERSION ID ="
                      + eventCrfBean.getCRFVersionId());

              // does this dao function work for repeating
              // events/groups?
              // ItemDataBean itemDataBean =
              // itemDataDao.findByEventCRFIdAndItemName(
              // eventCrfBean,
              // displayItemBean.getItem().getName());
              ItemDataBean itemDataBean2 =
                  itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(
                      displayItemBean.getItem().getId(),
                      eventCrfBean.getId(),
                      displayItemBean.getData().getOrdinal());
              logger.info(
                  "found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
              displayItemBean.getData().setId(itemDataBean2.getId());
            }
            // logger.info("created item data bean:
            // "+displayItemBean.getData().getId());
            // logger.info("created:
            // "+displayItemBean.getData().getName());
            // logger.info("continued:
            // "+displayItemBean.getData().getItemId());
            ItemDAO idao = new ItemDAO(sm.getDataSource());
            ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
            // logger.info("continued2: getName " +
            // ibean.getName());
            // System.out.println("*** checking for validation errors: " + ibean.getName());
            String itemOid =
                displayItemBean.getItem().getOid()
                    + "_"
                    + wrapper.getStudyEventRepeatKey()
                    + "_"
                    + displayItemBean.getData().getOrdinal()
                    + "_"
                    + wrapper.getStudySubjectOid();
            if (wrapper.getValidationErrors().containsKey(itemOid)) {
              ArrayList messageList = (ArrayList) wrapper.getValidationErrors().get(itemOid);
              // if
              // (wrapper.getValidationErrors().containsKey(ibean
              // .getName())) {
              // ArrayList messageList = (ArrayList)
              // wrapper.getValidationErrors
              // ().get(ibean.getName());
              // could be more then one will have to iterate
              // could it be more than one? tbh 08/2008
              for (int iter = 0; iter < messageList.size(); iter++) {
                String message = (String) messageList.get(iter);
                DiscrepancyNoteBean parentDn =
                    ImportSpringJob.createDiscrepancyNote(
                        ibean,
                        message,
                        eventCrfBean,
                        displayItemBean,
                        null,
                        ub,
                        sm.getDataSource(),
                        currentStudy);
                ImportSpringJob.createDiscrepancyNote(
                    ibean,
                    message,
                    eventCrfBean,
                    displayItemBean,
                    parentDn.getId(),
                    ub,
                    sm.getDataSource(),
                    currentStudy);
                // System.out.println("*** created disc note with message: " + message);
                // displayItemBean);
              }
            }
            // logger.info("created:
            // "+displayItemBean.getDbData().getName());
            if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
              crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
              // System.out.println("*** just updated event crf bean: " + eventCrfBean.getId());
              eventCrfInts.add(new Integer(eventCrfBean.getId()));
            }
          }
          // end of item datas, tbh
          // crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
          // System .out.println("*** just updated event crf bean: "+
          // eventCrfBean.getId());
          // need to update the study event status as well, tbh
          // crfBusinessLogicHelper.updateStudyEvent(eventCrfBean,
          // ub);
          // above should do it for us, tbh 08/2008
        }
      }

      addPageMessage(respage.getString("data_has_been_successfully_import"));
      // forwardPage(Page.SUBMIT_DATA_SERVLET);
      forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
      // replaced tbh, 06/2009
    }
  }