Search in sources :

Example 6 with DisplaySectionBean

use of org.akaza.openclinica.bean.submit.DisplaySectionBean 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 7 with DisplaySectionBean

use of org.akaza.openclinica.bean.submit.DisplaySectionBean 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 8 with DisplaySectionBean

use of org.akaza.openclinica.bean.submit.DisplaySectionBean 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 9 with DisplaySectionBean

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

the class FormBeanUtil method createDisplaySectionBeanWithItemGroups.

/**
     * Create a DisplaySectionBean with a list of FormGroupBeans.
     * 
     * @param crfVersionId
     *            The CRF version ID associated with the Items.
     * @param sectionBean
     *            The SectionBean with an ID associated with the Items, which
     *            end up providing the content of the tables.
     * @param sm
     *            A SessionManager, from which DataSources are acquired for the
     *            DAO objects.
     * @return A DisplaySectionBean.
     */
public DisplaySectionBean createDisplaySectionBeanWithItemGroups(int sectionId, EventCRFBean eventCrfBean, SectionBean sectionBean, SessionManager sm, ServletContext context) {
    DisplaySectionBean dBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
    ItemDAO itemDao = new ItemDAO(sm.getDataSource());
    // Get all items associated with this crfVersion ID; divide them up into
    // items with a group, and those without a group.
    // get all items associated with a section id, then split them up into
    // grouped
    // and non-grouped items
    List<ItemBean> allItems = itemDao.findAllParentsBySectionId(sectionId);
    // Get a List of FormGroupBeans for each group associated with
    // this crfVersionId.
    // List<ItemGroupBean> arrList =
    // formGroupDAO.findGroupByCRFVersionIDMap(crfVersionId);
    List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
    if (arrList.isEmpty())
        return dBean;
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayFormGBean;
    for (ItemGroupBean itemGroup : arrList) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
        // this requirement
        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);
        }
        // TODO: the last arg is a list of null value strings
        displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionBean.getId(), null, context);
        displayFormGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayFormGBean);
    }
    // sort the list according to the ordinal of the contained
    // FormGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            return disFormGroupBean.getGroupMetaBean().getOrdinal().compareTo(disFormGroupBean1.getGroupMetaBean().getOrdinal());
        }
    });
    dBean.setDisplayFormGroups(displayFormBeans);
    return dBean;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) 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) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 10 with DisplaySectionBean

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

the class PrintTableTag method doTag.

/**
     * This JSP Tag API method creates a instance of PrintHorizontalFormBuilder,
     * then generates that class's XHTML output into the web page. The tag shows
     * all sections of a CRF.
     *
     * @throws JspException
     * @throws IOException
     */
@Override
public void doTag() throws JspException, IOException {
    JspContext context = getJspContext();
    JspWriter tagWriter = context.getOut();
    // This request attribute is generated by the PrintCRf or PrintDataEntry
    // servlets
    List<DisplaySectionBean> listOfDisplayBeans = (ArrayList) context.findAttribute("listOfDisplaySectionBeans");
    StudyBean studyBean = (StudyBean) context.findAttribute("study");
    // EventCRFBean
    EventCRFBean eventCRFBean = (EventCRFBean) context.findAttribute("EventCRFBean");
    String isInternetExplorer = (String) context.findAttribute("isInternetExplorer");
    if (listOfDisplayBeans != null) {
        PrintHorizontalFormBuilder printFormBuilder = new PrintHorizontalFormBuilder();
        // Provide the form-building code with the list of display section
        // beans
        printFormBuilder.setDisplaySectionBeans(listOfDisplayBeans);
        // The body content of the tag contains 'true' or 'false', depending
        // on whether the
        // printed CRF involves data entry (and possible saved data) or not.
        JspFragment fragment = this.getJspBody();
        Writer stringWriter = new StringWriter();
        fragment.invoke(stringWriter);
        if ("true".equalsIgnoreCase(stringWriter.toString())) {
            printFormBuilder.setInvolvesDataEntry(true);
        }
        printFormBuilder.setEventCRFbean(eventCRFBean);
        if ("true".equalsIgnoreCase(isInternetExplorer)) {
            printFormBuilder.setInternetExplorer(true);
        }
        if (studyBean != null) {
            printFormBuilder.setStudyBean(studyBean);
        }
        if ("true".equalsIgnoreCase(stringWriter.toString())) {
            tagWriter.println(printFormBuilder.createMarkup());
        } else
            tagWriter.println(printFormBuilder.createMarkupNoDE());
    } else {
        tagWriter.println("The application could not generate the markup for the printable form.<br />" + "This error may have been caused by the altering of the web page's URL; the URL needs " + "an 'id' or an 'ecId' value in its query string at the URL end.");
    }
}
Also used : DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) PrintHorizontalFormBuilder(org.akaza.openclinica.view.form.PrintHorizontalFormBuilder) JspFragment(javax.servlet.jsp.tagext.JspFragment) JspContext(javax.servlet.jsp.JspContext) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StringWriter(java.io.StringWriter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) JspWriter(javax.servlet.jsp.JspWriter) StringWriter(java.io.StringWriter) JspWriter(javax.servlet.jsp.JspWriter) Writer(java.io.Writer)

Aggregations

DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)22 ArrayList (java.util.ArrayList)20 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)17 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)16 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)14 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)14 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)14 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)14 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)12 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)11 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)11 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)10 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)10 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)10 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)10 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)8 HttpSession (javax.servlet.http.HttpSession)7 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)7 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)7