Search in sources :

Example 41 with ItemFormMetadataBean

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

the class FormBeanUtil method getDisplayBeansFromItems.

public static List<DisplayItemBean> getDisplayBeansFromItems(List<ItemBean> itemBeans, DataSource dataSource, EventCRFBean eventCrfBean, int sectionId, EventDefinitionCRFBean edcb, int test, ServletContext context) {
    //int test is for method overloading. 
    List<DisplayItemBean> disBeans = new ArrayList<DisplayItemBean>();
    if (itemBeans == null || itemBeans.isEmpty())
        return disBeans;
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
    DisplayItemBean displayBean;
    ItemFormMetadataBean meta;
    for (ItemBean iBean : itemBeans) {
        displayBean = new DisplayItemBean();
        displayBean.setEventDefinitionCRF(edcb);
        meta = metaDao.findByItemIdAndCRFVersionId(iBean.getId(), eventCrfBean.getCRFVersionId());
        ItemDataBean itemDataBean = itemDataDao.findByItemIdAndEventCRFId(iBean.getId(), eventCrfBean.getId());
        if (meta.getSectionId() == sectionId) {
            displayBean.setItem(iBean);
            displayBean.setMetadata(runDynamicsCheck(meta, eventCrfBean, itemDataBean, context));
            displayBean.setData(itemDataBean);
            // << tbh 05/2010
            disBeans.add(displayBean);
        }
    }
    Collections.sort(disBeans);
    return disBeans;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 42 with ItemFormMetadataBean

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

the class FormBeanUtil method createDisplaySectionBWithFormGroups.

/**
     * Create a DisplaySectionBean with a list of ItemGroupBeans. This List will
     * include any ItemGroupBeans that are associated with ungrouped items; in
     * other words, the DisplaySectionBean will represent a section that has
     * both ungrouped and grouped tables.
     * 
     * @param sectionId
     *            The Section ID associated with the Items, which end up
     *            providing the content of the tables.
     * @param crfVersionId
     *            The CRF version ID associated with the Items.
     * @param dataSource
     * @param eventCRFDefId
     *            The id for the Event CRF Definition.
     * @return A DisplaySectionBean with sorted ItemGroupBeans, meaning the
     *         ItemGroupBeans should be listed in the order that they appear on
     *         the CRF section.
     * @return A DisplaySectionBean representing a CRF section.
     */
public DisplaySectionBean createDisplaySectionBWithFormGroups(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
    DisplaySectionBean displaySectionBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
    ItemDAO itemDao = new ItemDAO(dataSource);
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    SectionDAO sectionDao = new SectionDAO(dataSource);
    // Give the DisplaySectionBean a legitimate SectionBean
    SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
    displaySectionBean.setSection(secBean);
    // changed from: findGroupBySectionId
    List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
    // all items associated with the section, including those not in a group
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    // Sort these items according to their position on the CRF; their
    // ordinal
    Collections.sort(allMetas);
    // The DisplayItemGroupBean(s) for "nongrouped" items
    List<DisplayItemGroupBean> nonGroupBeans = null;
    // if(itemGroupBeans.isEmpty()) return displaySectionBean;
    // Find out whether there are any checkboxes/radios/select elements
    // and if so, get any null values
    // associated with them
    List<String> nullValuesList = new ArrayList<String>();
    boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
    if (itemsHaveChecksRadios && eventCRFDefId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : itemGroupBeans) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), crfVersionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), crfVersionId, sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata info
            // so we can get one of the metadata and set the metadata for
            // the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        displayItems = getDisplayBeansFromItems(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context);
        displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayItemGBean);
    }
    // We still have to sort these display item group beans on their
    // ItemGroupMetadataBean?
    // then number their ordinals accordingly
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
            return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
        }
    });
    // Now provide the display item group beans with an ordinal
    int digOrdinal = 0;
    for (DisplayItemGroupBean digBean : displayFormBeans) {
        digBean.setOrdinal(++digOrdinal);
    }
    // find out whether there are any ungrouped items by comparing the
    // number of
    // grouped items to allMetas.size()
    // List<DisplayItemGroupBean> nonGroupBeans=null;
    int tempCount = 0;
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        tempCount += groupBean.getItems().size();
    }
    if (tempCount < allMetas.size()) {
        nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
    }
    if (nonGroupBeans != null) {
        displayFormBeans.addAll(nonGroupBeans);
    }
    // sort the list according to the ordinal of the contained
    // DisplayItemGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            Integer compInt = disFormGroupBean1.getOrdinal();
            Integer compInt2 = disFormGroupBean.getOrdinal();
            return compInt2.compareTo(compInt);
        }
    });
    displaySectionBean.setDisplayFormGroups(displayFormBeans);
    return displaySectionBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 43 with ItemFormMetadataBean

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

the class PrintHorizontalFormBuilder method createTheadContentsFromDisplayItems.

public List<Element> createTheadContentsFromDisplayItems(List<DisplayItemBean> displayBeans, boolean generateExtraColumn) {
    List<Element> elements = new ArrayList<Element>();
    ItemFormMetadataBean itemFormBean;
    // header is blank; add question number labels potentially
    for (DisplayItemBean displayBean : displayBeans) {
        itemFormBean = displayBean.getMetadata();
        elements.add(createTHTagFromItemMeta(itemFormBean));
    }
    //        }
    return elements;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 44 with ItemFormMetadataBean

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

the class ImportHelper method validateDisplayItemBeanMultipleCV.

/**
     * Peform validation on a item which has a RADIO or SINGLESELECTresponse
     * type. This function checks that the input isn't blank, and that its value
     * comes from the controlled vocabulary (ResponseSetBean) in the
     * DisplayItemBean.
     * 
     * @param v
     *            The Validator to add validations to.
     * @param dib
     *            The DisplayItemBean to validate.
     * @return The DisplayItemBean which is validated.
     */
public DisplayItemBean validateDisplayItemBeanMultipleCV(DiscrepancyValidator v, DisplayItemBean dib, String inputName) {
    if (StringUtil.isBlank(inputName)) {
        inputName = getInputName(dib);
    }
    ItemFormMetadataBean ibMeta = dib.getMetadata();
    ItemDataBean idb = dib.getData();
    if (StringUtil.isBlank(idb.getValue())) {
        if (ibMeta.isRequired()) {
            v.addValidation(inputName, Validator.IS_REQUIRED);
        }
    } else {
    // comment this out since it should be a hard edit check, tbh
    // 05/2008
    // v.addValidation(inputName, Validator.IN_RESPONSE_SET,
    // dib.getMetadata().getResponseSet());
    }
    return dib;
}
Also used : ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 45 with ItemFormMetadataBean

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

the class BeanFactory method createItemFormMetadataBean.

/*
     * Create an ItemFormMetadataBean from the values referred to by a Map.Entry
     * object. The Map.Entry contains an integer pointing to a Map of Item
     * values from the Sreadsheet template, as in (item_name: Item1, etc...}
     */
public ItemFormMetadataBean createItemFormMetadataBean(Map.Entry<Integer, Map<String, String>> me, String crfName) {
    if (me == 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(me.getKey());
    Map<String, String> map = me.getValue();
    // response_layout property for checkboxes and radio buttons
    metadataBean.setResponseLayout(map.get("response_layout"));
    metadataBean.setDefaultValue(map.get("default_value"));
    metadataBean.setParentLabel(map.get("parent_item"));
    metadataBean.setLeftItemText(map.get("left_item_text"));
    metadataBean.setRightItemText(map.get("right_item_text"));
    metadataBean.setHeader(map.get("header"));
    metadataBean.setSubHeader(map.get("subheader"));
    metadataBean.setGroupLabel(map.get("group_label"));
    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");
    //We support any character in QUESTION_NUMBER field. So there is no need to do this number formatting.
    //        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)

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