Search in sources :

Example 11 with DisplayItemBean

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

the class DataEntryServlet method getParentDisplayItems.

/**
     * For each single item in this section which is a parent, get a DisplayItemBean corresponding to that item. Note that an item is a parent iff its parentId
     * == 0.
     * @param sb
     *            The section whose items we are retrieving.
     * @param hasUngroupedItems
     * @param request TODO
     *
     * @return An array of DisplayItemBean objects, one per parent item in the section. Note that there is no guarantee on the ordering of the objects.
     * @throws Exception
     */
private ArrayList getParentDisplayItems(boolean hasGroup, SectionBean sb, EventDefinitionCRFBean edcb, ItemDAO idao, ItemFormMetadataDAO ifmdao, ItemDataDAO iddao, boolean hasUngroupedItems, HttpServletRequest request) throws Exception {
    ArrayList answer = new ArrayList();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    HashMap displayItems = new HashMap();
    // ArrayList items = idao.findAllParentsBySectionId(sb.getId());
    ArrayList items = new ArrayList();
    ArrayList itemsUngrped = new ArrayList();
    if (hasGroup) {
        // See: FormBeanUtil.sectionHasUngroupedItems.
        if (hasUngroupedItems) {
            // @pgawade 05-Aug-2011 fix for issue 10628 - commented out the
            // if-else logic based on 'hasGroup' flag.
            // 'if' part is unchanged but else part is changed to be
            // executed always because that is to get the non-repeating and
            // ungrouped item details and was getting skipped in case the
            // section has repeating group items plus non-repeating group
            // items
            itemsUngrped = idao.findAllUngroupedParentsBySectionId(sb.getId(), sb.getCRFVersionId());
        }
    // however, if we have true:true, we exclude all grouped items
    // items.addAll(
    // idao.findAllGroupedParentsBySectionId(
    // sb.getId(), sb.getCRFVersionId()));
    }
    // else {
    LOGGER.trace("no item groups");
    // items = idao.findAllParentsBySectionId(sb.getId());
    items = idao.findAllNonRepeatingParentsBySectionId(sb.getId());
    items.addAll(itemsUngrped);
    // }
    LOGGER.debug("items size" + items.size());
    for (int i = 0; i < items.size(); i++) {
        DisplayItemBean dib = new DisplayItemBean();
        dib.setEventDefinitionCRF(edcb);
        ItemBean ib = (ItemBean) items.get(i);
        dib.setItem(ib);
        displayItems.put(new Integer(dib.getItem().getId()), dib);
    }
    ArrayList data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(idb.getItemId()));
        if (dib != null) {
            dib.setData(idb);
            dib.setDbData((ItemDataBean) BeanUtils.cloneBean(idb));
            displayItems.put(new Integer(idb.getItemId()), dib);
        }
    }
    ArrayList metadata = ifmdao.findAllBySectionId(sb.getId());
    for (int i = 0; i < metadata.size(); i++) {
        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metadata.get(i);
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(new Integer(ifmb.getItemId()));
        if (dib != null) {
            // boolean showItem = false;
            boolean needsHighlighting = !ifmb.isShowItem();
            logMe("Entering thread before getting ItemMetadataService:::" + Thread.currentThread());
            boolean showItem = getItemMetadataService().isShown(ifmb.getItemId(), ecb, dib.getData());
            if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
                showItem = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
            }
            // is the above needed for children items too?
            boolean passedDDE = getItemMetadataService().hasPassedDDE(ifmb, ecb, dib.getData());
            if (showItem) {
                // we are only showing, not hiding
                LOGGER.debug("set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE);
                // ifmb.setShowItem(showItem);
                ifmb.setShowItem(true);
            } else {
                LOGGER.debug("DID NOT set show item " + ifmb.getItemId() + " idb " + dib.getData().getId() + " show item " + showItem + " passed dde " + passedDDE + " value " + dib.getData().getValue());
            }
            dib.setMetadata(ifmb);
            displayItems.put(new Integer(ifmb.getItemId()), dib);
        }
    }
    Iterator hmIt = displayItems.keySet().iterator();
    while (hmIt.hasNext()) {
        Integer key = (Integer) hmIt.next();
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(key);
        answer.add(dib);
        LOGGER.debug("*** getting with key: " + key + " display item bean with value: " + dib.getData().getValue());
    }
    LOGGER.debug("*** test of the display items: " + displayItems.toString());
    return answer;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) Iterator(java.util.Iterator) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 12 with DisplayItemBean

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

the class DataEntryServlet method loadItemsWithGroupRows.

protected void loadItemsWithGroupRows(DisplayItemWithGroupBean itemWithGroup, SectionBean sb, EventDefinitionCRFBean edcb, EventCRFBean ecb, HttpServletRequest request) {
    //this method is a copy of the method: createItemWithGroups ,
    //only modified for load one DisplayItemWithGroupBean.
    //
    ItemDAO idao = new ItemDAO(getDataSource());
    // For adding null values to display items
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<String> nullValuesList = new ArrayList<String>();
    // BWP>> Get a List<String> of any null values such as NA or NI
    // method returns null values as a List<String>
    nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(edcb.getId(), getDataSource());
    // >>BWP
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    ArrayList data = iddao.findAllActiveBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
    DisplayItemGroupBean itemGroup = itemWithGroup.getItemGroup();
    // to arrange item groups and other single items, the ordinal of
    // a item group will be the ordinal of the first item in this
    // group
    DisplayItemBean firstItem = itemGroup.getItems().get(0);
    DisplayItemBean checkItem = firstItem;
    // does not work if there is not any data in the first item of the group
    // i.e. imports.
    // does it make a difference if we take a last item?
    boolean noNeedToSwitch = false;
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        if (idb.getItemId() == firstItem.getItem().getId()) {
            noNeedToSwitch = true;
        }
    }
    if (!noNeedToSwitch) {
        checkItem = itemGroup.getItems().get(itemGroup.getItems().size() - 1);
    }
    // so we are either checking the first or the last item, BUT ONLY ONCE
    itemWithGroup.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
    itemWithGroup.setItemGroup(itemGroup);
    itemWithGroup.setInGroup(true);
    itemWithGroup.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
    List<ItemBean> itBeans = idao.findAllItemsByGroupId(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
    boolean hasData = false;
    int checkAllColumns = 0;
    // first item should be same as the row number
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        LOGGER.debug("check all columns: " + checkAllColumns);
        if (idb.getItemId() == checkItem.getItem().getId()) {
            hasData = true;
            LOGGER.debug("set has data to --TRUE--");
            checkAllColumns = 0;
            // so that we only fire once a row
            LOGGER.debug("has data set to true");
            DisplayItemGroupBean digb = new DisplayItemGroupBean();
            // always get a fresh copy for items, may use other
            // better way to
            // do deep copy, like clone
            List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), edcb, 0, getServletContext());
            digb.setItems(dibs);
            LOGGER.trace("set with dibs list of : " + dibs.size());
            digb.setGroupMetaBean(runDynamicsCheck(itemGroup.getGroupMetaBean(), request));
            digb.setItemGroupBean(itemGroup.getItemGroupBean());
            itemWithGroup.getItemGroups().add(digb);
            itemWithGroup.getDbItemGroups().add(digb);
        }
    }
    List<DisplayItemGroupBean> groupRows = itemWithGroup.getItemGroups();
    LOGGER.trace("how many group rows:" + groupRows.size());
    LOGGER.trace("how big is the data:" + data.size());
    if (hasData) {
        // the group
        for (int i = 0; i < groupRows.size(); i++) {
            DisplayItemGroupBean displayGroup = groupRows.get(i);
            for (DisplayItemBean dib : displayGroup.getItems()) {
                for (int j = 0; j < data.size(); j++) {
                    ItemDataBean idb = (ItemDataBean) data.get(j);
                    if (idb.getItemId() == dib.getItem().getId() && !idb.isSelected()) {
                        idb.setSelected(true);
                        dib.setData(idb);
                        LOGGER.debug("--> set data " + idb.getId() + ": " + idb.getValue());
                        if (shouldLoadDBValues(dib)) {
                            LOGGER.debug("+++should load db values is true, set value");
                            dib.loadDBValue();
                            LOGGER.debug("+++data loaded: " + idb.getName() + ": " + idb.getOrdinal() + " " + idb.getValue());
                            LOGGER.debug("+++try dib OID: " + dib.getItem().getOid());
                        }
                        break;
                    }
                }
            }
        }
    } else {
        // no data, still add a blank row for displaying
        DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
        List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
        digb2.setItems(dibs);
        LOGGER.trace("set with nullValuesList of : " + nullValuesList);
        digb2.setEditFlag("initial");
        digb2.setGroupMetaBean(itemGroup.getGroupMetaBean());
        digb2.setItemGroupBean(itemGroup.getItemGroupBean());
        itemWithGroup.getItemGroups().add(digb2);
        itemWithGroup.getDbItemGroups().add(digb2);
    }
}
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) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Example 13 with DisplayItemBean

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

the class DataEntryServlet method populateNotesWithDBNoteCounts.

/*
     * change to explicitly re-set the section bean after reviewing the disc note counts, tbh 01/2010
     */
protected DisplaySectionBean populateNotesWithDBNoteCounts(FormDiscrepancyNotes discNotes, DisplaySectionBean section, HttpServletRequest request) {
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
    // ArrayList items = section.getItems();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    ArrayList<DiscrepancyNoteBean> ecNotes = dndao.findEventCRFDNotesFromEventCRF(ecb);
    ArrayList<DiscrepancyNoteBean> existingNameNotes = new ArrayList(), nameNotes = new ArrayList();
    ArrayList<DiscrepancyNoteBean> existingIntrvDateNotes = new ArrayList(), dateNotes = new ArrayList();
    long t = System.currentTimeMillis();
    logMe("Method:populateNotesWithDBNoteCounts" + t);
    int intNew = 0, intRes = 0, intUpdated = 0, intClosed = 0, intNA = 0;
    int dateNew = 0, dateRes = 0, dateUpdated = 0, dateClosed = 0, dateNA = 0;
    boolean hasMoreThreads = false;
    for (int i = 0; i < ecNotes.size(); i++) {
        DiscrepancyNoteBean dn = ecNotes.get(i);
        if (INTERVIEWER_NAME.equalsIgnoreCase(dn.getColumn())) {
            discNotes.setNumExistingFieldNotes(INPUT_INTERVIEWER, 1);
            request.setAttribute("hasNameNote", "yes");
            request.setAttribute(INTERVIEWER_NAME_NOTE, dn);
            if (dn.getParentDnId() == 0)
                existingNameNotes.add(dn);
        }
        if (DATE_INTERVIEWED.equalsIgnoreCase(dn.getColumn())) {
            discNotes.setNumExistingFieldNotes(INPUT_INTERVIEW_DATE, 1);
            request.setAttribute("hasDateNote", "yes");
            request.setAttribute(INTERVIEWER_DATE_NOTE, dn);
            if (dn.getParentDnId() == 0)
                existingIntrvDateNotes.add(dn);
        }
    }
    logMe("Method:populateNotesWithDBNoteCounts before calling setToolTipEventNotes" + System.currentTimeMillis() + "time took:" + (System.currentTimeMillis() - t));
    setToolTipEventNotes(request);
    request.setAttribute("nameNoteResStatus", getDiscrepancyNoteResolutionStatus(existingNameNotes));
    request.setAttribute("IntrvDateNoteResStatus", getDiscrepancyNoteResolutionStatus(existingIntrvDateNotes));
    request.setAttribute("existingNameNotes", existingNameNotes);
    request.setAttribute("existingIntrvDateNotes", existingIntrvDateNotes);
    List<DisplayItemWithGroupBean> allItems = section.getDisplayItemGroups();
    LOGGER.debug("start to populate notes: " + section.getDisplayItemGroups().size());
    this.output(allItems);
    logMe("Looping through allItems time:" + System.currentTimeMillis() + "time took from the begining" + (System.currentTimeMillis() - t));
    for (int k = 0; k < allItems.size(); k++) {
        DisplayItemWithGroupBean itemWithGroup = allItems.get(k);
        if (itemWithGroup.isInGroup()) {
            LOGGER.debug("group item DNote...");
            List<DisplayItemGroupBean> digbs = itemWithGroup.getItemGroups();
            LOGGER.trace("digbs size: " + digbs.size());
            for (int i = 0; i < digbs.size(); i++) {
                DisplayItemGroupBean displayGroup = digbs.get(i);
                List<DisplayItemBean> items = displayGroup.getItems();
                for (int j = 0; j < items.size(); j++) {
                    DisplayItemBean dib = items.get(j);
                    int itemDataId = dib.getData().getId();
                    int numNotes = dndao.findNumExistingNotesForItem(itemDataId);
                    int numNotes1 = dndao.findNumOfActiveExistingNotesForItemData(itemDataId);
                    int ordinal = this.getManualRows(digbs);
                    String inputName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), dib);
                    if (!displayGroup.isAuto()) {
                        inputName = getGroupItemManualInputName(displayGroup, i, dib);
                    }
                    discNotes.setNumExistingFieldNotes(inputName, numNotes1);
                    ArrayList notes = discNotes.getNotes(inputName);
                    // + notes2.size());
                    dib.setNumDiscrepancyNotes(numNotes + notes.size());
                    dib.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(itemDataId, notes));
                    dib = setTotals(dib, itemDataId, notes, ecb.getId());
                    LOGGER.debug("dib note size:" + dib.getNumDiscrepancyNotes() + " " + dib.getData().getId() + " " + inputName);
                    items.set(j, dib);
                }
                displayGroup.setItems(items);
                digbs.set(i, displayGroup);
            }
            itemWithGroup.setItemGroups(digbs);
        } else {
            LOGGER.trace("single item db note");
            DisplayItemBean dib = itemWithGroup.getSingleItem();
            try {
                ResponseOptionBean rob = (ResponseOptionBean) dib.getMetadata().getResponseSet().getOptions().get(0);
                LOGGER.trace("test print of options for coding: " + rob.getValue());
            } catch (NullPointerException e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            }
            int itemDataId = dib.getData().getId();
            int itemId = dib.getItem().getId();
            int numNotes = dndao.findNumExistingNotesForItem(itemDataId);
            int numNotes1 = dndao.findNumOfActiveExistingNotesForItemData(itemDataId);
            String inputFieldName = "input" + itemId;
            discNotes.setNumExistingFieldNotes(inputFieldName, numNotes1);
            dib.setNumDiscrepancyNotes(numNotes + discNotes.getNotes(inputFieldName).size());
            dib.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(itemDataId, discNotes.getNotes(inputFieldName)));
            dib = setTotals(dib, itemDataId, discNotes.getNotes(inputFieldName), ecb.getId());
            ArrayList childItems = dib.getChildren();
            for (int j = 0; j < childItems.size(); j++) {
                DisplayItemBean child = (DisplayItemBean) childItems.get(j);
                int childItemDataId = child.getData().getId();
                int childItemId = child.getItem().getId();
                int childNumNotes = dndao.findNumExistingNotesForItem(childItemDataId);
                String childInputFieldName = "input" + childItemId;
                LOGGER.debug("*** setting " + childInputFieldName);
                discNotes.setNumExistingFieldNotes(childInputFieldName, childNumNotes);
                child.setNumDiscrepancyNotes(childNumNotes + discNotes.getNotes(childInputFieldName).size());
                child.setDiscrepancyNoteStatus(getDiscrepancyNoteResolutionStatus(childItemDataId, discNotes.getNotes(childInputFieldName)));
                child = setTotals(child, childItemDataId, discNotes.getNotes(childInputFieldName), ecb.getId());
                childItems.set(j, child);
            }
            dib.setChildren(childItems);
            itemWithGroup.setSingleItem(runDynamicsItemCheck(dib, null, request));
        }
        // missing piece of the puzzle - reset the itemgroup into all items?
        allItems.set(k, itemWithGroup);
    }
    section.setDisplayItemGroups(allItems);
    return section;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Example 14 with DisplayItemBean

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

the class DataEntryServlet method createItemWithGroups.

//@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method createItemWithGroups
protected List<DisplayItemWithGroupBean> createItemWithGroups(DisplaySectionBean dsb, boolean hasItemGroup, int eventCRFDefId, HttpServletRequest request, boolean isSubmitted) {
    HttpSession session = request.getSession();
    List<DisplayItemWithGroupBean> displayItemWithGroups = new ArrayList<DisplayItemWithGroupBean>();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    ItemDAO idao = new ItemDAO(getDataSource());
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    // BWP>> Get a List<String> of any null values such as NA or NI
    // method returns null values as a List<String>
    // >>BWP
    ArrayList items = dsb.getItems();
    // For adding null values to display items
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<String> nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(eventCRFDefId, getDataSource());
    LOGGER.trace("single items size: " + items.size());
    for (int i = 0; i < items.size(); i++) {
        DisplayItemBean item = (DisplayItemBean) items.get(i);
        DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
        newOne.setSingleItem(runDynamicsItemCheck(item, null, request));
        newOne.setOrdinal(item.getMetadata().getOrdinal());
        newOne.setInGroup(false);
        newOne.setPageNumberLabel(item.getMetadata().getPageNumberLabel());
        displayItemWithGroups.add(newOne);
    // logger.trace("just added on line 1979:
    // "+newOne.getSingleItem().getData().getValue());
    }
    if (hasItemGroup) {
        ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
        ArrayList<ItemDataBean> data = iddao.findAllBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
        HashMap<String, ItemDataBean> dataMap = (HashMap<String, ItemDataBean>) getAllActive(data);
        if (data != null && data.size() > 0) {
            session.setAttribute(HAS_DATA_FLAG, true);
        }
        LOGGER.trace("found data: " + data.size());
        LOGGER.trace("data.toString: " + data.toString());
        for (DisplayItemGroupBean itemGroup : dsb.getDisplayFormGroups()) {
            LOGGER.debug("found one itemGroup");
            DisplayItemWithGroupBean newOne = new DisplayItemWithGroupBean();
            // to arrange item groups and other single items, the ordinal of
            // a item group will be the ordinal of the first item in this
            // group
            DisplayItemBean firstItem = itemGroup.getItems().get(0);
            // so we are either checking the first or the last item, BUT ONLY ONCE
            newOne.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
            newOne.setItemGroup(itemGroup);
            newOne.setInGroup(true);
            newOne.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
            List<ItemBean> itBeans = idao.findAllItemsByGroupIdOrdered(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
            List<DisplayItemBean> dibs = new ArrayList();
            boolean hasData = false;
            int checkAllColumns = 0;
            if (data.size() > 0)
                hasData = true;
            //@pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method buildMatrixForRepeatingGroups
            newOne = buildMatrixForRepeatingGroups(newOne, itemGroup, ecb, sb, itBeans, dataMap, nullValuesList, isSubmitted);
            if (hasData) {
                //TODO: fix the group_has_data flag on bean not on session
                session.setAttribute(GROUP_HAS_DATA, Boolean.TRUE);
            } else {
                session.setAttribute(GROUP_HAS_DATA, Boolean.FALSE);
                // no data, still add a blank row for displaying
                if (nullValuesList != null && nullValuesList.size() > 0) {
                    LOGGER.trace("set with nullValuesList of : " + nullValuesList);
                }
                dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
                DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
                digb2.setItems(dibs);
                digb2.setEditFlag("initial");
            }
            displayItemWithGroups.add(newOne);
        }
    }
    // if hasItemGroup
    Collections.sort(displayItemWithGroups);
    return displayItemWithGroups;
}
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) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 15 with DisplayItemBean

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

the class DataEntryServlet method loadFormValueForItemGroup.

/**
     * This methods will create an array of DisplayItemGroupBean, which contains multiple rows for an item group on the data entry form.
     *
     * @param digb
     *            The Item group which has multiple data rows
     * @param dbGroups
     *            The original array got from DB which contains multiple data rows
     * @param formGroups
     *            The new array got from front end which contains multiple data rows
     * @param request TODO
     * @return new constructed formGroups, compare to dbGroups, some rows are update, some new ones are added and some are removed
     */
protected List<DisplayItemGroupBean> loadFormValueForItemGroup(DisplayItemGroupBean digb, List<DisplayItemGroupBean> dbGroups, List<DisplayItemGroupBean> formGroups, int eventDefCRFId, HttpServletRequest request) {
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    int repeatMax = digb.getGroupMetaBean().getRepeatMax();
    FormProcessor fp = new FormProcessor(request);
    ItemDAO idao = new ItemDAO(getDataSource());
    List<ItemBean> itBeans = idao.findAllItemsByGroupId(digb.getItemGroupBean().getId(), sb.getCRFVersionId());
    LOGGER.debug("+++ starting to review groups: " + repeatMax);
    long timeCheck = System.currentTimeMillis();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    // adding this code from below, since we want to pass a null values list
    // in all cases of getDisplayBeansFromItems().
    // For adding null values to display items
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<String> nullValuesList = new ArrayList<String>();
    // BWP>> Get a List<String> of any null values such as NA or NI
    // method returns null values as a List<String>
    nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(eventDefCRFId, getDataSource());
    // >>BWP
    // logger.trace("+++ starting to review groups 2: " + repeatMax);
    long two = System.currentTimeMillis() - timeCheck;
    // logger.trace("time 2: " + two + "ms");
    // >>TBH below dual for loops need a breaker to avoid a performance hit
    int firstLoopBreak = 0;
    int secondLoopBreak = 0;
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    int maxOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, digb.getItemGroupBean());
    repeatMax = (repeatMax < maxOrdinal) ? maxOrdinal : repeatMax;
    for (int i = 0; i < repeatMax; i++) {
        DisplayItemGroupBean formGroup = new DisplayItemGroupBean();
        formGroup.setItemGroupBean(digb.getItemGroupBean());
        formGroup.setGroupMetaBean(runDynamicsCheck(digb.getGroupMetaBean(), request));
        ItemGroupBean igb = digb.getItemGroupBean();
        // want to do deep copy here, so always get a fresh copy for items,
        // may use other better way to do, like clone
        List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
        // and then get newly created rows later, tbh 01/2010
        if (fp.getStartsWith(igb.getOid() + "_manual" + i + "input")) {
            formGroup.setOrdinal(i);
            formGroup.setFormInputOrdinal(i);
            formGroup.setAuto(false);
            formGroup.setInputId(igb.getOid() + "_manual" + i);
            LOGGER.debug("1: set auto to false for " + igb.getOid() + " " + i);
            dibs = processInputForGroupItem(fp, dibs, i, digb, false);
            formGroup.setItems(dibs);
            formGroups.add(formGroup);
        } else if (!StringUtil.isBlank(fp.getString(igb.getOid() + "_manual" + i + ".newRow"))) {
            // ||
            // (fp.getStartsWith(igb.getOid() + "_manual" + i + "input"))) {
            // the ordinal is the number got from [ ] and submitted by
            // repetition javascript
            formGroup.setOrdinal(i);
            formGroup.setFormInputOrdinal(i);
            formGroup.setInputId(igb.getOid() + "_manual" + i + ".newRow");
            formGroup.setAuto(false);
            LOGGER.debug("2: set auto to false for " + igb.getOid() + " " + i);
            dibs = processInputForGroupItem(fp, dibs, i, digb, false);
            formGroup.setItems(dibs);
            formGroups.add(formGroup);
        } else {
            firstLoopBreak++;
        }
        if (firstLoopBreak > 14) {
            LOGGER.debug("break first loop");
            break;
        }
    }
    // end of for (int i = 0; i < repeatMax; i++)
    // >>TBH remove the above eventually, repeat some work here?
    LOGGER.trace("+++ starting to review groups 3: " + repeatMax);
    two = System.currentTimeMillis() - timeCheck;
    LOGGER.trace("time 3: " + two + "ms");
    // had the call to form bean utils here, tbh
    for (int i = 0; i < repeatMax; i++) {
        DisplayItemGroupBean formGroup = new DisplayItemGroupBean();
        formGroup.setItemGroupBean(digb.getItemGroupBean());
        //            try {
        //                // set isShown here, tbh 04/2010
        //                boolean showGroup = getItemMetadataService().isGroupShown(digb.getGroupMetaBean().getId(), ecb);
        //                logger.debug("found show group for group meta bean " + digb.getGroupMetaBean().getId() + ": " + showGroup);
        //                if (showGroup) {
        //                    digb.getGroupMetaBean().setShowGroup(showGroup);
        //                    // we are only hiding, not showing (for now) tbh
        //                }
        //                // << tbh 04/2010
        //            } catch (OpenClinicaException oce) {
        //                // do nothing for right now, just store the bean
        //                logger.debug("throws an OCE for " + digb.getGroupMetaBean().getId());
        //            }
        formGroup.setGroupMetaBean(runDynamicsCheck(digb.getGroupMetaBean(), request));
        ItemGroupBean igb = digb.getItemGroupBean();
        // adding this code from below, since we want to pass a null values
        // list
        // in all cases of getDisplayBeansFromItems().
        // For adding null values to display items
        // FormBeanUtil formBeanUtil = new FormBeanUtil();
        // List<String> nullValuesList = new ArrayList<String>();
        // BWP>> Get a List<String> of any null values such as NA or NI
        // method returns null values as a List<String>
        // >>BWP
        // want to do deep copy here, so always get a fresh copy for items,
        // may use other better way to do, like clone
        // moved it back down here to fix another bug, tbh 12-3-2007
        List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
        LOGGER.trace("+++count for dibs after deep copy: " + dibs.size());
        two = System.currentTimeMillis() - timeCheck;
        // created by rep model(add button)
        if (fp.getStartsWith(igb.getOid() + "_" + i + "input")) {
            formGroup.setInputId(igb.getOid() + "_" + i);
            if (i == 0) {
                // ordinal that will be saved into
                formGroup.setOrdinal(i);
            // DB
            } else {
                // from 0 again, the
                formGroup.setFormInputOrdinal(i);
            // ordinal from front
            // end page, needs to be
            // reprocessed
            }
            formGroup.setAuto(true);
            LOGGER.debug("1: set auto to TRUE for " + igb.getOid() + " " + i);
            dibs = processInputForGroupItem(fp, dibs, i, digb, true);
            LOGGER.trace("+++ group ordinal: " + i + " igb name " + igb.getName());
            formGroup.setItems(dibs);
            formGroups.add(formGroup);
        } else if (!StringUtil.isBlank(fp.getString(igb.getOid() + "_" + i + ".newRow"))) {
            // || (fp.getStartsWith(igb.getOid() + "_" + i + "input"))) {
            // the ordinal is the number got from [ ] and submitted by
            // repetition javascript
            formGroup.setInputId(igb.getOid() + "_" + i);
            if (i == 0) {
                // ordinal that will be saved into
                formGroup.setOrdinal(i);
            // DB
            } else {
                // from 0 again, the
                formGroup.setFormInputOrdinal(i);
            // ordinal from front
            // end page, needs to be
            // reprocessed
            }
            // String fieldName = igb.getOid() + "_" + i + this.getInputName(dib);
            // if (!StringUtil.isBlank(fp.getString(fieldName))) {
            // if (i != repeatMax) {
            // formGroup.setAuto(false);
            // logger.debug("set auto to false for " + igb.getOid() + " " + i);
            // } else {
            formGroup.setAuto(true);
            LOGGER.debug("2: set auto to TRUE for " + igb.getOid() + " " + i);
            dibs = processInputForGroupItem(fp, dibs, i, digb, true);
            LOGGER.trace("+++ group ordinal: " + i + " igb name " + igb.getName());
            formGroup.setItems(dibs);
            formGroups.add(formGroup);
        } else {
            secondLoopBreak++;
        }
        if (secondLoopBreak > 14) {
            LOGGER.debug("break second loop");
            break;
        }
    }
    // end of for (int i = 0; i < repeatMax; i++)
    LOGGER.debug("first loop: " + firstLoopBreak);
    LOGGER.debug("second loop: " + secondLoopBreak);
    LOGGER.trace("+++ starting to review groups 4: " + repeatMax);
    two = System.currentTimeMillis() - timeCheck;
    LOGGER.trace("time 4: " + two + "ms");
    // checks how many rows are manually created, not added by repetition
    // model
    int manualRows = getManualRows(formGroups);
    // for (int j = 0; j < formGroups.size(); j++) {
    // DisplayItemGroupBean formItemGroup = formGroups.get(j);
    // // logger.trace("begin formGroup Ordinal:" +
    // // formItemGroup.getOrdinal());
    // if (formItemGroup.isAuto() == false) {
    // manualRows = manualRows + 1;
    // }
    // }
    LOGGER.debug(" manual rows " + manualRows + " formGroup size " + formGroups.size());
    request.setAttribute("manualRows", new Integer(manualRows));
    // reset ordinal for the auto-created rows except for the first row
    for (int j = 0; j < formGroups.size(); j++) {
        DisplayItemGroupBean formItemGroup = formGroups.get(j);
        if (formItemGroup.isAuto() && formItemGroup.getFormInputOrdinal() > 0) {
            LOGGER.trace("+++ formInputOrdinal() " + formItemGroup.getFormInputOrdinal());
            // rows included in the model: first row, last existing row and
            // new rows
            // the rows in between are manually added
            // set the correct ordinal that will be saved into DB
            // the rows generated by model starts from 0, need to add the
            // number of manual rows to
            // get the correct ordinals, otherwise, we will have duplicate
            // ordinals like two ordinal 0
            formItemGroup.setOrdinal(formItemGroup.getFormInputOrdinal() + manualRows);
        }
    }
    LOGGER.trace("+++ starting to review groups 5: " + repeatMax);
    two = System.currentTimeMillis() - timeCheck;
    LOGGER.trace("time 5: " + two + "ms");
    // sort all the rows by ordinal
    Collections.sort(formGroups);
    LOGGER.trace("group row size:" + formGroups.size());
    // suppose we have 3 rows of data from db, the orginal order is 0,1,2,
    // repetition model will submit row number in [ ] like the following:
    // 0,1,2.. consecutive numbers, means no row removed in between
    // 0,1,3,4.. the 2rd row is removed, 3 and 4 are new rows
    int previous = -1;
    for (int j = 0; j < formGroups.size(); j++) {
        DisplayItemGroupBean formItemGroup = formGroups.get(j);
        LOGGER.trace("formGroup Ordinal:" + formItemGroup.getOrdinal());
        // tbh 08/2009
        if (formItemGroup.getOrdinal() == previous) {
            LOGGER.debug("found a match btw previous and ordinal");
            formItemGroup.setEditFlag("edit");
            formItemGroup.setOrdinal(previous + 1);
        // dbGroups.get(j).setEditFlag("edit");
        }
        // << tbh 08/2009
        if (formItemGroup.getOrdinal() > dbGroups.size() - 1) {
            formItemGroup.setEditFlag("add");
        } else {
            for (int i = 0; i < dbGroups.size(); i++) {
                DisplayItemGroupBean dbItemGroup = dbGroups.get(i);
                if (formItemGroup.getOrdinal() == i) {
                    // display, so need to insert this row, not update
                    if ("initial".equalsIgnoreCase(dbItemGroup.getEditFlag())) {
                        formItemGroup.setEditFlag("add");
                    } else {
                        dbItemGroup.setEditFlag("edit");
                        // need to set up item data id in order to update
                        for (DisplayItemBean dib : dbItemGroup.getItems()) {
                            ItemDataBean data = dib.getData();
                            for (DisplayItemBean formDib : formItemGroup.getItems()) {
                                if (formDib.getItem().getId() == dib.getItem().getId()) {
                                    formDib.getData().setId(data.getId());
                                    // this will save the data from IDE
                                    // complete, used only for DDE
                                    formDib.setDbData(dib.getData());
                                    // tbh removed below line so as not to
                                    // log so much, 112007
                                    LOGGER.debug("+++ +++ form dib get data set id " + data.getId());
                                    break;
                                }
                            }
                        }
                        formItemGroup.setEditFlag("edit");
                    }
                    // else
                    break;
                }
            }
        }
        // else
        previous = formItemGroup.getOrdinal();
    }
    LOGGER.trace("+++ === DB group row:" + dbGroups.size());
    LOGGER.trace("+++ === DB group contents: " + dbGroups.toString());
    // cannot get it.-jxu
    for (int i = 0; i < dbGroups.size(); i++) {
        DisplayItemGroupBean dbItemGroup = dbGroups.get(i);
        LOGGER.trace("+++ found edit flag of " + dbItemGroup.getEditFlag() + " for #" + dbItemGroup.getOrdinal());
        // logger.debug("+++ found edit flag of " + dbItemGroup.getEditFlag() + " for #" + dbItemGroup.getOrdinal() + ": " + i);
        if (!"edit".equalsIgnoreCase(dbItemGroup.getEditFlag()) && !"initial".equalsIgnoreCase(dbItemGroup.getEditFlag())) {
            // >> tbh if the group is not shown, we should not touch it 05/2010
            if (dbItemGroup.getGroupMetaBean().isShowGroup()) {
                LOGGER.trace("+++ one row removed, edit flag was " + dbItemGroup.getEditFlag());
                LOGGER.debug("+++ one row removed, edit flag was " + dbItemGroup.getEditFlag());
                dbItemGroup.setEditFlag("remove");
            }
        // << tbh
        }
    }
    LOGGER.debug("+++ about to return form groups: " + formGroups.toString());
    for (int j = 0; j < formGroups.size(); j++) {
        DisplayItemGroupBean formGroup = formGroups.get(j);
        formGroup.setIndex(j);
    }
    return formGroups;
}
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) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean)

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