Search in sources :

Example 31 with ItemFormMetadataDAO

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

Aggregations

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