Search in sources :

Example 71 with DisplayItemBean

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

the class PrintHorizontalFormBuilder method addResponseLayoutRow.

private void addResponseLayoutRow(ArrayList subHeadList, List<DisplayItemBean> displayBeans) {
    Element thRow = new Element("tr");
    String responseName;
    String responseLayout;
    ItemFormMetadataBean metaBean;
    // Now create the th row
    Element th2;
    ResponseSetBean respBean;
    ResponseOptionBean optBean;
    int j = 0;
    for (DisplayItemBean dBean : displayBeans) {
        j++;
        metaBean = dBean.getMetadata();
        respBean = metaBean.getResponseSet();
        responseName = respBean.getResponseType().getName();
        if (responseName == null) {
            responseName = "";
        }
        responseLayout = metaBean.getResponseLayout();
        if (responseLayout == null) {
            responseLayout = "";
        }
        // next to a rad or check *with* a horizontal layout.
        if ((responseName.equalsIgnoreCase("radio") || responseName.equalsIgnoreCase("checkbox")) && responseLayout.equalsIgnoreCase("horizontal")) {
            for (int i = 0; i < respBean.getOptions().size(); i++) {
                optBean = (ResponseOptionBean) respBean.getOptions().get(i);
                if (optBean != null) {
                    th2 = createThCell(optBean.getText(), 1);
                    // Add font for printing
                    String classNames = th2.getAttribute("class").getValue();
                    classNames = classNames + " general_font";
                    th2.setAttribute("class", classNames);
                    thRow.addContent(th2);
                }
            }
        } else {
            // create empty cells for non-radios or checks, or rads and
            // checks
            // without horizontal layout
            th2 = createThCell("", 1);
            thRow.addContent(th2);
        }
        if (j % maxColRow == 0) {
            subHeadList.add(thRow);
            thRow = new Element("tr");
        }
    }
    if (j % maxColRow != 0)
        subHeadList.add(thRow);
    // now add the final empty th cell for the row
    th2 = createThCell();
    thRow.addContent(th2);
}
Also used : Element(org.jdom.Element) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 72 with DisplayItemBean

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

the class PrintHorizontalFormBuilder method createMarkup.

@Override
public String createMarkup() {
    // If the CRF has
    // data associated with it, pass on the responsibility to another object
    ViewPersistanceHandler persistanceHandler = new ViewPersistanceHandler();
    ViewBuilderPrintDecorator builderUtil = new ViewBuilderPrintDecorator();
    // This object holds the printed output of the JDom Document object,
    // which represents
    // the XML for each section's HTML tables. The object is re-written
    // each time a new section is generated
    Writer writer = new StringWriter();
    // This object contains all of the markup for all of the sections.
    StringBuilder webPageBuilder = new StringBuilder();
    // Keep track of the section number so we can create page numbers
    int pageNumber = 0;
    if (isInternetExplorer) {
        for (DisplaySectionBean displaySecBean : this.displaySectionBeans) {
            this.reconfigureView = builderUtil.hasThreePlusColumns(displaySecBean);
            // reformulated for IE
            if (reconfigureView)
                break;
        }
    }
    int uniqueId = 0;
    // Print all the sections of a group-type table
    for (DisplaySectionBean displaySecBean : this.displaySectionBeans) {
        // The CellFactoryPrintDecorator object that generates the content
        // for HTML table TD cells.
        CellFactoryPrintDecorator cellFactory = new CellFactoryPrintDecorator();
        // The object that handles the repetition model attributes for the
        // HTML table elements
        RepeatManager repeatManager = new RepeatManager();
        // These classes "decorate" the FormBeanUtil and ViewBuilderUtil
        // classes to
        // provide special services required in printing
        FormBeanUtilDecorator formUtilDecorator = new FormBeanUtilDecorator();
        // Does this particular section have to be reconfigured for printing
        // in IE browsers?
        boolean changeHTMLForIE = false;
        if (reconfigureView) {
        //                changeHTMLForIE = builderUtil.hasThreePlusColumns(displaySecBean);
        }
        // We have to change the Section's ItemGroupBeans if the Section has
        // group tables exceeding three columns, in terms of printing for IE
        // browsers.
        // Any ItemGroupBean specifically has to be reduced to one column,
        // if it exceeds
        // three columns; changeHTMLForIE is 'true' if this section has any
        // group tables
        // that are 3+ columns
        //            if (changeHTMLForIE) {
        //                List<DisplayItemGroupBean> newGroupBeans = builderUtil.reduceColumnsGroupTables(displaySecBean.getDisplayFormGroups());
        //
        //                // Now set the display section beans groups to the reshuffled
        //                // list
        //                displaySecBean.setDisplayFormGroups(newGroupBeans);
        //            }
        // increment the page number
        ++pageNumber;
        // The SectionBean associated with this section
        sectionBean = displaySecBean.getSection();
        if (involvesDataEntry) {
            List<ItemDataBean> itemDataBeans;
            persistanceHandler = new ViewPersistanceHandler();
            itemDataBeans = persistanceHandler.fetchPersistedData(sectionBean.getId(), eventCRFbean.getId());
            if (!itemDataBeans.isEmpty()) {
                hasDbFormValues = true;
            }
            persistanceHandler.setItemDataBeans(itemDataBeans);
        }
        // Keep track of whether a group has any repeat behavior; true or
        // false
        boolean repeatFlag;
        // The number of repeating table rows that the group will start
        // with.
        int repeatNumber;
        // the div tag that will be the root node for each printable section
        Element divRoot = new Element("div");
        divRoot.setAttribute("id", ("toplevel" + pageNumber));
        divRoot.setAttribute("class", "toplevel");
        // remove float properties for IE browsers
        if (isInternetExplorer) {
            divRoot.setAttribute("style", "float:none");
        }
        Document doc = new Document(divRoot);
        // Show the section's title, subtitle, or instructions
        builderUtil.showTitles(divRoot, sectionBean, pageNumber, isInternetExplorer);
        // One way to generate an id for the repeating tbody or tr element
        // The tabindex attribute for select and input tags
        int tabindex = 1;
        // Should discrepancy note icons be displayed
        boolean hasDiscrepancyMgt = false;
        StudyBean studBean = this.getStudyBean();
        if (studBean != null && studBean.getStudyParameterConfig().getDiscrepancyManagement().equalsIgnoreCase("true")) {
            hasDiscrepancyMgt = true;
        }
        // its list of DisplayItemBeans
        for (DisplayItemGroupBean displayItemGroup : displaySecBean.getDisplayFormGroups()) {
            ArrayList headerlist = new ArrayList();
            ArrayList bodylist = new ArrayList();
            ArrayList subHeadList = new ArrayList();
            List<DisplayItemBean> currentDisplayItems = displayItemGroup.getItems();
            // A Map that contains persistent (stored in a database),
            // repeated rows
            // in a matrix type table
            // The Map index is the Item id of the first member of the row;
            // the value is a List
            // of item beans that make up the row
            SortedMap<Integer, List<ItemDataBean>> ordinalItemDataMap = new TreeMap<Integer, List<ItemDataBean>>();
            // Is this a persistent matrix table and does it already have
            // repeated rows
            // in the database?
            boolean hasStoredRepeatedRows = false;
            // Is this a non-group type table that shares the same section
            // as a group table?
            boolean unGroupedTable = displayItemGroup.getItemGroupBean().getName().equalsIgnoreCase(BeanFactory.UNGROUPED);
            // Load any database values into the DisplayItemBeans
            if (hasDbFormValues) {
                currentDisplayItems = persistanceHandler.loadDataIntoDisplayBeans(currentDisplayItems, (!unGroupedTable));
                /*
                     * The highest number ordinal represents how many repeated
                     * rows there are. If the ordinal in ItemDataBeans > 1, then
                     * we know that the group has persistent repeated rows. Get
                     * a structure that maps each ordinal (i.e., >= 2) to its
                     * corresponding List of ItemDataBeans. Then iterate the
                     * existing DisplayBeans, with the number of new rows
                     * equaling the highest ordinal number minus 1 (meaning, the
                     * first row represents the row of the group table that
                     * would exist if the user displayed the table, but didn't
                     * generate any new rows). For example, in a List of
                     * ItemDataBeans, if the highest ordinal property among
                     * these beans is 5, then the matrix table has 4 repeated
                     * rows from the database. Provide each new row with its
                     * values by using the ItemDataBeans.
                     */
                if (involvesDataEntry && !unGroupedTable && persistanceHandler.hasPersistentRepeatedRows(currentDisplayItems)) {
                    hasStoredRepeatedRows = true;
                    // if the displayitems contain duplicate item ids, then
                    // these duplicates
                    // represent repeated rows. Separate them into a Map of
                    // new rows that
                    // will be appended to the HTML table.
                    ordinalItemDataMap = persistanceHandler.handleExtraGroupRows();
                }
            }
            // end if hasDbFormValues
            // Does the table have a group header?
            String groupHeader = displayItemGroup.getGroupMetaBean().getHeader();
            boolean hasGroupHeader = groupHeader != null && groupHeader.length() > 0;
            // Add group header, if there is one
            if (hasGroupHeader) {
                Element divGroupHeader = new Element("div");
                // necessary?
                divGroupHeader.setAttribute("class", "aka_group_header");
                Element strong = new Element("strong");
                strong.setAttribute("style", "float:none");
                strong.addContent(groupHeader);
                divGroupHeader.addContent(strong);
                divRoot.addContent(divGroupHeader);
            }
            Element tableDiv = new Element("div");
            tableDiv.setAttribute("class", "tableDiv");
            if (isInternetExplorer) {
                tableDiv.setAttribute("style", "float:none");
            }
            divRoot.addContent(tableDiv);
            // This group represents "orphaned" items (those without a
            // group) if
            // the FormGroupBean has a group label of UNGROUPED
            Element orphanTable = null;
            if (unGroupedTable) {
                orphanTable = formUtilDecorator.createXHTMLTableFromNonGroup(currentDisplayItems, tabindex, hasDiscrepancyMgt, hasDbFormValues, true);
                // We have to track the point the tabindex has reached here
                // The tabindex will increment by the size of the
                // displayItemGroup List
                tabindex += currentDisplayItems.size();
                tableDiv.addContent(orphanTable);
                continue;
            }
            // end if unGroupedTable
            uniqueId++;
            String repeatParentId = "repeatParent" + uniqueId;
            repeatNumber = displayItemGroup.getGroupMetaBean().getRepeatNum();
            // If the form has repeat behavior, this number is > 0
            // Do not allow repeat numbers < 1
            repeatNumber = repeatNumber < 1 ? 1 : repeatNumber;
            // And a limit of 12
            repeatNumber = repeatNumber > 12 ? 12 : repeatNumber;
            // This is always true during this iteration
            repeatFlag = true;
            Element table = createTable();
            // add the thead element
            Element thead = new Element("tr");
            tableDiv.addContent(table);
            //                table.addContent(thead);
            // Does this group involve a Horizontal checkbox or radio
            // button?
            boolean hasResponseLayout = builderUtil.hasResponseLayout(currentDisplayItems);
            // add th elements to the thead element
            // We have to create an extra thead column for the Remove Row
            // button, if
            // the table involves repeating rows; thus the final boolean
            // parameter
            List<Element> thTags = repeatFlag ? createTheadContentsFromDisplayItems(currentDisplayItems, true) : createTheadContentsFromDisplayItems(currentDisplayItems, false);
            int i = 0;
            for (Element el : thTags) {
                i++;
                thead.addContent(el);
                if (i % maxColRow == 0) {
                    headerlist.add(thead);
                    thead = new Element("tr");
                }
            }
            if (i % maxColRow != 0)
                headerlist.add(thead);
            // in this manner.
            if (hasResponseLayout) {
                addResponseLayoutRow(subHeadList, currentDisplayItems);
            }
            Element row;
            Element td;
            // For each row in the table
            row = new Element("tr");
            // tag
            if (repeatFlag && !(involvesDataEntry && hasStoredRepeatedRows)) {
                table = repeatManager.addParentRepeatAttributes(table, repeatParentId, repeatNumber, displayItemGroup.getGroupMetaBean().getRepeatMax());
            }
            // The content for the table cells. For each item...
            int j = 0;
            for (DisplayItemBean displayBean : currentDisplayItems) {
                j++;
                // What type of input: text, radio, checkbox, etc.?
                String responseName = displayBean.getMetadata().getResponseSet().getResponseType().getName();
                // horizontal
                if (displayBean.getMetadata().getResponseLayout().equalsIgnoreCase("horizontal") && (responseName.equalsIgnoreCase("checkbox") || responseName.equalsIgnoreCase("radio"))) {
                    // The final true parameter is for disabling D Notes
                    Element[] elements = cellFactory.createCellContentsForChecks(responseName, displayBean, displayBean.getMetadata().getResponseSet().getOptions().size(), ++tabindex, false, true);
                    for (Element el : elements) {
                        el = builderUtil.setClassNames(el);
                        if (repeatFlag) {
                        //                                el = repeatManager.addChildRepeatAttributes(el, repeatParentId, displayBean.getItem().getId(), null);
                        }
                        row.addContent(el);
                    }
                    // move to the next item
                    continue;
                }
                td = new Element("td");
                td = builderUtil.setClassNames(td);
                // Create cells within each row
                td = cellFactory.createCellContents(td, responseName, displayBean, ++tabindex, hasDiscrepancyMgt, hasDbFormValues, true);
                if (repeatFlag) {
                }
                row.addContent(td);
                if (j % maxColRow == 0) {
                    bodylist.add(row);
                    row = new Element("tr");
                    if (repeatFlag) {
                        repeatParentId = repeatParentId + uniqueId++;
                    }
                }
            }
            // end for displayBean
            if (j % maxColRow != 0)
                bodylist.add(row);
            //Creating the first/main table
            if ((repeatNumber > 1) || hasStoredRepeatedRows) {
                Element newRow = new Element("tr");
                Element div = new Element("div");
                div.setAttribute("id", "repeatCaption");
                Element newCol = new Element("td");
                Element strong = new Element("strong");
                strong.addContent("Repeat: 1");
                div.addContent(strong);
                newCol.addContent(div);
                newRow.addContent(newCol);
                table.addContent(newRow);
            }
            for (int k = 0; k < headerlist.size(); k++) {
                Element head = (Element) headerlist.get(k);
                Element body = (Element) bodylist.get(k);
                table.addContent(head);
                if (subHeadList.size() > 0) {
                    try {
                        Element subHead = (Element) subHeadList.get(k);
                        table.addContent(subHead);
                    } catch (IndexOutOfBoundsException IOB) {
                    }
                }
                table.addContent(body);
            }
            // being clicked
            if (hasStoredRepeatedRows) {
                List storedRepeatedRows = builderUtil.generatePersistentMatrixRows(ordinalItemDataMap, currentDisplayItems, tabindex, repeatParentId, hasDiscrepancyMgt, true, maxColRow);
                // add these new rows to the table
                int count = 1;
                for (int l = 0; l < storedRepeatedRows.size(); l++) {
                    ++count;
                    List<Element> rowsList = (ArrayList) storedRepeatedRows.get(l);
                    divRoot.addContent(createTableWithData(rowsList, headerlist, subHeadList, count));
                }
            }
        }
        // end for displayFormGroup
        XMLOutputter outp = new XMLOutputter();
        Format format = Format.getPrettyFormat();
        format.setOmitDeclaration(true);
        outp.setFormat(format);
        // The writer object contains the markup for one printable section
        writer = new StringWriter();
        try {
            outp.output(doc, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // The webPageBuilder object contains the markup for all of the
        // sections
        // in the print view
        webPageBuilder.append(writer.toString());
    }
    return webPageBuilder.toString();
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Document(org.jdom.Document) Format(org.jdom.output.Format) StringWriter(java.io.StringWriter) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ArrayList(java.util.ArrayList) List(java.util.List) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) IOException(java.io.IOException) TreeMap(java.util.TreeMap) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 73 with DisplayItemBean

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

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

the class FormBeanUtil method getDisplayBeanFromSingleItem.

public DisplayItemBean getDisplayBeanFromSingleItem(ItemFormMetadataBean itemFBean, int sectionId, DataSource dataSource, EventCRFBean eventCrfBean, List<String> nullValuesList, ServletContext context) {
    DisplayItemBean disBean = new DisplayItemBean();
    ItemBean itemBean = new ItemBean();
    ItemDAO itemDAO = new ItemDAO(dataSource);
    ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
    if (itemFBean == null)
        return disBean;
    itemBean = (ItemBean) itemDAO.findByPK(itemFBean.getItemId());
    if (itemBean == null) {
        itemBean = new ItemBean();
    }
    // Add any null values to checks or radios
    String responseName;
    List<ResponseOptionBean> respOptions;
    ResponseOptionBean respBean;
    boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
    // Only include Items that belong to the associated section
    if (itemFBean.getSectionId() == sectionId) {
        ItemDataBean itemDataBean = itemDataDao.findByItemIdAndEventCRFId(itemBean.getId(), eventCrfBean.getId());
        disBean.setItem(itemBean);
        disBean.setMetadata(runDynamicsCheck(itemFBean, eventCrfBean, itemDataBean, context));
        disBean.setData(itemDataBean);
        logger.debug("3. just set: " + itemDataBean.getValue());
        responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
        respOptions = disBean.getMetadata().getResponseSet().getOptions();
        if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
            this.addBeansToResponseOptions(nullValuesList, respOptions);
        }
    }
    return disBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO)

Example 75 with DisplayItemBean

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

the class FormBeanUtil method createXHTMLTableFromNonGroup.

/**
     * Create an XHTML table that encompasses the Items that are not part of a
     * group.
     * 
     * @param items
     *            A List of DisplayItemBeans that make up the table content.
     * @param tabindex
     *            The tab index for any form fields created in the table.
     * @param hasDiscrepancyMgt
     *            'true' is the items should be accompanied by discrepancy
     *            notes.
     * @param hasDBValues
     *            'true' if the items within the table are pre-filled with
     *            database values.
     * @param forPrinting
     * @return The org.jdom Element that represents the table.
     */
public Element createXHTMLTableFromNonGroup(List<DisplayItemBean> items, Integer tabindex, boolean hasDiscrepancyMgt, boolean hasDBValues, boolean forPrinting) {
    Element table = new Element("table");
    String cssClasses = CssRules.getClassNamesForTag(table.getName());
    table.setAttribute("class", cssClasses);
    /*
         * Don't add header cells to orphan-type tables, because when the header
         * is empty, Firefox does not show any borders: Element thead = new
         * Element("thead"); table.addContent(thead);
         */
    Element tbody = new Element("tbody");
    table.addContent(tbody);
    // divide up items into columns
    int numberOfColumns = getNumberOfColumnsFromItems(items);
    // numberOfColumns = 5;
    // Fixing table width for orphan table Mantis issue: 9087.
    // ToDo recheck why the main table getting fixed 
    // int tableWidth = numberOfColumns*300;
    //   table.setAttribute("style", "width:" + tableWidth + "px;");
    // A Map designed to hold DisplayItemBeans according to their column
    // number
    // The Map index is the column number; it is sorted so it begins with
    // column 1
    SortedMap<Integer, List<DisplayItemBean>> colMap = new TreeMap<Integer, List<DisplayItemBean>>();
    // A row by row Map for multi-col tables; the index is sorted and begins
    // with the first row of DisplayItemBeans
    SortedMap<Integer, List<DisplayItemBean>> multiRowMap = new TreeMap<Integer, List<DisplayItemBean>>();
    // This isn't necessary unless there is more than one column
    if (numberOfColumns > 1) {
        int column;
        for (DisplayItemBean displayItem : items) {
            column = displayItem.getMetadata().getColumnNumber();
            if (colMap.get(column) == null) {
                colMap.put(column, new ArrayList<DisplayItemBean>());
            }
            colMap.get(column).add(displayItem);
        }
        int numberOfRows = getNumberOfTableRows(colMap);
        // numberOfRows = 2;
        List<DisplayItemBean> itemsList;
        // the list inside multiRowMap
        List<DisplayItemBean> rowsList;
        for (int i = 1; i <= numberOfRows; i++) {
            rowsList = new ArrayList<DisplayItemBean>();
            for (int j = 1; j <= colMap.size(); j++) {
                itemsList = colMap.get(j);
                if (itemsList != null && itemsList.size() >= i) {
                    rowsList.add(itemsList.get(i - 1));
                }
            // iterate through the columns map
            }
            multiRowMap.put(i, rowsList);
        }
    }
    // made clickable
    if (numberOfColumns == 1) {
        createSingleColumn(tbody, items, tabindex, hasDiscrepancyMgt, hasDBValues, forPrinting);
    } else {
        createMultipleCols(tbody, multiRowMap, tabindex, hasDiscrepancyMgt, numberOfColumns, hasDBValues, forPrinting);
    }
    return table;
}
Also used : Element(org.jdom.Element) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

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