Search in sources :

Example 11 with SubjectGroupMapDAO

use of org.akaza.openclinica.dao.submit.SubjectGroupMapDAO in project OpenClinica by OpenClinica.

the class StudySubjectDAO method create.

/**
 * Create a study subject (that is, enroll a subject in a study).
 *
 * @param sb
 *            The study subject to create.
 * @param withGroup
 *            <code>true</code> if the group id has been set (primarily
 *            for use with genetic studies); <code>false</false> otherwise.
 * @return The study subject with id set to the insert id if the operation
 *         was successful, or 0 otherwise.
 */
public StudySubjectBean create(StudySubjectBean sb, boolean withGroup) {
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();
    int ind = 1;
    variables.put(new Integer(ind), sb.getLabel());
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getSubjectId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStudyId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStatus().getId()));
    ind++;
    // Date_created is now()
    variables.put(new Integer(ind), new Integer(sb.getOwner().getId()));
    ind++;
    // if (withGroup) {
    // variables.put(new Integer(ind), new Integer(sb.getStudyGroupId()));
    // ind++;
    // } else {
    // nullVars.put(new Integer(ind), new Integer(TypeNames.INT));
    // variables.put(new Integer(ind), null);
    // ind++;
    // }
    Date enrollmentDate = sb.getEnrollmentDate();
    if (enrollmentDate == null) {
        nullVars.put(new Integer(ind), new Integer(Types.DATE));
        variables.put(new Integer(ind), null);
        ind++;
    } else {
        variables.put(new Integer(ind), enrollmentDate);
        ind++;
    }
    variables.put(new Integer(ind), sb.getSecondaryLabel());
    ind++;
    variables.put(new Integer(ind), getValidOid(sb));
    ind++;
    this.executeWithPK(digester.getQuery("create"), variables, nullVars);
    if (isQuerySuccessful()) {
        sb.setId(getLatestPK());
    }
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(ds);
    ArrayList groupMaps = sb.getStudyGroupMaps();
    for (int i = 0; i < groupMaps.size(); i++) {
        SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groupMaps.get(i);
        sgmb = (SubjectGroupMapBean) sgmdao.create(sgmb);
        if (sgmdao.isQuerySuccessful()) {
            sgmb.setId(sgmdao.getCurrentPK());
        }
    }
    return sb;
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 12 with SubjectGroupMapDAO

use of org.akaza.openclinica.dao.submit.SubjectGroupMapDAO in project OpenClinica by OpenClinica.

the class ReassignStudySubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt("id");
    if (studySubId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_to_reassign"));
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
        return;
    } else {
        StudySubjectBean studySub = (StudySubjectBean) ssdao.findByPK(studySubId);
        int subjectId = studySub.getSubjectId();
        request.setAttribute("studySub", studySub);
        SubjectBean subject = (SubjectBean) subdao.findByPK(subjectId);
        request.setAttribute("subject", subject);
        SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
        ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
        if (StringUtil.isBlank(action)) {
            ArrayList studies = null;
            DisplayStudyBean displayStudy = new DisplayStudyBean();
            StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
            if (study.getParentStudyId() > 0) {
                // current in site
                studies = (ArrayList) sdao.findAllByParent(study.getParentStudyId());
                StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId());
                displayStudy.setParent(parent);
                // studies.add(parent);
                displayStudy.setChildren(studies);
            } else {
                studies = (ArrayList) sdao.findAllByParent(study.getId());
                displayStudy.setParent(study);
                displayStudy.setChildren(studies);
            // studies.add(study);
            }
            // request.setAttribute("studies", studies);
            request.setAttribute("displayStudy", displayStudy);
            forwardPage(Page.REASSIGN_STUDY_SUBJECT);
        } else {
            int studyId = fp.getInt("studyId");
            if (studyId == 0) {
                addPageMessage(respage.getString("please_choose_a_study_site_to_reassign_the_subject"));
                forwardPage(Page.REASSIGN_STUDY_SUBJECT);
                return;
            }
            StudyBean st = (StudyBean) sdao.findByPK(studyId);
            if ("confirm".equalsIgnoreCase(action)) {
                StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(studySub.getLabel(), studyId, studySub.getId());
                if (sub1.getId() > 0) {
                    addPageMessage(respage.getString("the_study_subject_ID_used_by_another_in_study_site"));
                    forwardPage(Page.REASSIGN_STUDY_SUBJECT);
                    return;
                }
                // YW << comment out this message
                // if (groupMaps.size() > 0) {
                // addPageMessage("Warning: This subject has Group data
                // assoicated with current study,"
                // + "the group data will be lost if it is reassigned to
                // another study.");
                // }
                // YW >>
                request.setAttribute("newStudy", st);
                forwardPage(Page.REASSIGN_STUDY_SUBJECT_CONFIRM);
            } else {
                logger.info("submit to reassign the subject");
                studySub.setUpdatedDate(new Date());
                studySub.setUpdater(ub);
                studySub.setStudyId(studyId);
                ssdao.update(studySub);
                for (int i = 0; i < groupMaps.size(); i++) {
                    SubjectGroupMapBean sgm = (SubjectGroupMapBean) groupMaps.get(i);
                    sgm.setUpdatedDate(new Date());
                    sgm.setUpdater(ub);
                    sgm.setStatus(Status.DELETED);
                    sgmdao.update(sgm);
                }
                MessageFormat mf = new MessageFormat("");
                mf.applyPattern(respage.getString("subject_reassigned"));
                Object[] arguments = { studySub.getLabel(), st.getName() };
                addPageMessage(mf.format(arguments));
                forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) MessageFormat(java.text.MessageFormat) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DisplayStudyBean(org.akaza.openclinica.bean.admin.DisplayStudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 13 with SubjectGroupMapDAO

use of org.akaza.openclinica.dao.submit.SubjectGroupMapDAO in project OpenClinica by OpenClinica.

the class UpdateStudySubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormDiscrepancyNotes discNotes = null;
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    String fromResolvingNotes = fp.getString("fromResolvingNotes", true);
    if (StringUtil.isBlank(fromResolvingNotes)) {
        session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
        session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
        checkStudyLocked(Page.LIST_STUDY_SUBJECTS_SERVLET, respage.getString("current_study_locked"));
        checkStudyFrozen(Page.LIST_STUDY_SUBJECTS_SERVLET, respage.getString("current_study_frozen"));
    }
    // studySubjectId
    int studySubId = fp.getInt("id", true);
    if (studySubId == 0) {
        addPageMessage(respage.getString("please_choose_study_subject_to_edit"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
    } else {
        String action = fp.getString("action", true);
        if (StringUtil.isBlank(action)) {
            addPageMessage(respage.getString("no_action_specified"));
            forwardPage(Page.LIST_STUDY_SUBJECTS);
            return;
        }
        StudySubjectBean sub = (StudySubjectBean) subdao.findByPK(studySubId);
        StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
        StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
        SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
        ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
        HashMap gMaps = new HashMap();
        for (int i = 0; i < groupMaps.size(); i++) {
            SubjectGroupMapBean groupMap = (SubjectGroupMapBean) groupMaps.get(i);
            gMaps.put(new Integer(groupMap.getStudyGroupClassId()), groupMap);
        }
        StudyDAO stdao = new StudyDAO(sm.getDataSource());
        ArrayList classes = new ArrayList();
        if (!"submit".equalsIgnoreCase(action)) {
            // YW <<
            int parentStudyId = currentStudy.getParentStudyId();
            if (parentStudyId > 0) {
                StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
                classes = sgcdao.findAllActiveByStudy(parentStudy);
            } else {
                classes = sgcdao.findAllActiveByStudy(currentStudy);
            }
            // YW >>
            for (int i = 0; i < classes.size(); i++) {
                StudyGroupClassBean group = (StudyGroupClassBean) classes.get(i);
                ArrayList studyGroups = sgdao.findAllByGroupClass(group);
                group.setStudyGroups(studyGroups);
                SubjectGroupMapBean gMap = (SubjectGroupMapBean) gMaps.get(new Integer(group.getId()));
                if (gMap != null) {
                    group.setStudyGroupId(gMap.getStudyGroupId());
                    group.setGroupNotes(gMap.getNotes());
                }
            }
            session.setAttribute("groups", classes);
        }
        if ("show".equalsIgnoreCase(action)) {
            session.setAttribute("studySub", sub);
            // below added tbh 092007
            String enrollDateStr = sub.getEnrollmentDate() != null ? local_df.format(sub.getEnrollmentDate()) : "";
            session.setAttribute("enrollDateStr", enrollDateStr);
            // above added tbh 092007
            discNotes = new FormDiscrepancyNotes();
            session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
            forwardPage(Page.UPDATE_STUDY_SUBJECT);
        } else if ("confirm".equalsIgnoreCase(action)) {
            confirm(sgdao);
        } else if ("submit".equalsIgnoreCase(action)) {
            // submit to DB
            StudySubjectBean subject = (StudySubjectBean) session.getAttribute("studySub");
            subject.setUpdater(ub);
            subdao.update(subject);
            // save discrepancy notes into DB
            FormDiscrepancyNotes fdn = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
            AddNewSubjectServlet.saveFieldNotes("enrollmentDate", fdn, dndao, subject.getId(), "studySub", currentStudy);
            ArrayList groups = (ArrayList) session.getAttribute("groups");
            if (!groups.isEmpty()) {
                for (int i = 0; i < groups.size(); i++) {
                    StudyGroupClassBean sgc = (StudyGroupClassBean) groups.get(i);
                    /*We will be allowing users to remove a subject from all groups. Issue-4524*/
                    if (sgc.getStudyGroupId() == 0) {
                        Collection subjectGroups = sgmdao.findAllByStudySubject(subject.getId());
                        for (Iterator it = subjectGroups.iterator(); it.hasNext(); ) {
                            sgmdao.deleteTestGroupMap(((SubjectGroupMapBean) it.next()).getId());
                        }
                    } else {
                        SubjectGroupMapBean sgm = new SubjectGroupMapBean();
                        SubjectGroupMapBean gMap = (SubjectGroupMapBean) gMaps.get(new Integer(sgc.getId()));
                        sgm.setStudyGroupId(sgc.getStudyGroupId());
                        sgm.setNotes(sgc.getGroupNotes());
                        sgm.setStudyGroupClassId(sgc.getId());
                        sgm.setStudySubjectId(subject.getId());
                        sgm.setStatus(Status.AVAILABLE);
                        if (sgm.getStudyGroupId() > 0) {
                            if (gMap != null && gMap.getId() > 0) {
                                sgm.setUpdater(ub);
                                sgm.setId(gMap.getId());
                                sgmdao.update(sgm);
                            } else {
                                sgm.setOwner(ub);
                                sgmdao.create(sgm);
                            }
                        }
                    }
                }
            }
            addPageMessage(respage.getString("study_subject_updated_succesfully"));
            session.removeAttribute("studySub");
            session.removeAttribute("groups");
            session.removeAttribute("enrollDateStr");
            session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        } else {
            addPageMessage(respage.getString("no_action_specified"));
            forwardPage(Page.LIST_STUDY_SUBJECTS);
            return;
        }
    }
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) HashMap(java.util.HashMap) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) Iterator(java.util.Iterator) Collection(java.util.Collection) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 14 with SubjectGroupMapDAO

use of org.akaza.openclinica.dao.submit.SubjectGroupMapDAO in project OpenClinica by OpenClinica.

the class RemoveSubjectGroupClassServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    FormProcessor fp = new FormProcessor(request);
    int classId = fp.getInt("id");
    if (classId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_group_class_to_remove"));
        forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
    } else {
        StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
        StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
        SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
        if (action.equalsIgnoreCase("confirm")) {
            StudyGroupClassBean sgcb = (StudyGroupClassBean) sgcdao.findByPK(classId);
            if (sgcb.getStatus().equals(Status.DELETED)) {
                addPageMessage(respage.getString("this_subject_group_class_has_been_deleted_already"));
                forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
                return;
            }
            ArrayList groups = sgdao.findAllByGroupClass(sgcb);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupBean sg = (StudyGroupBean) groups.get(i);
                ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassAndGroup(sgcb.getId(), sg.getId());
                sg.setSubjectMaps(subjectMaps);
            }
            session.setAttribute("group", sgcb);
            session.setAttribute("studyGroups", groups);
            forwardPage(Page.REMOVE_SUBJECT_GROUP_CLASS);
        } else if (action.equalsIgnoreCase("submit")) {
            StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
            group.setStatus(Status.DELETED);
            group.setUpdater(ub);
            sgcdao.update(group);
            ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
            for (int i = 0; i < subjectMaps.size(); i++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) subjectMaps.get(i);
                if (!sgmb.getStatus().equals(Status.DELETED)) {
                    sgmb.setStatus(Status.AUTO_DELETED);
                    sgmb.setUpdater(ub);
                    sgmdao.update(sgmb);
                }
            }
            addPageMessage(respage.getString("this_subject_group_class_was_removed_succesfully"));
            forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
        } else {
            addPageMessage(respage.getString("no_action_specified"));
            forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) ArrayList(java.util.ArrayList) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean)

Example 15 with SubjectGroupMapDAO

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

Aggregations

SubjectGroupMapDAO (org.akaza.openclinica.dao.submit.SubjectGroupMapDAO)16 ArrayList (java.util.ArrayList)15 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)13 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)13 SubjectGroupMapBean (org.akaza.openclinica.bean.submit.SubjectGroupMapBean)12 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)12 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)12 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)11 StudyGroupClassDAO (org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO)10 StudyGroupDAO (org.akaza.openclinica.dao.managestudy.StudyGroupDAO)10 Date (java.util.Date)9 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)9 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)9 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)9 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)8 HashMap (java.util.HashMap)7 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)7 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)7 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)6