Search in sources :

Example 6 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method getChildrenDisplayItems.

/**
     * Get the DisplayItemBean objects corresponding to the items which are children of the specified parent.
     *
     * @param parent
     *            The item whose children are to be retrieved.
     * @param request TODO
     * @return An array of DisplayItemBean objects corresponding to the items which are children of parent, and are sorted by column number (ascending), then
     *         ordinal (ascending).
     */
private ArrayList getChildrenDisplayItems(DisplayItemBean parent, EventDefinitionCRFBean edcb, HttpServletRequest request) {
    ArrayList answer = new ArrayList();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    int parentId = parent.getItem().getId();
    ItemDAO idao = new ItemDAO(getDataSource());
    ArrayList childItemBeans = idao.findAllByParentIdAndCRFVersionId(parentId, ecb.getCRFVersionId());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
    for (int i = 0; i < childItemBeans.size(); i++) {
        ItemBean child = (ItemBean) childItemBeans.get(i);
        ItemDataBean data = iddao.findByItemIdAndEventCRFId(child.getId(), ecb.getId());
        ItemFormMetadataBean metadata = ifmdao.findByItemIdAndCRFVersionId(child.getId(), ecb.getCRFVersionId());
        DisplayItemBean dib = new DisplayItemBean();
        dib.setEventDefinitionCRF(edcb);
        dib.setItem(child);
        // tbh
        if (!getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
            dib.setData(data);
        }
        // <<tbh 07/2009, bug #3883
        // ItemDataBean dbData = iddao.findByItemIdAndEventCRFIdAndOrdinal(itemId, eventCRFId, ordinal)
        dib.setDbData(data);
        boolean showItem = getItemMetadataService().isShown(metadata.getItemId(), ecb, data);
        if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
            showItem = getItemMetadataService().hasPassedDDE(metadata, ecb, data);
        }
        // boolean passedDDE = getItemMetadataService().hasPassedDDE(data);
        if (showItem) {
            LOGGER.debug("set show item: " + metadata.getItemId() + " data " + data.getId());
            // metadata.setShowItem(showItem);
            metadata.setShowItem(true);
        }
        // logger.debug("did not catch NPE");
        dib.setMetadata(metadata);
        if (shouldLoadDBValues(dib)) {
            LOGGER.trace("should load db values is true, set value");
            dib.loadDBValue();
            LOGGER.trace("just loaded the child value: " + dib.getData().getValue());
        }
        answer.add(dib);
    }
    // this is a pretty slow and memory intensive way to sort... see if we
    // can
    // have the db do this instead
    Collections.sort(answer);
    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) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 7 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method getDisplayBean.

/**
     * Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
     * @param request TODO
     * @param isSubmitted TODO
     */
protected DisplaySectionBean getDisplayBean(boolean hasGroup, boolean includeUngroupedItems, HttpServletRequest request, boolean isSubmitted) throws Exception {
    DisplaySectionBean section = new DisplaySectionBean();
    FormProcessor fp = new FormProcessor(request);
    HttpSession session = request.getSession();
    Locale loc = this.locale == null ? LocaleResolver.getLocale(request) : this.locale;
    StudyBean study = (StudyBean) session.getAttribute("study");
    SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    SectionDAO sdao;
    // Find out whether there are ungrouped items in this section
    boolean hasUngroupedItems = false;
    int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    if (eventDefinitionCRFId <= 0) {
        // TODO: this block of code repeats
        // many times, need to clean up
        //synchronized(this)
        {
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
            EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
            eventDefinitionCRFId = edcBean.getId();
        }
    }
    LOGGER.trace("eventDefinitionCRFId " + eventDefinitionCRFId);
    // Use this class to find out whether there are ungrouped items in this
    // section
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
    if (hasGroup) {
        DisplaySectionBean newDisplayBean = new DisplaySectionBean();
        if (includeUngroupedItems) {
            // Null values: this method adds null values to the
            // displayitembeans
            newDisplayBean = formBeanUtil.createDisplaySectionBWithFormGroups(sb.getId(), ecb.getCRFVersionId(), getDataSource(), eventDefinitionCRFId, ecb, getServletContext());
        } else {
            newDisplayBean = formBeanUtil.createDisplaySectionWithItemGroups(study, sb.getId(), ecb, ecb.getStudyEventId(), sm, eventDefinitionCRFId, getServletContext());
        }
        itemGroups = newDisplayBean.getDisplayFormGroups();
        // setDataForDisplayItemGroups(itemGroups, sb,ecb,sm);
        LOGGER.trace("found item group size: " + itemGroups.size() + " and to string: " + itemGroups.toString());
        section.setDisplayFormGroups(itemGroups);
    }
    // Find out whether any display items are *not* grouped; see issue 1689
    hasUngroupedItems = formBeanUtil.sectionHasUngroupedItems(getDataSource(), sb.getId(), itemGroups);
    sdao = new SectionDAO(getDataSource());
    //
    sb.setHasSCDItem(hasUngroupedItems ? sdao.hasSCDItem(sb.getId()) : false);
    section.setEventCRF(ecb);
    if (sb.getParentId() > 0) {
        SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
        sb.setParent(parent);
    }
    section.setSection(sb);
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
    section.setCrfVersion(cvb);
    CRFDAO cdao = new CRFDAO(getDataSource());
    CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
    section.setCrf(cb);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    // EventDefinitionCRFBean edcb =
    // edcdao.findByStudyEventIdAndCRFVersionId(study,
    // ecb.getStudyEventId(), cvb.getId());
    section.setEventDefinitionCRF(edcb);
    // setup DAO's here to avoid creating too many objects
    ItemDAO idao = new ItemDAO(getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), loc);
    // Use itemGroups to determine if there are any ungrouped items
    // get all the parent display item beans not in group
    logMe("Entering getParentDisplayItems::: Thread is? " + Thread.currentThread());
    ArrayList displayItems = getParentDisplayItems(hasGroup, sb, edcb, idao, ifmdao, iddao, hasUngroupedItems, request);
    logMe("Entering getParentDisplayItems::: Done and Thread is? " + Thread.currentThread());
    LOGGER.debug("just ran get parent display, has group " + hasGroup + " has ungrouped " + hasUngroupedItems);
    // now sort them by ordinal,
    //JN: Commenting out this logic, its wrong and will give erroneous results.
    Collections.sort(displayItems);
    // now get the child DisplayItemBeans
    for (int i = 0; i < displayItems.size(); i++) {
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
        dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
        //
        if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
            if (shouldLoadDBValues(dib) && !isSubmitted) {
                dib.loadDBValue();
            }
        } else {
            if (shouldLoadDBValues(dib)) {
                LOGGER.trace("should load db values is true, set value");
                dib.loadDBValue();
                LOGGER.trace("just got data loaded: " + dib.getData().getValue());
            }
        }
        displayItems.set(i, dib);
    }
    section.setItems(displayItems);
    return section;
}
Also used : Locale(java.util.Locale) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) HttpSession(javax.servlet.http.HttpSession) SessionManager(org.akaza.openclinica.core.SessionManager) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 8 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method createDisplaySectionWithItemGroups.

/**
     * Create a DisplaySectionBean with a list of ItemGroupBeans. NOTE:
     * unGrouped Items are not included
     * 
     * @param study
     *            The StudyBean
     * @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 studyEventId
     *            The Study Event ID associated with the CRF Version ID.
     * @param sm
     *            A SessionManager, from which DataSources are acquired for the
     *            DAO objects.
     * @return A DisplaySectionBean.
     */
public DisplaySectionBean createDisplaySectionWithItemGroups(StudyBean study, int sectionId, EventCRFBean eventCrfBean, int studyEventId, SessionManager sm, int eventDefinitionCRFId, ServletContext context) {
    DisplaySectionBean dBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
    ItemDAO itemDao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(sm.getDataSource());
    List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(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());
    }
    // Collections.sort(allMetas);
    if (arrList.isEmpty())
        return dBean;
    // 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);
    // "+eventDefinitionCRFId);
    if (eventDefinitionCRFId <= 0) {
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, studyEventId, eventCrfBean.getCRFVersionId());
        eventDefinitionCRFId = edcBean.getId();
    }
    // "+eventDefinitionCRFId);
    if (itemsHaveChecksRadios && eventDefinitionCRFId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventDefinitionCRFId, sm.getDataSource());
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : arrList) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata
            // so we can get one of them and set metadata for the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        // include arrayList parameter until I determine difference in
        // classes
        displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), 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);
    }
    dBean.setDisplayFormGroups(displayFormBeans);
    return dBean;
}
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) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 9 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO 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 10 with ItemFormMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO 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)

Aggregations

ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)31 ArrayList (java.util.ArrayList)25 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)25 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)21 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)13 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)13 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 HashMap (java.util.HashMap)10 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)9 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)8 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)8 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)8 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)8 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)7 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)7