Search in sources :

Example 31 with DisplayItemBean

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

the class FormBeanUtil method createGroupBeansForNongroupedItems.

/**
     * This method is designed to make it easier to order grouped and nongrouped
     * items on a CRF. This method generates a List of DisplayItemGroupBeans
     * representing the items that are not formally part of a group-type
     * horizontal table (they have a name in the database of 'Ungrouped' ). The
     * DisplayItemGroupBeans are ordered according to the position of the items
     * on the CRF, compared with the CRF items that are in groups. When this
     * List is combined with a List of DisplayItemGroupBeans representing
     * *grouped* items, the combined List can be sorted and displayed in the
     * proper order on a CRF.
     * 
     * @param allItems
     *            A List of the ItemFormMetadataBeans associated with the CRF.
     * @param displayFormBeans
     *            The List of DisplayItemGroupBeans
     * @param sectionId
     *            The section ID associated with the items
     * @param dataSource
     *            The DataSource used to acquire the DAO-related connections
     * @param nullValuesList
     *            The list of any "null values" associated with the items (like
     *            "not applicable")
     * @return An ArrayList of DisplayItemGroupBeans for 'Ungrouped' items.
     */
private List<DisplayItemGroupBean> createGroupBeansForNongroupedItems(List<ItemFormMetadataBean> allItems, List<DisplayItemGroupBean> displayFormBeans, int sectionId, DataSource dataSource, List<String> nullValuesList, EventCRFBean eventCrfBean, ServletContext context) {
    // This will hold the List of placeholder groupBeans for orphaned items
    List<DisplayItemGroupBean> groupBeans = new ArrayList<DisplayItemGroupBean>();
    // Now create a Map that maps the item to the group ordinal
    // (e.g., 1) or 0 (non-group),
    // as a convenient way to position an item on a CRF
    // and associate an item with the ordinal of its group.
    // The inner Map maps the ItemFormMetadataBean to its group ordinal;
    // The Integer index to this Map represents the order of the item on the
    // CRF.
    SortedMap<Integer, Map<ItemFormMetadataBean, Integer>> groupMapping = new TreeMap<Integer, Map<ItemFormMetadataBean, Integer>>();
    Map<ItemFormMetadataBean, Integer> innerMap;
    int counter = 0;
    int tmpOrdinal;
    for (ItemFormMetadataBean imetaBean : allItems) {
        innerMap = new HashMap<ItemFormMetadataBean, Integer>();
        if (isGrouped(imetaBean, displayFormBeans)) {
            tmpOrdinal = getGroupOrdinal(imetaBean, displayFormBeans);
            innerMap.put(imetaBean, tmpOrdinal);
        } else {
            innerMap.put(imetaBean, 0);
        }
        groupMapping.put(++counter, innerMap);
    }
    // The groupMapping Map maps the index position of the item on the CRF
    // form (1,2,3...) to
    // the ItemFormMetadataBean and its associated group ordinal, if it has
    // one
    // If the ordinal is 0, then the associated ItemFormMetadataBean
    // represents an
    // ungrouped or orphaned item
    DisplayItemGroupBean nongroupedBean;
    ItemGroupBean itemGroup = new ItemGroupBean();
    ItemGroupMetadataBean metaBean = new ItemGroupMetadataBean();
    metaBean.setName(UNGROUPED);
    List<DisplayItemBean> items;
    // Now cycle through the groupMapping and create default groups or
    // DisplayItemGroupBeans, in order, for
    // the orphaned items.
    // A DisplayItemGroupBean is only created and stored in the returned
    // List
    // if its contents or associated items are nongrouped.
    // This int tracks the ordinal associated with each grouped item's
    // associated
    // DisplayItemGroupBean
    // as that item is incremented
    int ordinalTracker = 0;
    // This int is set to the latest DisplayItemGroupBean ordinal containing
    // nongrouped beans, so that it can be incremented and used to change
    // the ordinal of any DisplayItemGroupBeans (containing *grouped* items)
    // that follow this bean on the CRF
    // int nonGroupOrdinal=0;
    Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>> entry;
    Map<ItemFormMetadataBean, Integer> beanMap;
    nongroupedBean = new DisplayItemGroupBean();
    ItemFormMetadataBean tempItemMeta;
    int tempOrdinal;
    // a flag indicating that the last item handled was an orphaned one
    // so that if the next item is grouped, that's a signal to store the
    // new itemgroupbean just created for orphaned items in in the
    // itemgroupbean List.
    boolean isOrphaned = false;
    // any of the orphaned items
    for (Iterator<Map.Entry<Integer, Map<ItemFormMetadataBean, Integer>>> iter = groupMapping.entrySet().iterator(); iter.hasNext(); ) {
        entry = iter.next();
        // the ItemFormMetadataBean and any
        beanMap = entry.getValue();
        // group ordinal
        // the
        tempItemMeta = beanMap.keySet().iterator().next();
        // ItemFormMetadataBean
        // If this value is 0, the item is orphaned; if > 0 the item is
        // grouped
        // and doesn't need a new itemgroupbean
        tempOrdinal = beanMap.get(tempItemMeta);
        // ordinalTracker != 0
        if (tempOrdinal == 0) {
            if (ordinalTracker == 0 || !isOrphaned) {
                // initialize a new group for the item
                nongroupedBean = new DisplayItemGroupBean();
                itemGroup = new ItemGroupBean();
                itemGroup.setName(UNGROUPED);
                nongroupedBean.setItemGroupBean(itemGroup);
                // set this flag, so that if the next item is orphaned, then
                // the code can place it in the existing itemgroupbean
                isOrphaned = true;
                ordinalTracker++;
                nongroupedBean.setOrdinal(ordinalTracker);
            // nonGroupOrdinal=nongroupedBean.getOrdinal();
            // nonGroupOrdinal= ordinalTracker;
            }
            // Add the item as a displayitem to the itemgroupbean
            nongroupedBean.getItems().add(getDisplayBeanFromSingleItem(tempItemMeta, sectionId, dataSource, eventCrfBean, nullValuesList, context));
        } else {
            // been created; therefore, store it in the List.
            if (isOrphaned) {
                groupBeans.add(nongroupedBean);
                // We also know that the ordinal has changed, because a
                // nongroupedBean
                // has been created
                ordinalTracker++;
                incrementOrdinal(tempItemMeta, displayFormBeans, ordinalTracker);
            } else {
                ordinalTracker = getGroupOrdinal(tempItemMeta, displayFormBeans);
            }
            isOrphaned = false;
        }
    }
    // is leftover and must be added to the List
    if (isOrphaned) {
        groupBeans.add(nongroupedBean);
    }
    return groupBeans;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 32 with DisplayItemBean

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

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

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

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

the class FormBeanUtil method createMultipleCols.

/**
     * Create a multiple column XHTML table from a list of display items.
     * 
     * @param tbody
     *            The Element to add the rows to.
     * @param displayItemRows
     *            The list of DisplayItemBean and the column they should appear
     *            in.
     * @param tabindex
     *            The tab index of the form field.
     * @param hasDiscrepancyMgt
     *            A flag indicating whether or not the Item is involved with
     * @param numberOfColumns
     *            An integer representing the highest number of columns with
     *            cell content in this group of rows (e.g., one row has five td
     *            cells with content, the highest number of any
     * @param hasDBValues
     * @param forPrinting
     */
private void createMultipleCols(Element tbody, Map<Integer, List<DisplayItemBean>> displayItemRows, Integer tabindex, boolean hasDiscrepancyMgt, int numberOfColumns, boolean hasDBValues, boolean forPrinting) {
    CellFactory cellFactory = new CellFactory();
    // Use this decorator class to generate vertical checkboxes or radios,
    // if any of the
    // items have this type of layout
    CellFactoryPrintDecorator cellFactoryPrintDecorator = new CellFactoryPrintDecorator();
    // Create header/subheader rows, if necessary
    Map.Entry<Integer, List<DisplayItemBean>> me;
    List<DisplayItemBean> itemsList;
    int numberOfBeansInRow;
    Element formFieldRow = new Element("tr");
    ;
    Element headerRow;
    Element subHeaderRow;
    for (Iterator<Map.Entry<Integer, List<DisplayItemBean>>> iter = displayItemRows.entrySet().iterator(); iter.hasNext(); ) {
        me = iter.next();
        itemsList = me.getValue();
        numberOfBeansInRow = itemsList.size();
        // Each Entry points to a List of DisplayItemBeans that are in the
        // rows
        // Create the row containing the item + form field
        headerRow = new Element("tr");
        subHeaderRow = new Element("tr");
        String leftSideTxt = "";
        // with any necessary empty td cells
        for (DisplayItemBean disBean : me.getValue()) {
            // Each row has its own instance of headerRow and subHeaderRow
            if (disBean.getMetadata().getHeader().length() > 0) {
                headerRow = createHeaderCellMultiColumn(disBean, true, headerRow, numberOfBeansInRow);
            }
            if (disBean.getMetadata().getSubHeader().length() > 0) {
                subHeaderRow = createHeaderCellMultiColumn(disBean, false, subHeaderRow, numberOfBeansInRow);
            }
            String responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
            Element tdCell = new Element("td");
            String classNames = CssRules.getClassNamesForTag("td");
            tdCell.setAttribute("class", classNames);
            String questNumber = "";
            questNumber = disBean.getMetadata().getQuestionNumberLabel();
            boolean hasQuestion = questNumber.length() > 0;
            leftSideTxt = disBean.getMetadata().getLeftItemText();
            // use vertical-alignment for these TD cells
            tdCell.setAttribute("style", "vertical-align:top");
            boolean horizontalLayout = "horizontal".equalsIgnoreCase(disBean.getMetadata().getResponseLayout());
            // discrepancy note icons
            if (("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName)) && !horizontalLayout) {
                cellFactoryPrintDecorator.createCellContentsForVerticalLayout(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
            } else {
                cellFactory.createCellContents(tdCell, responseName, disBean, ++tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
            }
            cellFactory.addTextToCell(tdCell, leftSideTxt, CellFactory.LEFT);
            if (hasQuestion) {
                addQuestionNumbers(tdCell, questNumber);
            }
            formFieldRow.addContent(tdCell);
        }
        int cellCountDif;
        int childrenCount;
        // then add them to the tbody element
        if ((childrenCount = headerRow.getChildren("td").size()) > 0) {
            // if the header row has fewer cells then the number of item TD
            // cells,
            // then pad the header row with empty td cells to make up the
            // difference
            cellCountDif = numberOfBeansInRow - childrenCount;
            if (cellCountDif > 0) {
                headerRow = addEmptyTDcells(headerRow, cellCountDif);
            }
            tbody.addContent(headerRow);
        }
        if ((childrenCount = subHeaderRow.getChildren("td").size()) > 0) {
            cellCountDif = numberOfBeansInRow - childrenCount;
            if (cellCountDif > 0) {
                subHeaderRow = addEmptyTDcells(subHeaderRow, cellCountDif);
            }
            tbody.addContent(subHeaderRow);
        }
        // pad the actual row of form fields with td cells, to make the
        // columns equivalent
        cellCountDif = numberOfColumns - numberOfBeansInRow;
        if (cellCountDif > 0) {
            formFieldRow = addEmptyTDcells(formFieldRow, cellCountDif);
        }
    }
    tbody.addContent(formFieldRow);
}
Also used : Element(org.jdom.Element) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)80 ArrayList (java.util.ArrayList)44 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)37 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)33 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)24 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)22 HashMap (java.util.HashMap)19 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)18 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)16 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)16 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)15 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)15 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)12 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)12 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)12 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)11 Element (org.jdom.Element)10 List (java.util.List)8 Map (java.util.Map)8 HttpSession (javax.servlet.http.HttpSession)8