Search in sources :

Example 96 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class DefineStudyEventServlet method processRequest.

/**
 * Processes the 'define study event' request
 */
@Override
public void processRequest() throws Exception {
    FormProcessor fpr = new FormProcessor(request);
    // logger.info("actionName*******" + fpr.getString("actionName"));
    // logger.info("pageNum*******" + fpr.getString("pageNum"));
    String actionName = request.getParameter("actionName");
    ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
    if (crfsWithVersion == null) {
        crfsWithVersion = new ArrayList();
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        ArrayList crfs = (ArrayList) cdao.findAllByStatus(Status.AVAILABLE);
        for (int i = 0; i < crfs.size(); i++) {
            CRFBean crf = (CRFBean) crfs.get(i);
            ArrayList versions = cvdao.findAllByCRFId(crf.getId());
            if (!versions.isEmpty()) {
                crfsWithVersion.add(crf);
            }
        }
        session.setAttribute("crfsWithVersion", crfsWithVersion);
    }
    if (StringUtil.isBlank(actionName)) {
        StudyEventDefinitionBean sed = new StudyEventDefinitionBean();
        sed.setStudyId(currentStudy.getId());
        session.setAttribute("definition", sed);
        session.removeAttribute("tmpCRFIdMap");
        forwardPage(Page.DEFINE_STUDY_EVENT1);
    } else {
        if ("confirm".equalsIgnoreCase(actionName)) {
            confirmWholeDefinition();
        } else if ("submit".equalsIgnoreCase(actionName)) {
            // 092007 tbh
            try {
                Integer nextAction = Integer.valueOf(request.getParameter("nextAction"));
                if (nextAction != null) {
                    if (nextAction.intValue() == 1) {
                        session.removeAttribute("definition");
                        addPageMessage(respage.getString("the_new_event_definition_creation_cancelled"));
                        forwardPage(Page.LIST_DEFINITION_SERVLET);
                    } else if (nextAction.intValue() == 2) {
                        submitDefinition();
                        // forwardPage(Page.LIST_DEFINITION_SERVLET);
                        ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
                        session.setAttribute("pageMessages", pageMessages);
                        response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
                    // forwardPage(Page.MANAGE_STUDY_MODULE);
                    // request.getRequestDispatcher("/pages/studymodule").forward(request, response);
                    // org.akaza.openclinica.service.sdv.SDVUtil sdvUtil = new org.akaza.openclinica.service.sdv.SDVUtil();
                    // sdvUtil.forwardRequestFromController(request,response,"http://localhost:8080/OpenClinica-SNAPSHOT/pages/studymodule");
                    // This last part is necessary because the compiler will complain about the return;
                    // statement in the absence of the "if" [the following statements are "reachable"]
                    // boolean redir = "y".equalsIgnoreCase((String)request.getParameter("r"));
                    // if(redir)  { return;}
                    } else {
                        logger.debug("actionName ==> 3");
                        submitDefinition();
                        StudyEventDefinitionBean sed = new StudyEventDefinitionBean();
                        sed.setStudyId(currentStudy.getId());
                        session.setAttribute("definition", sed);
                        forwardPage(Page.DEFINE_STUDY_EVENT1);
                    }
                }
            } catch (NumberFormatException e) {
                e.printStackTrace();
                addPageMessage(respage.getString("the_new_event_definition_creation_cancelled"));
                forwardPage(Page.LIST_DEFINITION_SERVLET);
            } catch (NullPointerException e) {
                e.printStackTrace();
                addPageMessage(respage.getString("the_new_event_definition_creation_cancelled"));
                forwardPage(Page.LIST_DEFINITION_SERVLET);
            }
        // above added 092007 tbh
        } else if ("next".equalsIgnoreCase(actionName)) {
            Integer pageNumber = Integer.valueOf(request.getParameter("pageNum"));
            if (pageNumber != null) {
                if (pageNumber.intValue() == 2) {
                    String nextListPage = request.getParameter("next_list_page");
                    if (nextListPage != null && nextListPage.equalsIgnoreCase("true")) {
                        confirmDefinition1();
                    } else {
                        confirmDefinition2();
                    }
                } else {
                    confirmDefinition1();
                }
            } else {
                if (session.getAttribute("definition") == null) {
                    StudyEventDefinitionBean sed = new StudyEventDefinitionBean();
                    sed.setStudyId(currentStudy.getId());
                    session.setAttribute("definition", sed);
                }
                forwardPage(Page.DEFINE_STUDY_EVENT1);
            }
        }
    }
}
Also used : 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) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 97 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ListEventsForSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    String pageNumber = fp.getString(ListStudySubjectServlet.SUBJECT_PAGE_NUMBER);
    String filterKeyword = fp.getString(ListStudySubjectServlet.FILTER_KEYWORD);
    String tmpSearch = fp.getString(ListStudySubjectServlet.SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword);
    SubjectMatrixUtil matrixUtil = new SubjectMatrixUtil();
    String query = matrixUtil.createPaginatingQuery(pageNumber);
    StringBuilder extendedQuery = new StringBuilder(query);
    // 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) {
        extendedQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        extendedQuery.append("&").append(ListStudySubjectServlet.FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(ListStudySubjectServlet.PAGINATING_QUERY, extendedQuery.toString());
    int definitionId = fp.getInt("defId");
    int tabId = fp.getInt("tab");
    if (definitionId <= 0) {
        addPageMessage(respage.getString("please_choose_an_ED_ta_to_vies_details"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
        return;
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(definitionId);
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    // find all the groups in the current study
    ArrayList studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
    // information for the event tabs
    ArrayList allDefs = seddao.findAllActiveByStudy(currentStudy);
    boolean isASite = false;
    if (currentStudy.getParentStudyId() > 0) {
        StudyDAO stdao = new StudyDAO(sm.getDataSource());
        StudyBean parent = (StudyBean) stdao.findByPK(currentStudy.getParentStudyId());
        allDefs = seddao.findAllActiveByStudy(parent);
    }
    ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(this.currentStudy, definitionId);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        CRFBean crf = (CRFBean) crfdao.findByPK(edc.getCrfId());
        edc.setCrf(crf);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    request.setAttribute("allDefsArray", allDefs);
    request.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    request.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    request.setAttribute("eventDefCRFSize", new Integer(eventDefinitionCRFs.size()));
    request.setAttribute("tabId", new Integer(tabId));
    request.setAttribute("studyEventDef", sed);
    request.setAttribute("eventDefCRFs", eventDefinitionCRFs);
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList displayStudySubs = new ArrayList();
    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());
            }
        }
        // find all eventcrfs for each event, for each event tab
        ArrayList displaySubjectEvents = new ArrayList();
        ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
        ArrayList events = sedao.findAllByStudySubjectAndDefinition(studySub, sed);
        for (int k = 0; k < events.size(); k++) {
            StudyEventBean seb = (StudyEventBean) events.get(k);
            DisplayStudyEventBean dseb = ListStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, seb, sm.getDataSource(), ub, currentRole, this.currentStudy);
            // ArrayList eventCRFs = ecdao.findAllByStudyEvent(seb);
            // ArrayList al =
            // ViewStudySubjectServlet.getUncompletedCRFs(sm.getDataSource(),
            // eventDefinitionCRFs, eventCRFs);
            // dseb.getUncompletedCRFs().add(al);
            displayEvents.add(dseb);
        }
        ArrayList al = new ArrayList();
        for (int k = 0; k < displayEvents.size(); k++) {
            DisplayStudyEventBean dseb = displayEvents.get(k);
            ArrayList eventCRFs = dseb.getDisplayEventCRFs();
            for (int a = 0; a < eventDefinitionCRFs.size(); a++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(a);
                int crfId = edc.getCrfId();
                boolean hasCRF = false;
                for (int b = 0; b < eventCRFs.size(); b++) {
                    DisplayEventCRFBean decb = (DisplayEventCRFBean) eventCRFs.get(b);
                    // decb.getStage().getName() );
                    if (decb.getEventCRF().getCrf().getId() == crfId) {
                        dseb.getAllEventCRFs().add(decb);
                        // logger.info("hasCRf" + crfId +
                        // decb.getEventCRF().getCrf().getName());
                        hasCRF = true;
                        break;
                    }
                }
                if (hasCRF == false) {
                    DisplayEventCRFBean db = new DisplayEventCRFBean();
                    db.setEventDefinitionCRF(edc);
                    db.getEventDefinitionCRF().setCrf(edc.getCrf());
                    dseb.getAllEventCRFs().add(db);
                // logger.info("noCRf" + crfId);
                }
            }
            // Issue 3212 BWP <<
            if (currentStudy.getParentStudyId() > 0) {
                // check each eventDefCRFBean and set its isHidden property
                // to true, if its
                // persistent/database-derived hideCrf is true (domain rule:
                // hide the CRF from users logged into a site)
                HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
                hideCRFManager.optionallyCheckHideCRFProperty(dseb);
                // remove a DisplayEventCRFBean from a DisplayStudyEventBean
                // in the list
                // if it contains a hidden CRF in its event definition
                hideCRFManager.removeHiddenEventCRF(dseb);
                // generate a boolean request attribute indicating whether
                // any of the CRFs
                // should be hidden
                boolean hideCRFs = hideCRFManager.studyEventHasAHideCRFProperty(dseb);
                request.setAttribute("hideCRFs", hideCRFs);
            }
        // >>
        }
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        dssb.setStudyEvents(displayEvents);
        if (definitionId > 0) {
            dssb.setSedId(definitionId);
        } else {
            dssb.setSedId(-1);
        }
        displayStudySubs.add(dssb);
    }
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectEventsRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("gender"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    // columnArray.add("Event Sequence");
    columnArray.add(resword.getString("event_status"));
    columnArray.add(resword.getString("event_date"));
    // Issue 3212 BWP <<
    HideCRFManager hideCRFMgr = HideCRFManager.createHideCRFManager();
    hideCRFMgr.hideSpecifiedEventCRFDefBeans(eventDefinitionCRFs);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        // Issue 3212 BWP <<
        if (!(currentStudy.getParentStudyId() > 0)) {
            columnArray.add(edc.getCrf().getName());
        } else {
            if (!edc.isHideCrf()) {
                columnArray.add(edc.getCrf().getName());
            }
        }
    // >>
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery("ListEventsForSubject?module=" + module + "&defId=" + definitionId + "&tab=" + tabId, new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // if(currentStudy.getStatus().isAvailable()){
    // table.addLink(resword.getString("add_new_subject"), "AddNewSubject");
    // }
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    forwardPage(Page.LIST_EVENTS_FOR_SUBJECT);
}
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) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 98 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class PrintAllSiteEventCRFServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // The PrintDataEntry servlet handles this parameter
    int siteId = fp.getInt("siteId");
    // JN:The following were the the global variables, moved as local.
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    ArrayList<SectionBean> allSectionBeans;
    StudyDAO studyDao = new StudyDAO(getDataSource());
    StudyBean site = (StudyBean) studyDao.findByPK(siteId);
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    seds = sedao.findAllByStudy(site);
    // ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    CRFDAO cdao = new CRFDAO(getDataSource());
    boolean isSubmitted = false;
    ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
    for (StudyEventDefinitionBean sed : seds) {
        int defId = sed.getId();
        edcs.addAll(edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId, siteId, site.getParentStudyId()));
    }
    Map eventDefinitionDefaultVersions = new LinkedHashMap();
    Map eventDefinitionEventDefCrf = new LinkedHashMap<StudyEventDefinitionBean, EventDefinitionCRFBean>();
    for (int i = 0; i < edcs.size(); i++) {
        EventDefinitionCRFBean edc = edcs.get(i);
        if (!edc.getStatus().equals(Status.AVAILABLE)) {
            continue;
        }
        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());
        StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
        edc.setDefaultVersionName(defaultVersion.getName());
        if (defaultVersion.getStatus().isAvailable()) {
            List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
            if (list == null)
                list = new ArrayList();
            list.add(defaultVersion);
            eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
            eventDefinitionEventDefCrf.put(studyEventDefinitionBean, edc);
        }
    }
    // Whether IE6 or IE7 is involved
    String isIE = fp.getString("ie");
    if ("y".equalsIgnoreCase(isIE)) {
        request.setAttribute("isInternetExplorer", "true");
    }
    SectionDAO sdao = new SectionDAO(getDataSource());
    CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
    CRFDAO crfDao = new CRFDAO(getDataSource());
    Map sedCrfBeans = null;
    for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
        if (sedCrfBeans == null)
            sedCrfBeans = new LinkedHashMap();
        StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
        List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
        for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
            CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
            allSectionBeans = new ArrayList<SectionBean>();
            ArrayList sectionBeans = new ArrayList();
            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);
                printCrfBean.setGrouped(true);
                List list = (ArrayList) sedCrfBeans.get(sedBean);
                if (list == null)
                    list = new ArrayList();
                list.add(printCrfBean);
                sedCrfBeans.put(sedBean, list);
                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);
                int sectId = sb.getId();
                if (sectId > 0) {
                    allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
                }
            }
            EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) eventDefinitionEventDefCrf.get(sedBean);
            request.setAttribute(EVENT_DEF_CRF_BEAN, edcBean);
            request.setAttribute(INPUT_EVENT_CRF, ecb);
            request.setAttribute(SECTION_BEAN, sb);
            request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
            sectionBeans = super.getAllDisplayBeans(request);
            DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
            PrintCRFBean printCrfBean = new PrintCRFBean();
            printCrfBean.setAllSections(sectionBeans);
            printCrfBean.setDisplaySectionBean(dsb);
            printCrfBean.setEventCrfBean(ecb);
            printCrfBean.setCrfVersionBean(crfVersionBean);
            printCrfBean.setCrfBean(crfBean);
            printCrfBean.setGrouped(false);
            List list = (ArrayList) sedCrfBeans.get(sedBean);
            if (list == null)
                list = new ArrayList();
            list.add(printCrfBean);
            sedCrfBeans.put(sedBean, list);
        }
    }
    StudyBean parentStudy = (StudyBean) studyDao.findByPK(site.getParentStudyId());
    String studyName = parentStudy.getName();
    String siteName = site.getName();
    request.setAttribute("sedCrfBeans", sedCrfBeans);
    request.setAttribute("studyName", studyName);
    request.setAttribute("site", siteName);
    forwardPage(Page.VIEW_ALL_SITE_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) LinkedHashMap(java.util.LinkedHashMap) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) 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) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 99 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class PrintCRFServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // 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);
    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");
    }
    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<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
    ArrayList sectionBeans = new ArrayList();
    // The existing application doesn't print null values, even if they are
    // defined in the event definition
    int crfVersionId = fp.getInt("id", true);
    boolean isSubmitted = false;
    if (crfVersionId == 0) {
        addPageMessage(respage.getString("please_choose_a_crf_to_view_details"), request);
        forwardPage(Page.CRF_LIST_SERVLET, request, response);
    } else {
        // 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(crfVersionId);
        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(crfVersionId);
            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(crfVersionId);
            request.setAttribute("crfVersionBean", crfverBean);
            CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
            request.setAttribute("crfBean", crfBean);
            // Set an attribute signaling that data is not involved
            request.setAttribute("dataInvolved", "false");
            // request.setAttribute("displaySection",displaySection);
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
            // IllegalStateException
            return;
        }
        // JN:Revisit ME
        ecb = new EventCRFBean();
        ecb.setCRFVersionId(crfVersionId);
        CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
        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(INPUT_EVENT_CRF, ecb);
    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", ecb);
    forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) 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) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) 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) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler)

Example 100 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean 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

CRFBean (org.akaza.openclinica.bean.admin.CRFBean)138 ArrayList (java.util.ArrayList)95 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)78 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)78 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)70 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)67 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)63 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)44 HashMap (java.util.HashMap)43 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)43 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)37 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)27 Iterator (java.util.Iterator)26 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)26 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)22 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)20