public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int itemId = fp.getInt(ITEM_ID);
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());

    if (itemId == 0) {
      addPageMessage("Please choose an item first.");
      forwardPage(Page.ITEM_DETAIL);
      return;
    }
    ItemBean item = (ItemBean) idao.findByPK(itemId);
    ArrayList versions = idao.findAllVersionsByItemId(item.getId());
    ArrayList versionItems = new ArrayList();
    // finds each item metadata for each version
    for (int i = 0; i < versions.size(); i++) {
      Integer versionId = (Integer) versions.get(i);
      CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId.intValue());
      if (versionId != null && versionId.intValue() > 0) {
        ItemFormMetadataBean imfBean =
            ifmdao.findByItemIdAndCRFVersionId(item.getId(), versionId.intValue());
        imfBean.setCrfVersionName(version.getName());
        CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
        imfBean.setCrfName(crf.getName());
        versionItems.add(imfBean);
      }
    }
    request.setAttribute(VERSION_ITEMS, versionItems);
    request.setAttribute(ITEM_BEAN, item);
    forwardPage(Page.ITEM_DETAIL);
  }
  /**
   * Performs calculation. <br>
   * Notice: both parameter 'itemdata' and parameter 'errs' might be updated in this method.
   *
   * @param displayItems
   * @param items
   * @param itemdata
   * @param errs
   * @return
   * @author ywang (Jan. 2008)
   */
  public String doCalculation(
      DisplayItemBean displayItem,
      HashMap<String, ItemBean> items,
      HashMap<String, String> itemdata,
      HashMap<Integer, TreeSet<Integer>> itemOrdinals,
      StringBuffer errs,
      int ordinal) {
    if (itemdata == null) {
      logger.error("In DataEntryServlet doCalculation(), itemdata map is empty!");
      errs.append("Calculation cannot be started because needed items are empty" + "; ");
      return "";
    }
    String value = "";
    NumberFormat nf = NumberFormat.getInstance();
    Parser parser = new Parser(items, itemdata);

    ItemBean ib = displayItem.getItem();
    ItemFormMetadataBean ifm = displayItem.getMetadata();
    ResponseOptionBean rob = (ResponseOptionBean) ifm.getResponseSet().getOptions().get(0);
    ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
    int type = ifm.getResponseSet().getResponseTypeId();
    if (type == 8) {
      parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), ordinal);
    } else if (type == 9) {
      // YW, 1-16-2008, for group-calculation type. Current restrictions:
      // 1. only calculate sum(), avg(), min(), max(), median(), stdev()
      // 2. formula arguments only contain item beans
      // 3. only one item bean per argument
      parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), itemOrdinals);
    }
    if (parser.getErrors().length() > 0) {
      errs.append(parser.getErrors());
    } else {
      try {
        value = ScoreUtil.eval(parsedExp);
      } catch (ScoreException se) {
        logger.error(se.getMessage());
      }
      ItemDataType idt = ib.getDataType();
      if (value == null || value.length() == 0) {
        value = "";
        String exp = rob.getValue();
        exp = exp.replace("##", ",");
        errs.append("Result is empty in" + " " + exp + "; ");
        // errors.append(resexception.getString("result_is_empty_in") +
        // " " + exp + "; ");
      } else {
        value = this.getMathContextValue(value, ifm, idt, errs);
      }
      // idb.setStatus(Status.UNAVAILABLE);
      itemdata.put(ib.getId() + "_" + ordinal, value);
    }

    return value;
  }
Exemple #3
0
  private String getOid(ItemBean itemBean, String crfName, String itemLabel) {

    String oid;
    try {
      oid =
          itemBean.getOid() != null
              ? itemBean.getOid()
              : itemBean.getOidGenerator().generateOid(crfName, itemLabel);
      return oid;
    } catch (Exception e) {
      throw new RuntimeException("CANNOT GENERATE OID");
    }
  }
Exemple #4
0
 public EntityBean update(EntityBean eb) {
   ItemBean ib = (ItemBean) eb;
   HashMap variables = new HashMap();
   variables.put(new Integer(1), ib.getName());
   variables.put(new Integer(2), ib.getDescription());
   variables.put(new Integer(3), ib.getUnits());
   variables.put(new Integer(4), new Boolean(ib.isPhiStatus()));
   variables.put(new Integer(5), new Integer(ib.getItemDataTypeId()));
   variables.put(new Integer(6), new Integer(ib.getItemReferenceTypeId()));
   variables.put(new Integer(7), new Integer(ib.getStatus().getId()));
   variables.put(new Integer(8), new Integer(ib.getUpdaterId()));
   variables.put(new Integer(9), new Integer(ib.getId()));
   this.execute(digester.getQuery("update"), variables);
   return eb;
 }
  public static DiscrepancyNoteBean createDiscrepancyNote(
      ItemBean itemBean,
      String message,
      EventCRFBean eventCrfBean,
      DisplayItemBean displayItemBean,
      Integer parentId,
      UserAccountBean uab,
      DataSource ds,
      StudyBean study) {
    // DisplayItemBean displayItemBean) {
    DiscrepancyNoteBean note = new DiscrepancyNoteBean();
    StudySubjectDAO ssdao = new StudySubjectDAO(ds);
    note.setDescription(message);
    note.setDetailedNotes("Failed Validation Check");
    note.setOwner(uab);
    note.setCreatedDate(new Date());
    note.setResolutionStatusId(ResolutionStatus.OPEN.getId());
    note.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
    if (parentId != null) {
      note.setParentDnId(parentId);
    }

    note.setField(itemBean.getName());
    note.setStudyId(study.getId());
    note.setEntityName(itemBean.getName());
    note.setEntityType("ItemData");
    note.setEntityValue(displayItemBean.getData().getValue());

    note.setEventName(eventCrfBean.getName());
    note.setEventStart(eventCrfBean.getCreatedDate());
    note.setCrfName(displayItemBean.getEventDefinitionCRF().getCrfName());

    StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
    note.setSubjectName(ss.getName());

    note.setEntityId(displayItemBean.getData().getId());
    note.setColumn("value");

    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(ds);
    note = (DiscrepancyNoteBean) dndao.create(note);
    // so that the below method works, need to set the entity above
    // System.out.println("trying to create mapping with " + note.getId() + " " + note.getEntityId()
    // + " " + note.getColumn() + " " + note.getEntityType());
    dndao.createMapping(note);
    // System.out.println("just created mapping");
    return note;
  }
Exemple #6
0
  public ArrayList<ItemBean> findAllWithItemDataByCRFVersionId(int crfVersionId, int eventCRFId) {
    this.unsetTypeExpected();

    this.setTypeExpected(1, TypeNames.STRING); // (item)name
    this.setTypeExpected(2, TypeNames.INT); // ordinal
    this.setTypeExpected(3, TypeNames.STRING); // oc_oid
    this.setTypeExpected(4, TypeNames.INT); // item_data_id
    this.setTypeExpected(5, TypeNames.INT); // item_id
    this.setTypeExpected(6, TypeNames.STRING); // (item)value

    ArrayList<ItemBean> answer = new ArrayList<ItemBean>();

    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(crfVersionId));
    variables.put(new Integer(2), new Integer(eventCRFId));

    String sql = digester.getQuery("findAllWithItemDataByCRFVersionId");

    ArrayList rows = super.select(sql, variables);
    Iterator it = rows.iterator();
    int cur_item_id = 0;
    ItemBean item_bean = null;
    ItemDataBean item_data_bean = null;
    while (it.hasNext()) {
      HashMap row = (HashMap) it.next();
      Integer id = (Integer) row.get("item_id");
      if (cur_item_id != id.intValue()) {
        item_bean = new ItemBean();
        answer.add(item_bean);
        cur_item_id = id.intValue();
        item_bean.setId(cur_item_id);
        item_bean.setName((String) row.get("name"));
        item_bean.setOid((String) row.get("oc_oid"));
      }
      item_data_bean = new ItemDataBean();
      item_data_bean.setValue((String) row.get("value"));
      item_data_bean.setOrdinal(((Integer) row.get("ordinal")).intValue());
      item_data_bean.setId(((Integer) row.get("item_data_id")).intValue());
      item_data_bean.setItemId(cur_item_id);
      item_bean.addItemDataElement(item_data_bean);
    }

    return answer;
  }
  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();
  }
Exemple #8
0
  public String getValidOid(
      ItemBean itemBean, String crfName, String itemLabel, ArrayList<String> oidList) {

    String oid = getOid(itemBean, crfName, itemLabel);
    logger.debug(oid);
    String oidPreRandomization = oid;
    while (findByOid(oid).size() > 0 || oidList.contains(oid)) {
      oid = itemBean.getOidGenerator().randomizeOid(oidPreRandomization);
    }
    return oid;
  }
Exemple #9
0
 public EntityBean create(EntityBean eb) {
   ItemBean ib = (ItemBean) eb;
   // per the create sql statement
   HashMap variables = new HashMap();
   variables.put(new Integer(1), ib.getName());
   variables.put(new Integer(2), ib.getDescription());
   variables.put(new Integer(3), ib.getUnits());
   variables.put(new Integer(4), new Boolean(ib.isPhiStatus()));
   variables.put(new Integer(5), new Integer(ib.getItemDataTypeId()));
   variables.put(new Integer(6), new Integer(ib.getItemReferenceTypeId()));
   variables.put(new Integer(7), new Integer(ib.getStatus().getId()));
   variables.put(new Integer(8), new Integer(ib.getOwnerId()));
   // date_created=now() in Postgres
   this.execute(digester.getQuery("create"), variables);
   // set the id here????
   return eb;
 }
Exemple #10
0
 public ArrayList findAllActiveByCRF(CRFBean crf) {
   HashMap variables = new HashMap();
   this.setTypesExpected();
   this.setTypeExpected(14, TypeNames.INT); // crf_version_id
   this.setTypeExpected(15, TypeNames.STRING); // version name
   variables.put(new Integer(1), new Integer(crf.getId()));
   String sql = digester.getQuery("findAllActiveByCRF");
   ArrayList alist = this.select(sql, variables);
   ArrayList al = new ArrayList();
   Iterator it = alist.iterator();
   while (it.hasNext()) {
     HashMap hm = (HashMap) it.next();
     ItemBean eb = (ItemBean) this.getEntityFromHashMap(hm);
     Integer versionId = (Integer) hm.get("crf_version_id");
     String versionName = (String) hm.get("cvname");
     ItemFormMetadataBean imf = new ItemFormMetadataBean();
     imf.setCrfVersionName(versionName);
     // logger.info("versionName" + imf.getCrfVersionName());
     imf.setCrfVersionId(versionId.intValue());
     eb.setItemMeta(imf);
     al.add(eb);
   }
   return al;
 }
  /**
   * createSPSSFile, added by tbh, 01/2009
   *
   * @param db
   * @param eb
   * @param currentstudyid
   * @param parentstudy
   * @return
   */
  public HashMap<String, Integer> createSPSSFile(
      DatasetBean db,
      ExtractBean eb2,
      StudyBean currentStudy,
      StudyBean parentStudy,
      long sysTimeBegin,
      String generalFileDir,
      SPSSReportBean answer,
      String generalFileDirCopy) {
    setUpResourceBundles();

    String SPSSFileName = db.getName() + "_data_spss.dat";
    String DDLFileName = db.getName() + "_ddl_spss.sps";
    String ZIPFileName = db.getName() + "_spss";

    SPSSVariableNameValidationBean svnvbean = new SPSSVariableNameValidationBean();
    answer.setDatFileName(SPSSFileName);
    // DatasetDAO dsdao = new DatasetDAO(ds);

    // create the extract bean here, tbh
    // ExtractBean eb = this.generateExtractBean(db, currentStudy,
    // parentStudy);

    // eb = dsdao.getDatasetData(eb, currentStudy.getId(),
    // parentStudy.getId());

    // eb.getMetadata();

    // eb.computeReport(answer);

    answer.setItems(eb2.getItemNames()); // set up items here to get
    // itemMetadata

    // set up response sets for each item here
    ItemDAO itemdao = new ItemDAO(ds);
    ItemFormMetadataDAO imfdao = new ItemFormMetadataDAO(ds);
    ArrayList items = answer.getItems();
    for (int i = 0; i < items.size(); i++) {
      DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
      ItemBean item = dih.getItem();
      ArrayList metas = imfdao.findAllByItemId(item.getId());
      // for (int h = 0; h < metas.size(); h++) {
      // ItemFormMetadataBean ifmb = (ItemFormMetadataBean)
      // metas.get(h);
      // logger.info("group name found:
      // "+ifmb.getGroupLabel());
      // }
      // logger.info("crf versionname" +
      // meta.getCrfVersionName());
      item.setItemMetas(metas);
    }

    HashMap eventDescs = new HashMap<String, String>();

    eventDescs = eb2.getEventDescriptions();

    eventDescs.put("SubjID", resword.getString("study_subject_ID"));
    eventDescs.put("ProtocolID", resword.getString("protocol_ID_site_ID"));
    eventDescs.put("DOB", resword.getString("date_of_birth"));
    eventDescs.put("YOB", resword.getString("year_of_birth"));
    eventDescs.put("Gender", resword.getString("gender"));
    answer.setDescriptions(eventDescs);

    ArrayList generatedReports = new ArrayList<String>();
    try {
      // YW <<
      generatedReports.add(answer.getMetadataFile(svnvbean, eb2).toString());
      generatedReports.add(answer.getDataFile().toString());
      // YW >>
    } catch (IndexOutOfBoundsException i) {
      generatedReports.add(answer.getMetadataFile(svnvbean, eb2).toString());
      logger.debug("throw the error here");
    }

    long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;

    ArrayList titles = new ArrayList();
    // YW <<
    titles.add(DDLFileName);
    titles.add(SPSSFileName);
    // YW >>

    // create new createFile method that accepts array lists to
    // put into zip files
    int fId =
        this.createFile(
            ZIPFileName,
            titles,
            generalFileDir,
            generatedReports,
            db,
            sysTimeEnd,
            ExportFormatBean.TXTFILE,
            true);
    if (!"".equals(generalFileDirCopy)) {
      int fId2 =
          this.createFile(
              ZIPFileName,
              titles,
              generalFileDirCopy,
              generatedReports,
              db,
              sysTimeEnd,
              ExportFormatBean.TXTFILE,
              false);
    }
    // return DDLFileName;
    HashMap answerMap = new HashMap<String, Integer>();
    answerMap.put(DDLFileName, new Integer(fId));
    return answerMap;
  }
  /**
   * Re-do calculations if funcs include changed item(s) and funcs are not included in the current
   * section. If calculation can not sucessfully redo, old value will be erased and "<erased>" will
   * be saved in database. <br>
   * The parameter 'itemdata' might be overwritten.
   *
   * @param itemGroupSizes
   * @param items
   * @param itemdata
   * @param oldItemdata
   * @param updatedData
   * @param sectionId
   * @return ArrayList<String> which records left_item_text of items who failed to be updated into
   *     database.
   */
  public ArrayList<String> redoCalculations(
      HashMap<String, ItemBean> items,
      HashMap<String, String> itemdata,
      TreeSet<String> changedItems,
      HashMap<Integer, TreeSet<Integer>> itemOrdinals,
      int sectionId) {
    ArrayList<String> updateFailedItems = new ArrayList<String>();
    if (itemdata == null) {
      logger.error("In ScoreCalculator redoCalculations(), itemdata is empty!");
      errors.add("In ScoreCalculator redoCalculations(), 'itemdata' map is empty!");
      return updateFailedItems;
    }
    if (changedItems == null) {
      logger.error("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
      errors.add("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
      return updateFailedItems;
    }
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());

    NumberFormat nf = NumberFormat.getInstance();
    Parser parser = new Parser(items, itemdata);
    try {
      // for calculation type
      List<ItemFormMetadataBean> derivedItemList =
          ifmdao.findAllByCRFVersionIdAndResponseTypeId(
              ecb.getCRFVersionId(), ResponseType.CALCULATION.getId());
      if (derivedItemList.size() > 0) {
        Collections.sort(derivedItemList);
        for (ItemFormMetadataBean ifmb : derivedItemList) {
          if (ifmb.getSectionId() != sectionId) {
            ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
            ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
            int groupsize = 1;
            if (itemOrdinals.containsKey(ib.getId())) {
              groupsize = itemOrdinals.get(ib.getId()).size();
            }
            String value = "";
            ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
            for (int i = 0; i < groupsize; ++i) {
              ItemDataBean idb =
                  iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), i + 1);
              // is there any changed item
              Parser p = new Parser(items, itemdata);
              parsedExp = parser.parseScoreTokens(rob.getValue());
              if (p.isChanged(changedItems, parsedExp)) {
                StringBuffer err = new StringBuffer();
                parsedExp = parser.assignVariables(parsedExp, i + 1);
                // if parser has error and has been calculated
                // before, set "<erased>"
                if (parser.getErrors().length() > 0) {
                  err.append(parser.getErrors());
                  if (idb.isActive()) {
                    idb.setValue("<erased>");
                    idb.setStatus(Status.UNAVAILABLE);
                    idb = (ItemDataBean) iddao.update(idb);
                    if (!idb.isActive()) {
                      String key =
                          i + 1 > 1
                              ? ifmb.getLeftItemText() + "_" + (i + 1)
                              : ifmb.getLeftItemText();
                      updateFailedItems.add(key);
                    }
                  }
                  parser.setErrors(new StringBuffer());
                }
                // otherwise do calculation
                else {
                  try {
                    value = ScoreUtil.eval(parsedExp);
                  } catch (ScoreException se) {
                    logger.error(se.getMessage());
                  }
                  String exp = rob.getValue();
                  exp = exp.replace("##", ",");
                  if (writeToDB(ib, ifmb, idb, exp, value, err)) {
                    changedItems.add(ib.getName());
                    itemdata.put(ib.getId() + "_" + (i + 1), idb.getValue());
                  } else {
                    String key =
                        i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
                    updateFailedItems.add(key);
                  }
                }
                if (err.length() > 0) {
                  String key =
                      i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
                  errors.add("Item " + key + " contains calculation errors: " + err.toString());
                }
              }
            }
          }
        }
      }

      List<ItemFormMetadataBean> itemList =
          ifmdao.findAllByCRFVersionIdAndResponseTypeId(
              ecb.getCRFVersionId(), ResponseType.GROUP_CALCULATION.getId());
      if (itemList.size() > 0) {
        Collections.sort(itemList);
        for (ItemFormMetadataBean ifmb : itemList) {
          if (ifmb.getSectionId() != sectionId) {
            ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
            ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
            String value = "";
            Parser p = new Parser(items, itemdata);
            ArrayList<ScoreToken> parsedExp = parser.parseScoreTokens(rob.getValue());
            if (p.isChanged(changedItems, parsedExp)) {
              StringBuffer err = new StringBuffer();
              parser.setErrors(err);
              parsedExp = parser.assignVariables(parsedExp, itemOrdinals);
              ItemDataBean idb =
                  iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), 1);
              if (parser.getErrors().length() > 0) {
                err.append(parser.getErrors());
                if (idb.isActive()) {
                  idb.setValue("<erased>");
                  idb.setStatus(Status.UNAVAILABLE);
                  idb = (ItemDataBean) iddao.update(idb);
                  if (!idb.isActive()) {
                    updateFailedItems.add(ifmb.getLeftItemText());
                  }
                }
              } else {
                try {
                  value = ScoreUtil.eval(parsedExp);
                } catch (ScoreException se) {
                  logger.error(se.getMessage());
                }
                String exp = rob.getValue();
                exp = exp.replace("##", ",");
                if (writeToDB(ib, ifmb, idb, exp, value, err)) {
                  changedItems.add(ib.getName());
                  itemdata.put(ib.getId() + "_" + idb.getOrdinal(), idb.getValue());
                } else {
                  updateFailedItems.add(ifmb.getLeftItemText());
                }
              }
              if (err.length() > 0) {
                errors.add(
                    "Item "
                        + ifmb.getLeftItemText()
                        + " contains calculation errors: "
                        + err.toString());
              }
            }
          }
        }
      }
    } catch (OpenClinicaException e) {
      logger.error(e.getMessage());
    }

    return updateFailedItems;
  }
Exemple #13
0
  public Object getEntityFromHashMap(HashMap hm) {
    ItemBean eb = new ItemBean();
    // below inserted to find out a class cast exception, tbh
    Date dateCreated = (Date) hm.get("date_created");
    Date dateUpdated = (Date) hm.get("date_updated");
    Integer statusId = (Integer) hm.get("status_id");
    Integer ownerId = (Integer) hm.get("owner_id");
    Integer updateId = (Integer) hm.get("update_id");

    eb.setCreatedDate(dateCreated);
    eb.setUpdatedDate(dateUpdated);
    eb.setStatus(Status.get(statusId.intValue()));
    eb.setOwnerId(ownerId.intValue());
    eb.setUpdaterId(updateId.intValue());
    // something to trip over
    // something else to trip over
    // eb = (ItemBean)this.getEntityAuditInformation(hm);
    eb.setName((String) hm.get("name"));
    eb.setId(((Integer) hm.get("item_id")).intValue());
    eb.setDescription((String) hm.get("description"));
    eb.setUnits((String) hm.get("units"));
    eb.setPhiStatus(((Boolean) hm.get("phi_status")).booleanValue());
    eb.setItemDataTypeId(((Integer) hm.get("item_data_type_id")).intValue());
    eb.setItemReferenceTypeId(((Integer) hm.get("item_reference_type_id")).intValue());
    // logger.info("item name|date type id" + eb.getName() + "|" +
    // eb.getItemDataTypeId());
    eb.setDataType(ItemDataType.get(eb.getItemDataTypeId()));
    eb.setOid((String) hm.get("oc_oid"));
    // the rest should be all set
    return eb;
  }
  /**
   * Organize objects in a certain way so that we can show to Users on UI. step1 : Get StudyEvent ,
   * eventCrf , crfVersion from studyEventId.
   *
   * @param crfViewSpecificOrderedObjects
   * @param ruleSet
   * @param rule
   * @return
   */
  private HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>
      populateForCrfBasedRulesView(
          HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>>
              crfViewSpecificOrderedObjects,
          RuleSetBean ruleSet,
          RuleBean rule,
          String result,
          StudyBean currentStudy,
          List<RuleActionBean> actions) {

    // step1
    StudyEventBean studyEvent =
        (StudyEventBean)
            getStudyEventDao()
                .findByPK(
                    Integer.valueOf(
                        getExpressionService()
                            .getStudyEventDefenitionOrdninalCurated(
                                ruleSet.getTarget().getValue())));
    EventCRFBean eventCrf =
        (EventCRFBean)
            getEventCrfDao()
                .findAllByStudyEventAndCrfOrCrfVersionOid(
                    studyEvent, getExpressionService().getCrfOid(ruleSet.getTarget().getValue()))
                .get(0);
    CRFVersionBean crfVersion =
        (CRFVersionBean) getCrfVersionDao().findByPK(eventCrf.getCRFVersionId());

    RuleBulkExecuteContainer key =
        new RuleBulkExecuteContainer(crfVersion.getName(), rule, result, actions);
    String key2String =
        getExpressionService()
            .getCustomExpressionUsedToCreateView(
                ruleSet.getTarget().getValue(), studyEvent.getSampleOrdinal());
    String studyEventDefinitionName =
        getExpressionService()
            .getStudyEventDefinitionFromExpression(ruleSet.getTarget().getValue(), currentStudy)
            .getName();
    studyEventDefinitionName += " [" + studyEvent.getSampleOrdinal() + "]";
    // String itemGroupName =
    // getExpressionService().getItemGroupNameAndOrdinal(ruleSet.getTarget().getValue());
    // String itemName =
    // getExpressionService().getItemGroupExpression(ruleSet.getTarget().getValue()).getName();

    String itemGroupName =
        getExpressionService().getItemGroupNameAndOrdinal(ruleSet.getTarget().getValue());
    ItemGroupBean itemGroupBean =
        getExpressionService().getItemGroupExpression(ruleSet.getTarget().getValue());
    ItemBean itemBean =
        getExpressionService().getItemExpression(ruleSet.getTarget().getValue(), itemGroupBean);
    String itemName = itemBean.getName();

    RuleBulkExecuteContainerTwo key2 =
        new RuleBulkExecuteContainerTwo(
            key2String, studyEvent, studyEventDefinitionName, itemGroupName, itemName);
    StudySubjectBean studySubject =
        (StudySubjectBean) getStudySubjectDao().findByPK(studyEvent.getStudySubjectId());

    if (crfViewSpecificOrderedObjects.containsKey(key)) {
      HashMap<RuleBulkExecuteContainerTwo, Set<String>> k = crfViewSpecificOrderedObjects.get(key);
      if (k.containsKey(key2)) {
        k.get(key2).add(String.valueOf(studySubject.getLabel()));
      } else {
        HashSet<String> values = new HashSet<String>();
        values.add(String.valueOf(studySubject.getLabel()));
        k.put(key2, values);
      }
    } else {
      HashMap<RuleBulkExecuteContainerTwo, Set<String>> k =
          new HashMap<RuleBulkExecuteContainerTwo, Set<String>>();
      HashSet<String> values = new HashSet<String>();
      values.add(String.valueOf(studySubject.getLabel()));
      k.put(key2, values);
      crfViewSpecificOrderedObjects.put(key, k);
    }
    return crfViewSpecificOrderedObjects;
  }