Search in sources :

Example 41 with DisplayItemGroupBean

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

the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.

public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(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) {
        //TODO:fix me!
        itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        //TODO:fix me add item_form_metadata.section_id to the query
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(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 = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
        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 42 with DisplayItemGroupBean

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

the class FormBeanUtil method sectionHasUngroupedItems.

public boolean sectionHasUngroupedItems(DataSource dataSource, int sectionId, List<DisplayItemGroupBean> displayFormBeans) {
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    int size = allMetas.size();
    int tempCount = 0;
    String grpName = "";
    // Only count grouped items
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        grpName = groupBean.getItemGroupBean().getName();
        if (!(grpName.equalsIgnoreCase("Ungrouped") || grpName.length() < 1)) {
            tempCount += groupBean.getItems().size();
        }
    }
    return tempCount < size;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 43 with DisplayItemGroupBean

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

the class FormBeanUtil method addNullValuesToDisplayItemWithGroupBeans.

public void addNullValuesToDisplayItemWithGroupBeans(List<DisplayItemWithGroupBean> groupBeans, List<String> nullValuesList) {
    if (nullValuesList == null || nullValuesList.isEmpty() || groupBeans == null || groupBeans.isEmpty()) {
        return;
    }
    DisplayItemGroupBean displayItemGroupBean = null;
    List<DisplayItemBean> disBeans = new ArrayList<DisplayItemBean>();
    String responseName = "";
    List<ResponseOptionBean> respOptions;
    for (DisplayItemWithGroupBean withGroupBean : groupBeans) {
        displayItemGroupBean = withGroupBean.getItemGroup();
        disBeans = displayItemGroupBean.getItems();
        for (DisplayItemBean singleBean : disBeans) {
            responseName = singleBean.getMetadata().getResponseSet().getResponseType().getName();
            respOptions = singleBean.getMetadata().getResponseSet().getOptions();
            if (respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
                this.addBeansToResponseOptions(nullValuesList, respOptions);
            }
        }
    }
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)43 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)33 ArrayList (java.util.ArrayList)24 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)13 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)13 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)12 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)11 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)10 HashMap (java.util.HashMap)9 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)9 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)9 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)9 HttpSession (javax.servlet.http.HttpSession)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)7 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)6 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)6 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)6 Map (java.util.Map)5 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)5