Search in sources :

Example 46 with EventCRFBean

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

the class DataEntryServlet method writeToDB.

protected boolean writeToDB(ItemDataBean itemData, DisplayItemBean dib, ItemDataDAO iddao, int ordinal, HttpServletRequest request) {
    ItemDataBean idb = itemData;
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    idb.setItemId(dib.getItem().getId());
    idb.setEventCRFId(ecb.getId());
    if (idb.getValue().equals("")) {
        idb.setStatus(getBlankItemStatus());
    } else {
        idb.setStatus(getNonBlankItemStatus(request));
    }
    if (StringUtils.isBlank(dib.getEditFlag())) {
        if (!idb.isActive()) {
            // will this need to change for double data entry?
            idb.setOrdinal(ordinal);
            idb.setCreatedDate(new Date());
            idb.setOwner(ub);
            idb = (ItemDataBean) iddao.create(idb);
        } else {
            idb.setUpdater(ub);
            // tbh 5990: should we update the logic here for nonrepeats?
            // //System.out.println("string util is blank: update an item data " + idb.getId() + " :" + idb.getValue());
            LOGGER.debug("update item update_id " + idb.getUpdater().getId());
            idb = (ItemDataBean) iddao.updateValue(idb);
        }
    } else {
        // for the items in group, they have editFlag
        if ("add".equalsIgnoreCase(dib.getEditFlag())) {
            idb.setOrdinal(ordinal);
            idb.setCreatedDate(new Date());
            idb.setOwner(ub);
            LOGGER.debug("create a new item data" + idb.getItemId() + idb.getValue());
            // idb = (ItemDataBean) iddao.create(idb);
            // >>tbh 08/2008
            idb.setUpdater(ub);
            // idb = (ItemDataBean) iddao.updateValue(idb);
            // instead of two hits to the db, we perform an 'upsert'
            // combining them into one
            idb = (ItemDataBean) iddao.upsert(idb);
        // <<tbh
        } else if ("edit".equalsIgnoreCase(dib.getEditFlag())) {
            idb.setUpdater(ub);
            // //System.out.println("update an item data - running update value " + idb.getId() + " :" + idb.getValue());
            LOGGER.debug("update item update_id " + idb.getUpdater().getId());
            // to make sure we are running the correct command on the db
            if (idb.getId() != 0) {
                idb.setUpdatedDate(new Date());
                idb = (ItemDataBean) iddao.updateValue(idb);
            } else {
                idb.setCreatedDate(new Date());
                idb.setOrdinal(ordinal);
                idb.setOwner(ub);
                idb = (ItemDataBean) iddao.upsert(idb);
                LOGGER.debug("just ran upsert! " + idb.getId());
            }
        }
    //             else if ("remove".equalsIgnoreCase(dib.getEditFlag())) {
    //                LOGGER.debug("REMOVE an item data" + idb.getItemId() + idb.getValue());
    //                idb.setUpdater(ub);
    //                idb.setStatus(Status.DELETED);
    //                idb = (ItemDataBean) iddao.updateValueForRemoved(idb);
    //
    //                DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(getDataSource());
    //                List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(idb.getId());
    //                if (!dnNotesOfRemovedItem.isEmpty()) {
    //                    DiscrepancyNoteBean itemParentNote = null;
    //                    for (Object obj : dnNotesOfRemovedItem) {
    //                        if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
    //                            itemParentNote = (DiscrepancyNoteBean) obj;
    //                        }
    //                    }
    //                    DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
    //                    if (itemParentNote != null) {
    //                        dnb.setParentDnId(itemParentNote.getId());
    //                        dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
    //                    }
    //                    dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
    //                    dnb.setStudyId(currentStudy.getId());
    //                    dnb.setAssignedUserId(ub.getId());
    //                    dnb.setOwner(ub);
    //                    dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
    //                    dnb.setEntityId(idb.getId());
    //                    dnb.setCreatedDate(new Date());
    //                    dnb.setColumn("value");
    //                    dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
    //                    dnDao.create(dnb);
    //                    dnDao.createMapping(dnb);
    //                    itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
    //                    dnDao.update(itemParentNote);
    //                }
    // }
    }
    return idb.isActive();
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Date(java.util.Date)

Example 47 with EventCRFBean

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

the class DataEntryServlet method createEventCRF.

/**
     * Creates a new Event CRF or update the exsiting one, that is, an event CRF can be created but not item data yet, in this case, still consider it is not
     * started(called uncompleted before)
     * @param request TODO
     * @param fp TODO
     *
     * @return
     * @throws Exception
     */
private EventCRFBean createEventCRF(HttpServletRequest request, FormProcessor fp) throws InconsistentStateException {
    locale = LocaleResolver.getLocale(request);
    // < resmessage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    EventCRFBean ecb;
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
    LOGGER.trace("***FOUND*** crfversionid: " + crfVersionId);
    int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
    int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
    int subjectId = fp.getInt(INPUT_SUBJECT_ID);
    int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
    LOGGER.trace("look specifically wrt event crf id: " + eventCRFId);
    LOGGER.trace("Creating event CRF.  Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
    StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
    StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
    if (ssb.getId() <= 0) {
        LOGGER.trace("throwing ISE with study subject bean id of " + ssb.getId());
        // "begin_data_entry_without_event_but_subject"));
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_subject"));
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
    StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
    // logger.trace("study event definition:" + sedb.getId());
    if (sedb.getId() <= 0) {
        addPageMessage(resexception.getString("begin_data_entry_without_event_but_study"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_study"));
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    EntityBean eb = cvdao.findByPK(crfVersionId);
    if (eb.getId() <= 0) {
        //addPageMessage(resexception.getString("begin_data_entry_without_event_but_CRF"));
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_CRF"));
    }
    StudyEventDAO sedao = new StudyEventDAO(getDataSource());
    StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
    StudyBean studyWithSED = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithSED = new StudyBean();
        studyWithSED.setId(currentStudy.getParentStudyId());
    }
    AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
    if (aeb.getId() <= 0) {
        addPageMessage(resexception.getString("begin_data_entry_without_event_but_especified_event"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("begin_data_entry_without_event_but_especified_event"));
    }
    ecb = new EventCRFBean();
    if (eventCRFId == 0) {
        // no event CRF created yet
        ArrayList ecList = ecdao.findByEventSubjectVersion(sEvent, ssb, (CRFVersionBean) eb);
        if (ecList.size() > 0) {
            ecb = (EventCRFBean) ecList.get(0);
        } else {
            ecb.setAnnotations("");
            ecb.setCreatedDate(new Date());
            ecb.setCRFVersionId(crfVersionId);
            if (currentStudy.getStudyParameterConfig().getInterviewerNameDefault().equals("blank")) {
                ecb.setInterviewerName("");
            } else {
                // default will be event's owner name
                ecb.setInterviewerName(sEvent.getOwner().getName());
            }
            if (!currentStudy.getStudyParameterConfig().getInterviewDateDefault().equals("blank")) {
                if (sEvent.getDateStarted() != null) {
                    // default
                    ecb.setDateInterviewed(sEvent.getDateStarted());
                // date
                } else {
                    // logger.trace("evnet start date is null, so date
                    // interviewed is null");
                    ecb.setDateInterviewed(null);
                }
            } else {
                ecb.setDateInterviewed(null);
            // logger.trace("date interviewed is
            // null,getInterviewDateDefault() is blank");
            }
            // ecb.setOwnerId(ub.getId());
            // above depreciated, try without it, tbh
            ecb.setOwner(ub);
            ecb.setStatus(Status.AVAILABLE);
            ecb.setCompletionStatusId(1);
            ecb.setStudySubjectId(ssb.getId());
            ecb.setStudyEventId(studyEventId);
            ecb.setValidateString("");
            ecb.setValidatorAnnotations("");
            ecb = (EventCRFBean) ecdao.create(ecb);
            LOGGER.debug("*********CREATED EVENT CRF");
        }
    } else {
        // there is an event CRF already, only need to update
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        ecb.setCRFVersionId(crfVersionId);
        ecb.setUpdatedDate(new Date());
        ecb.setUpdater(ub);
        ecb = updateECB(sEvent, request);
        ecb = (EventCRFBean) ecdao.update(ecb);
    }
    if (ecb.getId() <= 0) {
        addPageMessage(resexception.getString("new_event_CRF_not_created"), request);
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created"));
    } else {
        if (sEvent.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
            sEvent.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
            sEvent.setUpdater(ub);
            sEvent.setUpdatedDate(new Date());
            sedao.update(sEvent);
        } else {
            sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
            sEvent.setUpdater(ub);
            sEvent.setUpdatedDate(new Date());
            sedao.update(sEvent);
        }
    }
    return ecb;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 48 with EventCRFBean

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

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

the class DataEntryServlet method isCreateItemReqd.

protected boolean isCreateItemReqd(SectionBean sb, HttpServletRequest request) {
    SectionDAO sdao = new SectionDAO(getDataSource());
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    DataEntryStage stage = ecb.getStage();
    HashMap numItemsHM = sdao.getNumItemsBySectionId();
    HashMap numItemsPendingHM = sdao.getNumItemsPendingBySectionId(ecb);
    HashMap numItemsCompletedHM = sdao.getNumItemsCompletedBySection(ecb);
    HashMap numItemsBlankHM = sdao.getNumItemsBlankBySectionId(ecb);
    Integer key = new Integer(sb.getId());
    int numItems = TableOfContentsServlet.getIntById(numItemsHM, key);
    int numItemsPending = TableOfContentsServlet.getIntById(numItemsPendingHM, key);
    int numItemsCompleted = TableOfContentsServlet.getIntById(numItemsCompletedHM, key);
    int numItemsBlank = TableOfContentsServlet.getIntById(numItemsBlankHM, key);
    LOGGER.debug(" for " + key + " num items " + numItems + " num items blank " + numItemsBlank + " num items pending " + numItemsPending + " completed " + numItemsCompleted);
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
        if (numItemsPending == 0 && numItems > 0) {
            // System.out.println("returns false on ide loop " + key);
            return false;
        }
    } else {
        if (numItemsCompleted < numItems) {
            return false;
        }
    }
    return true;
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage)

Example 50 with EventCRFBean

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

Aggregations

EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)198 ArrayList (java.util.ArrayList)118 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)89 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)85 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)68 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)64 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)63 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)62 HashMap (java.util.HashMap)54 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)52 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)52 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)48 Date (java.util.Date)47 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)47 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)44 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)43 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)42 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)41 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)41 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)41