Search in sources :

Example 36 with DisplayItemBean

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

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

the class FormBeanUtil method getNumberOfColumnsFromItems.

/**
     * Get the highest column number for a List of DisplayItemBeans.
     * 
     * @param displayItems
     *            The List of DisplayItemBeans.
     * @return An int representing the highest column number in the List,
     *         obained by getting the ItemFormMetadataBean columnNumber
     *         property.
     */
public int getNumberOfColumnsFromItems(List<DisplayItemBean> displayItems) {
    if (displayItems == null)
        return 0;
    // one column is the default
    int highestColumnNum = 1;
    int temp;
    for (DisplayItemBean displayItem : displayItems) {
        temp = displayItem.getMetadata().getColumnNumber();
        highestColumnNum = highestColumnNum < temp ? temp : highestColumnNum;
    }
    return highestColumnNum;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Example 38 with DisplayItemBean

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

the class PrintHorizontalFormBuilder method createTheadContentsFromDisplayItems.

public List<Element> createTheadContentsFromDisplayItems(List<DisplayItemBean> displayBeans, boolean generateExtraColumn) {
    List<Element> elements = new ArrayList<Element>();
    ItemFormMetadataBean itemFormBean;
    // header is blank; add question number labels potentially
    for (DisplayItemBean displayBean : displayBeans) {
        itemFormBean = displayBean.getMetadata();
        elements.add(createTHTagFromItemMeta(itemFormBean));
    }
    //        }
    return elements;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 39 with DisplayItemBean

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

the class ViewPersistanceHandler method sortDuplicatesIntoRows.

public Map<Integer, List<DisplayItemBean>> sortDuplicatesIntoRows(List<DisplayItemBean> displayBeans) {
    // We know a DisplayItemBean is part of a duplicate row because its:
    // 1. ItemDataBean ordinal is greater than 1 and
    // 2. it shares the same ordinal with other members of its row.
    Map<Integer, List<DisplayItemBean>> rowMap = new HashMap<Integer, List<DisplayItemBean>>();
    List<DisplayItemBean> mapList = new ArrayList<DisplayItemBean>();
    List<DisplayItemBean> dupesList = new ArrayList<DisplayItemBean>();
    for (DisplayItemBean disBean : displayBeans) {
        if (disBean.getData().getOrdinal() > 1) {
            dupesList.add(disBean);
        }
    }
    // Now separate clusters of the same ordinal into different Lists
    int currentOrdinal = 0;
    int currentItemId = 0;
    for (DisplayItemBean disBean : dupesList) {
        if (currentItemId == 0) {
            currentItemId = disBean.getItem().getId();
            currentOrdinal = disBean.getData().getOrdinal();
            mapList.add(disBean);
            rowMap.put(currentItemId, mapList);
            continue;
        }
        if (disBean.getData().getOrdinal() == currentOrdinal) {
            mapList.add(disBean);
        } else {
            // A different ordinal means create a new row
            currentOrdinal = disBean.getData().getOrdinal();
            mapList = new ArrayList<DisplayItemBean>();
            mapList.add(disBean);
            rowMap.put(disBean.getItem().getId(), mapList);
        }
    }
    return rowMap;
}
Also used : HashMap(java.util.HashMap) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 40 with DisplayItemBean

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

the class DataImportService method submitData.

public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
    boolean discNotesGenerated = false;
    ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
    itemDataDao.setFormatDates(false);
    EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
    StringBuffer auditMsg = new StringBuffer();
    int eventCrfBeanId = -1;
    EventCRFBean eventCrfBean = null;
    ArrayList<Integer> eventCrfInts;
    ItemDataBean itemDataBean;
    CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
    for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
        boolean resetSDV = false;
        logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
        if (wrapper.isSavable()) {
            eventCrfInts = new ArrayList<Integer>();
            logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
            if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
                return getReturnList("fail", "", "No items to submit. Please check your XML.");
            }
            for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
                eventCrfBeanId = displayItemBean.getData().getEventCRFId();
                eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
                logger.debug("found value here: " + displayItemBean.getData().getValue());
                logger.debug("found status here: " + eventCrfBean.getStatus().getName());
                itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
                    if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
                        resetSDV = true;
                    logger.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
                    itemDataBean.setUpdatedDate(new Date());
                    itemDataBean.setUpdater(userBean);
                    itemDataBean.setValue(displayItemBean.getData().getValue());
                    // set status?
                    itemDataDao.update(itemDataBean);
                    logger.debug("updated: " + itemDataBean.getItemId());
                    // need to set pk here in order to create dn
                    displayItemBean.getData().setId(itemDataBean.getId());
                } else {
                    resetSDV = true;
                    itemDataDao.create(displayItemBean.getData());
                    logger.debug("created: " + displayItemBean.getData().getItemId());
                    itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
                    // logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
                    displayItemBean.getData().setId(itemDataBean.getId());
                }
                ItemDAO idao = new ItemDAO(dataSource);
                ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
                // logger.debug("*** checking for validation errors: " + ibean.getName());
                String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
                // wrapper.getValidationErrors().toString());
                if (wrapper.getValidationErrors().containsKey(itemOid)) {
                    ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
                    for (String message : messageList) {
                        DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
                        createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
                        discNotesGenerated = true;
                        logger.debug("*** created disc note with message: " + message);
                        auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
                    // split by this ? later, tbh
                    // displayItemBean);
                    }
                }
                if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
                    String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
                    if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
                        crfBusinessLogicHelper.markCRFStarted(eventCrfBean, userBean, true);
                    } else {
                        crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
                    }
                    eventCrfInts.add(new Integer(eventCrfBean.getId()));
                }
            }
            // Reset the SDV status if item data has been changed or added
            if (eventCrfBean != null && resetSDV)
                eventCrfDao.setSDVStatus(false, userBean.getId(), eventCrfBean.getId());
        }
    }
    if (!discNotesGenerated) {
        return getReturnList("success", "", auditMsg.toString());
    } else {
        return getReturnList("warn", "", auditMsg.toString());
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) CrfBusinessLogicHelper(org.akaza.openclinica.web.job.CrfBusinessLogicHelper) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)

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