Search in sources :

Example 11 with DisplaySectionBean

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

the class ViewSectionDataEntryServlet method processRequest.

// BWP 01/08>>
@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", fp.getString("exitTo"));
    }
    int crfVersionId = fp.getInt("crfVersionId", true);
    int sectionId = fp.getInt("sectionId");
    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");
    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 {
            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);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(getDataSource());
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(getDataSource());
    StudyEventDAO studyEventDAO = new StudyEventDAO(getDataSource());
    StudyEventDefinitionBean studyEventDefinition = (StudyEventDefinitionBean) studyEventDefinitionDAO.findByPK(edcb.getStudyEventDefinitionId());
    StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByPK(ecb.getStudyEventId());
    VariableSubstitutionHelper.replaceVariables(dsb, currentStudy, (StudySubjectBean) studySubjectDAO.findByPK(studySubjectId), studyEventDefinition, studyEvent, getDataSource());
    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) 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) 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) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) 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 12 with DisplaySectionBean

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

the class ViewSectionDataEntryPreview method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    // These numbers will be zero if the
    // params are not present in the URL
    int crfid = fp.getInt("crfId");
    int tabNum = fp.getInt("tabId");
    HttpSession session = request.getSession();
    request.setAttribute("crfId", crfid);
    String crfName = "";
    String verNumber = "";
    // All the data on the uploaded Excel file
    // see org.akaza.openclinica.control.admin.SpreadsheetPreview
    // createCrfMetaObject() method
    Map<String, Map> crfMap = (Map) session.getAttribute("preview_crf");
    if (crfMap == null) {
        // addPageMessage
        String msg = respage.getString("preview_data_has_timed_out");
        this.addPageMessage(msg, request);
        LOGGER.debug("The session attribute \"preview_crf\" has expired or gone out of scope in: " + this.getClass().getName());
        this.forwardPage(Page.CRF_LIST_SERVLET, request, response);
    }
    Map<String, String> crfIdnameInfo = null;
    if (crfMap != null) {
        crfIdnameInfo = crfMap.get("crf_info");
    }
    // Get the CRF name and version String
    if (crfIdnameInfo != null) {
        Map.Entry mapEnt = null;
        for (Object element : crfIdnameInfo.entrySet()) {
            mapEnt = (Map.Entry) element;
            if (((String) mapEnt.getKey()).equalsIgnoreCase("crf_name")) {
                crfName = (String) mapEnt.getValue();
            }
            if (((String) mapEnt.getKey()).equalsIgnoreCase("version")) {
                verNumber = (String) mapEnt.getValue();
            }
        }
    }
    // Set up the beans that DisplaySectionBean and the preview
    // depend on
    EventCRFBean ebean = new EventCRFBean();
    CRFVersionBean crfverBean = new CRFVersionBean();
    crfverBean.setName(verNumber);
    CRFBean crfbean = new CRFBean();
    crfbean.setId(crfid);
    crfbean.setName(crfName);
    ebean.setCrf(crfbean);
    // This happens in ViewSectionDataEntry
    // It's an assumption that it has to happen here as well
    ecb = ebean;
    // All the groups data, if it's present in the CRF
    Map<Integer, Map<String, String>> groupsMap = null;
    if (crfMap != null)
        groupsMap = crfMap.get("groups");
    // Find out whether this CRF involves groups
    // At least one group is involved if the groups Map is not null or
    // empty, and the first group entry (there may be only one) has a
    // valid group label
    boolean hasGroups = false;
    /*
         * if(groupsMap != null && (! groupsMap.isEmpty()) &&
         * groupsMap.get(1).get("group_label").length() > 0) hasGroups = true;
         */
    // A SortedMap containing the row number as the key, and the
    // section headers/values (contained in a Map) as the value
    Map<Integer, Map<String, String>> sectionsMap = null;
    if (crfMap != null)
        sectionsMap = crfMap.get("sections");
    // The itemsMap contains the spreadsheet table items row number as a
    // key,
    // followed by a map of the column names/values; it contains values for
    // display
    // such as 'left item text'
    Map<Integer, Map<String, String>> itemsMap = null;
    if (crfMap != null)
        itemsMap = crfMap.get("items");
    // Create a list of FormGroupBeans from Maps of groups,
    // items, and sections
    BeanFactory beanFactory = new BeanFactory();
    // FormBeanUtil formUtil = new FormBeanUtil();
    // Set up sections for the preview
    Map.Entry me = null;
    SectionBean secbean = null;
    ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
    String name_str = "";
    String pageNum = "";
    Map secMap = null;
    // SpreadsheetPreviewNw returns doubles (via the
    // HSSFCell API, which parses Excel files)
    // as Strings (such as "1.0") for "1" in a spreadsheet cell,
    // so make sure only "1" is displayed using
    // this NumberFormat object
    NumberFormat numFormatter = NumberFormat.getInstance();
    numFormatter.setMaximumFractionDigits(0);
    if (sectionsMap != null) {
        for (Object element : sectionsMap.entrySet()) {
            secbean = new SectionBean();
            me = (Map.Entry) element;
            secMap = (Map) me.getValue();
            name_str = (String) secMap.get("section_label");
            secbean.setName(name_str);
            secbean.setTitle((String) secMap.get("section_title"));
            secbean.setInstructions((String) secMap.get("instructions"));
            secbean.setSubtitle((String) secMap.get("subtitle"));
            pageNum = (String) secMap.get("page_number");
            // type a number in that Spreadsheet cell
            try {
                pageNum = numFormatter.format(Double.parseDouble(pageNum));
            } catch (NumberFormatException nfe) {
                pageNum = "";
            }
            secbean.setPageNumberLabel(pageNum);
            // Sift through the items to see if their section label matches
            // the section's section_label column
            secbean.setNumItems(this.getNumberOfItems(itemsMap, secbean.getName()));
            allSectionBeans.add(secbean);
        }
    }
    DisplayTableOfContentsBean dtocBean = new DisplayTableOfContentsBean();
    // Methods should just take Lists, the interface, not
    // ArrayList only!
    dtocBean.setSections(allSectionBeans);
    request.setAttribute("toc", dtocBean);
    request.setAttribute("sectionNum", allSectionBeans.size() + "");
    // Assuming that the super class' SectionBean sb variable must be
    // initialized,
    // since it happens in ViewSectionDataEntryServlet. TODO: verify this
    sb = allSectionBeans.get(0);
    // This is the StudySubjectBean
    // Not sure if this is needed for a Preview, but leaving
    // it in for safety/consisitency reasons
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(SECTION_BEAN, sb);
    setupStudyBean(request);
    // Create a DisplaySectionBean for the SectionBean specified by the
    // tab number.
    tabNum = tabNum == 0 ? 1 : tabNum;
    String sectionTitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_TITLE);
    String secLabel = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_LABEL);
    String secSubtitle = getSectionColumnBySecNum(sectionsMap, tabNum, SECTION_SUBTITLE);
    String instructions = getSectionColumnBySecNum(sectionsMap, tabNum, INSTRUCTIONS);
    int secBorders = getSectionBordersBySecNum(sectionsMap, tabNum, BORDERS);
    DisplaySectionBean displaySection = beanFactory.createDisplaySectionBean(itemsMap, sectionTitle, secLabel, secSubtitle, instructions, crfName, secBorders);
    //
    // the variable hasGroups should only be true if the group appears in
    // this section
    List<DisplayItemBean> disBeans = displaySection.getItems();
    ItemFormMetadataBean metaBean;
    String groupLabel;
    hasGroups = false;
    for (DisplayItemBean diBean : disBeans) {
        metaBean = diBean.getMetadata();
        groupLabel = metaBean.getGroupLabel();
        if (groupLabel != null && groupLabel.length() > 0) {
            hasGroups = true;
            break;
        }
    }
    // Create groups associated with this section
    List<DisplayItemGroupBean> disFormGroupBeans = null;
    if (hasGroups) {
        disFormGroupBeans = beanFactory.createGroupBeans(itemsMap, groupsMap, secLabel, crfName);
        displaySection.setDisplayFormGroups(disFormGroupBeans);
    }
    /*
         * DisplaySectionBean displaySection =
         * beanFactory.createDisplaySectionBean (itemsMap, sectionTitle,
         * secLabel, secSubtitle, instructions, crfName);
         */
    displaySection.setCrfVersion(crfverBean);
    displaySection.setCrf(crfbean);
    displaySection.setEventCRF(ebean);
    // Not sure if this is needed? The JSPs pull it out
    // as a request attribute
    SectionBean aSecBean = new SectionBean();
    request.setAttribute(BEAN_DISPLAY, displaySection);
    // TODO: verify these attributes, from the original servlet, are
    // necessary
    request.setAttribute("sec", aSecBean);
    request.setAttribute("EventCRFBean", ebean);
    try {
        request.setAttribute("tabId", Integer.toString(tabNum));
    } catch (NumberFormatException nfe) {
        request.setAttribute("tabId", new Integer("1"));
    }
    if (hasGroups) {
        LOGGER.debug("has group, new_table is true");
        request.setAttribute("new_table", true);
    }
    // YW 07-23-2007 << for issue 0000937
    forwardPage(Page.CREATE_CRF_VERSION_CONFIRM, request, response);
// YW >>
}
Also used : ArrayList(java.util.ArrayList) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) HttpSession(javax.servlet.http.HttpSession) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) Map(java.util.Map) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Example 13 with DisplaySectionBean

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

the class DisplaySectionBeanHandler method getDisplaySectionBeans.

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

Example 14 with DisplaySectionBean

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

the class PrintEventCRFServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    // The PrintDataEntry servlet handles this parameter
    int eventCRFId = fp.getInt("ecId");
    //JN:The following were the the global variables, moved as local.
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
    int defId = fp.getInt("id", true);
    boolean isSubmitted = false;
    ArrayList<SectionBean> allSectionBeans;
    if (defId == 0) {
        addPageMessage(respage.getString("please_choose_a_definition_to_view"), request);
        forwardPage(Page.LIST_DEFINITION_SERVLET, request, response);
    } else {
        // definition id
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sedao.findByPK(defId);
        EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
        ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
        CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
        CRFDAO cdao = new CRFDAO(getDataSource());
        ArrayList defaultVersions = new ArrayList();
        for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
            EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
            ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
            edc.setVersions(versions);
            CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
            // edc.setCrfLabel(crf.getLabel());
            edc.setCrfName(crf.getName());
            // to show/hide edit action on jsp page
            if (crf.getStatus().equals(Status.AVAILABLE)) {
                edc.setOwner(crf.getOwner());
            }
            CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
            //There could be separate EventDefinitionCRF objects with same default version id.
            if (defaultVersions.contains(defaultVersion)) {
                continue;
            }
            edc.setDefaultVersionName(defaultVersion.getName());
            if (edc.getStatus().isAvailable()) {
                defaultVersions.add(defaultVersion);
            }
        }
        // Whether IE6 or IE7 is involved
        String isIE = fp.getString("ie");
        if ("y".equalsIgnoreCase(isIE)) {
            request.setAttribute("isInternetExplorer", "true");
        }
        int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
        // EventDefinitionCRFDao findByStudyEventIdAndCRFVersionId(int
        // studyEventId, int crfVersionId)
        SectionDAO sdao = new SectionDAO(getDataSource());
        CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
        CRFDAO crfDao = new CRFDAO(getDataSource());
        ArrayList printCrfBeans = new ArrayList();
        for (Iterator it = defaultVersions.iterator(); it.hasNext(); ) {
            allSectionBeans = new ArrayList<SectionBean>();
            ArrayList sectionBeans = new ArrayList();
            CRFVersionBean crfVersionBean = (CRFVersionBean) it.next();
            // The existing application doesn't print null values, even if they are
            // defined in the event definition
            //            int crfVersionId = fp.getInt("id");
            // BWP 2/7/2008>> Find out if the CRF has grouped tables, and if so,
            // use
            // that dedicated JSP
            ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
            // Find truely grouped tables, not groups with a name of 'Ungrouped'
            List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
            CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
            if (itemGroupBeans.size() > 0) {
                // get a DisplaySectionBean for each section of the CRF, sort
                // them, then
                // dispatch the request to a print JSP. The constructor for this
                // handler takes
                // a boolean value depending on whether data is involved or not
                // ('false' in terms of this
                // servlet; see PrintDataEntryServlet).
                DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
                handler.setCrfVersionId(crfVersionBean.getId());
                handler.setEventCRFId(eventCRFId);
                List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
                request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
                // Make available the CRF names and versions for
                // the web page's header
                CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
                request.setAttribute("crfVersionBean", crfverBean);
                request.setAttribute("crfBean", crfBean);
                // Set an attribute signaling that data is not involved
                request.setAttribute("dataInvolved", "false");
                PrintCRFBean printCrfBean = new PrintCRFBean();
                printCrfBean.setDisplaySectionBeans(displaySectionBeans);
                printCrfBean.setCrfVersionBean(crfVersionBean);
                printCrfBean.setCrfBean(crfBean);
                printCrfBean.setEventCrfBean(ecb);
                printCrfBeans.add(printCrfBean);
                printCrfBean.setGrouped(true);
                // IllegalStateException
                continue;
            }
            ecb = new EventCRFBean();
            ecb.setCRFVersionId(crfVersionBean.getId());
            CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
            ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
            for (int i = 0; i < sects.size(); i++) {
                sb = (SectionBean) sects.get(i);
                //super.sb = sb;
                int sectId = sb.getId();
                if (sectId > 0) {
                    allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
                }
            }
            request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
            request.setAttribute(INPUT_EVENT_CRF, ecb);
            sectionBeans = super.getAllDisplayBeans(request);
            request.setAttribute(SECTION_BEAN, sb);
            DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
            //            request.setAttribute("allSections", sectionBeans);
            //            request.setAttribute("displayAllCRF", "1");
            //            request.setAttribute(BEAN_DISPLAY, dsb);
            //            request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
            //            request.setAttribute("sec", sb);
            //            request.setAttribute("EventCRFBean", super.ecb);
            PrintCRFBean printCrfBean = new PrintCRFBean();
            printCrfBean.setAllSections(sectionBeans);
            printCrfBean.setDisplaySectionBean(dsb);
            printCrfBean.setEventCrfBean(ecb);
            printCrfBean.setCrfVersionBean(crfVersionBean);
            printCrfBean.setCrfBean(crfBean);
            printCrfBeans.add(printCrfBean);
            printCrfBean.setGrouped(false);
        }
        String studyName = null;
        String siteName = null;
        if (currentStudy.getParentStudyId() > 0) {
            studyName = currentStudy.getParentStudyName();
            siteName = currentStudy.getName();
        } else {
            studyName = currentStudy.getName();
        }
        request.setAttribute("printCrfBeans", printCrfBeans);
        request.setAttribute("studyName", studyName);
        request.setAttribute("site", siteName);
        request.setAttribute("eventDefinition", sed.getName());
        forwardPage(Page.VIEW_DEFAULT_CRF_VERSIONS_PRINT, request, response);
    }
}
Also used : ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) PrintCRFBean(org.akaza.openclinica.bean.managestudy.PrintCRFBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) Iterator(java.util.Iterator) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) PrintCRFBean(org.akaza.openclinica.bean.managestudy.PrintCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 15 with DisplaySectionBean

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

the class PrintDataEntryServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    boolean isSubmitted = false;
    int eventCRFId = fp.getInt("ecId");
    //JN:The following were the the global variables, moved as local.
    EventCRFBean ecb;
    SectionDAO sdao = new SectionDAO(getDataSource());
    ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
    ArrayList sectionBeans = new ArrayList();
    String age = "";
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    // Whether IE6 or IE7 is involved
    String isIE = fp.getString("ie");
    if ("y".equalsIgnoreCase(isIE)) {
        request.setAttribute("isInternetExplorer", "true");
    }
    if (eventCRFId == 0) {
        ecb = new EventCRFBean();
    // super.ecb.setCRFVersionId(sb.getCRFVersionId());
    } else {
        EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        // Get all the SectionBeans attached to this ECB
        ArrayList sects = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
        for (int i = 0; i < sects.size(); i++) {
            sb = (SectionBean) sects.get(i);
            //                super.sb = sb;
            int sectId = sb.getId();
            if (sectId > 0) {
                allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
            }
        }
        // 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);
        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);
        // Let us process the age
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
            // 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() + " - " + study.getName());
        } else {
            request.setAttribute("studyTitle", study.getName());
        }
        request.setAttribute("studySubject", sub);
        request.setAttribute("subject", subject);
        request.setAttribute("studyEvent", se);
        request.setAttribute("age", age);
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
        // Get the section beans from super
        sectionBeans = super.getAllDisplayBeans(request);
    }
    // Find out whether the sections involve groups
    ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
    // Find truely grouped tables, not groups with a name of 'Ungrouped'
    // CRF VERSION ID WILL BE 0 IF "ecId" IS NOT IN THE QUERYSTRING
    int crfVersionId = ecb.getCRFVersionId();
    List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
    boolean sectionsHaveGroups = false;
    if (itemGroupBeans.size() > 0) {
        sectionsHaveGroups = true;
        // get a DisplaySectionBean for each section of the CRF, sort them,
        // then
        // dispatch the request to a print JSP. the constructor for this
        // handler takes
        // a boolean value depending on whether an event or data is involved
        // or not
        DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(true, getDataSource(), getServletContext());
        handler.setCrfVersionId(crfVersionId);
        handler.setEventCRFId(eventCRFId);
        List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
        CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
        CRFDAO crfDao = new CRFDAO(getDataSource());
        request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
        // Make available the CRF names and versions for
        // the web page's header
        CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
        request.setAttribute("crfVersionBean", crfverBean);
        CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
        request.setAttribute("crfBean", crfBean);
        // Set an attribute signaling that an event and/or data is involved
        request.setAttribute("dataInvolved", "true");
    }
    request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
    request.setAttribute("EventCRFBean", ecb);
    // We do not need most of these attributes if groups are involved
    if (!sectionsHaveGroups) {
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
        request.setAttribute("allSections", sectionBeans);
        request.setAttribute("displayAll", "1");
        request.setAttribute(BEAN_DISPLAY, dsb);
        request.setAttribute("sec", sb);
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
    } else {
        // end if(! sectionsHaveGroups)
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) 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) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) 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) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)22 ArrayList (java.util.ArrayList)20 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)17 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)16 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)14 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)14 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)14 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)14 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)12 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)11 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)11 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)10 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)10 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)10 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)10 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)8 HttpSession (javax.servlet.http.HttpSession)7 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)7 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)7