Search in sources :

Example 41 with StudyGroupClassBean

use of org.akaza.openclinica.bean.managestudy.StudyGroupClassBean in project OpenClinica by OpenClinica.

the class CreateDatasetServlet method getGroupAttr.

private void getGroupAttr(FormProcessor fp, DatasetBean db) {
    String group = fp.getString(GROUP_INFORMATION);
    ArrayList allSelectedGroups = new ArrayList();
    // allSelectedGroups = (ArrayList)
    // session.getAttribute("allSelectedGroups");
    // we don't check the session on purpose, since we want to check/uncheck
    // groups every time
    // if (!StringUtil.isBlank(group) &&
    // "yes".equalsIgnoreCase(group.trim())) {
    // db.setShowSubjectGroupInformation(true);
    // if (allSelectedGroups == null || allSelectedGroups.size()==0) {
    // allSelectedGroups = setUpStudyGroups();
    // }
    ArrayList allGroups = setUpStudyGroups();
    for (int j = 0; j < allGroups.size(); j++) {
        StudyGroupClassBean sgclass = (StudyGroupClassBean) allGroups.get(j);
        String checked = fp.getString("groupSelected" + sgclass.getId());
        if (!StringUtil.isBlank(checked) && "yes".equalsIgnoreCase(checked.trim())) {
            db.setShowSubjectGroupInformation(true);
            // were they all checked? yes or no, we need to set this flag
            sgclass.setSelected(true);
            logger.info("just set a group to true: " + sgclass.getName());
            // StudyGroupClass_id <<
            if (db.getSubjectGroupIds() != null && !db.getSubjectGroupIds().contains(sgclass.getId())) {
                db.getSubjectGroupIds().add(new Integer(sgclass.getId()));
            }
        // YW >>
        } else {
            sgclass.setSelected(false);
            // subjectGroupIds if appliable<<
            if (db.getSubjectGroupIds() != null && db.getSubjectGroupIds().contains(sgclass.getId())) {
                db.getSubjectGroupIds().remove(new Integer(sgclass.getId()));
            }
        // YW >>
        }
        allSelectedGroups.add(sgclass);
        // db.getSubjectGroupIds().add(new Integer(sgclass.getId()));
        logger.info("just added subject group ids: " + sgclass.getId());
    }
    session.setAttribute("allSelectedGroups", allSelectedGroups);
    request.setAttribute("allSelectedGroups", allSelectedGroups);
    // above really necessary? tbh
    logger.info("added SUBJECT group info");
    // if it's been set previously and we've unchecked everything, run this
    if (db.isShowSubjectGroupInformation() && allSelectedGroups.size() == 0) {
        db.setShowSubjectGroupInformation(false);
        logger.info("show subject group info was TRUE, set to FALSE");
    }
// } else if (db.isShowSubjectGroupInformation()) {
// db.setShowSubjectGroupInformation(false);
// }
}
Also used : ArrayList(java.util.ArrayList) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)

Example 42 with StudyGroupClassBean

use of org.akaza.openclinica.bean.managestudy.StudyGroupClassBean in project OpenClinica by OpenClinica.

the class UpdateSubjectGroupClassServlet method submitGroup.

private void submitGroup() throws OpenClinicaException {
    StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
    ArrayList studyGroups = (ArrayList) session.getAttribute("studyGroups");
    ArrayList newStudyGroups = (ArrayList) session.getAttribute("newStudyGroups");
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    group.setUpdater(ub);
    group.setUpdatedDate(new Date());
    group = (StudyGroupClassBean) sgcdao.update(group);
    if (!group.isActive()) {
        addPageMessage(respage.getString("the_subject_group_class_no_updated_database"));
    } else {
        StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
        for (int i = 0; i < studyGroups.size(); i++) {
            StudyGroupBean sg = (StudyGroupBean) studyGroups.get(i);
            sg.setStudyGroupClassId(group.getId());
            if (sg.getId() == 0) {
                sg.setOwner(ub);
                sg.setStatus(Status.AVAILABLE);
                sgdao.create(sg);
            } else {
                sg.setUpdater(ub);
                sg.setStatus(Status.AVAILABLE);
                sgdao.update(sg);
            }
        }
        addPageMessage(respage.getString("the_subject_group_class_updated_succesfully"));
    }
    forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
}
Also used : 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) Date(java.util.Date) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean)

Example 43 with StudyGroupClassBean

use of org.akaza.openclinica.bean.managestudy.StudyGroupClassBean in project OpenClinica by OpenClinica.

the class UpdateStudySubjectServlet method confirm.

/**
     * Processes 'confirm' request, validate the study subject object
     *
     * @param sub
     * @throws Exception
     */
private void confirm(StudyGroupDAO sgdao) throws Exception {
    ArrayList classes = (ArrayList) session.getAttribute("groups");
    StudySubjectBean sub = (StudySubjectBean) session.getAttribute("studySub");
    FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
    FormProcessor fp = new FormProcessor(request);
    java.util.Date enrollDate = sub.getEnrollmentDate();
    if (ub.isSysAdmin() || currentRole.isManageStudy() || currentRole.isInvestigator() || currentStudy.getParentStudyId() > 0 && currentRole.isResearchAssistant() || currentStudy.getParentStudyId() > 0 && currentRole.isResearchAssistant2()) {
        //currentRole.getRoleName().equals(Role.STUDYDIRECTOR) || currentRole.getRoleName().equals(Role.COORDINATOR)) {
        v.addValidation("label", Validator.NO_BLANKS);
        v.addValidation("label", Validator.DOES_NOT_CONTAIN_HTML_LESSTHAN_GREATERTHAN_ELEMENTS);
        v.addValidation("secondaryLabel", Validator.DOES_NOT_CONTAIN_HTML_LESSTHAN_GREATERTHAN_ELEMENTS);
        String eDateString = fp.getString("enrollmentDate");
        if (!StringUtil.isBlank(eDateString)) {
            v.addValidation("enrollmentDate", Validator.IS_A_DATE);
            v.alwaysExecuteLastValidation("enrollmentDate");
        }
        errors = v.validate();
        if (!StringUtil.isBlank(fp.getString("label"))) {
            StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
            StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(fp.getString("label").trim(), currentStudy.getId(), sub.getId());
            // JRWS>> Also look for labels in the child studies
            if (sub1.getId() == 0) {
                sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabelInSites(fp.getString("label").trim(), currentStudy.getId(), sub.getId());
            }
            if (sub1.getId() > 0) {
                Validator.addError(errors, "label", resexception.getString("subject_ID_used_by_another_choose_unique"));
            }
        }
        sub.setLabel(fp.getString("label"));
        sub.setSecondaryLabel(fp.getString("secondaryLabel"));
        try {
            local_df.setLenient(false);
            if (!StringUtil.isBlank(eDateString)) {
                enrollDate = local_df.parse(eDateString);
            } else {
                enrollDate = null;
            }
        } catch (ParseException fe) {
            logger.warn("Enrollment Date cannot be parsed.");
        }
        sub.setEnrollmentDate(enrollDate);
    }
    // below added tbh 092007, fix for YY vs YYYY formatting
    String enrollDateStr = enrollDate != null ? local_df.format(enrollDate) : "";
    session.setAttribute("enrollDateStr", enrollDateStr);
    // above added tbh 092007
    session.setAttribute("studySub", sub);
    if (!classes.isEmpty()) {
        for (int i = 0; i < classes.size(); i++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) classes.get(i);
            int groupId = fp.getInt("studyGroupId" + i);
            String notes = fp.getString("notes" + i);
            v.addValidation("notes" + i, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
            sgc.setStudyGroupId(groupId);
            sgc.setGroupNotes(notes);
            if (groupId > 0) {
                StudyGroupBean sgb = (StudyGroupBean) sgdao.findByPK(groupId);
                sgc.setStudyGroupName(sgb.getName());
            }
        }
    }
    session.setAttribute("groups", classes);
    if (!errors.isEmpty()) {
        logger.info("has errors");
        if (StringUtil.isBlank(sub.getLabel())) {
            addPageMessage(respage.getString("must_enter_subject_ID_for_identifying") + respage.getString("this_may_be_external_ID_number") + respage.getString("you_may_enter_study_subject_ID_listed") + respage.getString("study_subject_ID_should_not_contain_protected_information"));
        } else {
            StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
            StudySubjectBean sub1 = (StudySubjectBean) subdao.findAnotherBySameLabel(sub.getLabel(), sub.getStudyId(), sub.getId());
            if (sub1.getId() > 0) {
                addPageMessage(resexception.getString("subject_ID_used_by_another_choose_unique"));
            }
        }
        request.setAttribute("formMessages", errors);
        forwardPage(Page.UPDATE_STUDY_SUBJECT);
    } else {
        forwardPage(Page.UPDATE_STUDY_SUBJECT_CONFIRM);
    }
}
Also used : FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) ParseException(java.text.ParseException)

Example 44 with StudyGroupClassBean

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

Aggregations

StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)44 ArrayList (java.util.ArrayList)35 StudyGroupClassDAO (org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO)21 HashMap (java.util.HashMap)17 StudyGroupDAO (org.akaza.openclinica.dao.managestudy.StudyGroupDAO)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)14 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)14 StudyGroupBean (org.akaza.openclinica.bean.managestudy.StudyGroupBean)10 SubjectGroupMapBean (org.akaza.openclinica.bean.submit.SubjectGroupMapBean)10 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)9 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)9 SubjectGroupMapDAO (org.akaza.openclinica.dao.submit.SubjectGroupMapDAO)9 Iterator (java.util.Iterator)8 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)7 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)6 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)6 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)5 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)5