Search in sources :

Example 1 with FormDiscrepancyNotes

use of org.akaza.openclinica.control.form.FormDiscrepancyNotes in project OpenClinica by OpenClinica.

the class ListStudySubjectServlet method processRequest.

// >>
// < ResourceBundleresword;
@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    locale = LocaleResolver.getLocale(request);
    // < resword =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
    // BWP 3098 << close the info side panel and show icons
    request.setAttribute("closeInfoShowIcons", true);
    // >>
    // BWP 3195, 3330 : designed to address pagination issues
    String pageNumber = fp.getString(SUBJECT_PAGE_NUMBER);
    StringBuilder paginatingQuery = new StringBuilder("");
    String filterKeyword = fp.getString(FILTER_KEYWORD);
    String tmpSearch = fp.getString(SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword) && !"+".equalsIgnoreCase(filterKeyword);
    if (pageNumber != null && !"".equalsIgnoreCase(pageNumber)) {
        int tempNum = 0;
        try {
            tempNum = Integer.parseInt(pageNumber);
        } catch (NumberFormatException nfe) {
        // tempNum is already initialized to 0
        }
        if (tempNum > 0) {
            paginatingQuery = new StringBuilder(SUBJECT_PAGE_NUMBER).append("=").append(pageNumber);
            paginatingQuery.append("&ebl_paginated=1");
        }
    }
    // URL encode the search keyword, since it will be a parameter in the
    // URL
    String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
    if (searchSubmitted) {
        paginatingQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        paginatingQuery.append("&").append(FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(PAGINATING_QUERY, paginatingQuery.toString());
    StudyDAO stdao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    // YW << update study parameters of current study.
    // "collectDob" and "genderRequired" are set as the same as the parent
    // study
    // tbh, also add the params "subjectPersonIdRequired",
    // "subjectIdGeneration", "subjectIdPrefixSuffix"
    int parentStudyId = currentStudy.getParentStudyId();
    ArrayList studyGroupClasses = new ArrayList();
    ArrayList allDefs = new ArrayList();
    // tbh
    if (parentStudyId > 0) {
        StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
        studyGroupClasses = sgcdao.findAllActiveByStudy(parentStudy);
        allDefs = seddao.findAllActiveByStudy(parentStudy);
    } else {
        parentStudyId = currentStudy.getId();
        studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
        allDefs = seddao.findAllActiveByStudy(currentStudy);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
    currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
    currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
    currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
    currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdPrefixSuffix");
    currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
    // for all the study groups for each group class
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        ArrayList groups = sgdao.findAllByGroupClass(sgc);
        sgc.setStudyGroups(groups);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    // information for the event tabs
    session.setAttribute("allDefsArray", allDefs);
    session.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    session.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList<DisplayStudySubjectBean> displayStudySubs = new ArrayList<DisplayStudySubjectBean>();
    // BEGIN LOOPING THROUGH SUBJECTS
    for (int i = 0; i < subjects.size(); i++) {
        StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
        ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
        ArrayList subGClasses = new ArrayList();
        for (int j = 0; j < studyGroupClasses.size(); j++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
            boolean hasClass = false;
            for (int k = 0; k < groups.size(); k++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
                if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
                    subGClasses.add(sgmb);
                    hasClass = true;
                    break;
                }
            }
            if (!hasClass) {
                subGClasses.add(new SubjectGroupMapBean());
            }
        }
        ArrayList subEvents = new ArrayList();
        // find all events order by definition ordinal
        ArrayList events = sedao.findAllByStudySubject(studySub);
        for (int j = 0; j < allDefs.size(); j++) {
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(j);
            boolean hasDef = false;
            // logger.info("...set blank to "+blankid);
            for (int k = 0; k < events.size(); k++) {
                StudyEventBean se = (StudyEventBean) events.get(k);
                if (se.getStudyEventDefinitionId() == sed.getId()) {
                    se.setStudyEventDefinition(sed);
                    // logger.info(">>>found assigned id "+sed.getId()+" sed
                    // name: "+sed.getName()+" "+se.getId());
                    subEvents.add(se);
                    hasDef = true;
                }
            }
            if (!hasDef) {
                StudyEventBean blank = new StudyEventBean();
                blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
                blank.setStudyEventDefinitionId(sed.getId());
                // how can we set the following:
                // logger.info("...resetting blank id: "+blank.getId()+" to
                // "+blankid);
                // blank.setId(blankid);
                blank.setStudyEventDefinition(sed);
                // logger.info(">>>blank id: "+blank.getId());
                // logger.info(">>>found unassigned id "+sed.getId()+" sed
                // name: "+sed.getName()+" ");
                subEvents.add(blank);
            }
        }
        // logger.info("subevents size after all adds: "+subEvents.size());
        // reorganize the events and find the repeating ones
        // subEvents:[aa bbb cc d ee]
        // finalEvents:[a(2) b(3) c(2) d e(2)]
        int prevDefId = 0;
        int currDefId = 0;
        ArrayList finalEvents = new ArrayList();
        int repeatingNum = 1;
        int count = 0;
        StudyEventBean event = new StudyEventBean();
        // begin looping through subject events
        for (int j = 0; j < subEvents.size(); j++) {
            StudyEventBean se = (StudyEventBean) subEvents.get(j);
            currDefId = se.getStudyEventDefinitionId();
            if (currDefId != prevDefId) {
                // find a new event
                if (repeatingNum > 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
                // add current event to final
                finalEvents.add(se);
                event = se;
                count++;
            // logger.info("event id? "+event.getId());
            } else {
                // repeating event
                repeatingNum++;
                event.getRepeatEvents().add(se);
                // event.getRepeatEvents().size());
                if (j == subEvents.size() - 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
            }
            prevDefId = currDefId;
        }
        // end looping through subject events
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        // logger.info("final events size: "+finalEvents.size());
        dssb.setStudyEvents(finalEvents);
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        displayStudySubs.add(dssb);
    }
    // END LOOPING THROUGH SUBJECTS
    // Set a subject property to determine whether to show a signed-type
    // icon (electronic signature)
    // in the JSP view or not
    // Get all event crfs by studyevent id; then use
    // EventDefinitionCRFDAO.isRequired to
    // determine whether any uncompleted CRFs are required.
    boolean isRequiredUncomplete = false;
    for (DisplayStudySubjectBean subject : displayStudySubs) {
        for (Iterator it = subject.getStudyEvents().iterator(); it.hasNext(); ) {
            StudyEventBean event = (StudyEventBean) it.next();
            if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
                // disallow the subject from signing any studies
                subject.setStudySignable(false);
                break;
            } else {
                // determine whether the subject has any required,
                // uncompleted event CRFs
                isRequiredUncomplete = eventHasRequiredUncompleteCRFs(event);
                if (isRequiredUncomplete) {
                    subject.setStudySignable(false);
                    break;
                }
            }
        }
    }
    fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("study_subject_ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("OID"));
    columnArray.add(resword.getString("gender"));
    // new
    columnArray.add(resword.getString("secondary_ID"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    for (int i = 0; i < allDefs.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(i);
        columnArray.add(sed.getName());
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    // String[] columns = {"ID", "Subject Status", "Gender", "Enrollment
    // Date",
    // "Study Events", "Actions" };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery(getBaseURL(), new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // table.addLink("Enroll a new subject",
    // "javascript:leftnavExpand('addSubjectRowExpress');");
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    // request.setAttribute("subjects", subjects);
    String idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
    // set up auto study subject id
    if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
        // Shaoyu Su
        // int nextLabel = ssdao.findTheGreatestLabel() + 1;
        // request.setAttribute("label", new Integer(nextLabel).toString());
        request.setAttribute("label", resword.getString("id_generated_Save_Add"));
    }
    FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
    forwardPage(getJSP());
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) Iterator(java.util.Iterator) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO)

Example 2 with FormDiscrepancyNotes

use of org.akaza.openclinica.control.form.FormDiscrepancyNotes in project OpenClinica by OpenClinica.

the class DataEntryServlet method processRequest.

@Override
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // JN:The following were the the global variables, moved as local.
    locale = LocaleResolver.getLocale(request);
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    HttpSession session = request.getSession();
    StudyBean currentStudy = (StudyBean) session.getAttribute("study");
    StudyUserRoleBean currentRole = (StudyUserRoleBean) session.getAttribute("userRole");
    SectionDAO sdao = new SectionDAO(getDataSource());
    /**
     * Determines whether the form was submitted. Calculated once in processRequest. The reason we don't use the normal means to determine if the form was
     * submitted (ie FormProcessor.isSubmitted) is because when we use forwardPage, Java confuses the inputs from the just-processed form with the inputs for
     * the forwarded-to page. This is a problem since frequently we're forwarding from one (submitted) section to the next (unsubmitted) section. If we use the
     * normal means, Java will always think that the unsubmitted section is, in fact, submitted. This member is guaranteed to be calculated before
     * shouldLoadDBValues() is called.
     */
    boolean isSubmitted = false;
    boolean hasGroup = false;
    EventCRFDAO ecdao = null;
    FormProcessor fp = new FormProcessor(request);
    logMe("Enterting DataEntry Servlet" + System.currentTimeMillis());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    FormDiscrepancyNotes discNotes;
    panel.setStudyInfoShown(false);
    String age = "";
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    String instantAtt = CV_INSTANT_META + ecb.getCRFVersionId();
    // for 11958: repeating groups rows appear if validation returns to the same section
    int isFirstTimeOnSection = fp.getInt("isFirstTimeOnSection");
    request.setAttribute("isFirstTimeOnSection", isFirstTimeOnSection + "");
    if (getCrfLocker().isLocked(ecb.getId())) {
        int userId = getCrfLocker().getLockOwner(ecb.getId());
        UserAccountDAO udao = new UserAccountDAO(getDataSource());
        UserAccountBean ubean = (UserAccountBean) udao.findByPK(userId);
        if (ubean.getId() != ub.getId()) {
            addPageMessage(resword.getString("CRF_unavailable") + " " + ubean.getName() + " " + resword.getString("Currently_entering_data") + " " + resword.getString("Leave_the_CRF"), request);
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
        }
    } else {
        getCrfLocker().lock(ecb.getId(), ub.getId());
    }
    if (!ecb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("event_not_exists"));
    }
    logMe("Enterting DataEntry Get the status/number of item discrepancy notes" + System.currentTimeMillis());
    // Get the status/number of item discrepancy notes
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
    // BWP: this try block is not necessary try {
    dndao = new DiscrepancyNoteDAO(getDataSource());
    allNotes = dndao.findAllTopNotesByEventCRF(ecb.getId());
    eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
    if (!eventCrfNotes.isEmpty()) {
        allNotes.addAll(eventCrfNotes);
    }
    logMe("Entering DataEntry Create disc note threads out of the various notes" + System.currentTimeMillis());
    // Create disc note threads out of the various notes
    DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
    noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
    // variables that provide values for the CRF discrepancy note header
    int updatedNum = 0;
    int openNum = 0;
    int closedNum = 0;
    int resolvedNum = 0;
    int notAppNum = 0;
    DiscrepancyNoteBean tempBean;
    for (DiscrepancyNoteThread dnThread : noteThreads) {
        /*
             * 3014: do not count parent beans, only the last child disc note of the thread.
             */
        tempBean = dnThread.getLinkedNoteList().getLast();
        if (tempBean != null) {
            if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
                updatedNum++;
            } else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
                openNum++;
            } else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
                // if (dn.getParentDnId() > 0){
                closedNum++;
            // }
            } else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
                // if (dn.getParentDnId() > 0){
                resolvedNum++;
            // }
            } else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
                notAppNum++;
            }
        }
    }
    logMe("Entering DataEntry Create disc note threads out of the various notes DONE" + System.currentTimeMillis());
    request.setAttribute("updatedNum", updatedNum + "");
    request.setAttribute("openNum", openNum + "");
    request.setAttribute("closedNum", closedNum + "");
    request.setAttribute("resolvedNum", resolvedNum + "");
    request.setAttribute("notAppNum", notAppNum + "");
    String fromViewNotes = fp.getString("fromViewNotes");
    if (fromViewNotes != null && "1".equals(fromViewNotes)) {
        request.setAttribute("fromViewNotes", fromViewNotes);
    }
    logMe("Entering Create studySubjDao.. ++++stuff" + System.currentTimeMillis());
    StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
    StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
    // YW 11-07-2007, data entry could not be performed if its study subject
    // has been removed.
    // Notice: ViewSectionDataEntryServelet, ViewSectionDataEntryPreview,
    // PrintCRFServlet and PrintDataEntryServlet, have theirs own
    // processRequest
    Status s = ssb.getStatus();
    if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
        addPageMessage(respage.getString("you_may_not_perform_data_entry_on_a_CRF") + respage.getString("study_subject_has_been_deleted"), request);
        request.setAttribute("id", new Integer(ecb.getStudySubjectId()).toString());
        session.removeAttribute(instantAtt);
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
    }
    // YW >>
    HashMap<String, String> newUploadedFiles = (HashMap<String, String>) session.getAttribute("newUploadedFiles");
    if (newUploadedFiles == null) {
        newUploadedFiles = new HashMap<String, String>();
    }
    request.setAttribute("newUploadedFiles", newUploadedFiles);
    if (!fp.getString("exitTo").equals("")) {
        request.setAttribute("exitTo", fp.getString("exitTo"));
    }
    // some EVENT CRF CHECK
    logMe("Entering some EVENT CRF CHECK" + System.currentTimeMillis());
    if (!fp.getString(GO_EXIT).equals("")) {
        session.removeAttribute(GROUP_HAS_DATA);
        session.removeAttribute("to_create_crf");
        session.removeAttribute("mayProcessUploading");
        // Removing the user and EventCRF from the locked CRF List
        if (getCrfLocker().isLocked(ecb.getId()) && getCrfLocker().getLockOwner(ecb.getId()) == ub.getId())
            getCrfLocker().unlock(ecb.getId());
        if (newUploadedFiles.size() > 0) {
            if (this.unloadFiles(newUploadedFiles)) {
            } else {
                String missed = "";
                Iterator iter = newUploadedFiles.keySet().iterator();
                while (iter.hasNext()) {
                    missed += " " + newUploadedFiles.get(iter.next());
                }
                addPageMessage(respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request);
            }
        }
        session.removeAttribute("newUploadedFiles");
        addPageMessage(respage.getString("exit_without_saving"), request);
        // another servlet
        if (fromViewNotes != null && "1".equals(fromViewNotes)) {
            String viewNotesURL = (String) session.getAttribute("viewNotesURL");
            if (viewNotesURL != null && viewNotesURL.length() > 0) {
                response.sendRedirect(response.encodeRedirectURL(viewNotesURL));
            }
            return;
        }
        String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
        String winLocation = (String) session.getAttribute(ViewNotesServlet.WIN_LOCATION);
        session.removeAttribute(instantAtt);
        if (!StringUtil.isBlank(fromResolvingNotes) && !StringUtil.isBlank(winLocation)) {
            response.sendRedirect(response.encodeRedirectURL(winLocation));
        } else {
            if (!fp.getString("exitTo").equals("")) {
                response.sendRedirect(response.encodeRedirectURL(fp.getString("exitTo")));
            } else
                response.sendRedirect(response.encodeRedirectURL("ListStudySubjects"));
        }
        // forwardPage(Page.SUBMIT_DATA_SERVLET);
        return;
    }
    logMe("Entering some EVENT CRF CHECK DONE" + System.currentTimeMillis());
    // checks if the section has items in item group
    // for repeating items
    // hasGroup = getInputBeans();
    hasGroup = checkGroups(fp, ecb);
    Boolean b = (Boolean) request.getAttribute(INPUT_IGNORE_PARAMETERS);
    isSubmitted = fp.isSubmitted() && b == null;
    // variable is used for fetching any null values like "not applicable"
    int eventDefinitionCRFId = 0;
    if (fp != null) {
        eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    }
    StudyBean study = (StudyBean) session.getAttribute("study");
    // constructs the list of items used on UI
    // tbh>>
    // logger.trace("trying event def crf id: "+eventDefinitionCRFId);
    logMe("Entering some EVENT DEF CRF CHECK " + System.currentTimeMillis());
    if (eventDefinitionCRFId <= 0) {
        // TODO we have to get that id before we can continue
        EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
        eventDefinitionCRFId = edcBean.getId();
    }
    logMe("Entering some EVENT DEF CRF CHECK DONE " + System.currentTimeMillis());
    logMe("Entering some Study EVENT DEF CRF CHECK  " + System.currentTimeMillis());
    StudyEventDAO seDao = new StudyEventDAO(getDataSource());
    EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcdao.findByPK(eventDefinitionCRFId);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) edcdao.findByPK(eventDefinitionCRFId);
    // JN:Putting the event_def_crf_bean in the request attribute.
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    StudyEventBean studyEventBean = (StudyEventBean) seDao.findByPK(ecb.getStudyEventId());
    edcBean.setId(eventDefinitionCRFId);
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
    StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
    Phase phase2 = Phase.INITIAL_DATA_ENTRY;
    if (getServletPage(request).startsWith(Page.DOUBLE_DATA_ENTRY_SERVLET.getFileName())) {
        phase2 = Phase.DOUBLE_DATA_ENTRY;
    } else if (getServletPage(request).startsWith(Page.ADMIN_EDIT_SERVLET.getFileName())) {
        phase2 = Phase.ADMIN_EDITING;
    }
    logMe("Entering ruleSets::: CreateAndInitializeRuleSet:::" + Thread.currentThread());
    logMe("Entering ruleSets::: CreateAndInitializeRuleSet:::" + Thread.currentThread() + "currentStudy?" + currentStudy + "studyEventDefinition" + studyEventDefinition + "crfVersionBean" + crfVersionBean + "studyEventBean" + studyEventBean + "ecb" + ecb);
    // List<RuleSetBean> ruleSets = createAndInitializeRuleSet(currentStudy, studyEventDefinition, crfVersionBean, studyEventBean, ecb, true, request, response);
    // boolean shouldRunRules = getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets, phase2);
    logMe("Entering getDisplayBean:::::Thread::::" + Thread.currentThread());
    DisplaySectionBean section = getDisplayBean(hasGroup, false, request, isSubmitted);
    // hasSCDItem has been initialized in getDisplayBean() which is online above
    VariableSubstitutionHelper.replaceVariables(section, study, ssb, studyEventDefinition, studyEventBean, dataSource);
    if (section.getSection().hasSCDItem()) {
        SimpleConditionalDisplayService cds0 = (SimpleConditionalDisplayService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("simpleConditionalDisplayService");
        section = cds0.initConditionalDisplays(section);
    }
    logMe("Entering  Find out the id of the section's first field " + System.currentTimeMillis());
    // 2790: Find out the id of the section's first field
    String firstFieldId = getSectionFirstFieldId(section.getSection().getId());
    request.setAttribute("formFirstField", firstFieldId);
    // logger.trace("now trying event def crf id: "+eventDefinitionCRFId);
    // above is necessary to give us null values during DDE
    // ironically, this only covers vertical null value result sets
    // horizontal ones are covered in FormBeanUtil, tbh 112007
    logMe("Entering  displayItemWithGroups " + System.currentTimeMillis());
    // @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter 'isSubmitted' to method createItemWithGroups
    List<DisplayItemWithGroupBean> displayItemWithGroups = createItemWithGroups(section, hasGroup, eventDefinitionCRFId, request, isSubmitted);
    logMe("Entering  displayItemWithGroups end " + System.currentTimeMillis());
    this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups, section.getSection().getId(), ecb);
    section.setDisplayItemGroups(displayItemWithGroups);
    DisplayTableOfContentsBean toc = TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY), (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService"));
    request.setAttribute(TOC_DISPLAY, toc);
    LinkedList<Integer> sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc);
    // why do we get previousSec and nextSec here, rather than in
    // getDisplayBeans?
    // so that we can use them in forwarding the user to the previous/next
    // section
    // if the validation was successful
    logMe("Entering  displayItemWithGroups sdao.findPrevious  " + System.currentTimeMillis());
    int sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc);
    SectionBean previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex);
    logMe("Entering  displayItemWithGroups sdao.findPrevious  end " + System.currentTimeMillis());
    SectionBean nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex);
    section.setFirstSection(!previousSec.isActive());
    section.setLastSection(!nextSec.isActive());
    // this is for generating side info panel
    // and the information panel under the Title
    SubjectDAO subjectDao = new SubjectDAO(getDataSource());
    StudyDAO studydao = new StudyDAO(getDataSource());
    SubjectBean subject = (SubjectBean) subjectDao.findByPK(ssb.getSubjectId());
    // Get the study then the parent study
    logMe("Entering  Get the study then the parent study   " + System.currentTimeMillis());
    if (study.getParentStudyId() > 0) {
        // this is a site,find parent
        StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
        request.setAttribute("studyTitle", parentStudy.getName());
        request.setAttribute("siteTitle", study.getName());
    } else {
        request.setAttribute("studyTitle", study.getName());
    }
    logMe("Entering  Get the study then the parent study end  " + System.currentTimeMillis());
    // Let us process the age
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
        // YW 11-16-2007 erollment-date is used for calculating age.
        Date enrollmentDate = ssb.getEnrollmentDate();
        age = Utils.getInstacne().processAge(enrollmentDate, subject.getDateOfBirth());
    }
    // ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(ssb, getDataSource(), ub, currentRole);
    request.setAttribute("studySubject", ssb);
    request.setAttribute("subject", subject);
    // request.setAttribute("beans", beans);
    request.setAttribute("eventCRF", ecb);
    request.setAttribute("age", age);
    request.setAttribute("decryptedPassword", ((SecurityManager) SpringServletAccess.getApplicationContext(getServletContext()).getBean("securityManager")).encrytPassword("root", getUserDetails()));
    // set up interviewer name and date
    fp.addPresetValue(INPUT_INTERVIEWER, ecb.getInterviewerName());
    if (ecb.getDateInterviewed() != null) {
        DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
        String idateFormatted = local_df.format(ecb.getDateInterviewed());
        fp.addPresetValue(INPUT_INTERVIEW_DATE, idateFormatted);
    } else {
        fp.addPresetValue(INPUT_INTERVIEW_DATE, "");
    }
    setPresetValues(fp.getPresetValues(), request);
    logMe("Entering Checks !submitted  " + System.currentTimeMillis());
    if (!isSubmitted) {
        // TODO: prevent data enterer from seeing results of first round of
        // data
        // entry, if this is second round
        // FLAG--SLOW HERE WHEN LOADING
        logMe("Entering Checks !submitted entered  " + System.currentTimeMillis());
        long t = System.currentTimeMillis();
        request.setAttribute(BEAN_DISPLAY, section);
        request.setAttribute(BEAN_ANNOTATIONS, getEventCRFAnnotations(request));
        session.setAttribute("shouldRunValidation", null);
        session.setAttribute("rulesErrors", null);
        session.setAttribute(DataEntryServlet.NOTE_SUBMITTED, null);
        discNotes = new FormDiscrepancyNotes();
        // discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        // if (discNotes == null) {
        // discNotes = new FormDiscrepancyNotes();
        // }
        // << tbh 01/2010
        section = populateNotesWithDBNoteCounts(discNotes, section, request);
        populateInstantOnChange(request.getSession(), ecb, section);
        LOGGER.debug("+++ just ran populateNotes, printing field notes: " + discNotes.getFieldNotes().toString());
        LOGGER.debug("found disc notes: " + discNotes.getNumExistingFieldNotes().toString());
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
        if (section.getSection().hasSCDItem()) {
            section = SCDItemDisplayInfo.generateSCDDisplayInfo(section, this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
        }
        int keyId = ecb.getId();
        session.removeAttribute(DoubleDataEntryServlet.COUNT_VALIDATE + keyId);
        setUpPanel(section);
        if (newUploadedFiles.size() > 0) {
            if (this.unloadFiles(newUploadedFiles)) {
            } else {
                String missed = "";
                Iterator iter = newUploadedFiles.keySet().iterator();
                while (iter.hasNext()) {
                    missed += " " + newUploadedFiles.get(iter.next());
                }
                addPageMessage(respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request);
            }
        }
        logMe("Entering Checks !submitted entered end forwarding page " + System.currentTimeMillis());
        logMe("Time Took for this block" + (System.currentTimeMillis() - t));
        forwardPage(getJSPPage(), request, response);
        return;
    } else {
        logMe("Entering Checks !submitted not entered  " + System.currentTimeMillis());
        // 
        // VALIDATION / LOADING DATA
        // 
        // If validation is required for this round, we will go through
        // each item and add an appropriate validation to the Validator
        // 
        // Otherwise, we will just load the data into the DisplayItemBean
        // so that we can write to the database later.
        // 
        // Validation is required if two conditions are met:
        // 1. The user clicked a "Save" button, not a "Confirm" button
        // 2. In this type of data entry servlet, when the user clicks
        // a Save button, the inputs are validated
        // 
        boolean validate = fp.getBoolean(INPUT_CHECK_INPUTS) && validateInputOnFirstRound();
        // did the user click a "Save" button?
        // is validation required in this type of servlet when the user
        // clicks
        // "Save"?
        // We can conclude that the user is trying to save data; therefore,
        // set a request
        // attribute indicating that default values for items shouldn't be
        // displayed
        // in the application UI that will subsequently be displayed
        // TODO: find a better, less random place for this
        // session.setAttribute(HAS_DATA_FLAG, true);
        // section.setCheckInputs(fp.getBoolean(INPUT_CHECK_INPUTS));
        errors = new HashMap();
        // ArrayList items = section.getItems();
        discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        if (discNotes == null) {
            discNotes = new FormDiscrepancyNotes();
        }
        // populateNotesWithDBNoteCounts(discNotes, section);
        // all items- inlcude items in item groups and other single items
        List<DisplayItemWithGroupBean> allItems = section.getDisplayItemGroups();
        String attachedFilePath = Utils.getAttachedFilePath(currentStudy);
        DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
        RuleValidator ruleValidator = new RuleValidator(request);
        LOGGER.debug("SZE 1  :: " + allItems.size());
        logMe("Looping inside !submitted  " + System.currentTimeMillis());
        for (int i = 0; i < allItems.size(); i++) {
            LOGGER.trace("===itering through items: " + i);
            DisplayItemWithGroupBean diwg = allItems.get(i);
            if (diwg.isInGroup()) {
                // for the items in groups
                DisplayItemGroupBean dgb = diwg.getItemGroup();
                List<DisplayItemGroupBean> dbGroups = diwg.getDbItemGroups();
                // dbGroups = diwg.getItemGroups();
                List<DisplayItemGroupBean> formGroups = new ArrayList<DisplayItemGroupBean>();
                LOGGER.debug("got db item group size " + dbGroups.size());
                if (validate) {
                    // int manualGroups = getManualRows(dbGroups2);
                    // logger.debug("+++ found manual rows from db group 2: " + manualGroups);
                    LOGGER.debug("===IF VALIDATE NOT A SINGLE ITEM: got to this part in the validation loop: " + dgb.getGroupMetaBean().getName());
                    // TODO next marker tbh 112007
                    // formGroups = validateDisplayItemGroupBean(v,
                    // dgb,dbGroups, formGroups,
                    // ruleValidator,groupOrdinalPLusItemOid);
                    formGroups = validateDisplayItemGroupBean(v, dgb, dbGroups, formGroups, request, response);
                    LOGGER.debug("form group size after validation " + formGroups.size());
                } else {
                    LOGGER.debug("+++ELSE NOT A SINGLE ITEM: got to this part in the validation loop: " + dgb.getGroupMetaBean().getName());
                    formGroups = loadFormValueForItemGroup(dgb, dbGroups, formGroups, eventDefinitionCRFId, request);
                    LOGGER.debug("form group size without validation " + formGroups.size());
                }
                diwg.setItemGroup(dgb);
                diwg.setItemGroups(formGroups);
                allItems.set(i, diwg);
            } else {
                // other single items
                DisplayItemBean dib = diwg.getSingleItem();
                // dib = (DisplayItemBean) allItems.get(i);
                if (validate) {
                    // generate input name here?
                    // DisplayItemGroupBean dgb = diwg.getItemGroup();
                    String itemName = getInputName(dib);
                    // no Item group for single item, so just use blank
                    // string as parameter for inputName
                    // this
                    dib = validateDisplayItemBean(v, dib, "", request);
                    // should be
                    // used,
                    // otherwise,
                    // DDE not
                    // working-jxu
                    LOGGER.debug("&&& found name: " + itemName);
                    LOGGER.debug("input VALIDATE " + itemName + ": " + fp.getString(itemName));
                    // dib.loadFormValue(fp.getString(itemName));
                    LOGGER.debug("input " + itemName + " has a response set of " + dib.getMetadata().getResponseSet().getOptions().size() + " options");
                } else {
                    String itemName = getInputName(dib);
                    LOGGER.debug("input NONVALIDATE " + itemName + ": " + fp.getString(itemName));
                    // dib.loadFormValue(itemName);
                    dib = loadFormValue(dib, request);
                // String itemName = getInputName(dib);
                // dib = loadFormValue(itemName);
                }
                ArrayList children = dib.getChildren();
                for (int j = 0; j < children.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) children.get(j);
                    // DisplayItemGroupBean dgb = diwg.getItemGroup();
                    String itemName = getInputName(child);
                    child.loadFormValue(fp.getString(itemName));
                    if (validate) {
                        // child = validateDisplayItemBean(v, child,
                        // itemName, ruleValidator, groupOrdinalPLusItemOid,
                        // false);
                        child = validateDisplayItemBean(v, child, itemName, request);
                    // was null changed value 092007 tbh
                    } else {
                        // child.loadFormValue(itemName);
                        child = loadFormValue(child, request);
                    }
                    LOGGER.debug("Checking child value for " + itemName + ": " + child.getData().getValue());
                    children.set(j, child);
                }
                dib.setChildren(children);
                diwg.setSingleItem(runDynamicsItemCheck(dib, null, request));
                // logger.trace("just set single item on line 447:
                // "+dib.getData().getValue());
                // items.set(i, dib);
                LOGGER.debug(" I : " + i);
                allItems.set(i, diwg);
            }
        }
        logMe("Loop ended  " + System.currentTimeMillis());
        // JN: This is the list that contains all the scd-shown items.
        List<ItemBean> itemBeansWithSCDShown = new ArrayList<ItemBean>();
        if (validate && section.getSection().hasSCDItem()) {
            logMe(" Validate and Loop  " + System.currentTimeMillis());
            for (int i = 0; i < allItems.size(); ++i) {
                DisplayItemBean dib = allItems.get(i).getSingleItem();
                ItemFormMetadataBean ifmb = dib.getMetadata();
                if (ifmb.getParentId() == 0) {
                    if (dib.getScdData().getScdSetsForControl().size() > 0) {
                        // for control item
                        // dib has to loadFormValue first. Here loadFormValue has been done in validateDisplayItemBean(v, dib, "")
                        section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(dib, section.getShowSCDItemIds()));
                    }
                    if (dib.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
                        // for scd item
                        // a control item is always before its scd item
                        dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
                        if (dib.getIsSCDtoBeShown())
                            itemBeansWithSCDShown.add(dib.getItem());
                        validateSCDItemBean(v, dib);
                    }
                    ArrayList<DisplayItemBean> children = dib.getChildren();
                    for (int j = 0; j < children.size(); j++) {
                        DisplayItemBean child = children.get(j);
                        if (child.getScdData().getScdSetsForControl().size() > 0) {
                            // for control item
                            // dib has to loadFormValue first. Here loadFormValue has been done in validateDisplayItemBean(v, dib, "")
                            section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(child, section.getShowSCDItemIds()));
                        }
                        if (child.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
                            // for scd item
                            // a control item is always before its scd item
                            child.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
                            if (child.getIsSCDtoBeShown())
                                itemBeansWithSCDShown.add(dib.getItem());
                            validateSCDItemBean(v, child);
                        }
                    }
                }
            }
            logMe(" Validate and Loop end  " + System.currentTimeMillis());
        }
        logMe(" Validate and Loop end  " + System.currentTimeMillis());
        // JN:calling again here, for the items with simple conditional display and rules.
        List<RuleSetBean> ruleSets = createAndInitializeRuleSet(currentStudy, studyEventDefinition, crfVersionBean, studyEventBean, ecb, true, request, response, itemBeansWithSCDShown);
        boolean shouldRunRules = getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets, phase2);
        // this.getItemMetadataService().resetItemCounter();
        HashMap<String, ArrayList<String>> groupOrdinalPLusItemOid = null;
        groupOrdinalPLusItemOid = runRules(allItems, ruleSets, true, shouldRunRules, MessageType.ERROR, phase2, ecb, request);
        logMe("allItems  Loop begin  " + System.currentTimeMillis());
        for (int i = 0; i < allItems.size(); i++) {
            DisplayItemWithGroupBean diwg = allItems.get(i);
            if (diwg.isInGroup()) {
                // for the items in groups
                DisplayItemGroupBean dgb = diwg.getItemGroup();
                List<DisplayItemGroupBean> dbGroups = diwg.getDbItemGroups();
                // dbGroups = diwg.getItemGroups();
                // tbh 01/2010 change the group list?
                List<DisplayItemGroupBean> formGroups = new ArrayList<DisplayItemGroupBean>();
                // items again?
                if (validate) {
                    // int manualGroups = getManualRows(dbGroups2);
                    // logger.debug("+++ found manual rows for db group2: " + manualGroups);
                    formGroups = validateDisplayItemGroupBean(v, dgb, dbGroups, formGroups, ruleValidator, groupOrdinalPLusItemOid, request, response);
                    // formGroups = validateDisplayItemGroupBean(v, dgb,
                    // dbGroups, formGroups);
                    LOGGER.debug("*** form group size after validation " + formGroups.size());
                }
                diwg.setItemGroup(dgb);
                diwg.setItemGroups(formGroups);
                allItems.set(i, diwg);
            } else {
                // other single items
                DisplayItemBean dib = diwg.getSingleItem();
                // dib = (DisplayItemBean) allItems.get(i);
                if (validate) {
                    String itemName = getInputName(dib);
                    // 
                    dib = validateDisplayItemBean(v, dib, "", ruleValidator, groupOrdinalPLusItemOid, false, null, request);
                // / dib = validateDisplayItemBean(v, dib, "");// this
                }
                ArrayList children = dib.getChildren();
                for (int j = 0; j < children.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) children.get(j);
                    // DisplayItemGroupBean dgb = diwg.getItemGroup();
                    String itemName = getInputName(child);
                    child.loadFormValue(fp.getString(itemName));
                    if (validate) {
                        child = validateDisplayItemBean(v, child, "", ruleValidator, groupOrdinalPLusItemOid, false, null, request);
                    // child = validateDisplayItemBean(v, child,
                    // itemName);
                    }
                    children.set(j, child);
                    LOGGER.debug(" J (children): " + j);
                }
                dib.setChildren(children);
                diwg.setSingleItem(runDynamicsItemCheck(dib, null, request));
                LOGGER.debug(" I : " + i);
                allItems.set(i, diwg);
            }
        }
        logMe("allItems  Loop end  " + System.currentTimeMillis());
        // YW, 2-1-2008 <<
        // A map from item name to item bean object.
        HashMap<String, ItemBean> scoreItems = new HashMap<String, ItemBean>();
        HashMap<String, String> scoreItemdata = new HashMap<String, String>();
        HashMap<String, ItemDataBean> oldItemdata = prepareSectionItemdataObject(sb.getId(), request);
        // hold all item names of changed ItemBean in current section
        TreeSet<String> changedItems = new TreeSet<String>();
        // holds complete disply item beans for checking against 'request
        // for change' restriction
        ArrayList<DisplayItemBean> changedItemsList = new ArrayList<DisplayItemBean>();
        // key is repeating item name, value is its display item group bean
        HashMap<String, DisplayItemGroupBean> changedItemsMap = new HashMap<String, DisplayItemGroupBean>();
        // key is itemid, value is set of itemdata-ordinal
        HashMap<Integer, TreeSet<Integer>> itemOrdinals = prepareItemdataOrdinals(request);
        // prepare item data for scoring
        updateDataOrdinals(allItems);
        section.setDisplayItemGroups(allItems);
        scoreItems = prepareScoreItems(request);
        scoreItemdata = prepareScoreItemdata(request);
        logMe("allItems 2 Loop begin  " + System.currentTimeMillis());
        for (int i = 0; i < allItems.size(); i++) {
            DisplayItemWithGroupBean diwb = allItems.get(i);
            if (diwb.isInGroup()) {
                // for the items in groups
                DisplayItemGroupBean digb = diwb.getItemGroup();
                List<DisplayItemGroupBean> dbGroups = diwb.getDbItemGroups();
                for (int j = 0; j < dbGroups.size(); j++) {
                    DisplayItemGroupBean displayGroup = dbGroups.get(j);
                    List<DisplayItemBean> items = displayGroup.getItems();
                    if ("remove".equalsIgnoreCase(displayGroup.getEditFlag())) {
                        for (DisplayItemBean displayItem : items) {
                            if (displayItem.getMetadata().isShowItem() && digb.getGroupMetaBean().isShowGroup()) {
                                int itemId = displayItem.getItem().getId();
                                int ordinal = displayItem.getData().getOrdinal();
                                if (itemOrdinals.containsKey(itemId)) {
                                    itemOrdinals.get(itemId).remove(ordinal);
                                }
                                if (scoreItemdata.containsKey(itemId + "_" + ordinal)) {
                                    scoreItemdata.remove(itemId + "_" + ordinal);
                                }
                                changedItems.add(displayItem.getItem().getName());
                                changedItemsList.add(displayItem);
                                String formName = displayItem.getItem().getName();
                                // logger.debug("SET: formName:" + formName);
                                if (displayGroup.isAuto()) {
                                    formName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                    LOGGER.debug("GET: changed formName to " + formName);
                                } else {
                                    formName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                    LOGGER.debug("GET-MANUAL: changed formName to " + formName);
                                }
                                changedItemsMap.put(formName, displayGroup);
                                LOGGER.debug("adding to changed items map: " + formName);
                            }
                        }
                    }
                }
                List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                int groupsize = dgbs.size();
                HashMap<Integer, Integer> maxOrdinals = new HashMap<Integer, Integer>();
                boolean first = true;
                for (int j = 0; j < dgbs.size(); j++) {
                    DisplayItemGroupBean displayGroup = dgbs.get(j);
                    List<DisplayItemBean> items = displayGroup.getItems();
                    boolean isAdd = "add".equalsIgnoreCase(displayGroup.getEditFlag()) ? true : false;
                    for (DisplayItemBean displayItem : items) {
                        ItemBean ib = displayItem.getItem();
                        String itemName = ib.getName();
                        int itemId = ib.getId();
                        if (first) {
                            maxOrdinals.put(itemId, iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean()));
                        }
                        ItemDataBean idb = displayItem.getData();
                        String value = idb.getValue();
                        scoreItems.put(itemName, ib);
                        int ordinal = displayItem.getData().getOrdinal();
                        if (isAdd && scoreItemdata.containsKey(itemId + "_" + ordinal)) {
                            int formMax = 1;
                            if (maxOrdinals.containsKey(itemId)) {
                                formMax = maxOrdinals.get(itemId);
                            }
                            int dbMax = iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean());
                            ordinal = ordinal >= dbMax ? formMax + 1 : ordinal;
                            maxOrdinals.put(itemId, ordinal);
                            displayItem.getData().setOrdinal(ordinal);
                            scoreItemdata.put(itemId + "_" + ordinal, value);
                        } else {
                            scoreItemdata.put(itemId + "_" + ordinal, value);
                        }
                        if (itemOrdinals.containsKey(itemId)) {
                            itemOrdinals.get(itemId).add(ordinal);
                        } else {
                            TreeSet<Integer> ordinalSet = new TreeSet<Integer>();
                            ordinalSet.add(ordinal);
                            itemOrdinals.put(itemId, ordinalSet);
                        }
                        if (isChanged(displayItem, oldItemdata, attachedFilePath)) {
                            changedItems.add(itemName);
                            changedItemsList.add(displayItem);
                            String formName = displayItem.getItem().getName();
                            // logger.debug("SET: formName:" + formName);
                            if (displayGroup.isAuto()) {
                                formName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                LOGGER.debug("RESET: formName group-item-input:" + formName);
                            } else {
                                formName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                LOGGER.debug("RESET: formName group-item-input-manual:" + formName);
                            }
                            changedItemsMap.put(formName, displayGroup);
                            LOGGER.debug("adding to changed items map: " + formName);
                        }
                    }
                    first = false;
                }
            } else {
                DisplayItemBean dib = diwb.getSingleItem();
                ItemBean ib = dib.getItem();
                ItemDataBean idb = dib.getData();
                int itemId = ib.getId();
                String itemName = ib.getName();
                String value = idb.getValue();
                scoreItems.put(itemName, ib);
                // for items which are not in any group, their ordinal is
                // set as 1
                TreeSet<Integer> ordinalset = new TreeSet<Integer>();
                ordinalset.add(1);
                itemOrdinals.put(itemId, ordinalset);
                scoreItemdata.put(itemId + "_" + 1, value);
                if (isChanged(idb, oldItemdata, dib, attachedFilePath)) {
                    changedItems.add(itemName);
                    changedItemsList.add(dib);
                // changedItemsMap.put(dib.getItem().getName(), new
                // DisplayItemGroupBean());
                }
                ArrayList children = dib.getChildren();
                for (int j = 0; j < children.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) children.get(j);
                    ItemBean cib = child.getItem();
                    scoreItems.put(cib.getName(), cib);
                    TreeSet<Integer> cordinalset = new TreeSet<Integer>();
                    cordinalset.add(1);
                    itemOrdinals.put(itemId, cordinalset);
                    scoreItemdata.put(cib.getId() + "_" + 1, child.getData().getValue());
                    if (isChanged(child.getData(), oldItemdata, child, attachedFilePath)) {
                        changedItems.add(itemName);
                        changedItemsList.add(child);
                    // changedItemsMap.put(itemName, new
                    // DisplayItemGroupBean());
                    }
                }
            }
        }
        logMe("allItems 2 Loop end  " + System.currentTimeMillis());
        // do calculation for 'calculation' and 'group-calculation' type
        // items
        // and write the result in DisplayItemBean's ItemDateBean - data
        ScoreItemValidator sv = new ScoreItemValidator(request, discNotes);
        // *** doing calc here, load it where? ***
        SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
        ScoreCalculator sc = new ScoreCalculator(sm, ecb, ub);
        logMe("allItems 3 Loop begin  " + System.currentTimeMillis());
        for (int i = 0; i < allItems.size(); i++) {
            DisplayItemWithGroupBean diwb = allItems.get(i);
            if (diwb.isInGroup()) {
                List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                for (int j = 0; j < dgbs.size(); j++) {
                    DisplayItemGroupBean displayGroup = dgbs.get(j);
                    List<DisplayItemBean> items = displayGroup.getItems();
                    for (DisplayItemBean displayItem : items) {
                        ItemFormMetadataBean ifmb = displayItem.getMetadata();
                        int responseTypeId = ifmb.getResponseSet().getResponseTypeId();
                        if (responseTypeId == 8 || responseTypeId == 9) {
                            StringBuffer err = new StringBuffer();
                            ResponseOptionBean robBean = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
                            String value = "";
                            String inputName = "";
                            // getFormInputOrdinal() here, tbh 06/2009
                            if (displayGroup.isAuto()) {
                                inputName = getGroupItemInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                LOGGER.debug("returning input name: " + inputName);
                            } else {
                                inputName = getGroupItemManualInputName(displayGroup, displayGroup.getFormInputOrdinal(), displayItem);
                                LOGGER.debug("returning input name: " + inputName);
                            }
                            if (robBean.getValue().startsWith("func: getexternalvalue") || robBean.getValue().startsWith("func: getExternalValue")) {
                                value = fp.getString(inputName);
                                LOGGER.debug("*** just set " + fp.getString(inputName) + " for line 815 " + displayItem.getItem().getName() + " with input name " + inputName);
                            } else {
                                value = sc.doCalculation(displayItem, scoreItems, scoreItemdata, itemOrdinals, err, displayItem.getData().getOrdinal());
                            }
                            displayItem.loadFormValue(value);
                            if (isChanged(displayItem, oldItemdata, attachedFilePath)) {
                                changedItems.add(displayItem.getItem().getName());
                                changedItemsList.add(displayItem);
                            }
                            request.setAttribute(inputName, value);
                            if (validate) {
                                displayItem = validateCalcTypeDisplayItemBean(sv, displayItem, inputName, request);
                                if (err.length() > 0) {
                                    Validation validation = new Validation(Validator.CALCULATION_FAILED);
                                    validation.setErrorMessage(err.toString());
                                    sv.addValidation(inputName, validation);
                                }
                            }
                        }
                    }
                }
            } else {
                DisplayItemBean dib = diwb.getSingleItem();
                ItemFormMetadataBean ifmb = dib.getMetadata();
                int responseTypeId = ifmb.getResponseSet().getResponseTypeId();
                if (responseTypeId == 8 || responseTypeId == 9) {
                    StringBuffer err = new StringBuffer();
                    ResponseOptionBean robBean = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
                    String value = "";
                    if (robBean.getValue().startsWith("func: getexternalvalue") || robBean.getValue().startsWith("func: getExternalValue")) {
                        String itemName = getInputName(dib);
                        value = fp.getString(itemName);
                        LOGGER.debug("just set " + fp.getString(itemName) + " for " + dib.getItem().getName());
                        LOGGER.debug("found in fp: " + fp.getString(dib.getItem().getName()));
                    // logger.debug("scoreitemdata: " +
                    // scoreItemdata.toString());
                    } else {
                        value = sc.doCalculation(dib, scoreItems, scoreItemdata, itemOrdinals, err, 1);
                    }
                    dib.loadFormValue(value);
                    if (isChanged(dib.getData(), oldItemdata, dib, attachedFilePath)) {
                        changedItems.add(dib.getItem().getName());
                        changedItemsList.add(dib);
                    // changedItemsMap.put(dib.getItem().getName(), new
                    // DisplayItemGroupBean());
                    }
                    String inputName = getInputName(dib);
                    request.setAttribute(inputName, value);
                    if (validate) {
                        dib = validateCalcTypeDisplayItemBean(sv, dib, "", request);
                        if (err.length() > 0) {
                            Validation validation = new Validation(Validator.CALCULATION_FAILED);
                            validation.setErrorMessage(err.toString());
                            sv.addValidation(inputName, validation);
                        }
                    }
                }
                ArrayList children = dib.getChildren();
                for (int j = 0; j < children.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) children.get(j);
                    ItemFormMetadataBean cifmb = child.getMetadata();
                    int resTypeId = cifmb.getResponseSet().getResponseTypeId();
                    if (resTypeId == 8 || resTypeId == 9) {
                        StringBuffer cerr = new StringBuffer();
                        child.getDbData().setValue(child.getData().getValue());
                        ResponseOptionBean crobBean = (ResponseOptionBean) cifmb.getResponseSet().getOptions().get(0);
                        String cvalue = "";
                        if (crobBean.getValue().startsWith("func: getexternalvalue") || crobBean.getValue().startsWith("func: getExternalValue")) {
                            String itemName = getInputName(child);
                            cvalue = fp.getString(itemName);
                            LOGGER.debug("just set " + fp.getString(itemName) + " for " + child.getItem().getName());
                        } else {
                            cvalue = sc.doCalculation(child, scoreItems, scoreItemdata, itemOrdinals, cerr, 1);
                        }
                        child.loadFormValue(cvalue);
                        if (isChanged(child.getData(), oldItemdata, child, attachedFilePath)) {
                            changedItems.add(child.getItem().getName());
                            changedItemsList.add(child);
                        // changedItemsMap.put(child.getItem().getName(),
                        // new DisplayItemGroupBean());
                        }
                        String cinputName = getInputName(child);
                        request.setAttribute(cinputName, cvalue);
                        if (validate) {
                            child = validateCalcTypeDisplayItemBean(sv, child, "", request);
                            if (cerr.length() > 0) {
                                Validation cvalidation = new Validation(Validator.CALCULATION_FAILED);
                                cvalidation.setErrorMessage(cerr.toString());
                                sv.addValidation(cinputName, cvalidation);
                            }
                        }
                    }
                    children.set(j, child);
                }
            }
        }
        logMe("allItems 3 Loop end  " + System.currentTimeMillis());
        // YW >>
        // we have to do this since we loaded all the form values into the
        // display
        // item beans above
        // section.setItems(items);
        // setting this AFTER we populate notes - will that make a difference?
        section.setDisplayItemGroups(allItems);
        // logger.debug("+++ try to populate notes");
        section = populateNotesWithDBNoteCounts(discNotes, section, request);
        populateInstantOnChange(request.getSession(), ecb, section);
        if (currentStudy.getStudyParameterConfig().getInterviewerNameRequired().equals("yes")) {
            v.addValidation(INPUT_INTERVIEWER, Validator.NO_BLANKS);
        }
        if (currentStudy.getStudyParameterConfig().getInterviewDateRequired().equals("yes")) {
            v.addValidation(INPUT_INTERVIEW_DATE, Validator.NO_BLANKS);
        }
        if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
            v.addValidation(INPUT_INTERVIEW_DATE, Validator.IS_A_DATE);
            v.alwaysExecuteLastValidation(INPUT_INTERVIEW_DATE);
        }
        if (section.getSection().hasSCDItem()) {
            section = SCDItemDisplayInfo.generateSCDDisplayInfo(section, this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
        }
        // logger.debug("about to validate: " + v.getKeySet());
        errors = v.validate();
        // tbh >>
        if (this.isAdminForcedReasonForChange(request) && this.isAdministrativeEditing() && errors.isEmpty()) {
            // "You have changed data after this CRF was marked complete. "
            // +
            // "You must provide a Reason For Change discrepancy note for this item before you can save this updated information."
            String error = respage.getString("reason_for_change_error");
            // "Please enter a reason for change discrepancy note before saving."
            // ;
            int nonforcedChanges = 0;
            // items map
            if (changedItemsList.size() > 0) {
                LOGGER.debug("found admin force reason for change: changed items " + changedItems.toString() + " and changed items list: " + changedItemsList.toString() + " changed items map: " + changedItemsMap.toString());
                logMe("DisplayItemBean  Loop begin  " + System.currentTimeMillis());
                for (DisplayItemBean displayItem : changedItemsList) {
                    String formName = getInputName(displayItem);
                    ItemDataBean idb = displayItem.getData();
                    ItemBean item_bean = displayItem.getItem();
                    ItemFormMetadataBean ifmb = displayItem.getMetadata();
                    LOGGER.debug("-- found group label " + ifmb.getGroupLabel());
                    if (!ifmb.getGroupLabel().equalsIgnoreCase("Ungrouped") && !ifmb.getGroupLabel().equalsIgnoreCase("")) {
                        // << tbh 11/2009 sometimes the group label is blank instead of ungrouped???
                        Iterator iter = changedItemsMap.entrySet().iterator();
                        while (iter.hasNext()) {
                            Map.Entry<String, DisplayItemGroupBean> pairs = (Map.Entry) iter.next();
                            String formName2 = pairs.getKey();
                            DisplayItemGroupBean dgb = pairs.getValue();
                            // logger.debug("found auto: " +
                            // dgb.isAuto());
                            String testFormName = "";
                            if (dgb.isAuto()) {
                                // testFormName = getGroupItemInputName(dgb, dgb.getFormInputOrdinal(), getManualRows(dgbs), displayItem);
                                testFormName = getGroupItemInputName(dgb, dgb.getFormInputOrdinal(), displayItem);
                            } else {
                                testFormName = getGroupItemManualInputName(dgb, dgb.getFormInputOrdinal(), displayItem);
                            }
                            LOGGER.debug("found test form name: " + testFormName);
                            // if our test is the same with both the display
                            // item and the display group ...
                            // logger.debug("comparing " +
                            // testFormName + " and " + formName2);
                            int existingNotes = dndao.findNumExistingNotesForItem(idb.getId());
                            if (testFormName.equals(formName2)) {
                                formName = formName2;
                                this.setReasonForChangeError(ecb, item_bean, idb, formName, error, request);
                                changedItemsMap.remove(formName2);
                                LOGGER.debug("form name changed: " + formName);
                                break;
                            // .., send it as the form name
                            }
                        // ... otherwise, don't touch it
                        // how to tell vs. manual and just plain input?
                        }
                    } else {
                        this.setReasonForChangeError(ecb, item_bean, idb, formName, error, request);
                        LOGGER.debug("form name added: " + formName);
                    }
                }
                logMe("DisplayItemBean  Loop end  " + System.currentTimeMillis());
            }
            if (nonforcedChanges > 0) {
            // do smething here?
            }
        }
        LOGGER.debug("errors here: " + errors.toString());
        // <<
        logMe("error check  Loop begin  " + System.currentTimeMillis());
        if (errors.isEmpty() && shouldRunRules) {
            LOGGER.debug("Errors was empty");
            if (session.getAttribute("rulesErrors") != null) {
                // rules have already generated errors, Let's compare old
                // error list with new
                // error list, if lists not same show errors.
                HashMap h = ruleValidator.validate();
                Set<String> a = (Set<String>) session.getAttribute("rulesErrors");
                Set<String> ba = h.keySet();
                Boolean showErrors = false;
                for (Object key : ba) {
                    if (!a.contains(key)) {
                        showErrors = true;
                    }
                }
                if (showErrors) {
                    errors = h;
                    if (errors.size() > 0) {
                        session.setAttribute("shouldRunValidation", "1");
                        session.setAttribute("rulesErrors", errors.keySet());
                    } else {
                        session.setAttribute("shouldRunValidation", null);
                        session.setAttribute("rulesErrors", null);
                    }
                } else {
                    session.setAttribute("shouldRunValidation", null);
                    session.setAttribute("rulesErrors", null);
                }
            } else if (session.getAttribute("shouldRunValidation") != null && session.getAttribute("shouldRunValidation").toString().equals("1")) {
                session.setAttribute("shouldRunValidation", null);
                session.setAttribute("rulesErrors", null);
            } else {
                errors = ruleValidator.validate();
                if (errors.size() > 0) {
                    session.setAttribute("shouldRunValidation", "1");
                    session.setAttribute("rulesErrors", errors.keySet());
                }
            }
        }
        if (!errors.isEmpty()) {
            LOGGER.debug("threw an error with data entry...");
            // copying below three lines, tbh 03/2010
            String[] textFields = { INPUT_INTERVIEWER, INPUT_INTERVIEW_DATE };
            fp.setCurrentStringValuesAsPreset(textFields);
            setPresetValues(fp.getPresetValues(), request);
            // YW, 2-4-2008 <<
            logMe("!errors if  Loop begin  " + System.currentTimeMillis());
            HashMap<String, ArrayList<String>> siErrors = sv.validate();
            if (siErrors != null && !siErrors.isEmpty()) {
                Iterator iter = siErrors.keySet().iterator();
                while (iter.hasNext()) {
                    String fieldName = iter.next().toString();
                    errors.put(fieldName, siErrors.get(fieldName));
                }
            }
            // we should 'shift' the names here, tbh 02/2010
            // need: total number of rows, manual rows, all row names
            // plus: error names
            Iterator iter2 = errors.keySet().iterator();
            while (iter2.hasNext()) {
                String fieldName = iter2.next().toString();
                LOGGER.debug("found error " + fieldName);
            }
            // for (int i = 0; i < allItems.size(); i++) {
            // DisplayItemWithGroupBean diwb = allItems.get(i);
            // 
            // if (diwb.isInGroup()) {
            // List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
            // logger.debug("found manual rows " + getManualRows(dgbs) + " and total rows " + dgbs.size() + " from ordinal " + diwb.getOrdinal());
            // }
            // }
            errors = reshuffleErrorGroupNamesKK(errors, allItems, request);
            reshuffleReasonForChangeHashAndDiscrepancyNotes(allItems, request, ecb);
            // reset manual rows, so that we can catch errors correctly
            // but it needs to be set per block of repeating items?  what if there are two or more?
            /*
                int manualRows = 0; // getManualRows(formGroups);
                for (int i = 0; i < allItems.size(); i++) {
                    DisplayItemWithGroupBean diwb = allItems.get(i);

                    if (diwb.isInGroup()) {
                        List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                        manualRows = getManualRows(dgbs);
                    }
                }
                */
            // request.setAttribute("manualRows", new Integer(manualRows));
            Iterator iter3 = errors.keySet().iterator();
            while (iter3.hasNext()) {
                String fieldName = iter3.next().toString();
                LOGGER.debug("found error after shuffle " + fieldName);
            }
            // Mantis Issue: 8116. Parsist the markComplete chebox on error
            request.setAttribute("markComplete", fp.getString(INPUT_MARK_COMPLETE));
            // << tbh, 02/2010
            // YW >>
            // copied
            request.setAttribute(BEAN_DISPLAY, section);
            request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS));
            setInputMessages(errors, request);
            addPageMessage(respage.getString("errors_in_submission_see_below"), request);
            request.setAttribute("hasError", "true");
            // addPageMessage("To override these errors and keep the data as
            // you
            // entered it, click one of the \"Confirm\" buttons. ");
            // if (section.isCheckInputs()) {
            // addPageMessage("Please notice that you must enter data for
            // the
            // <b>required</b> entries.");
            // }
            // we do not save any DNs if we get here, so we have to set it back into session...
            session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
            // << tbh 01/2010
            setUpPanel(section);
            forwardPage(getJSPPage(), request, response);
        } else {
            // reshuffleReasonForChangeHashAndDiscrepancyNotes( allItems, request, ecb);
            LOGGER.debug("Do we hit this in save ?????");
            logMe("Do we hit this in save ????  " + System.currentTimeMillis());
            boolean success = true;
            boolean temp = true;
            // save interviewer name and date into DB
            ecb.setInterviewerName(fp.getString(INPUT_INTERVIEWER));
            if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
                ecb.setDateInterviewed(fp.getDate(INPUT_INTERVIEW_DATE));
            } else {
                ecb.setDateInterviewed(null);
            }
            if (ecdao == null) {
                ecdao = new EventCRFDAO(getDataSource());
            }
            // set validator id for DDE
            DataEntryStage stage = ecb.getStage();
            if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
                ecb.setValidatorId(ub.getId());
            }
            // for Administrative editing
            if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) && changedItemsList.size() > 0) {
                studyEventBean.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
                studyEventBean.setUpdater(ub);
                studyEventBean.setUpdatedDate(new Date());
                seDao.update(studyEventBean);
            }
            // If the Study Subject's Satus is signed and we save a section
            // , change status to available
            LOGGER.debug("Status of Study Subject {}", ssb.getStatus().getName());
            if (ssb.getStatus() == Status.SIGNED && changedItemsList.size() > 0) {
                LOGGER.debug("Status of Study Subject is Signed we are updating");
                StudySubjectDAO studySubjectDao = new StudySubjectDAO(getDataSource());
                ssb.setStatus(Status.AVAILABLE);
                ssb.setUpdater(ub);
                ssb.setUpdatedDate(new Date());
                studySubjectDao.update(ssb);
            }
            if (ecb.isSdvStatus() && changedItemsList.size() > 0) {
                LOGGER.debug("Status of Study Subject is SDV we are updating");
                StudySubjectDAO studySubjectDao = new StudySubjectDAO(getDataSource());
                ssb.setStatus(Status.AVAILABLE);
                ssb.setUpdater(ub);
                ssb.setUpdatedDate(new Date());
                studySubjectDao.update(ssb);
                ecb.setSdvStatus(false);
                ecb.setSdvUpdateId(ub.getId());
            }
            ecb = (EventCRFBean) ecdao.update(ecb);
            // save discrepancy notes into DB
            FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            dndao = new DiscrepancyNoteDAO(getDataSource());
            AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEWER, fdn, dndao, ecb.getId(), "EventCRF", currentStudy);
            AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEW_DATE, fdn, dndao, ecb.getId(), "EventCRF", currentStudy);
            // items = section.getItems();
            allItems = section.getDisplayItemGroups();
            int nextOrdinal = 0;
            LOGGER.debug("all items before saving into DB" + allItems.size());
            this.output(allItems);
            // TODO:Seems longer here, check this
            logMe("DisplayItemWithGroupBean allitems4 " + System.currentTimeMillis());
            for (int i = 0; i < allItems.size(); i++) {
                DisplayItemWithGroupBean diwb = allItems.get(i);
                // from executing writeToDB.
                if (diwb.isInGroup()) {
                    List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                    // using the above gets us the correct number of manual groups, tbh 01/2010
                    List<DisplayItemGroupBean> dbGroups = diwb.getDbItemGroups();
                    LOGGER.debug("item group size: " + dgbs.size());
                    LOGGER.debug("item db-group size: " + dbGroups.size());
                    for (int j = 0; j < dgbs.size(); j++) {
                        DisplayItemGroupBean displayGroup = dgbs.get(j);
                        List<DisplayItemBean> items = displayGroup.getItems();
                        // this ordinal will only useful to create a new
                        // item data
                        // update an item data won't touch its ordinal
                        // int nextOrdinal = iddao.getMaxOrdinalForGroup(ecb, sb, displayGroup.getItemGroupBean()) + 1;
                        // Determine if any items in this group have data.  If so we need to undelete and previously deleted items.
                        boolean undelete = false;
                        for (DisplayItemBean displayItem : items) {
                            String currItemVal = displayItem.getData().getValue();
                            if (currItemVal != null && !currItemVal.equals("")) {
                                undelete = true;
                                break;
                            }
                        }
                        for (DisplayItemBean displayItem : items) {
                            String fileName = this.addAttachedFilePath(displayItem, attachedFilePath);
                            boolean writeDN = true;
                            displayItem.setEditFlag(displayGroup.getEditFlag());
                            LOGGER.debug("group item value: " + displayItem.getData().getValue());
                            // if ("add".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                            // displayItem.getData().setValue("");
                            // }
                            // 15350, this particular logic, takes into consideration that a DN is created properly as long as the item data record exists and it fails to get created when it doesnt.
                            // so, we are expanding the logic from writeToDb method to avoid creating duplicate records.
                            writeDN = writeDN(displayItem);
                            // pulling from dataset instead of database and correcting the flawed logic of using the database ordinals as max ordinal...
                            nextOrdinal = displayItem.getData().getOrdinal();
                            temp = writeToDB(displayItem, iddao, nextOrdinal, request);
                            LOGGER.debug("just executed writeToDB - 1");
                            LOGGER.debug("next ordinal: " + nextOrdinal);
                            // Undelete item if any item in the repeating group has data.
                            if (undelete && displayItem.getDbData() != null && displayItem.getDbData().isDeleted()) {
                                iddao.undelete(displayItem.getDbData().getId(), ub.getId());
                            }
                            if (temp && newUploadedFiles.containsKey(fileName)) {
                                newUploadedFiles.remove(fileName);
                            }
                            // maybe put ordinal in the place of j? maybe subtract max rows from next ordinal if j is gt
                            // next ordinal?
                            String inputName = getGroupItemInputName(displayGroup, j, displayItem);
                            // String inputName2 = getGroupItemManualInputName(displayGroup, j, displayItem);
                            if (!displayGroup.isAuto()) {
                                LOGGER.trace("not auto");
                                inputName = this.getGroupItemManualInputName(displayGroup, j, displayItem);
                            }
                            // htaycher last DN is not stored for new rows
                            // if (j == dgbs.size() - 1) {
                            // // LAST ONE
                            // logger.trace("last one");
                            // int ordinal = j - this.getManualRows(dgbs);
                            // logger.debug("+++ found manual rows from line 1326: " + ordinal);
                            // inputName = getGroupItemInputName(displayGroup, ordinal, displayItem);
                            // }
                            // logger.trace("&&& we get previous looking at input name: " + inputName + " " + inputName2);
                            LOGGER.trace("&&& we get previous looking at input name: " + inputName);
                            // input name 2 removed from below
                            inputName = displayItem.getFieldName();
                            if (writeDN) {
                                AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, displayItem.getData().getId(), "itemData", currentStudy, ecb.getId());
                            }
                            success = success && temp;
                        }
                    }
                    for (int j = 0; j < dbGroups.size(); j++) {
                        DisplayItemGroupBean displayGroup = dbGroups.get(j);
                        // JN: Since remove button is gone, the following code can be commented out, however it needs to be tested? Can be tackled when handling discrepancy note w/repeating groups issues.
                        if ("remove".equalsIgnoreCase(displayGroup.getEditFlag())) {
                            List<DisplayItemBean> items = displayGroup.getItems();
                            for (DisplayItemBean displayItem : items) {
                                String fileName = this.addAttachedFilePath(displayItem, attachedFilePath);
                                displayItem.setEditFlag(displayGroup.getEditFlag());
                                LOGGER.debug("group item value: " + displayItem.getData().getValue());
                                // if ("add".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                                // displayItem.getData().setValue("");
                                // }
                                temp = writeToDB(displayItem, iddao, 0, request);
                                LOGGER.debug("just executed writeToDB - 2");
                                if (temp && newUploadedFiles.containsKey(fileName)) {
                                    newUploadedFiles.remove(fileName);
                                }
                                // just use 0 here since update doesn't
                                // touch ordinal
                                success = success && temp;
                            }
                        }
                    }
                } else {
                    DisplayItemBean dib = diwb.getSingleItem();
                    // TODO work on this line
                    // this.addAttachedFilePath(dib, attachedFilePath);
                    String fileName = addAttachedFilePath(dib, attachedFilePath);
                    boolean writeDN = writeDN(dib);
                    temp = writeToDB(dib, iddao, 1, request);
                    LOGGER.debug("just executed writeToDB - 3");
                    if (temp && (newUploadedFiles.containsKey(dib.getItem().getId() + "") || newUploadedFiles.containsKey(fileName))) {
                        // so newUploadedFiles will contain only failed file
                        // items;
                        newUploadedFiles.remove(dib.getItem().getId() + "");
                        newUploadedFiles.remove(fileName);
                    }
                    String inputName = getInputName(dib);
                    LOGGER.trace("3 - found input name: " + inputName);
                    if (writeDN)
                        AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, dib.getData().getId(), "itemData", currentStudy, ecb.getId());
                    success = success && temp;
                    ArrayList childItems = dib.getChildren();
                    for (int j = 0; j < childItems.size(); j++) {
                        DisplayItemBean child = (DisplayItemBean) childItems.get(j);
                        this.addAttachedFilePath(child, attachedFilePath);
                        writeDN = writeDN(child);
                        temp = writeToDB(child, iddao, 1, request);
                        LOGGER.debug("just executed writeToDB - 4");
                        if (temp && newUploadedFiles.containsKey(child.getItem().getId() + "")) {
                            // so newUploadedFiles will contain only failed
                            // file items;
                            newUploadedFiles.remove(child.getItem().getId() + "");
                        }
                        inputName = getInputName(child);
                        if (writeDN)
                            AddNewSubjectServlet.saveFieldNotes(inputName, fdn, dndao, child.getData().getId(), "itemData", currentStudy, ecb.getId());
                        success = success && temp;
                    }
                }
            }
            logMe("DisplayItemWithGroupBean allitems4 end " + System.currentTimeMillis());
            LOGGER.debug("running rules: " + phase2.name());
            List<Integer> prevShownDynItemDataIds = shouldRunRules ? this.getItemMetadataService().getDynamicsItemFormMetadataDao().findShowItemDataIdsInSection(section.getSection().getId(), ecb.getCRFVersionId(), ecb.getId()) : new ArrayList<Integer>();
            logMe("DisplayItemWithGroupBean dryrun  start" + System.currentTimeMillis());
            HashMap<String, ArrayList<String>> rulesPostDryRun = runRules(allItems, ruleSets, false, shouldRunRules, MessageType.WARNING, phase2, ecb, request);
            HashMap<String, ArrayList<String>> errorsPostDryRun = new HashMap<String, ArrayList<String>>();
            // additional step needed, run rules and see if any items are 'shown' AFTER saving data
            logMe("DisplayItemWithGroupBean dryrun  end" + System.currentTimeMillis());
            boolean inSameSection = false;
            logMe("DisplayItemWithGroupBean allitems4 " + System.currentTimeMillis());
            if (!rulesPostDryRun.isEmpty()) {
                // in same section?
                // iterate through the OIDs and see if any of them belong to this section
                Iterator iter3 = rulesPostDryRun.keySet().iterator();
                while (iter3.hasNext()) {
                    String fieldName = iter3.next().toString();
                    LOGGER.debug("found oid after post dry run " + fieldName);
                    // set up a listing of OIDs in the section
                    // BUT: Oids can have the group name in them.
                    int ordinal = -1;
                    String newFieldName = fieldName;
                    String[] fieldNames = fieldName.split("\\.");
                    if (fieldNames.length == 2) {
                        newFieldName = fieldNames[1];
                        // check items in item groups here?
                        if (fieldNames[0].contains("[")) {
                            int p1 = fieldNames[0].indexOf("[");
                            int p2 = fieldNames[0].indexOf("]");
                            try {
                                ordinal = Integer.valueOf(fieldNames[0].substring(p1 + 1, p2));
                            } catch (NumberFormatException e) {
                                ordinal = -1;
                            }
                            fieldNames[0] = fieldNames[0].substring(0, p1);
                        }
                    }
                    List<DisplayItemWithGroupBean> displayGroupsWithItems = section.getDisplayItemGroups();
                    // ArrayList<DisplayItemBean> displayItems = section.getItems();
                    for (int i = 0; i < displayGroupsWithItems.size(); i++) {
                        DisplayItemWithGroupBean itemWithGroup = displayGroupsWithItems.get(i);
                        if (itemWithGroup.isInGroup()) {
                            LOGGER.debug("found group: " + fieldNames[0]);
                            // do something there
                            List<DisplayItemGroupBean> digbs = itemWithGroup.getItemGroups();
                            LOGGER.debug("digbs size: " + digbs.size());
                            for (int j = 0; j < digbs.size(); j++) {
                                DisplayItemGroupBean displayGroup = digbs.get(j);
                                if (displayGroup.getItemGroupBean().getOid().equals(fieldNames[0]) && displayGroup.getOrdinal() == ordinal - 1) {
                                    List<DisplayItemBean> items = displayGroup.getItems();
                                    for (int k = 0; k < items.size(); k++) {
                                        DisplayItemBean dib = items.get(k);
                                        if (dib.getItem().getOid().equals(newFieldName)) {
                                            // inSameSection = true;
                                            if (!dib.getMetadata().isShowItem()) {
                                                LOGGER.debug("found item in group " + this.getGroupItemInputName(displayGroup, j, dib) + " vs. " + fieldName + " and is show item: " + dib.getMetadata().isShowItem());
                                                dib.getMetadata().setShowItem(true);
                                            }
                                            if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(dib.getData().getId())) {
                                                inSameSection = true;
                                                errorsPostDryRun.put(this.getGroupItemInputName(displayGroup, j, dib), rulesPostDryRun.get(fieldName));
                                            }
                                        }
                                        items.set(k, dib);
                                    }
                                    displayGroup.setItems(items);
                                    digbs.set(j, displayGroup);
                                }
                            }
                            itemWithGroup.setItemGroups(digbs);
                        } else {
                            DisplayItemBean displayItemBean = itemWithGroup.getSingleItem();
                            ItemBean itemBean = displayItemBean.getItem();
                            if (newFieldName.equals(itemBean.getOid())) {
                                // System.out.println("check run dynamics item check " + runDynamicsItemCheck(displayItemBean).getMetadata().isShowItem());
                                if (!displayItemBean.getMetadata().isShowItem()) {
                                    // double check there?
                                    LOGGER.debug("found item " + this.getInputName(displayItemBean) + " vs. " + fieldName + " and is show item: " + displayItemBean.getMetadata().isShowItem());
                                    // if is repeating, use the other input name? no
                                    displayItemBean.getMetadata().setShowItem(true);
                                    if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(displayItemBean.getData().getId())) {
                                        inSameSection = true;
                                        errorsPostDryRun.put(this.getInputName(displayItemBean), rulesPostDryRun.get(fieldName));
                                    }
                                }
                            }
                            itemWithGroup.setSingleItem(displayItemBean);
                        }
                        displayGroupsWithItems.set(i, itemWithGroup);
                    }
                    logMe("DisplayItemWithGroupBean allitems4  end,begin" + System.currentTimeMillis());
                    // check groups
                    // List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
                    // itemGroups = section.getDisplayFormGroups();
                    // But in jsp: section.displayItemGroups.itemGroup.groupMetaBean.showGroup
                    List<DisplayItemWithGroupBean> itemGroups = section.getDisplayItemGroups();
                    // List<DisplayItemGroupBean> newItemGroups = new ArrayList<DisplayItemGroupBean>();
                    for (DisplayItemWithGroupBean itemGroup : itemGroups) {
                        DisplayItemGroupBean displayGroup = itemGroup.getItemGroup();
                        if (newFieldName.equals(displayGroup.getItemGroupBean().getOid())) {
                            if (!displayGroup.getGroupMetaBean().isShowGroup()) {
                                inSameSection = true;
                                LOGGER.debug("found itemgroup " + displayGroup.getItemGroupBean().getOid() + " vs. " + fieldName + " and is show item: " + displayGroup.getGroupMetaBean().isShowGroup());
                                // hmmm how to set highlighting for a group?
                                errorsPostDryRun.put(displayGroup.getItemGroupBean().getOid(), rulesPostDryRun.get(fieldName));
                                displayGroup.getGroupMetaBean().setShowGroup(true);
                                // add necessary rows to the display group here????
                                // we have to set the items in the itemGroup for the displayGroup
                                loadItemsWithGroupRows(itemGroup, sb, edcb, ecb, request);
                            }
                        }
                    // newItemGroups.add(displayGroup);
                    }
                    logMe("DisplayItemWithGroupBean allitems4  end,end" + System.currentTimeMillis());
                    // trying to reset the display form groups here, tbh
                    // section.setItems(displayItems);
                    section.setDisplayItemGroups(displayGroupsWithItems);
                    populateInstantOnChange(request.getSession(), ecb, section);
                // section.setDisplayFormGroups(newDisplayBean.getDisplayFormGroups());
                }
                // 
                this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups, section.getSection().getId(), ecb);
                toc = TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY), (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService"));
                request.setAttribute(TOC_DISPLAY, toc);
                sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc);
                sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc);
                previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex);
                nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex);
                section.setFirstSection(!previousSec.isActive());
                section.setLastSection(!nextSec.isActive());
                // 
                // we need the following for repeating groups, tbh
                // >> tbh 06/2010
                // List<DisplayItemWithGroupBean> displayItemWithGroups2 = createItemWithGroups(section, hasGroup, eventDefinitionCRFId);
                // section.setDisplayItemGroups(displayItemWithGroups2);
                // if so, stay at this section
                LOGGER.debug(" in same section: " + inSameSection);
                if (inSameSection) {
                    // copy of one line from early on around line 400, forcing a re-show of the items
                    // section = getDisplayBean(hasGroup, true);// include all items, tbh
                    // below a copy of three lines from the if errors = true line, tbh 03/2010
                    String[] textFields = { INPUT_INTERVIEWER, INPUT_INTERVIEW_DATE };
                    fp.setCurrentStringValuesAsPreset(textFields);
                    setPresetValues(fp.getPresetValues(), request);
                    // below essetially a copy except for rulesPostDryRun
                    request.setAttribute(BEAN_DISPLAY, section);
                    request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS));
                    setInputMessages(errorsPostDryRun, request);
                    addPageMessage(respage.getString("your_answers_activated_hidden_items"), request);
                    request.setAttribute("hasError", "true");
                    request.setAttribute("hasShown", "true");
                    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
                    setUpPanel(section);
                    forwardPage(getJSPPage(), request, response);
                }
            }
            if (!inSameSection) {
                // else if not in same section, progress as usual
                /*
                    toc =
                        TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(), (DisplayTableOfContentsBean) request.getAttribute(TOC_DISPLAY),
                                (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService"));
                    request.setAttribute(TOC_DISPLAY, toc);
                    sectionIdsInToc = TableOfContentsServlet.sectionIdsInToc(toc);
                    sIndex = TableOfContentsServlet.sectionIndexInToc(section.getSection(), toc, sectionIdsInToc);
                    previousSec = this.prevSection(section.getSection(), ecb, toc, sIndex);
                    nextSec = this.nextSection(section.getSection(), ecb, toc, sIndex);
                    section.setFirstSection(!previousSec.isActive());
                    section.setLastSection(!nextSec.isActive());
                    */
                // can we just forward page or do we actually need an ELSE here?
                // yes, we do. tbh 05/03/2010
                ArrayList<String> updateFailedItems = sc.redoCalculations(scoreItems, scoreItemdata, changedItems, itemOrdinals, sb.getId());
                success = updateFailedItems.size() > 0 ? false : true;
                // now check if CRF is marked complete
                boolean markComplete = fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES);
                // if the CRF was marked
                boolean markSuccessfully = false;
                // successfully
                if (markComplete && section.isLastSection()) {
                    LOGGER.debug("need to mark CRF as complete");
                    markSuccessfully = markCRFComplete(request);
                    LOGGER.debug("...marked CRF as complete: " + markSuccessfully);
                    if (!markSuccessfully) {
                        request.setAttribute(BEAN_DISPLAY, section);
                        request.setAttribute(BEAN_ANNOTATIONS, fp.getString(INPUT_ANNOTATIONS));
                        setUpPanel(section);
                        forwardPage(getJSPPage(), request, response);
                        return;
                    }
                }
                // now write the event crf bean to the database
                String annotations = fp.getString(INPUT_ANNOTATIONS);
                setEventCRFAnnotations(annotations, request);
                Date now = new Date();
                ecb.setUpdatedDate(now);
                ecb.setUpdater(ub);
                ecb = (EventCRFBean) ecdao.update(ecb);
                success = success && ecb.isActive();
                StudyEventDAO sedao = new StudyEventDAO(getDataSource());
                StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
                seb.setUpdatedDate(now);
                seb.setUpdater(ub);
                seb = (StudyEventBean) sedao.update(seb);
                success = success && seb.isActive();
                request.setAttribute(INPUT_IGNORE_PARAMETERS, Boolean.TRUE);
                if (newUploadedFiles.size() > 0) {
                    if (this.unloadFiles(newUploadedFiles)) {
                    } else {
                        String missed = "";
                        Iterator iter = newUploadedFiles.keySet().iterator();
                        while (iter.hasNext()) {
                            missed += " " + newUploadedFiles.get(iter.next());
                        }
                        addPageMessage(respage.getString("uploaded_files_not_deleted_or_not_exist") + ": " + missed, request);
                    }
                }
                if (!success) {
                    // YW, 3-6-2008 <<
                    if (updateFailedItems.size() > 0) {
                        String mess = "";
                        for (String ss : updateFailedItems) {
                            mess += ss + ", ";
                        }
                        mess = mess.substring(0, mess.length() - 2);
                        addPageMessage(resexception.getString("item_save_failed_because_database_error") + mess, request);
                    } else {
                        // YW>>
                        addPageMessage(resexception.getString("database_error"), request);
                    }
                    request.setAttribute(BEAN_DISPLAY, section);
                    session.removeAttribute(GROUP_HAS_DATA);
                    session.removeAttribute(HAS_DATA_FLAG);
                    session.removeAttribute(DDE_PROGESS);
                    session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
                    LOGGER.debug("try to remove to_create_crf");
                    session.removeAttribute("to_create_crf");
                    session.removeAttribute(instantAtt);
                    // forwardPage(Page.SUBMIT_DATA_SERVLET);
                    forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
                // >> changed tbh, 06/2009
                } else {
                    boolean forwardingSucceeded = false;
                    if (!fp.getString(GO_PREVIOUS).equals("")) {
                        if (previousSec.isActive()) {
                            forwardingSucceeded = true;
                            request.setAttribute(INPUT_EVENT_CRF, ecb);
                            request.setAttribute(INPUT_SECTION, previousSec);
                            int tabNum = 0;
                            if (fp.getString("tab") == null) {
                                tabNum = 1;
                            } else {
                                tabNum = fp.getInt("tab");
                            }
                            request.setAttribute("tab", new Integer(tabNum - 1).toString());
                            // forwardPage(getServletPage(request), request, response);
                            getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response);
                        }
                    } else if (!fp.getString(GO_NEXT).equals("")) {
                        if (nextSec.isActive()) {
                            forwardingSucceeded = true;
                            request.setAttribute(INPUT_EVENT_CRF, ecb);
                            request.setAttribute(INPUT_SECTION, nextSec);
                            int tabNum = 0;
                            if (fp.getString("tab") == null) {
                                tabNum = 1;
                            } else {
                                tabNum = fp.getInt("tab");
                            }
                            request.setAttribute("tab", new Integer(tabNum + 1).toString());
                            getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response);
                        // forwardPage(getServletPage(request), request, response);
                        }
                    }
                    if (!forwardingSucceeded) {
                        // ecb);
                        if (markSuccessfully) {
                            addPageMessage(respage.getString("data_saved_CRF_marked_complete"), request);
                            session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
                            session.removeAttribute(GROUP_HAS_DATA);
                            session.removeAttribute(HAS_DATA_FLAG);
                            session.removeAttribute(DDE_PROGESS);
                            session.removeAttribute("to_create_crf");
                            request.setAttribute("eventId", new Integer(ecb.getStudyEventId()).toString());
                            forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET, request, response);
                        } else {
                            // use clicked 'save'
                            addPageMessage(respage.getString("data_saved_continue_entering_edit_later"), request);
                            request.setAttribute(INPUT_EVENT_CRF, ecb);
                            request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()).toString());
                            // is not the last section
                            if (!section.isLastSection()) {
                                request.setAttribute(INPUT_SECTION, nextSec);
                                request.setAttribute(INPUT_SECTION_ID, new Integer(nextSec.getId()).toString());
                                session.removeAttribute("mayProcessUploading");
                            } else if (section.isLastSection()) {
                                // JN ADDED TO avoid return down
                                // already the last section, should go back to
                                // view event page
                                session.removeAttribute(GROUP_HAS_DATA);
                                session.removeAttribute(HAS_DATA_FLAG);
                                session.removeAttribute(DDE_PROGESS);
                                session.removeAttribute("to_create_crf");
                                session.removeAttribute("mayProcessUploading");
                                request.setAttribute("eventId", new Integer(ecb.getStudyEventId()).toString());
                                if (fromViewNotes != null && "1".equals(fromViewNotes)) {
                                    String viewNotesPageFileName = (String) session.getAttribute("viewNotesPageFileName");
                                    session.removeAttribute("viewNotesPageFileName");
                                    session.removeAttribute("viewNotesURL");
                                    if (viewNotesPageFileName != null && viewNotesPageFileName.length() > 0) {
                                        // forwardPage(Page.setNewPage(viewNotesPageFileName, "View Notes"), request, response);
                                        getServletContext().getRequestDispatcher(viewNotesPageFileName).forward(request, response);
                                    }
                                }
                                session.removeAttribute(instantAtt);
                                forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET, request, response);
                                return;
                            }
                            int tabNum = 0;
                            if (fp.getString("tab") == null) {
                                tabNum = 1;
                            } else {
                                tabNum = fp.getInt("tab");
                            }
                            if (!section.isLastSection()) {
                                request.setAttribute("tab", new Integer(tabNum + 1).toString());
                            }
                            // forwardPage(getServletPage(request), request, response);
                            getServletContext().getRequestDispatcher(getServletPage(request)).forward(request, response);
                        }
                    // session.removeAttribute(AddNewSubjectServlet.
                    // FORM_DISCREPANCY_NOTES_NAME);
                    // forwardPage(Page.SUBMIT_DATA_SERVLET);
                    }
                }
            }
        // end of if-block for dynamic rules not in same section, tbh 05/2010
        }
    // end of save
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) TreeSet(java.util.TreeSet) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ScoreCalculator(org.akaza.openclinica.logic.score.ScoreCalculator) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) DynamicsMetadataService(org.akaza.openclinica.service.crfdata.DynamicsMetadataService) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Status(org.akaza.openclinica.bean.core.Status) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) Validation(org.akaza.openclinica.control.form.Validation) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ScoreItemValidator(org.akaza.openclinica.control.form.ScoreItemValidator) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) Map(java.util.Map) HashMap(java.util.HashMap) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO) Phase(org.akaza.openclinica.domain.rule.action.RuleActionRunBean.Phase) Set(java.util.Set) TreeSet(java.util.TreeSet) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) HttpSession(javax.servlet.http.HttpSession) SessionManager(org.akaza.openclinica.core.SessionManager) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) Date(java.util.Date) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) SimpleConditionalDisplayService(org.akaza.openclinica.service.crfdata.SimpleConditionalDisplayService) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) SimpleDateFormat(java.text.SimpleDateFormat) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) RuleValidator(org.akaza.openclinica.control.form.RuleValidator)

Example 3 with FormDiscrepancyNotes

use of org.akaza.openclinica.control.form.FormDiscrepancyNotes in project OpenClinica by OpenClinica.

the class AddNewSubjectServlet method processRequest.

// YW >>
/*
     * (non-Javadoc)
     * 
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    checkStudyLocked(Page.LIST_STUDY_SUBJECTS, respage.getString("current_study_locked"));
    checkStudyFrozen(Page.LIST_STUDY_SUBJECTS, respage.getString("current_study_frozen"));
    StudySubjectDAO ssd = new StudySubjectDAO(sm.getDataSource());
    StudyDAO stdao = new StudyDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    ArrayList classes = new ArrayList();
    panel.setStudyInfoShown(false);
    FormProcessor fp = new FormProcessor(request);
    FormDiscrepancyNotes discNotes;
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    // TODO l10n for dates? Note that in some places we hard-code the YOB by
    // using "01/01/"+yob,
    // not exactly supporting i18n...tbh
    // YW << update study parameters of current study.
    // "collectDob" and "genderRequired" are set as the same as the parent
    // study
    int parentStudyId = currentStudy.getParentStudyId();
    if (parentStudyId <= 0) {
        parentStudyId = currentStudy.getId();
        classes = sgcdao.findAllActiveByStudy(currentStudy);
    } else {
        StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
        classes = sgcdao.findAllActiveByStudy(parentStudy);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
    currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
    currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
    // YW >>
    // tbh
    StudyParameterValueBean checkPersonId = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
    currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(checkPersonId.getValue());
    if (!fp.isSubmitted()) {
        if (fp.getBoolean("instr")) {
            session.removeAttribute(FORM_DISCREPANCY_NOTES_NAME);
            forwardPage(Page.INSTRUCTIONS_ENROLL_SUBJECT);
        } else {
            setUpBeans(classes);
            Date today = new Date(System.currentTimeMillis());
            String todayFormatted = local_df.format(today);
            fp.addPresetValue(INPUT_ENROLLMENT_DATE, todayFormatted);
            // YW 10-07-2007 <<
            String idSetting = "";
            if (currentStudy.getParentStudyId() > 0) {
                parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
                currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
            }
            idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
            // YW >>
            logger.info("subject id setting :" + idSetting);
            // available ID (label) for now
            if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
                // Shaoyu Su
                // int nextLabel = ssd.findTheGreatestLabel() + 1;
                // fp.addPresetValue(INPUT_LABEL, new Integer(nextLabel).toString());
                fp.addPresetValue(INPUT_LABEL, resword.getString("id_generated_Save_Add"));
            }
            setPresetValues(fp.getPresetValues());
            discNotes = new FormDiscrepancyNotes();
            session.setAttribute(FORM_DISCREPANCY_NOTES_NAME, discNotes);
            forwardPage(Page.ADD_NEW_SUBJECT);
        }
    } else {
        // values in database <subject> table for "add existing subject"
        if (!fp.getBoolean(EXISTING_SUB_SHOWN)) {
            DOB = fp.getString(INPUT_DOB);
            YOB = fp.getString(INPUT_YOB);
            GENDER = fp.getString(INPUT_GENDER);
        }
        // YW >>
        discNotes = (FormDiscrepancyNotes) session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
        if (discNotes == null) {
            discNotes = new FormDiscrepancyNotes();
        }
        DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
        v.addValidation(INPUT_LABEL, Validator.NO_BLANKS);
        String subIdSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
        if (!subIdSetting.equalsIgnoreCase("auto non-editable") && !subIdSetting.equalsIgnoreCase("auto editable")) {
            v.addValidation(INPUT_LABEL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
        }
        if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required")) {
            v.addValidation(INPUT_UNIQUE_IDENTIFIER, Validator.NO_BLANKS);
        }
        v.addValidation(INPUT_UNIQUE_IDENTIFIER, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
        if (!StringUtils.isBlank(fp.getString(INPUT_SECONDARY_LABEL))) {
            v.addValidation(INPUT_SECONDARY_LABEL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
        }
        String dobSetting = currentStudy.getStudyParameterConfig().getCollectDob();
        if (dobSetting.equals("1")) {
            // date of birth
            v.addValidation(INPUT_DOB, Validator.IS_A_DATE);
            if (!StringUtils.isBlank(fp.getString("INPUT_DOB"))) {
                v.alwaysExecuteLastValidation(INPUT_DOB);
            }
            v.addValidation(INPUT_DOB, Validator.DATE_IN_PAST);
        } else if (dobSetting.equals("2")) {
            // year of birth
            v.addValidation(INPUT_YOB, Validator.IS_AN_INTEGER);
            v.alwaysExecuteLastValidation(INPUT_YOB);
            v.addValidation(INPUT_YOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, 1000);
            // get today's year
            Date today = new Date();
            Calendar c = Calendar.getInstance();
            c.setTime(today);
            int currentYear = c.get(Calendar.YEAR);
            v.addValidation(INPUT_YOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, currentYear);
        } else {
            // DOB not used, added tbh 102007
            logger.info("should read this only if DOB not used");
        }
        ArrayList acceptableGenders = new ArrayList();
        acceptableGenders.add("m");
        acceptableGenders.add("f");
        if (!currentStudy.getStudyParameterConfig().getGenderRequired().equals("false")) {
            v.addValidation(INPUT_GENDER, Validator.IS_IN_SET, acceptableGenders);
        }
        v.addValidation(INPUT_ENROLLMENT_DATE, Validator.IS_A_DATE);
        v.alwaysExecuteLastValidation(INPUT_ENROLLMENT_DATE);
        v.addValidation(INPUT_ENROLLMENT_DATE, Validator.DATE_IN_PAST);
        boolean locationError = false;
        if (fp.getBoolean("addWithEvent")) {
            v.addValidation(INPUT_EVENT_START_DATE, Validator.IS_A_DATE);
            v.alwaysExecuteLastValidation(INPUT_EVENT_START_DATE);
            if (currentStudy.getStudyParameterConfig().getEventLocationRequired().equalsIgnoreCase("required")) {
                v.addValidation("location", Validator.NO_BLANKS);
                locationError = true;
            }
        }
        HashMap errors = v.validate();
        SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
        // global
        String uniqueIdentifier = fp.getString(INPUT_UNIQUE_IDENTIFIER);
        // Id
        SubjectBean subjectWithSameId = new SubjectBean();
        SubjectBean subjectWithSameIdInParent = new SubjectBean();
        boolean showExistingRecord = false;
        if (!uniqueIdentifier.equals("")) {
            boolean subjectWithSameIdInCurrentStudyTree = false;
            // checks whether there is a subject with same id inside current
            // study/site
            subjectWithSameId = sdao.findByUniqueIdentifierAndStudy(uniqueIdentifier, currentStudy.getId());
            // tbh
            if (subjectWithSameId.isActive()) {
                // ||
                // subjectWithSameIdInParent.isActive())
                // {
                Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("subject_with_person_ID") + " " + uniqueIdentifier + " " + resexception.getString("is_already_enrolled_in_this_study"));
                subjectWithSameIdInCurrentStudyTree = true;
                logger.info("just added unique id in study tree");
            } else {
                // checks whether there is a subject with same id inside
                // sites of
                // current study
                subjectWithSameId = sdao.findByUniqueIdentifierAndParentStudy(uniqueIdentifier, currentStudy.getId());
                if (subjectWithSameId.isActive()) {
                    StudySubjectBean ssub = ssd.findBySubjectIdAndStudy(subjectWithSameId.getId(), currentStudy);
                    StudyBean site = (StudyBean) stdao.findByPK(ssub.getStudyId());
                    Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_site") + site.getName() + resexception.getString("of_current_study_need_to_move") + resexception.getString("please_have_user_manage_privileges"));
                    subjectWithSameIdInCurrentStudyTree = true;
                } else {
                    // check whether there is a subject with same id in the
                    // parent study
                    subjectWithSameId = sdao.findByUniqueIdentifierAndStudy(uniqueIdentifier, currentStudy.getParentStudyId());
                    if (subjectWithSameId.isActive()) {
                        Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_with_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_parent_study"));
                        subjectWithSameIdInCurrentStudyTree = true;
                    } else {
                        // YW 11-26-2007 << check whether there is a subject
                        // with the same id in other sites of the same study
                        subjectWithSameId = sdao.findByUniqueIdentifierAndParentStudy(uniqueIdentifier, currentStudy.getParentStudyId());
                        if (subjectWithSameId.isActive()) {
                            Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("this_subject_with_person_ID") + " " + uniqueIdentifier + resexception.getString("has_already_enrolled_site_study"));
                            subjectWithSameIdInCurrentStudyTree = true;
                        }
                    // YW >>
                    }
                }
            }
            if (!subjectWithSameIdInCurrentStudyTree) {
                subjectWithSameId = sdao.findByUniqueIdentifier(uniqueIdentifier);
                // found subject with same id in other study
                if (subjectWithSameId.isActive()) {
                    showExistingRecord = true;
                }
            }
        }
        // end of the block if(!uniqueIdentifier.equals(""))
        String label = fp.getString(INPUT_LABEL);
        String personId = fp.getString(INPUT_UNIQUE_IDENTIFIER);
        String secondaryLable = fp.getString(INPUT_SECONDARY_LABEL);
        // then Study Subject ID should be created when db row is inserted.
        if (label.contains("<") || label.contains(">")) {
            Validator.addError(errors, INPUT_LABEL, resexception.getString("study_subject_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
        }
        if (secondaryLable.contains("<") || secondaryLable.contains(">")) {
            Validator.addError(errors, INPUT_SECONDARY_LABEL, resexception.getString("secondary_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
        }
        if (personId.contains("<") || personId.contains(">")) {
            Validator.addError(errors, INPUT_UNIQUE_IDENTIFIER, resexception.getString("person_id_can_not_contain_html_lessthan_or_greaterthan_elements"));
        }
        if (!label.equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
            StudySubjectBean subjectWithSameLabel = ssd.findByLabelAndStudy(label, currentStudy);
            StudySubjectBean subjectWithSameLabelInParent = new StudySubjectBean();
            // tbh
            if (currentStudy.getParentStudyId() > 0) {
                // <
                subjectWithSameLabelInParent = ssd.findSameByLabelAndStudy(label, currentStudy.getParentStudyId(), 0);
            // --
            // blank
            // id
            // since
            // the
            // ss
            // hasn't
            // been
            // created
            // yet,
            // tbh
            }
            // tbh
            if (subjectWithSameLabel.isActive() || subjectWithSameLabelInParent.isActive()) {
                Validator.addError(errors, INPUT_LABEL, resexception.getString("another_assigned_this_ID_choose_unique"));
            }
        }
        if (!classes.isEmpty()) {
            for (int i = 0; i < classes.size(); i++) {
                StudyGroupClassBean sgc = (StudyGroupClassBean) classes.get(i);
                int groupId = fp.getInt("studyGroupId" + i);
                String notes = fp.getString("notes" + i);
                if ("Required".equals(sgc.getSubjectAssignment()) && groupId == 0) {
                    Validator.addError(errors, "studyGroupId" + i, resexception.getString("group_class_is_required"));
                }
                if (notes.trim().length() > 255) {
                    Validator.addError(errors, "notes" + i, resexception.getString("notes_cannot_longer_255"));
                }
                sgc.setStudyGroupId(groupId);
                sgc.setGroupNotes(notes);
            }
        }
        if (!errors.isEmpty()) {
            addPageMessage(respage.getString("there_were_some_errors_submission"));
            if (locationError) {
                addPageMessage(respage.getString("location_blank_error"));
            }
            setInputMessages(errors);
            fp.addPresetValue(INPUT_DOB, fp.getString(INPUT_DOB));
            fp.addPresetValue(INPUT_YOB, fp.getString(INPUT_YOB));
            fp.addPresetValue(INPUT_GENDER, fp.getString(INPUT_GENDER));
            fp.addPresetValue(INPUT_UNIQUE_IDENTIFIER, uniqueIdentifier);
            fp.addPresetValue(INPUT_LABEL, label);
            fp.addPresetValue(INPUT_SECONDARY_LABEL, fp.getString(INPUT_SECONDARY_LABEL));
            fp.addPresetValue(INPUT_ENROLLMENT_DATE, fp.getString(INPUT_ENROLLMENT_DATE));
            fp.addPresetValue(INPUT_EVENT_START_DATE, fp.getString(INPUT_EVENT_START_DATE));
            fp.addPresetValue(STUDY_EVENT_DEFINITION, fp.getInt(STUDY_EVENT_DEFINITION));
            fp.addPresetValue(LOCATION, fp.getString(LOCATION));
            fp.addPresetValue(EDIT_DOB, fp.getString(EDIT_DOB));
            setPresetValues(fp.getPresetValues());
            setUpBeans(classes);
            boolean existingSubShown = fp.getBoolean(EXISTING_SUB_SHOWN);
            if (!existingSubShown) {
                Object isSubjectOverlay = fp.getRequest().getParameter("subjectOverlay");
                if (isSubjectOverlay != null) {
                    int eventId = fp.getInt("studyEventDefinition");
                    if (eventId < 1) {
                        Validator.addError(errors, STUDY_EVENT_DEFINITION, resexception.getString("input_not_acceptable_option"));
                    }
                    String location = fp.getString(LOCATION);
                    if (location == null && location.length() == 0) {
                        Validator.addError(errors, LOCATION, resexception.getString("field_not_blank"));
                    }
                    request.setAttribute("showOverlay", true);
                    forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
                } else {
                    forwardPage(Page.ADD_NEW_SUBJECT);
                }
            } else {
                forwardPage(Page.ADD_EXISTING_SUBJECT);
            }
        } else {
            // no errors
            StudySubjectBean studySubject = new StudySubjectBean();
            SubjectBean subject = new SubjectBean();
            boolean existingSubShown = fp.getBoolean(EXISTING_SUB_SHOWN);
            if (showExistingRecord && !existingSubShown) {
                needUpdate = false;
                subject = subjectWithSameId;
                Calendar cal = Calendar.getInstance();
                int year = 0;
                if (subject.getDateOfBirth() != null) {
                    cal.setTime(subject.getDateOfBirth());
                    year = cal.get(Calendar.YEAR);
                    fp.addPresetValue(INPUT_DOB, local_df.format(subject.getDateOfBirth()));
                } else {
                    fp.addPresetValue(INPUT_DOB, "");
                }
                if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1") && !subject.isDobCollected()) {
                    // fp.addPresetValue(EDIT_DOB, "yes");
                    fp.addPresetValue(INPUT_DOB, fp.getString(INPUT_DOB));
                }
                // YW << it has been taken off to solve bug0001125
                /*
                     * else { fp.addPresetValue(INPUT_DOB, ""); }
                     */
                // YW >>
                fp.addPresetValue(INPUT_YOB, String.valueOf(year));
                if (!currentStudy.getStudyParameterConfig().getGenderRequired().equals("false")) {
                    fp.addPresetValue(INPUT_GENDER, subject.getGender() + "");
                } else {
                    fp.addPresetValue(INPUT_GENDER, "");
                }
                // Shaoyu Su: delay setting INPUT_LABEL field
                if (!label.equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
                    fp.addPresetValue(INPUT_LABEL, label);
                }
                fp.addPresetValue(INPUT_SECONDARY_LABEL, fp.getString(INPUT_SECONDARY_LABEL));
                fp.addPresetValue(INPUT_ENROLLMENT_DATE, fp.getString(INPUT_ENROLLMENT_DATE));
                fp.addPresetValue(INPUT_EVENT_START_DATE, fp.getString(INPUT_EVENT_START_DATE));
                // YW >>
                fp.addPresetValue(INPUT_UNIQUE_IDENTIFIER, subject.getUniqueIdentifier());
                setPresetValues(fp.getPresetValues());
                setUpBeans(classes);
                // YW <<
                int warningCount = 0;
                if (currentStudy.getStudyParameterConfig().getGenderRequired().equalsIgnoreCase("true")) {
                    if (String.valueOf(subjectWithSameId.getGender()).equals(" ")) {
                        fp.addPresetValue(G_WARNING, "emptytrue");
                        fp.addPresetValue(INPUT_GENDER, GENDER);
                        needUpdate = true;
                        updateSubject = subjectWithSameId;
                        updateSubject.setGender(GENDER.toCharArray()[0]);
                        warningCount++;
                    } else if (!String.valueOf(subjectWithSameId.getGender()).equals(GENDER)) {
                        fp.addPresetValue(G_WARNING, "true");
                        warningCount++;
                    } else {
                        fp.addPresetValue(G_WARNING, "false");
                    }
                } else {
                    fp.addPresetValue(G_WARNING, "false");
                }
                // Current study required DOB
                if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
                    // date-of-birth in subject table is not completed
                    if (subjectWithSameId.isDobCollected() == false) {
                        needUpdate = true;
                        updateSubject = subjectWithSameId;
                        updateSubject.setDobCollected(true);
                        if (subjectWithSameId.getDateOfBirth() == null) {
                            fp.addPresetValue(INPUT_DOB, DOB);
                            updateSubject.setDateOfBirth(new Date(DOB));
                        } else {
                            String y = String.valueOf(subjectWithSameId.getDateOfBirth()).split("\\-")[0];
                            String[] d = DOB.split("\\/");
                            // if year-of-birth in subject table
                            if (!y.equals("0001")) {
                                // year, use year-of-birth
                                if (!y.equals(d[2])) {
                                    fp.addPresetValue(D_WARNING, "dobYearWrong");
                                    fp.addPresetValue(INPUT_DOB, d[0] + "/" + d[1] + "/" + y);
                                    updateSubject.setDateOfBirth(sdf.parse(d[0] + "/" + d[1] + "/" + y));
                                } else {
                                    fp.addPresetValue(D_WARNING, "dobUsed");
                                    fp.addPresetValue(INPUT_DOB, DOB);
                                    updateSubject.setDateOfBirth(sdf.parse(DOB));
                                }
                            } else // date-of-birth is not required in subject
                            // table
                            {
                                fp.addPresetValue(D_WARNING, "emptyD");
                                fp.addPresetValue(INPUT_DOB, DOB);
                                updateSubject.setDateOfBirth(sdf.parse(DOB));
                            }
                        }
                        warningCount++;
                    } else // date-of-birth in subject table but doesn't match DOB
                    if (!local_df.format(subjectWithSameId.getDateOfBirth()).toString().equals(DOB)) {
                        // System.out.println("comparing " +
                        // local_df.format(
                        // subjectWithSameId.getDateOfBirth()).toString());
                        fp.addPresetValue(D_WARNING, "currentDOBWrong");
                        warningCount++;
                    } else // date-of-birth in subject table matchs DOB
                    {
                        fp.addPresetValue(D_WARNING, "false");
                    }
                } else // current Study require YOB
                if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
                    String y = String.valueOf(subjectWithSameId.getDateOfBirth()).split("\\-")[0];
                    // year of date-of-birth in subject table is avaible
                    if (!y.equals("0001")) {
                        // year in subject table doesn't match YOB,
                        if (!y.equals(YOB)) {
                            fp.addPresetValue(Y_WARNING, "yobWrong");
                            warningCount++;
                        } else // year in subject table matches YOB
                        {
                            fp.addPresetValue(Y_WARNING, "false");
                        }
                    } else // year of date-of-birth in the subject talbe is not
                    // availbe, YOB is used
                    {
                        needUpdate = true;
                        updateSubject = subjectWithSameId;
                        fp.addPresetValue(Y_WARNING, "yearEmpty");
                        fp.addPresetValue(INPUT_YOB, YOB);
                        updateSubject.setDateOfBirth(sdf.parse("01/01/" + YOB));
                        warningCount++;
                    }
                } else // current study require no DOB, there is no need to check
                // date-of-birth in the subject table
                {
                    fp.addPresetValue(Y_WARNING, "false");
                }
                if (warningCount > 0) {
                    warningCount = 0;
                    forwardPage(Page.ADD_EXISTING_SUBJECT);
                    return;
                }
            // forwardPage(Page.ADD_EXISTING_SUBJECT);
            // return;
            // YW >>
            }
            // to be inserted into both <subject> and <studysubject> tables
            if (!showExistingRecord) {
                // YW >>
                if (!StringUtil.isBlank(fp.getString(INPUT_GENDER))) {
                    subject.setGender(fp.getString(INPUT_GENDER).charAt(0));
                } else {
                    subject.setGender(' ');
                }
                subject.setUniqueIdentifier(uniqueIdentifier);
                if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
                    if (!StringUtil.isBlank(fp.getString(INPUT_DOB))) {
                        subject.setDateOfBirth(fp.getDate(INPUT_DOB));
                        subject.setDobCollected(true);
                    } else {
                        subject.setDateOfBirth(null);
                        subject.setDobCollected(false);
                    }
                } else if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
                    // generate a fake birthday in 01/01/YYYY format, only
                    // the year is
                    // valid
                    // added the "2" to make sure that 'not used' is kept to
                    // null, tbh 102007
                    subject.setDobCollected(false);
                    int yob = fp.getInt(INPUT_YOB);
                    Date fakeDate = new Date("01/01/" + yob);
                    // Calendar fakeCal = Calendar.getInstance();
                    // fakeCal.set(Calendar.YEAR, yob);
                    // fakeCal.set(Calendar.MONTH, 1);
                    // fakeCal.set(Calendar.DAY_OF_MONTH, 1);
                    // String dobString = "01/01/" + yob;
                    String dobString = local_df.format(fakeDate);
                    try {
                        Date fakeDOB = local_df.parse(dobString);
                        subject.setDateOfBirth(fakeDOB);
                    } catch (ParseException pe) {
                        subject.setDateOfBirth(new Date());
                        addPageMessage(respage.getString("problem_happened_saving_year"));
                    }
                }
                subject.setStatus(Status.AVAILABLE);
                subject.setOwner(ub);
                subject = sdao.create(subject);
                if (!subject.isActive()) {
                    throw new OpenClinicaException(resexception.getString("could_not_create_subject"), "3");
                }
            // YW << for showExistingRecord && existingSubShown,
            // If input value(s) is(are) different from database,
            // warning will be shown.
            // If value(s) in database is(are) empty, entered value(s)
            // could be used;
            // Otherwise, value(s) in database will be used.
            // For date-of-birth, if database only has year-of-birth,
            // the year in database will be used for year part
            } else if (existingSubShown) {
                if (!needUpdate) {
                    subject = subjectWithSameId;
                } else {
                    updateSubject.setUpdater(ub);
                    updateSubject = (SubjectBean) sdao.update(updateSubject);
                    if (!updateSubject.isActive()) {
                        throw new OpenClinicaException("Could not create subject.", "5");
                    }
                    subject = updateSubject;
                    needUpdate = false;
                }
            }
            // YW >>
            // enroll the subject in the active study
            studySubject.setSubjectId(subject.getId());
            studySubject.setStudyId(currentStudy.getId());
            studySubject.setLabel(fp.getString(INPUT_LABEL));
            studySubject.setSecondaryLabel(fp.getString(INPUT_SECONDARY_LABEL));
            studySubject.setStatus(Status.AVAILABLE);
            studySubject.setEnrollmentDate(fp.getDate(INPUT_ENROLLMENT_DATE));
            if (fp.getBoolean("addWithEvent")) {
                studySubject.setEventStartDate(fp.getDate(INPUT_EVENT_START_DATE));
            }
            studySubject.setOwner(ub);
            // Shaoyu Su: prevent same label ("Study Subject ID")
            if (fp.getString(INPUT_LABEL).equalsIgnoreCase(resword.getString("id_generated_Save_Add"))) {
                synchronized (simpleLockObj) {
                    int nextLabel = ssd.findTheGreatestLabel() + 1;
                    studySubject.setLabel(nextLabel + "");
                    studySubject = ssd.createWithoutGroup(studySubject);
                    if (showExistingRecord && !existingSubShown) {
                        fp.addPresetValue(INPUT_LABEL, label);
                    }
                }
            } else {
                studySubject = ssd.createWithoutGroup(studySubject);
            }
            if (!classes.isEmpty() && studySubject.isActive()) {
                SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
                for (int i = 0; i < classes.size(); i++) {
                    StudyGroupClassBean group = (StudyGroupClassBean) classes.get(i);
                    int studyGroupId = group.getStudyGroupId();
                    String notes = group.getGroupNotes();
                    SubjectGroupMapBean map = new SubjectGroupMapBean();
                    map.setNotes(group.getGroupNotes());
                    map.setStatus(Status.AVAILABLE);
                    map.setStudyGroupId(group.getStudyGroupId());
                    map.setStudySubjectId(studySubject.getId());
                    map.setStudyGroupClassId(group.getId());
                    map.setOwner(ub);
                    if (map.getStudyGroupId() > 0) {
                        sgmdao.create(map);
                    }
                }
            }
            if (!studySubject.isActive()) {
                throw new OpenClinicaException(resexception.getString("could_not_create_study_subject"), "4");
            }
            // save discrepancy notes into DB
            FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(FORM_DISCREPANCY_NOTES_NAME);
            DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
            String[] subjectFields = { INPUT_DOB, INPUT_YOB, INPUT_GENDER };
            for (String element : subjectFields) {
                saveFieldNotes(element, fdn, dndao, subject.getId(), "subject", currentStudy);
            }
            saveFieldNotes(INPUT_ENROLLMENT_DATE, fdn, dndao, studySubject.getId(), "studySub", currentStudy);
            request.removeAttribute(FormProcessor.FIELD_SUBMITTED);
            request.setAttribute(CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT, studySubject);
            request.setAttribute(CreateNewStudyEventServlet.INPUT_REQUEST_STUDY_SUBJECT, "no");
            request.setAttribute(FormProcessor.FIELD_SUBMITTED, "0");
            addPageMessage(respage.getString("subject_with_unique_identifier") + studySubject.getLabel() + respage.getString("X_was_created_succesfully"));
            if (fp.getBoolean("addWithEvent")) {
                createStudyEvent(fp, studySubject);
                // YW <<
                request.setAttribute("id", studySubject.getId() + "");
                // String url= response.encodeRedirectURL("ViewStudySubject?id=" + studySubject.getId());
                // response.sendRedirect(url);
                forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
                // + studySubject.getId()));
                return;
            }
            String submitEvent = fp.getString(SUBMIT_EVENT_BUTTON);
            String submitEnroll = fp.getString(SUBMIT_ENROLL_BUTTON);
            String submitDone = fp.getString(SUBMIT_DONE_BUTTON);
            session.removeAttribute(FORM_DISCREPANCY_NOTES_NAME);
            if (!StringUtil.isBlank(submitEvent)) {
                forwardPage(Page.CREATE_NEW_STUDY_EVENT_SERVLET);
            } else if (!StringUtil.isBlank(submitEnroll)) {
                // NEW MANTIS ISSUE 4770
                setUpBeans(classes);
                Date today = new Date(System.currentTimeMillis());
                String todayFormatted = local_df.format(today);
                fp.addPresetValue(INPUT_ENROLLMENT_DATE, todayFormatted);
                // YW 10-07-2007 <<
                String idSetting = "";
                if (currentStudy.getParentStudyId() > 0) {
                    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
                    currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
                }
                idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
                // YW >>
                logger.info("subject id setting :" + idSetting);
                // set up auto study subject id
                if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
                    // Shaoyu Su
                    // int nextLabel = ssd.findTheGreatestLabel() + 1;
                    // fp.addPresetValue(INPUT_LABEL, new Integer(nextLabel).toString());
                    fp.addPresetValue(INPUT_LABEL, resword.getString("id_generated_Save_Add"));
                }
                setPresetValues(fp.getPresetValues());
                discNotes = new FormDiscrepancyNotes();
                session.setAttribute(FORM_DISCREPANCY_NOTES_NAME, discNotes);
                // End of 4770
                forwardPage(Page.ADD_NEW_SUBJECT);
            } else {
                // forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
                // forwardPage(Page.SUBMIT_DATA_SERVLET);
                request.setAttribute("id", studySubject.getId() + "");
                // String url=response.encodeRedirectURL("ViewStudySubject?id=" + studySubject.getId());
                // response.sendRedirect(url);
                forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
                return;
            }
        }
    // end of no error (errors.isEmpty())
    }
// end of fp.isSubmitted()
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) Calendar(java.util.Calendar) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) DisplaySubjectBean(org.akaza.openclinica.bean.submit.DisplaySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ParseException(java.text.ParseException) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with FormDiscrepancyNotes

use of org.akaza.openclinica.control.form.FormDiscrepancyNotes in project OpenClinica by OpenClinica.

the class ViewSectionDataEntryRESTUrlServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    boolean isSubmitted = false;
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    if (!fp.getString("exitTo").equals("")) {
        request.setAttribute("exitTo", request.getContextPath() + "/" + fp.getString("exitTo"));
    }
    int crfVersionId = fp.getInt("crfVersionId", true);
    Integer sectionId = (Integer) request.getAttribute("sectionId");
    if (sectionId == null || sectionId == 0) {
        sectionId = new Integer(1);
    }
    int eventCRFId = fp.getInt(EVENT_CRF_ID, true);
    int studySubjectId = fp.getInt("studySubjectId", true);
    String action = fp.getString("action");
    HttpSession session = request.getSession();
    String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
    if (StringUtil.isBlank(fromResolvingNotes)) {
        session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
        session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    }
    // Added for
    request.setAttribute("studySubjectId", studySubjectId + "");
    // Mantis
    // Issue
    // 2268
    // Added
    request.setAttribute("crfListPage", fp.getString("crfListPage"));
    // for
    // Mantis
    // Issue
    // 2268
    // Added for
    request.setAttribute("eventId", fp.getString("eventId"));
    // Mantis
    // Issue
    // 2268
    // YW <<
    int sedId = fp.getInt("sedId");
    request.setAttribute("sedId", sedId + "");
    int crfId = fp.getInt("crfId");
    // BWP>> ... try to get crfId from crfVersionId
    if (crfId == 0 && crfVersionId > 0) {
        CRFVersionDAO crfVDao = new CRFVersionDAO(getDataSource());
        CRFVersionBean crvVBean = (CRFVersionBean) crfVDao.findByPK(crfVersionId);
        if (crvVBean != null) {
            crfId = crvVBean.getCrfId();
        }
    }
    // YW >>
    // int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    Integer eventDefinitionCRFId = (Integer) (request.getAttribute("eventDefinitionCRFId"));
    EventDefinitionCRFDAO eventCrfDao = new EventDefinitionCRFDAO(getDataSource());
    edcb = (EventDefinitionCRFBean) eventCrfDao.findByPK(eventDefinitionCRFId);
    if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_study_contact_sysadmin"), request);
        throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
    }
    if (crfId == 0 && eventDefinitionCRFId > 0) {
        // eventCrfDao.findByPK(eventDefinitionCRFId);
        if (edcb != null) {
            crfId = edcb.getCrfId();
        }
    }
    request.setAttribute("crfId", crfId + "");
    request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId + "");
    String printVersion = fp.getString("print");
    // BWP>> this has to be removed for CRFs that do not display an
    // interviewdate
    // for a particular event
    session.removeAttribute("presetValues");
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    SectionDAO sdao = new SectionDAO(getDataSource());
    String age = "";
    if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"), request);
        // forwardPage(Page.SUBMIT_DATA_SERVLET);
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
        // >> changed tbh, 06/2009
        return;
    }
    if (studySubjectId > 0) {
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(studySubjectId);
        request.setAttribute("studySubject", sub);
    }
    if (eventCRFId > 0) {
        // for event crf, the input crfVersionId from url =0
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudyEventDAO sedao = new StudyEventDAO(getDataSource());
        StudyEventBean event = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
        // event.getSubjectEventStatus().getName());
        if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
            request.setAttribute("isLocked", "yes");
        // System.out.println("this event crf is locked");
        } else // @pgawade 28-Aug-2012 Reverted the change no. 2 in
        // https://issuetracker.openclinica.com/view.php?id=12343#c56722
        {
            request.setAttribute("isLocked", "no");
        }
        if (studySubjectId <= 0) {
            studySubjectId = event.getStudySubjectId();
            request.setAttribute("studySubjectId", studySubjectId + "");
        }
        // Get the status/number of item discrepancy notes
        DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
        ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
        List<DiscrepancyNoteBean> eventCrfNotes = new ArrayList<DiscrepancyNoteBean>();
        List<DiscrepancyNoteThread> noteThreads = new ArrayList<DiscrepancyNoteThread>();
        // if (eventCRFId > 0) {
        // this method finds only parent notes
        allNotes = dndao.findAllTopNotesByEventCRF(eventCRFId);
        // add interviewer.jsp related notes to this Collection
        eventCrfNotes = dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
        if (!eventCrfNotes.isEmpty()) {
            allNotes.addAll(eventCrfNotes);
            // make sure a necessary request attribute "hasNameNote" is set
            // properly
            this.setAttributeForInterviewerDNotes(eventCrfNotes, request);
        }
        // }
        // Create disc note threads out of the various notes
        DiscrepancyNoteUtil dNoteUtil = new DiscrepancyNoteUtil();
        noteThreads = dNoteUtil.createThreadsOfParents(allNotes, getDataSource(), currentStudy, null, -1, true);
        // variables that provide values for the CRF discrepancy note header
        int updatedNum = 0;
        int openNum = 0;
        int closedNum = 0;
        int resolvedNum = 0;
        int notAppNum = 0;
        DiscrepancyNoteBean tempBean;
        for (DiscrepancyNoteThread dnThread : noteThreads) {
            /*
                 * 3014: do not count parent beans, only the last child disc
                 * note of the thread.
                 */
            tempBean = dnThread.getLinkedNoteList().getLast();
            if (tempBean != null) {
                if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
                    updatedNum++;
                } else if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
                    openNum++;
                } else if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
                    // if (dn.getParentDnId() > 0){
                    closedNum++;
                // }
                } else if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
                    // if (dn.getParentDnId() > 0){
                    resolvedNum++;
                // }
                } else if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
                    notAppNum++;
                }
            }
        }
        request.setAttribute("updatedNum", updatedNum + "");
        request.setAttribute("openNum", openNum + "");
        request.setAttribute("closedNum", closedNum + "");
        request.setAttribute("resolvedNum", resolvedNum + "");
        request.setAttribute("notAppNum", notAppNum + "");
        DisplayTableOfContentsBean displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
        // Make sure that the interviewDate in the eventCRF is properly
        // formatted
        // for viewSectionDataEntry.jsp --> interviewer.jsp
        // int studyEventId = (Integer)request.getAttribute("studyEvent");
        // SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        // 
        Date tmpDate = displayBean.getEventCRF().getDateInterviewed();
        String formattedInterviewerDate;
        try {
            DateFormat local_df = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
            formattedInterviewerDate = local_df.format(tmpDate);
        } catch (Exception e) {
            formattedInterviewerDate = "";
        }
        HashMap presetVals = (HashMap) session.getAttribute("presetValues");
        if (presetVals == null) {
            presetVals = new HashMap();
            session.setAttribute("presetValues", presetVals);
        }
        presetVals.put("interviewDate", formattedInterviewerDate);
        request.setAttribute("toc", displayBean);
        ArrayList sections = displayBean.getSections();
        request.setAttribute("sectionNum", sections.size() + "");
        if (!sections.isEmpty()) {
            if (sectionId == 0) {
                SectionBean firstSec = (SectionBean) sections.get(0);
                sectionId = firstSec.getId();
            }
        } else {
            addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF"), request);
            // forwardPage(Page.SUBMIT_DATA_SERVLET);
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
            // >> changed tbh, 06/2009
            return;
        }
    } else if (crfVersionId > 0) {
        // for viewing blank CRF
        DisplayTableOfContentsBean displayBean = ViewTableOfContentServlet.getDisplayBean(getDataSource(), crfVersionId);
        request.setAttribute("toc", displayBean);
        ArrayList sections = displayBean.getSections();
        request.setAttribute("sectionNum", sections.size() + "");
        if (!sections.isEmpty()) {
            if (sectionId == 0) {
                SectionBean firstSec = (SectionBean) sections.get(0);
                sectionId = firstSec.getId();
            }
        } else {
            addPageMessage(respage.getString("there_are_no_sections_ins_this_CRF_version"), request);
            if (eventCRFId == 0) {
                forwardPage(Page.CRF_LIST_SERVLET, request, response);
            } else {
                // forwardPage(Page.SUBMIT_DATA_SERVLET);
                forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET, request, response);
            // >> changed tbh, 06/2009
            }
            return;
        }
    }
    sb = (SectionBean) sdao.findByPK(sectionId);
    if (eventCRFId == 0) {
        ecb = new EventCRFBean();
        ecb.setCRFVersionId(sb.getCRFVersionId());
        if (currentStudy.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyDAO studydao = new StudyDAO(getDataSource());
            StudyBean parentStudy = (StudyBean) studydao.findByPK(currentStudy.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName());
            request.setAttribute("siteTitle", currentStudy.getName());
        } else {
            request.setAttribute("studyTitle", currentStudy.getName());
        }
    } else {
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        // This is the StudySubjectBean
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
        // This is the SubjectBean
        SubjectDAO subjectDao = new SubjectDAO(getDataSource());
        int subjectId = sub.getSubjectId();
        int studyId = sub.getStudyId();
        SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
        // Let us process the age
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
            StudyEventDAO sedao = new StudyEventDAO(getDataSource());
            StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setStudyEventDefinition(sed);
            request.setAttribute("studyEvent", se);
            // YW 11-16-2007 enrollment-date is used for computing age
            age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
        }
        // Get the study then the parent study
        StudyDAO studydao = new StudyDAO(getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studyId);
        if (study.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName());
            request.setAttribute("siteTitle", study.getName());
        } else {
            request.setAttribute("studyTitle", study.getName());
        }
        request.setAttribute("studySubject", sub);
        request.setAttribute("subject", subject);
        request.setAttribute("age", age);
    }
    // FormBeanUtil formUtil = new FormBeanUtil();
    // DisplaySectionBean newDisplayBean = new DisplaySectionBean();
    boolean hasItemGroup = false;
    // we will look into db to see if any repeating items for this CRF
    // section
    ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
    List<ItemGroupBean> itemGroups = igdao.findLegitGroupBySectionId(sectionId);
    if (!itemGroups.isEmpty()) {
        hasItemGroup = true;
    }
    // if the List of DisplayFormGroups is empty, then the servlet defers to
    // the prior method
    // of generating a DisplaySectionBean for the application
    DisplaySectionBean dsb;
    // want to get displayBean with grouped and ungrouped items
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(SECTION_BEAN, sb);
    dsb = super.getDisplayBean(hasItemGroup, false, request, isSubmitted);
    FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    if (discNotes == null) {
        discNotes = new FormDiscrepancyNotes();
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
    }
    /*
         * if (hasItemGroup) { //
         * dsb.setDisplayItemGroups(newDisplayBean.getDisplayItemGroups());
         * request.setAttribute("new_table", true); }
         */
    // If the Horizontal type table will be used, then set the
    // DisplaySectionBean's
    // DisplayFormGroups List to the ones we have just generated
    // @pgawade 30-May-2012 Fix for issue 13963 - added an extra parameter
    // 'isSubmitted' to method createItemWithGroups
    List<DisplayItemWithGroupBean> displayItemWithGroups = super.createItemWithGroups(dsb, hasItemGroup, eventDefinitionCRFId, request, isSubmitted);
    dsb.setDisplayItemGroups(displayItemWithGroups);
    super.populateNotesWithDBNoteCounts(discNotes, dsb, request);
    if (fp.getString("fromViewNotes") != null && "1".equals(fp.getString("fromViewNotes"))) {
        request.setAttribute("fromViewNotes", fp.getString("fromViewNotes"));
    } else {
        session.removeAttribute("viewNotesURL");
    }
    if ("saveNotes".equalsIgnoreCase(action)) {
        LOGGER.info("33333how many group rows:" + dsb.getDisplayItemGroups().size());
        // let's save notes for the blank items
        DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(getDataSource());
        discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        for (int i = 0; i < dsb.getDisplayItemGroups().size(); i++) {
            DisplayItemWithGroupBean diwb = dsb.getDisplayItemGroups().get(i);
            if (diwb.isInGroup()) {
                List<DisplayItemGroupBean> dgbs = diwb.getItemGroups();
                LOGGER.info("dgbs size: " + dgbs.size());
                for (int j = 0; j < dgbs.size(); j++) {
                    DisplayItemGroupBean displayGroup = dgbs.get(j);
                    List<DisplayItemBean> items = displayGroup.getItems();
                    LOGGER.info("item size: " + items.size());
                    for (DisplayItemBean displayItem : items) {
                        String inputName = getGroupItemInputName(displayGroup, j, displayItem);
                        LOGGER.info("inputName:" + inputName);
                        LOGGER.info("item data id:" + displayItem.getData().getId());
                        AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, displayItem.getData().getId(), "itemData", currentStudy);
                    }
                }
            } else {
                DisplayItemBean dib = diwb.getSingleItem();
                // TODO work on this line
                String inputName = getInputName(dib);
                AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
                ArrayList childItems = dib.getChildren();
                for (int j = 0; j < childItems.size(); j++) {
                    DisplayItemBean child = (DisplayItemBean) childItems.get(j);
                    inputName = getInputName(child);
                    AddNewSubjectServlet.saveFieldNotes(inputName, discNotes, dndao, dib.getData().getId(), DiscrepancyNoteBean.ITEM_DATA, currentStudy);
                }
            }
        }
        addPageMessage("Discrepancy notes are saved successfully.", request);
        request.setAttribute("id", studySubjectId + "");
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET, request, response);
        // "ViewStudySubject?id=" + studySubjectId));
        return;
    } else {
        request.setAttribute(BEAN_DISPLAY, dsb);
        request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
        request.setAttribute("sec", sb);
        request.setAttribute("EventCRFBean", ecb);
        int tabNum = 1;
        if ("".equalsIgnoreCase(fp.getString("tabId"))) {
            tabNum = 1;
        } else {
            tabNum = fp.getInt("tabId");
        }
        request.setAttribute("tabId", new Integer(tabNum).toString());
        // 2808: Signal interviewer.jsp that the containing page is
        // viewSectionData,
        // for the purpose of suppressing discrepancy note icons for the
        // interview date and name fields
        request.setAttribute(ENCLOSING_PAGE, "viewSectionData");
        if ("yes".equalsIgnoreCase(printVersion)) {
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
        } else {
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY, request, response);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DisplayItemWithGroupBean(org.akaza.openclinica.bean.submit.DisplayItemWithGroupBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DiscrepancyNoteThread(org.akaza.openclinica.service.DiscrepancyNoteThread) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) HttpSession(javax.servlet.http.HttpSession) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with FormDiscrepancyNotes

use of org.akaza.openclinica.control.form.FormDiscrepancyNotes in project OpenClinica by OpenClinica.

the class ViewDiscrepancyNoteServlet method processRequest.

@Override
@SuppressWarnings("unchecked")
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int eventCRFId = fp.getInt(CreateDiscrepancyNoteServlet.EVENT_CRF_ID);
    request.setAttribute(CreateDiscrepancyNoteServlet.EVENT_CRF_ID, new Integer(eventCRFId));
    request.setAttribute(DIS_TYPES, DiscrepancyNoteType.list);
    if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
        ArrayList<ResolutionStatus> resStatuses = new ArrayList();
        resStatuses.add(ResolutionStatus.UPDATED);
        resStatuses.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES, resStatuses);
        // it's for parentDNId is null or 0
        request.setAttribute(WHICH_RES_STATUSES, "22");
        ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
        resStatuses2.add(ResolutionStatus.OPEN);
        resStatuses2.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES2, resStatuses2);
        List<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>(DiscrepancyNoteType.list);
        types2.remove(DiscrepancyNoteType.QUERY);
        request.setAttribute(DIS_TYPES2, types2);
    } else if (currentRole.getRole().equals(Role.MONITOR)) {
        ArrayList<ResolutionStatus> resStatuses = new ArrayList();
        resStatuses.add(ResolutionStatus.OPEN);
        resStatuses.add(ResolutionStatus.UPDATED);
        resStatuses.add(ResolutionStatus.CLOSED);
        request.setAttribute(RES_STATUSES, resStatuses);
        request.setAttribute(WHICH_RES_STATUSES, "1");
        ArrayList<DiscrepancyNoteType> types2 = new ArrayList<DiscrepancyNoteType>();
        types2.add(DiscrepancyNoteType.QUERY);
        request.setAttribute(DIS_TYPES2, types2);
    } else {
        // Role.STUDYDIRECTOR Role.COORDINATOR
        List<ResolutionStatus> resStatuses = new ArrayList<ResolutionStatus>(ResolutionStatus.list);
        resStatuses.remove(ResolutionStatus.NOT_APPLICABLE);
        request.setAttribute(RES_STATUSES, resStatuses);
        ;
        // it's for parentDNId is null or 0 and FVC
        request.setAttribute(WHICH_RES_STATUSES, "2");
        ArrayList<ResolutionStatus> resStatuses2 = new ArrayList<ResolutionStatus>();
        resStatuses2.add(ResolutionStatus.OPEN);
        resStatuses2.add(ResolutionStatus.RESOLVED);
        request.setAttribute(RES_STATUSES2, resStatuses2);
    }
    // logic from CreateDiscrepancyNoteServlet
    request.setAttribute("unlock", "0");
    fp.getBoolean(IS_REASON_FOR_CHANGE);
    fp.getBoolean(ERROR_FLAG);
    String monitor = fp.getString("monitor");
    // } else if ("1".equalsIgnoreCase(monitor)) {// change to allow user to
    if ("1".equalsIgnoreCase(monitor)) {
        // change to allow user to
        // enter note for all items,
        // not just blank items
        request.setAttribute(CAN_MONITOR, "1");
        request.setAttribute("monitor", monitor);
    } else {
        request.setAttribute(CAN_MONITOR, "0");
    }
    Boolean fromBox = fp.getBoolean(FROM_BOX);
    if (fromBox == null || !fromBox) {
        session.removeAttribute(BOX_TO_SHOW);
        session.removeAttribute(BOX_DN_MAP);
        session.removeAttribute(AUTOVIEWS);
    }
    Boolean refresh = fp.getBoolean("refresh");
    request.setAttribute("refresh", refresh + "");
    String ypos = fp.getString("y");
    if (ypos == null || ypos.length() == 0) {
        ypos = "0";
    }
    request.setAttribute("y", ypos);
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    int entityId = fp.getInt(ENTITY_ID, true);
    String name = fp.getString(ENTITY_TYPE, true);
    String column = fp.getString(ENTITY_COLUMN, true);
    String field = fp.getString(ENTITY_FIELD, true);
    String isLocked = fp.getString(LOCKED_FLAG);
    if (!StringUtil.isBlank(isLocked) && "yes".equalsIgnoreCase(isLocked)) {
        request.setAttribute(LOCKED_FLAG, "yes");
    } else {
        request.setAttribute(LOCKED_FLAG, "no");
    }
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
    int subjectId = fp.getInt(CreateDiscrepancyNoteServlet.SUBJECT_ID, true);
    int itemId = fp.getInt(CreateDiscrepancyNoteServlet.ITEM_ID, true);
    StudySubjectBean ssub = new StudySubjectBean();
    if (subjectId > 0) {
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        ssub = (StudySubjectBean) ssdao.findByPK(subjectId);
        request.setAttribute("noteSubject", ssub);
    }
    ItemBean item = new ItemBean();
    if (itemId > 0) {
        ItemDAO idao = new ItemDAO(sm.getDataSource());
        item = (ItemBean) idao.findByPK(itemId);
        request.setAttribute("item", item);
        request.setAttribute("entityName", item.getName());
    }
    ItemDataBean itemData = new ItemDataBean();
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    int preUserId = 0;
    if (!StringUtil.isBlank(name)) {
        if ("itemData".equalsIgnoreCase(name)) {
            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
            itemData = (ItemDataBean) iddao.findByPK(entityId);
            request.setAttribute("entityValue", itemData.getValue());
            request.setAttribute("entityName", item.getName());
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
            preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
            StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
            StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setName(sedb.getName());
            request.setAttribute("studyEvent", se);
            CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
            CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
            CRFDAO cdao = new CRFDAO(sm.getDataSource());
            CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
            request.setAttribute("crf", crf);
        } else if ("studySub".equalsIgnoreCase(name)) {
            StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
            ssub = (StudySubjectBean) ssdao.findByPK(entityId);
            SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
            SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
            request.setAttribute("noteSubject", ssub);
            if (!StringUtil.isBlank(column)) {
                if ("enrollment_date".equalsIgnoreCase(column)) {
                    if (ssub.getEnrollmentDate() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(ssub.getEnrollmentDate()));
                    }
                    request.setAttribute("entityName", resword.getString("enrollment_date"));
                } else if ("gender".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", sub.getGender() + "");
                    request.setAttribute("entityName", resword.getString("gender"));
                } else if ("date_of_birth".equalsIgnoreCase(column)) {
                    if (sub.getDateOfBirth() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
                    }
                    request.setAttribute("entityName", resword.getString("date_of_birth"));
                } else if ("unique_identifier".equalsIgnoreCase(column)) {
                    if (sub.getUniqueIdentifier() != null) {
                        request.setAttribute("entityValue", sub.getUniqueIdentifier());
                    }
                    request.setAttribute("entityName", resword.getString("unique_identifier"));
                }
            }
            preUserId = ssub.getOwnerId() > 0 ? ssub.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ssub.getCreatedDate()));
        } else if ("subject".equalsIgnoreCase(name)) {
            SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
            SubjectBean sub = (SubjectBean) sdao.findByPK(entityId);
            // be caution: here for subject, noteSubject is SubjectBean and
            // label is unique_identifier
            sub.setLabel(sub.getUniqueIdentifier());
            request.setAttribute("noteSubject", sub);
            if (!StringUtil.isBlank(column)) {
                if ("gender".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", ssub.getGender() + "");
                    request.setAttribute("entityName", resword.getString("gender"));
                } else if ("date_of_birth".equalsIgnoreCase(column)) {
                    if (sub.getDateOfBirth() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(sub.getDateOfBirth()));
                    }
                    request.setAttribute("entityName", resword.getString("date_of_birth"));
                } else if ("unique_identifier".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", sub.getUniqueIdentifier());
                    request.setAttribute("entityName", resword.getString("unique_identifier"));
                }
            }
            preUserId = sub.getOwnerId() > 0 ? sub.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(sub.getCreatedDate()));
        } else if ("studyEvent".equalsIgnoreCase(name)) {
            StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
            StudyEventBean se = (StudyEventBean) sed.findByPK(entityId);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
            se.setName(sedb.getName());
            request.setAttribute("studyEvent", se);
            request.setAttribute("noteSubject", new StudySubjectDAO(sm.getDataSource()).findByPK(se.getStudySubjectId()));
            if (!StringUtil.isBlank(column)) {
                if ("location".equalsIgnoreCase(column)) {
                    request.setAttribute("entityValue", se.getLocation());
                    request.setAttribute("entityName", resword.getString("location"));
                } else if ("start_date".equalsIgnoreCase(column)) {
                    if (se.getDateStarted() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(se.getDateStarted()));
                    }
                    request.setAttribute("entityName", resword.getString("start_date"));
                } else if ("end_date".equalsIgnoreCase(column)) {
                    if (se.getDateEnded() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(se.getDateEnded()));
                    }
                    request.setAttribute("entityName", resword.getString("end_date"));
                }
            }
            preUserId = se.getOwnerId() > 0 ? se.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(se.getCreatedDate()));
        } else if ("eventCrf".equalsIgnoreCase(name)) {
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            EventCRFBean ec = (EventCRFBean) ecdao.findByPK(entityId);
            if (!StringUtil.isBlank(column)) {
                if ("date_interviewed".equals(column)) {
                    if (ec.getDateInterviewed() != null) {
                        request.setAttribute("entityValue", dateFormatter.format(ec.getDateInterviewed()));
                    }
                    request.setAttribute("entityName", resword.getString("date_interviewed"));
                } else if ("interviewer_name".equals(column)) {
                    request.setAttribute("entityValue", ec.getInterviewerName());
                    request.setAttribute("entityName", resword.getString("interviewer_name"));
                }
            }
            setupStudyEventCRFAttributes(ec);
            preUserId = ec.getOwnerId() > 0 ? ec.getOwnerId() : 0;
            request.setAttribute("entityCreatedDate", sdf.format(ec.getCreatedDate()));
        }
    }
    boolean writeToDB = fp.getBoolean(CreateDiscrepancyNoteServlet.WRITE_TO_DB, true);
    HashMap<Integer, Integer> autoviews = (HashMap<Integer, Integer>) session.getAttribute(AUTOVIEWS);
    autoviews = autoviews == null ? new HashMap<Integer, Integer>() : autoviews;
    HashMap<Integer, DiscrepancyNoteBean> boxDNMap = (HashMap<Integer, DiscrepancyNoteBean>) session.getAttribute(BOX_DN_MAP);
    if (boxDNMap == null || !boxDNMap.containsKey(0)) {
        boxDNMap = new HashMap<Integer, DiscrepancyNoteBean>();
        // initialize dn for a new thread
        DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
        if (currentRole.getRole().equals(Role.RESEARCHASSISTANT) || currentRole.getRole().equals(Role.RESEARCHASSISTANT2) || currentRole.getRole().equals(Role.INVESTIGATOR)) {
            dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.ANNOTATION.getId());
            dnb.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
            autoviews.put(0, 0);
        // request.setAttribute("autoView", "0");
        } else {
            dnb.setDiscrepancyNoteTypeId(DiscrepancyNoteType.QUERY.getId());
            dnb.setAssignedUserId(preUserId);
            autoviews.put(0, 1);
        // request.setAttribute("autoView", "1");
        }
        boxDNMap.put(0, dnb);
    } else if (boxDNMap.containsKey(0)) {
        int dnTypeId = boxDNMap.get(0).getDiscrepancyNoteTypeId();
        autoviews.put(0, dnTypeId == 3 ? 1 : 0);
    }
    if (boxDNMap.containsKey(0)) {
        int dnTypeId0 = boxDNMap.get(0).getDiscrepancyNoteTypeId();
        if (dnTypeId0 == 2 || dnTypeId0 == 4) {
            request.setAttribute("typeID0", dnTypeId0 + "");
        }
    }
    // request.setAttribute("enterData", enterData);
    request.setAttribute("monitor", monitor);
    request.setAttribute(ENTITY_ID, entityId + "");
    request.setAttribute(ENTITY_TYPE, name);
    request.setAttribute(ENTITY_FIELD, field);
    request.setAttribute(ENTITY_COLUMN, column);
    request.setAttribute(CreateDiscrepancyNoteServlet.WRITE_TO_DB, writeToDB ? "1" : "0");
    ArrayList notes = (ArrayList) dndao.findAllByEntityAndColumn(name, entityId, column);
    if (notes.size() > 0) {
        notes.get(0);
        // @pgawade 21-May-2011 Corrected the condition to throw no access
        // error
        StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
        int parentStudyForNoteSub = 0;
        // @pgawade #9801: 07-June-2011 corrected the way to get study
        // subject id associated with discrepancy note
        // int noteSubId = note.getOwnerId();
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        // StudySubjectBean notessub = (StudySubjectBean)
        // ssdao.findByPK(noteSubId);
        StudySubjectBean notessub = (StudySubjectBean) ssdao.findByPK(subjectId);
        StudyBean studyBeanSub = (StudyBean) studyDAO.findByPK(notessub.getStudyId());
        if (null != studyBeanSub) {
            parentStudyForNoteSub = studyBeanSub.getParentStudyId();
        }
        if (notessub.getStudyId() != currentStudy.getId() && currentStudy.getId() != parentStudyForNoteSub) {
            addPageMessage(noAccessMessage);
            throw new InsufficientPermissionException(Page.MENU_SERVLET, exceptionName, "1");
        }
    }
    FormDiscrepancyNotes newNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    Map<Integer, DiscrepancyNoteBean> noteTree = new LinkedHashMap<Integer, DiscrepancyNoteBean>();
    String session_key = eventCRFId + "_" + field;
    ArrayList newFieldNotes = null;
    if (newNotes != null && (!newNotes.getNotes(field).isEmpty() || !newNotes.getNotes(session_key).isEmpty())) {
        newFieldNotes = newNotes.getNotes(field);
        if (newFieldNotes == null || newFieldNotes.size() == 0) {
            newFieldNotes = newNotes.getNotes(session_key);
        }
        // System.out.println("how many notes:" + newFieldNotes.size());
        for (int i = 0; i < newFieldNotes.size(); i++) {
            DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
            note.setLastUpdator(ub);
            note.setLastDateUpdated(new Date());
            note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
            note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
            note.setSaved(false);
            if (itemId > 0) {
                note.setEntityName(item.getName());
                note.setEntityValue(itemData.getValue());
            }
            note.setSubjectName(ssub.getName());
            note.setEntityType(name);
            int pId = note.getParentDnId();
            if (pId == 0) {
                // we can only keep one unsaved note because
                // note.id == 0
                noteTree.put(note.getId(), note);
            }
        }
        for (int i = 0; i < newFieldNotes.size(); i++) {
            DiscrepancyNoteBean note = (DiscrepancyNoteBean) newFieldNotes.get(i);
            int pId = note.getParentDnId();
            if (pId > 0) {
                note.setSaved(false);
                note.setLastUpdator(ub);
                note.setLastDateUpdated(new Date());
                note.setEntityName(item.getName());
                note.setSubjectName(ssub.getName());
                note.setEntityType(name);
                note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
                note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
                DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
                if (parent != null) {
                    parent.getChildren().add(note);
                }
            }
        }
    }
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    HashMap<Integer, String> fvcInitAssigns = new HashMap<Integer, String>();
    for (int i = 0; i < notes.size(); i++) {
        DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
        note.setColumn(column);
        note.setEntityId(entityId);
        note.setEntityType(name);
        note.setField(field);
        Date lastUpdatedDate = note.getCreatedDate();
        UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
        note.setLastUpdator(lastUpdator);
        note.setLastDateUpdated(lastUpdatedDate);
        int pId = note.getParentDnId();
        note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
        note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
        if (pId == 0) {
            noteTree.put(new Integer(note.getId()), note);
        }
    }
    for (int i = 0; i < notes.size(); i++) {
        DiscrepancyNoteBean note = (DiscrepancyNoteBean) notes.get(i);
        int pId = note.getParentDnId();
        if (itemId > 0) {
            note.setEntityName(item.getName());
            note.setEntityValue(itemData.getValue());
        }
        note.setSubjectName(ssub.getName());
        note.setEntityType(name);
        Date lastUpdatedDate = note.getCreatedDate();
        UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
        note.setLastUpdator(lastUpdator);
        note.setLastDateUpdated(lastUpdatedDate);
        note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
        note.setResStatus(ResolutionStatus.get(note.getResolutionStatusId()));
        if (pId > 0) {
            DiscrepancyNoteBean parent = noteTree.get(new Integer(pId));
            if (parent != null) {
                parent.getChildren().add(note);
                if (!note.getCreatedDate().before(parent.getLastDateUpdated())) {
                    parent.setLastDateUpdated(note.getCreatedDate());
                }
                if (note.getDiscrepancyNoteTypeId() == 1 && note.getAssignedUserId() > 0) {
                    int ownerId = note.getOwnerId();
                    if (fvcInitAssigns.containsKey(pId)) {
                        String f = fvcInitAssigns.get(pId);
                        String fn = note.getId() + "." + ownerId;
                        if (fn.compareTo(f) < 0) {
                            fvcInitAssigns.put(pId, fn);
                        }
                    } else {
                        fvcInitAssigns.put(pId, note.getId() + "." + ownerId);
                    }
                }
            }
        }
    }
    Set parents = noteTree.keySet();
    Iterator it = parents.iterator();
    while (it.hasNext()) {
        Integer key = (Integer) it.next();
        DiscrepancyNoteBean note = noteTree.get(key);
        note.setNumChildren(note.getChildren().size());
        note.setEntityType(name);
        if (!boxDNMap.containsKey(key)) {
            DiscrepancyNoteBean dn = new DiscrepancyNoteBean();
            dn.setId(key);
            int dnTypeId = note.getDiscrepancyNoteTypeId();
            dn.setDiscrepancyNoteTypeId(dnTypeId);
            if (dnTypeId == 3) {
                // Query
                dn.setAssignedUserId(note.getOwnerId());
            } else if (dnTypeId == 1) {
                // FVC
                if (fvcInitAssigns.containsKey(key)) {
                    String[] s = fvcInitAssigns.get(key).split("\\.");
                    int i = Integer.parseInt(s.length == 2 ? s[1].trim() : "0");
                    dn.setAssignedUserId(i);
                }
            }
            Role r = currentRole.getRole();
            // currentStudy.getId() != currentStudy.getParentStudyId()) {
            if (r.equals(Role.RESEARCHASSISTANT) || r.equals(Role.RESEARCHASSISTANT2) || r.equals(Role.INVESTIGATOR)) {
                if (dn.getDiscrepancyNoteTypeId() == DiscrepancyNoteType.QUERY.getId() && note.getResStatus().getId() == ResolutionStatus.UPDATED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else {
                    dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
                }
                if (dn.getAssignedUserId() > 0) {
                    autoviews.put(key, 1);
                } else {
                    autoviews.put(key, 0);
                }
            // copied from CreateDiscrepancyNoteServlet
            // request.setAttribute("autoView", "0");
            // hide the panel, tbh
            } else {
                if (note.getResStatus().getId() == ResolutionStatus.RESOLVED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
                } else if (note.getResStatus().getId() == ResolutionStatus.CLOSED.getId()) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else if (r.equals(Role.MONITOR)) {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                } else if (dn.getDiscrepancyNoteTypeId() == 1) {
                    dn.setResolutionStatusId(ResolutionStatus.RESOLVED.getId());
                } else {
                    dn.setResolutionStatusId(ResolutionStatus.UPDATED.getId());
                }
                autoviews.put(key, 1);
                if (dn.getAssignedUserId() > 0) {
                } else {
                    dn.setAssignedUserId(preUserId);
                }
            }
            boxDNMap.put(key, dn);
        }
    }
    session.setAttribute(BOX_DN_MAP, boxDNMap);
    session.setAttribute(AUTOVIEWS, autoviews);
    // noteTree is a Hashmap mapping note id to a parent note, with all the
    // child notes
    // stored in the children List.
    // BWP 3029>>make sure the parent note has an updated resolution status
    // and
    // updated date
    fixStatusUpdatedDate(noteTree);
    request.setAttribute(DIS_NOTES, noteTree);
    // copied from CreatediscrepancyNoteServlet generateUserAccounts
    StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
    StudyBean subjectStudy = studyDAO.findByStudySubjectId(subjectId);
    int studyId = currentStudy.getId();
    ArrayList<UserAccountBean> userAccounts = new ArrayList();
    if (currentStudy.getParentStudyId() > 0) {
        userAccounts = udao.findAllUsersByStudyOrSite(studyId, currentStudy.getParentStudyId(), subjectId);
    } else if (subjectStudy.getParentStudyId() > 0) {
        userAccounts = udao.findAllUsersByStudyOrSite(subjectStudy.getId(), subjectStudy.getParentStudyId(), subjectId);
    } else {
        userAccounts = udao.findAllUsersByStudyOrSite(studyId, 0, subjectId);
    }
    request.setAttribute(USER_ACCOUNTS, userAccounts);
    request.setAttribute(VIEW_DN_LINK, this.getPageServletFileName());
    // audit log items (from ViewItemAuditLogServlet.java)
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    if (name.equalsIgnoreCase("studysub")) {
        name = "study_subject";
    } else if (name.equalsIgnoreCase("eventcrf")) {
        name = "event_crf";
    } else if (name.equalsIgnoreCase("studyevent")) {
        name = "study_event";
    } else if (name.equalsIgnoreCase("itemdata")) {
        name = "item_data";
    }
    ArrayList itemAuditEvents = adao.findItemAuditEvents(entityId, name);
    request.setAttribute("itemAudits", itemAuditEvents);
    forwardPage(Page.VIEW_DISCREPANCY_NOTE);
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) LinkedHashMap(java.util.LinkedHashMap) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) Role(org.akaza.openclinica.bean.core.Role) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) Set(java.util.Set) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) DiscrepancyNoteType(org.akaza.openclinica.bean.core.DiscrepancyNoteType) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

FormDiscrepancyNotes (org.akaza.openclinica.control.form.FormDiscrepancyNotes)20 ArrayList (java.util.ArrayList)15 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 HashMap (java.util.HashMap)14 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)13 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)13 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)13 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)12 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)11 Date (java.util.Date)10 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)9 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)9 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)8 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)8 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)8 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)8 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)8 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)8 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)6