Search in sources :

Example 66 with EventDefinitionCRFDAO

use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.

the class LockEventDefinitionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String idString = request.getParameter("id");
    int defId = Integer.valueOf(idString.trim()).intValue();
    StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
    // find all CRFs
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    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.setCrfName(crf.getName());
    }
    // finds all events
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_SED_to_lock"));
        forwardPage(Page.LIST_DEFINITION_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            if (!sed.getStatus().equals(Status.AVAILABLE)) {
                addPageMessage(respage.getString("this_SED_is_not_available_for_this_study") + respage.getString("please_contact_sysadmin_for_more_information"));
                forwardPage(Page.LIST_DEFINITION_SERVLET);
                return;
            }
            request.setAttribute("definitionToLock", sed);
            request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
            request.setAttribute("events", events);
            forwardPage(Page.LOCK_DEFINITION);
        } else {
            logger.info("submit to lock the definition");
            // lock definition
            sed.setStatus(Status.LOCKED);
            sed.setUpdater(ub);
            sed.setUpdatedDate(new Date());
            sdao.update(sed);
            // lock all crfs
            for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
                edc.setStatus(Status.LOCKED);
                edc.setUpdater(ub);
                edc.setUpdatedDate(new Date());
                edao.update(edc);
            }
            // lock all events
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            for (int j = 0; j < events.size(); j++) {
                StudyEventBean event = (StudyEventBean) events.get(j);
                event.setStatus(Status.LOCKED);
                event.setUpdater(ub);
                event.setUpdatedDate(new Date());
                sedao.update(event);
                ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
                // remove all the item data
                ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                for (int k = 0; k < eventCRFs.size(); k++) {
                    EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                    eventCRF.setStatus(Status.LOCKED);
                    eventCRF.setUpdater(ub);
                    eventCRF.setUpdatedDate(new Date());
                    ecdao.update(eventCRF);
                    ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
                    for (int a = 0; a < itemDatas.size(); a++) {
                        ItemDataBean item = (ItemDataBean) itemDatas.get(a);
                        item.setStatus(Status.LOCKED);
                        item.setUpdater(ub);
                        item.setUpdatedDate(new Date());
                        iddao.update(item);
                    }
                }
            }
            String emailBody = respage.getString("the_SED") + sed.getName() + respage.getString("has_been_locked_for_the_study") + currentStudy.getName() + respage.getString("no_new_data_may_entered_for_this_SED");
            addPageMessage(emailBody);
            sendEmail(emailBody);
            forwardPage(Page.LIST_DEFINITION_SERVLET);
        }
    }
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 67 with EventDefinitionCRFDAO

use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method getAllDisplayBeans.

/**
     * Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
     * @param request TODO
     */
protected ArrayList getAllDisplayBeans(HttpServletRequest request) throws Exception {
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    ArrayList sections = new ArrayList();
    HttpSession session = request.getSession();
    StudyBean study = (StudyBean) session.getAttribute("study");
    SectionDAO sdao = new SectionDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    // ALL_SECTION_BEANS
    ArrayList<SectionBean> allSectionBeans = (ArrayList<SectionBean>) request.getAttribute(ALL_SECTION_BEANS);
    for (int j = 0; j < allSectionBeans.size(); j++) {
        SectionBean sb = allSectionBeans.get(j);
        DisplaySectionBean section = new DisplaySectionBean();
        section.setEventCRF(ecb);
        if (sb.getParentId() > 0) {
            SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
            sb.setParent(parent);
        }
        section.setSection(sb);
        CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
        section.setCrfVersion(cvb);
        CRFDAO cdao = new CRFDAO(getDataSource());
        CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
        section.setCrf(cb);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
        EventDefinitionCRFBean edcb = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), cvb.getId());
        section.setEventDefinitionCRF(edcb);
        // setup DAO's here to avoid creating too many objects
        ItemDAO idao = new ItemDAO(getDataSource());
        ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
        iddao = new ItemDataDAO(getDataSource(), locale);
        // get all the display item beans
        ArrayList displayItems = getParentDisplayItems(false, sb, edcb, idao, ifmdao, iddao, false, request);
        LOGGER.debug("222 just ran get parent display, has group " + " FALSE has ungrouped FALSE");
        // now sort them by ordinal
        Collections.sort(displayItems);
        // now get the child DisplayItemBeans
        for (int i = 0; i < displayItems.size(); i++) {
            DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
            dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
            if (shouldLoadDBValues(dib)) {
                LOGGER.trace("should load db values is true, set value");
                dib.loadDBValue();
            }
            displayItems.set(i, dib);
        }
        section.setItems(displayItems);
        sections.add(section);
    }
    return sections;
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HttpSession(javax.servlet.http.HttpSession) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 68 with EventDefinitionCRFDAO

use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method markCRFComplete.

/**
     * The following methods are for 'mark CRF complete'
     * @param request TODO
     *
     * @return
     */
protected boolean markCRFComplete(HttpServletRequest request) throws Exception {
    locale = LocaleResolver.getLocale(request);
    HttpSession session = request.getSession();
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    // < respage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    getEventCRFBean(request);
    getEventDefinitionCRFBean(request);
    DataEntryStage stage = ecb.getStage();
    // request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
    // ecb);
    // request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()));
    LOGGER.trace("inout_event_crf_id:" + ecb.getId());
    if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
        addPageMessage(respage.getString("not_mark_CRF_complete1"), request);
        return false;
    }
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        if (!edcb.isDoubleEntry()) {
            addPageMessage(respage.getString("not_mark_CRF_complete2"), request);
            return false;
        }
    }
    if (isEachRequiredFieldFillout(request) == false) {
        addPageMessage(respage.getString("not_mark_CRF_complete4"), request);
        return false;
    }
    /*
         * if (ecb.getInterviewerName().trim().equals("")) { throw new InconsistentStateException(errorPage, "You may not mark this Event CRF complete, because
         * the interviewer name is blank."); }
         */
    Status newStatus = ecb.getStatus();
    boolean ide = true;
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
        newStatus = Status.PENDING;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
        ide = false;
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        newStatus = Status.UNAVAILABLE;
        ecb.setDateValidateCompleted(new Date());
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ide = false;
    }
    // create them
    if (!isEachSectionReviewedOnce(request)) {
        boolean canSave = saveItemsToMarkComplete(newStatus, request);
        if (canSave == false) {
            addPageMessage(respage.getString("not_mark_CRF_complete3"), request);
            return false;
        }
    }
    ecb.setStatus(newStatus);
    /*
         * Marking the data entry as signed if the corresponding EventDefinitionCRF is being enabled for electronic signature.
         */
    if (edcb.isElectronicSignature()) {
        ecb.setElectronicSignatureStatus(true);
    }
    ecb = (EventCRFBean) ecdao.update(ecb);
    // note the below statement only updates the DATES, not the STATUS
    ecdao.markComplete(ecb, ide);
    // update all the items' status to complete
    iddao.updateStatusByEventCRF(ecb, newStatus);
    // change status for study event
    StudyEventDAO sedao = new StudyEventDAO(getDataSource());
    StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
    seb.setUpdatedDate(new Date());
    seb.setUpdater(ub);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    ArrayList allCRFs = ecdao.findAllByStudyEventAndStatus(seb, Status.UNAVAILABLE);
    StudyBean study = (StudyBean) session.getAttribute("study");
    ArrayList allEDCs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
    CRFVersionDAO crfversionDao = new CRFVersionDAO(getDataSource());
    boolean eventCompleted = true;
    boolean allRequired = true;
    //JN Adding another flag
    boolean allCrfsCompleted = false;
    int allEDCsize = allEDCs.size();
    ArrayList nonRequiredCrfIds = new ArrayList();
    ArrayList requiredCrfIds = new ArrayList();
    if (allCRFs.size() == allEDCs.size()) {
        // was
        //JN: all crfs are completed and then set the subject event status as complete
        seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
    }
    seb = (StudyEventBean) sedao.update(seb);
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    return true;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HttpSession(javax.servlet.http.HttpSession) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 69 with EventDefinitionCRFDAO

use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO 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 70 with EventDefinitionCRFDAO

use of org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO in project OpenClinica by OpenClinica.

the class ListDiscNotesSubjectServlet method processRequest.

// < ResourceBundleresexception,respage;
@Override
protected void processRequest() throws Exception {
    String module = request.getParameter("module");
    String moduleStr = "manage";
    if (module != null && module.trim().length() > 0) {
        if ("submit".equals(module)) {
            request.setAttribute("module", "submit");
            moduleStr = "submit";
        } else if ("admin".equals(module)) {
            request.setAttribute("module", "admin");
            moduleStr = "admin";
        } else {
            request.setAttribute("module", "manage");
        }
    }
    // << tbh 02/2010 filter out the entire module parameter to catch injections
    // BWP 3098>> close the info side panel and show icons
    request.setAttribute("closeInfoShowIcons", true);
    // <<
    // Determine whether to limit the displayed DN's to a certain DN type
    int resolutionStatus = 0;
    try {
        resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
    } catch (NumberFormatException nfe) {
        // Show all DN's
        resolutionStatus = -1;
    }
    // Determine whether we already have a collection of resolutionStatus
    // Ids, and if not
    // create a new attribute. If there is no resolution status, then the
    // Set object should be cleared,
    // because we do not have to save a set of filter IDs.
    boolean hasAResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 5;
    Set<Integer> resolutionStatusIds = (HashSet) session.getAttribute(RESOLUTION_STATUS);
    // remove the session if there is no resolution status
    if (!hasAResolutionStatus && resolutionStatusIds != null) {
        session.removeAttribute(RESOLUTION_STATUS);
        resolutionStatusIds = null;
    }
    if (hasAResolutionStatus) {
        if (resolutionStatusIds == null) {
            resolutionStatusIds = new HashSet<Integer>();
        }
        resolutionStatusIds.add(resolutionStatus);
        session.setAttribute(RESOLUTION_STATUS, resolutionStatusIds);
    }
    int discNoteType = 0;
    try {
        discNoteType = Integer.parseInt(request.getParameter("type"));
    } catch (NumberFormatException nfe) {
        // Show all DN's
        discNoteType = -1;
    }
    request.setAttribute(DISCREPANCY_NOTE_TYPE, discNoteType);
    DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
    // Generate a summary of how we are filtering;
    Map<String, List<String>> filterSummary = discNoteUtil.generateFilterSummary(discNoteType, resolutionStatusIds);
    if (!filterSummary.isEmpty()) {
        request.setAttribute(FILTER_SUMMARY, filterSummary);
    }
    locale = LocaleResolver.getLocale(request);
    StudyBean sbean = (StudyBean) session.getAttribute("study");
    //List<DiscrepancyNoteBean> allDiscNotes = discNoteUtil.getThreadedDNotesForStudy(sbean, resolutionStatusIds, sm.getDataSource(), discNoteType, true);
    //Map stats = discNoteUtil.generateDiscNoteSummary(allDiscNotes);
    Map stats = discNoteUtil.generateDiscNoteSummaryRefactored(sm.getDataSource(), currentStudy, resolutionStatusIds, discNoteType);
    request.setAttribute("summaryMap", stats);
    Set mapKeys = stats.keySet();
    request.setAttribute("mapKeys", mapKeys);
    // < resword =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
    StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO edao = new EventCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO eddao = new EventDefinitionCRFDAO(sm.getDataSource());
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    DiscrepancyNoteDAO dnDAO = new DiscrepancyNoteDAO(sm.getDataSource());
    ListDiscNotesSubjectTableFactory factory = new ListDiscNotesSubjectTableFactory(ResourceBundleProvider.getTermsBundle(locale));
    factory.setStudyEventDefinitionDao(seddao);
    factory.setSubjectDAO(subdao);
    factory.setStudySubjectDAO(sdao);
    factory.setStudyEventDAO(sedao);
    factory.setStudyBean(currentStudy);
    factory.setStudyGroupClassDAO(sgcdao);
    factory.setSubjectGroupMapDAO(sgmdao);
    factory.setStudyDAO(studyDAO);
    factory.setCurrentRole(currentRole);
    factory.setCurrentUser(ub);
    factory.setEventCRFDAO(edao);
    factory.setEventDefintionCRFDAO(eddao);
    factory.setStudyGroupDAO(sgdao);
    factory.setDiscrepancyNoteDAO(dnDAO);
    factory.setModule(moduleStr);
    factory.setDiscNoteType(discNoteType);
    // factory.setStudyHasDiscNotes(allDiscNotes != null &&
    // !allDiscNotes.isEmpty());
    factory.setResolutionStatus(resolutionStatus);
    factory.setResolutionStatusIds(resolutionStatusIds);
    factory.setResword(ResourceBundleProvider.getWordsBundle(locale));
    String listDiscNotesHtml = factory.createTable(request, response).render();
    request.setAttribute("listDiscNotesHtml", listDiscNotesHtml);
    forwardPage(getJSP());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ListDiscNotesSubjectTableFactory(org.akaza.openclinica.control.submit.ListDiscNotesSubjectTableFactory) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) List(java.util.List) DiscrepancyNoteUtil(org.akaza.openclinica.service.DiscrepancyNoteUtil) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) HashSet(java.util.HashSet) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) Map(java.util.Map)

Aggregations

EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)84 ArrayList (java.util.ArrayList)72 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)53 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)45 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)39 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)39 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)36 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)35 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)30 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)28 Date (java.util.Date)27 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26