Search in sources :

Example 21 with SubjectGroupMapBean

use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean 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 22 with SubjectGroupMapBean

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

Aggregations

SubjectGroupMapBean (org.akaza.openclinica.bean.submit.SubjectGroupMapBean)22 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)14 SubjectGroupMapDAO (org.akaza.openclinica.dao.submit.SubjectGroupMapDAO)12 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)11 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)10 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)9 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)9 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)8 StudyGroupClassDAO (org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO)8 StudyGroupDAO (org.akaza.openclinica.dao.managestudy.StudyGroupDAO)8 Date (java.util.Date)7 Iterator (java.util.Iterator)7 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)6 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)5 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)5 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)5