Search in sources :

Example 1 with FormBeanUtil

use of org.akaza.openclinica.view.form.FormBeanUtil in project OpenClinica by OpenClinica.

the class DataEntryServlet method getDisplayBean.

/**
 * Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
 * @param request TODO
 * @param isSubmitted TODO
 */
protected DisplaySectionBean getDisplayBean(boolean hasGroup, boolean includeUngroupedItems, HttpServletRequest request, boolean isSubmitted) throws Exception {
    DisplaySectionBean section = new DisplaySectionBean();
    FormProcessor fp = new FormProcessor(request);
    HttpSession session = request.getSession();
    Locale loc = this.locale == null ? LocaleResolver.getLocale(request) : this.locale;
    StudyBean study = (StudyBean) session.getAttribute("study");
    SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    SectionDAO sdao;
    // Find out whether there are ungrouped items in this section
    boolean hasUngroupedItems = false;
    int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    if (eventDefinitionCRFId <= 0) {
        // TODO: this block of code repeats
        // many times, need to clean up
        // synchronized(this)
        {
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
            EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
            eventDefinitionCRFId = edcBean.getId();
        }
    }
    LOGGER.trace("eventDefinitionCRFId " + eventDefinitionCRFId);
    // Use this class to find out whether there are ungrouped items in this
    // section
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
    if (hasGroup) {
        DisplaySectionBean newDisplayBean = new DisplaySectionBean();
        if (includeUngroupedItems) {
            // Null values: this method adds null values to the
            // displayitembeans
            newDisplayBean = formBeanUtil.createDisplaySectionBWithFormGroups(sb.getId(), ecb.getCRFVersionId(), getDataSource(), eventDefinitionCRFId, ecb, getServletContext());
        } else {
            newDisplayBean = formBeanUtil.createDisplaySectionWithItemGroups(study, sb.getId(), ecb, ecb.getStudyEventId(), sm, eventDefinitionCRFId, getServletContext());
        }
        itemGroups = newDisplayBean.getDisplayFormGroups();
        // setDataForDisplayItemGroups(itemGroups, sb,ecb,sm);
        LOGGER.trace("found item group size: " + itemGroups.size() + " and to string: " + itemGroups.toString());
        section.setDisplayFormGroups(itemGroups);
    }
    // Find out whether any display items are *not* grouped; see issue 1689
    hasUngroupedItems = formBeanUtil.sectionHasUngroupedItems(getDataSource(), sb.getId(), itemGroups);
    sdao = new SectionDAO(getDataSource());
    // 
    sb.setHasSCDItem(hasUngroupedItems ? sdao.hasSCDItem(sb.getId()) : false);
    section.setEventCRF(ecb);
    if (sb.getParentId() > 0) {
        SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
        sb.setParent(parent);
    }
    section.setSection(sb);
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
    section.setCrfVersion(cvb);
    CRFDAO cdao = new CRFDAO(getDataSource());
    CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
    section.setCrf(cb);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    // EventDefinitionCRFBean edcb =
    // edcdao.findByStudyEventIdAndCRFVersionId(study,
    // ecb.getStudyEventId(), cvb.getId());
    section.setEventDefinitionCRF(edcb);
    // setup DAO's here to avoid creating too many objects
    ItemDAO idao = new ItemDAO(getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), loc);
    // Use itemGroups to determine if there are any ungrouped items
    // get all the parent display item beans not in group
    logMe("Entering getParentDisplayItems::: Thread is? " + Thread.currentThread());
    ArrayList displayItems = getParentDisplayItems(hasGroup, sb, edcb, idao, ifmdao, iddao, hasUngroupedItems, request);
    logMe("Entering getParentDisplayItems::: Done and Thread is? " + Thread.currentThread());
    LOGGER.debug("just ran get parent display, has group " + hasGroup + " has ungrouped " + hasUngroupedItems);
    // now sort them by ordinal,
    // JN: Commenting out this logic, its wrong and will give erroneous results.
    Collections.sort(displayItems);
    // now get the child DisplayItemBeans
    for (int i = 0; i < displayItems.size(); i++) {
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
        dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
        // 
        if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
            if (shouldLoadDBValues(dib) && !isSubmitted) {
                dib.loadDBValue();
            }
        } else {
            if (shouldLoadDBValues(dib)) {
                LOGGER.trace("should load db values is true, set value");
                dib.loadDBValue();
                LOGGER.trace("just got data loaded: " + dib.getData().getValue());
            }
        }
        displayItems.set(i, dib);
    }
    section.setItems(displayItems);
    return section;
}
Also used : Locale(java.util.Locale) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) HttpSession(javax.servlet.http.HttpSession) SessionManager(org.akaza.openclinica.core.SessionManager) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 2 with FormBeanUtil

use of org.akaza.openclinica.view.form.FormBeanUtil 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 3 with FormBeanUtil

use of org.akaza.openclinica.view.form.FormBeanUtil 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
 *            FormProcessor holds the form data in a key-value pair with the following structure
 *              The first row of data points and new rows have a key that looks like GROUPOID_XinputITEMID
 *                  example: IG_01REP_01REPEATING_0input3008
 *              The existing rows of data points have a key that looks like GROUPOID_manualXinputITEMID
 *                  example: IG_01REP_01REPEATING_manual1input3008
 * @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());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    int maxOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, digb.getItemGroupBean());
    repeatMax = (repeatMax < maxOrdinal) ? maxOrdinal : repeatMax;
    // //////////////////////////////////////////////////////////////////////////////////////////
    // counter for rows preexisting data
    int manualRows = 1;
    // holds the ordinal of new data
    int newDataRowOrdinal = 0;
    // Size of existing repeating data retrieved from database
    int existingGroupSize = dbGroups.size();
    // Need to go through all of the rows of data
    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());
        // Process preexisting data marked by the word "manual" from the UI
        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);
            manualRows++;
        } else if (!StringUtil.isBlank(fp.getString(igb.getOid() + "_manual" + i + ".newRow"))) {
            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);
            manualRows++;
        } else if (manualRows == existingGroupSize || isNewRepeatingDataPresent(fp, i, igb)) {
            // process the new data of repeating group instances
            if (i == 0) {
                formGroup = processNewDataInRepeatingGroup(fp, igb, i, dibs, digb, formGroup);
            } else {
                formGroup = processNewDataInRepeatingGroup(fp, igb, newDataRowOrdinal, dibs, digb, formGroup);
            }
            // within the remaining data group displayed on the form
            if (formGroup != null) {
                if (formGroup.isAuto() && formGroup.getFormInputOrdinal() > 0) {
                    LOGGER.trace("+++ formInputOrdinal() " + formGroup.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
                    // formGroup.size() + 1 is the ordinal position of the new data point
                    formGroup.setOrdinal(formGroups.size() + 1);
                }
                formGroups.add(formGroup);
            }
            newDataRowOrdinal++;
        }
    }
    request.setAttribute("manualRows", new Integer(manualRows));
    LOGGER.debug(" manual rows " + manualRows + " formGroup size " + formGroups.size());
    // sort all the rows by ordinal
    Collections.sort(formGroups);
    // to tell OC what is new data and what data needs to be updated
    for (int j = 0; j < formGroups.size(); j++) {
        DisplayItemGroupBean formItemGroup = formGroups.get(j);
        LOGGER.trace("formGroup Ordinal:" + formItemGroup.getOrdinal());
        // Ready new data group to be added or existing data edited, respectively
        if (formItemGroup.getOrdinal() > dbGroups.size() - 1) {
            formItemGroup.setEditFlag("add");
        } else {
            // match existing data with data from form to update at the correct position
            DisplayItemGroupBean dbItemGroup = dbGroups.get(j);
            if (formItemGroup.getOrdinal() == j) {
                // 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");
                }
            }
        }
    }
    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)

Example 4 with FormBeanUtil

use of org.akaza.openclinica.view.form.FormBeanUtil 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 5 with FormBeanUtil

use of org.akaza.openclinica.view.form.FormBeanUtil in project OpenClinica by OpenClinica.

the class DisplaySectionBeanHandler method getDisplaySectionBeans.

/**
 * This method creates a List of DisplaySectionBeans, returning them in the
 * order that the sections appear in a CRF. This List is "lazily"
 * initialized the first time it is requested.
 *
 * @return A List of DisplaySectionBeans.
 * @see org.akaza.openclinica.control.managestudy.PrintCRFServlet
 * @see org.akaza.openclinica.control.managestudy.PrintDataEntryServlet
 */
public List<DisplaySectionBean> getDisplaySectionBeans() {
    FormBeanUtil formBeanUtil;
    ViewPersistanceHandler persistanceHandler;
    ArrayList<SectionBean> allCrfSections;
    // DAO classes for getting item definitions
    SectionDAO sectionDao;
    CRFVersionDAO crfVersionDao;
    if (displaySectionBeans == null) {
        displaySectionBeans = new ArrayList<DisplaySectionBean>();
        formBeanUtil = new FormBeanUtil();
        if (hasStoredData)
            persistanceHandler = new ViewPersistanceHandler();
        // We need a CRF version id to populate the form display
        if (this.crfVersionId == 0) {
            return displaySectionBeans;
        }
        sectionDao = new SectionDAO(dataSource);
        allCrfSections = (ArrayList) sectionDao.findByVersionId(this.crfVersionId);
        // for the purposes of null values, try to obtain a valid
        // eventCrfDefinition id
        EventDefinitionCRFBean eventDefBean = null;
        EventCRFBean eventCRFBean = new EventCRFBean();
        if (eventCRFId > 0) {
            EventCRFDAO ecdao = new EventCRFDAO(dataSource);
            eventCRFBean = (EventCRFBean) ecdao.findByPK(eventCRFId);
            StudyEventDAO sedao = new StudyEventDAO(dataSource);
            StudyEventBean studyEvent = (StudyEventBean) sedao.findByPK(eventCRFBean.getStudyEventId());
            EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(dataSource);
            StudyDAO sdao = new StudyDAO(dataSource);
            StudyBean study = sdao.findByStudySubjectId(eventCRFBean.getStudySubjectId());
            eventDefBean = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(study, studyEvent.getId(), this.crfVersionId);
        }
        eventDefBean = eventDefBean == null ? new EventDefinitionCRFBean() : eventDefBean;
        // Create an array or List of DisplaySectionBeans representing each
        // section
        // for printing
        DisplaySectionBean displaySectionBean;
        for (SectionBean sectionBean : allCrfSections) {
            displaySectionBean = formBeanUtil.createDisplaySectionBWithFormGroupsForPrint(sectionBean.getId(), this.crfVersionId, dataSource, eventDefBean.getId(), eventCRFBean, context);
            displaySectionBeans.add(displaySectionBean);
        }
    }
    return displaySectionBeans;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ViewPersistanceHandler(org.akaza.openclinica.view.form.ViewPersistanceHandler) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

FormBeanUtil (org.akaza.openclinica.view.form.FormBeanUtil)5 ArrayList (java.util.ArrayList)4 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)4 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)4 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)4 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)4 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)4 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)4 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)4 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)3 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)3 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)3 HttpSession (javax.servlet.http.HttpSession)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)2 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)2 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)2 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)2 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)2 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)2 HashMap (java.util.HashMap)1