Search in sources :

Example 26 with ResponseOptionBean

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

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

the class FormBeanUtil method getDisplayBeansFromItems.

/**
     * Create a List of DisplayItemBeans from a List of Items.
     * 
     * @param itemBeans
     *            A List of ItemBeans that will provide the source of each
     *            DisplayItemBean
     * @param dataSource
     *            A DataSource for the DAO classes.
     * @param crfVersionId
     *            The CRF version Id for fetching associated
     *            ItemFormMetadataBeans.
     * @param sectionId
     *            The section ID associated with the Items.
     * @param nullValuesList
     *            A List of Strings containing "null values" such as "not
     *            applicable" or NA.
     * @return A List of DisplayItemBeans.
     */
public static List<DisplayItemBean> getDisplayBeansFromItems(List<ItemBean> itemBeans, DataSource dataSource, EventCRFBean eventCrfBean, int sectionId, List<String> nullValuesList, ServletContext context) {
    // logger = LoggerFactory.getLogger(getClass().getName());
    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;
    // Add any null values to checks or radios
    String responseName;
    List<ResponseOptionBean> respOptions;
    ResponseOptionBean respBean;
    boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
    String tmpVal = "";
    // findByItemIdAndCRFVersionId
    for (ItemBean iBean : itemBeans) {
        displayBean = new DisplayItemBean();
        //TODO: eventcrfBean is not valid??
        meta = metaDao.findByItemIdAndCRFVersionId(iBean.getId(), eventCrfBean.getCRFVersionId());
        // Only include Items that belong to the associated section
        if (meta.getSectionId() == sectionId) {
            displayBean.setItem(iBean);
            //findByItemIdAndEventCRFIdAndOrdinal(iBean.getId(), eventCrfBean.getId(), ordinal)
            ItemDataBean itemDataBean = itemDataDAO.findByItemIdAndEventCRFId(iBean.getId(), eventCrfBean.getId());
            // null values is set by adding the event def. crf bean, but
            // here we have taken a different approach, tbh
            // displayBean.setEventDefinitionCRF();
            displayBean.setMetadata(runDynamicsCheck(meta, eventCrfBean, itemDataBean, context));
            displayBean.setData(itemDataBean);
            displayBean.setDbData(itemDataBean);
            // System.out.println("just set: " + itemDataBean.getValue() + " from " + itemDataBean.getItemId());
            responseName = displayBean.getMetadata().getResponseSet().getResponseType().getName();
            respOptions = displayBean.getMetadata().getResponseSet().getOptions();
            if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
                for (String val : nullValuesList) {
                    respBean = new ResponseOptionBean();
                    // BWP>> set text to the extended version, "not
                    // applicable"?
                    tmpVal = DataEntryInputGenerator.NULL_VALUES_LONGVERSION.get(val);
                    if (tmpVal != null && tmpVal.length() > 0) {
                        respBean.setText(tmpVal);
                    } else {
                        respBean.setText(val);
                    }
                    respBean.setValue(val);
                    respOptions.add(respBean);
                }
            }
            disBeans.add(displayBean);
        // logger.info("### respOptions size
        // "+respOptions.size()+" of item name "+iBean.getName());
        }
    // logger.info("### found name "+iBean.getName()+" and found
    // response size: "+
    // displayBean.getMetadata().getResponseSet().getOptions().size());
    }
    // sort the List of DisplayItemBeans on their ordinal
    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) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 28 with ResponseOptionBean

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

the class FormBeanUtil method addNullValuesToDisplayItemWithGroupBeans.

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

Example 29 with ResponseOptionBean

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

the class FormBeanUtil method getDisplayBeansFromItemsForPrint.

public static List<DisplayItemBean> getDisplayBeansFromItemsForPrint(List<ItemBean> itemBeans, DataSource dataSource, EventCRFBean eventCrfBean, int sectionId, List<String> nullValuesList, ServletContext context, int crfVersionId) {
    // logger = LoggerFactory.getLogger(getClass().getName());
    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;
    // Add any null values to checks or radios
    String responseName;
    List<ResponseOptionBean> respOptions;
    ResponseOptionBean respBean;
    boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
    String tmpVal = "";
    // findByItemIdAndCRFVersionId
    for (ItemBean iBean : itemBeans) {
        displayBean = new DisplayItemBean();
        //TODO: eventcrfBean is not valid??
        meta = metaDao.findByItemIdAndCRFVersionId(iBean.getId(), crfVersionId);
        // Only include Items that belong to the associated section
        if (meta.getSectionId() == sectionId) {
            displayBean.setItem(iBean);
            //findByItemIdAndEventCRFIdAndOrdinal(iBean.getId(), eventCrfBean.getId(), ordinal)
            ItemDataBean itemDataBean = itemDataDAO.findByItemIdAndEventCRFId(iBean.getId(), eventCrfBean.getId());
            // null values is set by adding the event def. crf bean, but
            // here we have taken a different approach, tbh
            // displayBean.setEventDefinitionCRF();
            displayBean.setMetadata(runDynamicsCheck(meta, eventCrfBean, itemDataBean, context));
            displayBean.setData(itemDataBean);
            displayBean.setDbData(itemDataBean);
            // System.out.println("just set: " + itemDataBean.getValue() + " from " + itemDataBean.getItemId());
            responseName = displayBean.getMetadata().getResponseSet().getResponseType().getName();
            respOptions = displayBean.getMetadata().getResponseSet().getOptions();
            if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
                for (String val : nullValuesList) {
                    respBean = new ResponseOptionBean();
                    // BWP>> set text to the extended version, "not
                    // applicable"?
                    tmpVal = DataEntryInputGenerator.NULL_VALUES_LONGVERSION.get(val);
                    if (tmpVal != null && tmpVal.length() > 0) {
                        respBean.setText(tmpVal);
                    } else {
                        respBean.setText(val);
                    }
                    respBean.setValue(val);
                    respOptions.add(respBean);
                }
            }
            disBeans.add(displayBean);
        // logger.info("### respOptions size
        // "+respOptions.size()+" of item name "+iBean.getName());
        }
    // logger.info("### found name "+iBean.getName()+" and found
    // response size: "+
    // displayBean.getMetadata().getResponseSet().getOptions().size());
    }
    // sort the List of DisplayItemBeans on their ordinal
    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) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 30 with ResponseOptionBean

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

the class DataEntryInputGenerator method createSingleSelectTag.

/*
     * This method generates a single select tag for a cell inside an HTML
     * table. Like the other methods, the user passes in a reference to the
     * Element object, and the object receives new attributes and content. Then
     * the method returns the altered Element object. The options List contains
     * ResponseOptionBeans, which represent each option child element of the
     * select tag.
     */
public Element createSingleSelectTag(Element tdCell, Integer itemId, List options, Integer tabNumber) {
    Element element = new Element("select");
    element.setAttribute("tabindex", tabNumber.toString());
    // A repeating attribute may already have had its "name" attribute set
    if (element.getAttribute("name") == null) {
        element.setAttribute("name", "item" + itemId.toString());
    }
    element.setAttribute("onChange", ONCHANGE_TEXT_INPUT);
    element.setAttribute("class", "formfield");
    Element optElement;
    String optValue;
    String optText;
    for (Object responseOptBean : options) {
        optElement = new Element("option");
        optValue = ((ResponseOptionBean) responseOptBean).getValue();
        optText = ((ResponseOptionBean) responseOptBean).getText();
        optElement.setAttribute("value", optValue);
        if (((ResponseOptionBean) responseOptBean).isSelected()) {
            optElement.setAttribute("selected", "selected");
        }
        optElement.addContent(optText);
        element.addContent(optElement);
    }
    tdCell.addContent(element);
    return tdCell;
}
Also used : Element(org.jdom.Element) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)31 ArrayList (java.util.ArrayList)20 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)9 Element (org.jdom.Element)8 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)5 HashMap (java.util.HashMap)4 NumberFormat (java.text.NumberFormat)3 Iterator (java.util.Iterator)3 NullValue (org.akaza.openclinica.bean.core.NullValue)3 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)3 DisplayItemWithGroupBean (org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)3 Random (java.util.Random)2 HttpSession (javax.servlet.http.HttpSession)2 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)2 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)2 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)2