Search in sources :

Example 26 with ItemFormMetadataBean

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.

the class ViewSelectedServlet method getAllSelected.

public static ArrayList getAllSelected(DatasetBean db, ItemDAO idao, ItemFormMetadataDAO imfdao) throws Exception {
    ArrayList items = new ArrayList();
    // ArrayList itemIds = db.getItemIds();
    ArrayList itemDefCrfs = db.getItemDefCrf();
    for (int i = 0; i < itemDefCrfs.size(); i++) {
        ItemBean item = (ItemBean) itemDefCrfs.get(i);
        item.setSelected(true);
        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());
        }
        item.setItemMetas(metas);
        items.add(item);
    }
    return items;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 27 with ItemFormMetadataBean

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.

the class BeanFactory method createDisplaySectionBean.

// Create a DisplaySectionBean using an items map, a section's title,
// the section's page number, and the CRF name/ The CRF name is needed for
// creating the ResponseSetBean.
public DisplaySectionBean createDisplaySectionBean(Map<Integer, Map<String, String>> map, String sectionTitle, String sectionLabel, String sectionSubtitle, String instructions, String crfName, int sectionBorders) {
    // Play defense!
    if (map == null)
        return new DisplaySectionBean();
    // Display a section title in the JSP
    SectionBean sbean = new SectionBean();
    sbean.setTitle(sectionTitle);
    sbean.setSubtitle(sectionSubtitle);
    sbean.setInstructions(instructions);
    sbean.setBorders(sectionBorders);
    DisplaySectionBean displaySectionBean = new DisplaySectionBean();
    displaySectionBean.setSection(sbean);
    ArrayList<DisplayItemBean> allDisplayItems = new ArrayList<DisplayItemBean>();
    List<DisplayItemBean> childrenItems = new ArrayList<DisplayItemBean>();
    DisplayItemBean displayItem;
    ItemFormMetadataBean itemMeta;
    Map.Entry<Integer, Map<String, String>> me;
    Map<String, String> innerMap;
    for (Iterator<Map.Entry<Integer, Map<String, String>>> iter = map.entrySet().iterator(); iter.hasNext(); ) {
        displayItem = new DisplayItemBean();
        // me is one row in the list of Items, indexed by the item number
        me = iter.next();
        if (itemSecLabelMatchesSection(me, sectionLabel)) {
            itemMeta = this.createItemFormMetadataBean(me, crfName);
            displayItem.setMetadata(itemMeta);
            innerMap = me.getValue();
            displayItem.setItem(this.createItemBean(innerMap));
            // Compensate for any items that identify themselves as parents
            String parentName = displayItem.getMetadata().getParentLabel();
            if (parentName.length() > 0 && !displayItem.getItem().getName().equalsIgnoreCase(parentName)) {
                displayItem.getMetadata().setParentId(1);
                childrenItems.add(displayItem);
            } else {
                allDisplayItems.add(displayItem);
            }
        }
    }
    // Set the children for each of the display items
    for (DisplayItemBean parentBean : allDisplayItems) {
        parentBean.setChildren(this.createChildren(childrenItems, parentBean));
    }
    // Sort the List of DisplayItemBeans based on their ordinal; see
    // getDisplayBean() in DataEntryServlet
    Collections.sort(allDisplayItems);
    displaySectionBean.setItems(allDisplayItems);
    return displaySectionBean;
}
Also used : ArrayList(java.util.ArrayList) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) Entry(java.util.Map.Entry) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) HashMap(java.util.HashMap) Map(java.util.Map) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 28 with ItemFormMetadataBean

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.

the class BeanFactory method createMetadataBean.

/**
     * Create an ItemFormMetadataBean from the values referred to by a Map
     * object. The Map contains the Item values from the Sreadsheet template, as
     * in (item_name: Item1, etc...}
     * 
     * @param map
     *            A Map involving the column names and values Of items.
     * @param ordinal
     *            The ordinal property for the meta data bean.
     * @param crfName
     *            The CRF name.
     * @return An ItemFormMetadataBean representing the values from the Map.
     */
public ItemFormMetadataBean createMetadataBean(Map<String, String> map, int ordinal, String crfName) {
    if (map == null)
        return new ItemFormMetadataBean();
    ItemFormMetadataBean metadataBean = new ItemFormMetadataBean();
    // the POI library returns all numbers as doubles (2.0), we round
    // off the numbers to 2, for instance
    NumberFormat numFormatter = NumberFormat.getInstance();
    numFormatter.setMaximumFractionDigits(0);
    String itemPageNum;
    String columnNum;
    String questNum;
    metadataBean.setOrdinal(ordinal);
    metadataBean.setResponseLayout(map.get("response_layout"));
    metadataBean.setParentLabel(map.get("parent_item"));
    metadataBean.setLeftItemText(map.get("left_item_text"));
    metadataBean.setRightItemText(map.get("right_item_text"));
    metadataBean.setDefaultValue(map.get("default_value"));
    metadataBean.setHeader(map.get("header"));
    metadataBean.setSubHeader(map.get("subheader"));
    itemPageNum = map.get("page_number");
    try {
        itemPageNum = numFormatter.format(Double.parseDouble(itemPageNum));
    } catch (NumberFormatException nfe) {
        itemPageNum = "";
    }
    metadataBean.setPageNumberLabel(itemPageNum);
    columnNum = map.get("column_number");
    try {
        columnNum = numFormatter.format(Double.parseDouble(columnNum));
        metadataBean.setColumnNumber(Integer.parseInt(columnNum));
    } catch (NumberFormatException nfe) {
        metadataBean.setColumnNumber(0);
    }
    questNum = map.get("question_number");
    try {
        questNum = numFormatter.format(Double.parseDouble(questNum));
    } catch (NumberFormatException nfe) {
        questNum = "";
    }
    metadataBean.setQuestionNumberLabel(questNum);
    String requStr = map.get("required");
    requStr = requStr.equalsIgnoreCase("") ? "0" : requStr;
    double required;
    try {
        required = Double.parseDouble(requStr);
    } catch (NumberFormatException nfe) {
        required = 0;
    }
    if (required > 0) {
        metadataBean.setRequired(true);
    }
    ResponseSetBean respBean = this.createResponseSetBean(map, crfName);
    metadataBean.setResponseSet(respBean);
    return metadataBean;
}
Also used : ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Example 29 with ItemFormMetadataBean

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.

the class ExtractBean method getMetadata.

/**
     * Implements the Column algorithm in "Dataset Export Algorithms" Must be
     * called after DatasetDAO.getDatasetData();
     */
public void getMetadata() {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
    CRFDAO cdao = new CRFDAO(ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(ds);
    ItemDAO idao = new ItemDAO(ds);
    ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
    StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
    StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
    // SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
    studyGroupClasses = new ArrayList();
    studyGroupMap = new HashMap();
    studyGroupMaps = new HashMap<Integer, ArrayList>();
    sedCrfColumns = new HashMap();
    displayed = new HashMap();
    sedCrfItemFormMetadataBeans = new HashMap();
    studyEvents = seddao.findAllByStudy(study);
    ArrayList finalStudyEvents = new ArrayList();
    if (dataset.isShowSubjectGroupInformation()) {
        // logger.info("found study id for maps: "+study.getId());
        studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
        // below is for a given subject; we need a data structure for
        // all subjects
        // studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
        // problem: can't use currentSubject here, since it's not 'set up'
        // properly
        // how to get the current subject?
        logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
        // studyGroupClasses = dataset.getSubjectGroupIds();
        for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
            Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
            StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
            // logger.info();
            // hmm how to link groups to subjects though? only through
            // subject group map
            logger.info("found a studygroupclass bean: " + sgclass.getName());
            studyGroupClasses.add(sgclass);
        }
    }
    for (int i = 0; i < studyEvents.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
        if (!selectedSED(sed)) {
            continue;
        }
        ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
        ArrayList CRFsDisplayedInThisSED = new ArrayList();
        for (int j = 0; j < CRFs.size(); j++) {
            CRFBean cb = (CRFBean) CRFs.get(j);
            if (!selectedSEDCRF(sed, cb)) {
                continue;
            } else {
                CRFsDisplayedInThisSED.add(cb);
                ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
                for (int k = 0; k < CRFVersions.size(); k++) {
                    CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
                    ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
                    // sort by ordinal/name
                    Collections.sort(Items);
                    for (int l = 0; l < Items.size(); l++) {
                        ItemBean ib = (ItemBean) Items.get(l);
                        if (selected(ib) && !getDisplayed(sed, cb, ib)) {
                            // logger.info("found at
                            // itemformmetadatadao: "+ib.getId()+",
                            // "+cvb.getId());
                            ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
                            addColumn(sed, cb, ib);
                            addItemFormMetadataBeans(sed, cb, ifmb);
                            markDisplayed(sed, cb, ib);
                        }
                    }
                }
            }
        // else
        }
        // for
        sed.setCrfs(CRFsDisplayedInThisSED);
        // make the setCrfs call "stick"
        finalStudyEvents.add(sed);
    }
    this.studyEvents = finalStudyEvents;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 30 with ItemFormMetadataBean

use of org.akaza.openclinica.bean.submit.ItemFormMetadataBean in project OpenClinica by OpenClinica.

the class DataEntryServlet method getParentDisplayItems.

/**
     * For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId
     * == 0.
     * @param sb
     *            The section whose items we are retrieving.
     * @param hasUngroupedItems
     * @param request TODO
     *
     * @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
     * @throws Exception
     */
private ArrayList getParentDisplayItems(boolean hasGroup, SectionBean sb, EventDefinitionCRFBean edcb, ItemDAO idao, ItemFormMetadataDAO ifmdao, ItemDataDAO iddao, boolean hasUngroupedItems, HttpServletRequest request) throws Exception {
    ArrayList answer = new ArrayList();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    HashMap displayItems = new HashMap();
    // ArrayList items = idao.findAllParentsBySectionId(sb.getId());
    ArrayList items = new ArrayList();
    ArrayList itemsUngrped = new ArrayList();
    if (hasGroup) {
        // See: FormBeanUtil.sectionHasUngroupedItems.
        if (hasUngroupedItems) {
            // @pgawade 05-Aug-2011 fix for issue 10628 - commented out the
            // if-else logic based on 'hasGroup' flag.
            // 'if' part is unchanged but else part is changed to be
            // executed always because that is to get the non-repeating and
            // ungrouped item details and was getting skipped in case the
            // section has repeating group items plus non-repeating group
            // items
            itemsUngrped = idao.findAllUngroupedParentsBySectionId(sb.getId(), sb.getCRFVersionId());
        }
    // however, if we have true:true, we exclude all grouped items
    // items.addAll(
    // idao.findAllGroupedParentsBySectionId(
    // sb.getId(), sb.getCRFVersionId()));
    }
    // else {
    LOGGER.trace("no item groups");
    // items = idao.findAllParentsBySectionId(sb.getId());
    items = idao.findAllNonRepeatingParentsBySectionId(sb.getId());
    items.addAll(itemsUngrped);
    // }
    LOGGER.debug("items size" + items.size());
    for (int i = 0; i < items.size(); i++) {
        DisplayItemBean dib = new DisplayItemBean();
        dib.setEventDefinitionCRF(edcb);
        ItemBean ib = (ItemBean) items.get(i);
        dib.setItem(ib);
        displayItems.put(new Integer(dib.getItem().getId()), dib);
    }
    ArrayList data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(idb.getItemId()));
        if (dib != null) {
            dib.setData(idb);
            dib.setDbData((ItemDataBean) BeanUtils.cloneBean(idb));
            displayItems.put(new Integer(idb.getItemId()), dib);
        }
    }
    ArrayList metadata = ifmdao.findAllBySectionId(sb.getId());
    for (int i = 0; i < metadata.size(); i++) {
        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metadata.get(i);
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(ifmb.getItemId()));
        if (dib != null) {
            // boolean showItem = false;
            boolean needsHighlighting = !ifmb.isShowItem();
            logMe("Entering thread before getting ItemMetadataService:::" + Thread.currentThread());
            boolean showItem = getItemMetadataService().isShown(ifmb.getItemId(), ecb, dib.getData());
            if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
                showItem = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
            }
            // is the above needed for children items too?
            boolean passedDDE = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
            if (showItem) {
                // we are only showing, not hiding
                LOGGER.debug("set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE);
                // ifmb.setShowItem(showItem);
                ifmb.setShowItem(true);
            } else {
                LOGGER.debug("DID NOT set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE + " value " + dib.getData().getValue());
            }
            dib.setMetadata(ifmb);
            displayItems.put(new Integer(ifmb.getItemId()), dib);
        }
    }
    Iterator hmIt = displayItems.keySet().iterator();
    while (hmIt.hasNext()) {
        Integer key = (Integer) hmIt.next();
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(key);
        answer.add(dib);
        LOGGER.debug("*** getting with key: " + key + " display item bean with value: " + dib.getData().getValue());
    }
    LOGGER.debug("*** test of the display items: " + displayItems.toString());
    return answer;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) Iterator(java.util.Iterator) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Aggregations

ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)93 ArrayList (java.util.ArrayList)57 HashMap (java.util.HashMap)36 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)36 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)29 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)25 DynamicsItemFormMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean)25 Iterator (java.util.Iterator)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)18 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)14 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)14 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)13 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)12 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)10 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)9 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9