Search in sources :

Example 31 with StudyEventDefinitionBean

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

the class ListDiscNotesSubjectTableFactory method setDataAndLimitVariables.

@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
    StudyBean study = this.getStudyBean();
    Limit limit = tableFacade.getLimit();
    ListDiscNotesSubjectFilter subjectFilter = getSubjectFilter(limit);
    subjectFilter.addFilter("dn.discrepancy_note_type_id", this.discNoteType);
    StringBuffer constraints = new StringBuffer();
    if (this.discNoteType > 0 && this.discNoteType < 10) {
        constraints.append(" and dn.discrepancy_note_type_id=" + this.discNoteType);
    }
    if (this.resolutionStatusIds != null && this.resolutionStatusIds.size() > 0) {
        String s = " and (";
        for (Integer resolutionStatusId : this.resolutionStatusIds) {
            s += "dn.resolution_status_id = " + resolutionStatusId + " or ";
        }
        s = s.substring(0, s.length() - 3) + " )";
        subjectFilter.addFilter("dn.resolution_status_id", s);
        constraints.append(s);
    }
    if (!limit.isComplete()) {
        int totalRows = getStudySubjectDAO().getCountWithFilter(subjectFilter, study);
        tableFacade.setTotalRows(totalRows);
    }
    ListDiscNotesSubjectSort subjectSort = getSubjectSort(limit);
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();
    Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(study, subjectFilter, subjectSort, rowStart, rowEnd);
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
    boolean hasDN = false;
    for (StudySubjectBean studySubjectBean : items) {
        HashMap<Object, Object> theItem = new HashMap<Object, Object>();
        theItem.put("studySubject", studySubjectBean);
        theItem.put("studySubject.label", studySubjectBean.getLabel());
        theItem.put("studySubject.status", studySubjectBean.getStatus());
        theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
        // Get All study events for this study subject and then put list in
        // HashMap with study event definition id as
        // key and a list of study events as the value.
        List<StudyEventBean> allStudyEventsForStudySubject = getStudyEventDAO().findAllByStudySubject(studySubjectBean);
        HashMap<Integer, List<StudyEventBean>> allStudyEventsForStudySubjectBySedId = new HashMap<Integer, List<StudyEventBean>>();
        theItem.put("isSignable", isSignable(allStudyEventsForStudySubject));
        for (StudyEventBean studyEventBean : allStudyEventsForStudySubject) {
            if (allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()) == null) {
                ArrayList<StudyEventBean> a = new ArrayList<StudyEventBean>();
                a.add(studyEventBean);
                allStudyEventsForStudySubjectBySedId.put(studyEventBean.getStudyEventDefinitionId(), a);
            } else {
                allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()).add(studyEventBean);
            }
        }
        for (StudyEventDefinitionBean studyEventDefinition : getStudyEventDefinitions()) {
            List<StudyEventBean> studyEvents = allStudyEventsForStudySubjectBySedId.get(studyEventDefinition.getId());
            SubjectEventStatus subjectEventStatus = null;
            HashMap<ResolutionStatus, Integer> discCounts = new HashMap<ResolutionStatus, Integer>();
            studyEvents = studyEvents == null ? new ArrayList<StudyEventBean>() : studyEvents;
            if (studyEvents.size() < 1) {
                subjectEventStatus = SubjectEventStatus.NOT_SCHEDULED;
            } else {
                for (StudyEventBean studyEventBean : studyEvents) {
                    discCounts = countAll(discCounts, studyEventBean, constraints, study.isSite(study.getParentStudyId()));
                    hasDN = hasDN == false ? discCounts.size() > 0 : hasDN;
                    if (studyEventBean.getSampleOrdinal() == 1) {
                        subjectEventStatus = studyEventBean.getSubjectEventStatus();
                    // break;
                    }
                }
            }
            theItem.put("sed_" + studyEventDefinition.getId() + "_discCounts", discCounts);
            theItem.put("sed_" + studyEventDefinition.getId(), subjectEventStatus.getId());
            theItem.put("sed_" + studyEventDefinition.getId() + "_studyEvents", studyEvents);
            theItem.put("sed_" + studyEventDefinition.getId() + "_object", studyEventDefinition);
        }
        theItems.add(theItem);
    }
    // Do not forget to set the items back on the tableFacade.
    tableFacade.setItems(theItems);
    setStudyHasDiscNotes(hasDN);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) List(java.util.List) ArrayList(java.util.ArrayList) ListDiscNotesSubjectFilter(org.akaza.openclinica.dao.managestudy.ListDiscNotesSubjectFilter) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ListDiscNotesSubjectSort(org.akaza.openclinica.dao.managestudy.ListDiscNotesSubjectSort) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) Limit(org.jmesa.limit.Limit)

Example 32 with StudyEventDefinitionBean

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

the class TableOfContentsServlet method createEventCRF.

/**
 * Creates a new Event CRF or update the exsiting one, that is, an event CRF
 * can be created but not item data yet, in this case, still consider it is
 * not started(called uncompleted before)
 *
 * @return
 * @throws Exception
 */
private EventCRFBean createEventCRF() throws Exception {
    EventCRFBean ecb;
    ecdao = new EventCRFDAO(sm.getDataSource());
    int crfVersionId = fp.getInt(INPUT_CRF_VERSION_ID);
    int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
    int eventDefinitionCRFId = fp.getInt(INPUT_EVENT_DEFINITION_CRF_ID);
    int subjectId = fp.getInt(INPUT_SUBJECT_ID);
    int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID);
    logger.info("Creating event CRF within Table of Contents.  Study id: " + currentStudy.getId() + "; CRF Version id: " + crfVersionId + "; Study Event id: " + studyEventId + "; Event Definition CRF id: " + eventDefinitionCRFId + "; Subject: " + subjectId);
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
    if (!ssb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE1"));
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sedb = seddao.findByEventDefinitionCRFId(eventDefinitionCRFId);
    if (!ssb.isActive() || !sedb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE2"));
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    EntityBean eb = cvdao.findByPK(crfVersionId);
    if (!eb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE3"));
    }
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
    StudyBean studyWithSED = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithSED = new StudyBean();
        studyWithSED.setId(currentStudy.getParentStudyId());
    }
    AuditableEntityBean aeb = sedao.findByPKAndStudy(studyEventId, studyWithSED);
    if (!aeb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("trying_to_begin_DE4"));
    }
    ecb = new EventCRFBean();
    if (eventCRFId == 0) {
        // no event CRF created yet
        ecb.setAnnotations("");
        ecb.setCreatedDate(new Date());
        ecb.setCRFVersionId(crfVersionId);
        ecb.setInterviewerName("");
        if (sEvent.getDateStarted() != null) {
            // default date
            ecb.setDateInterviewed(sEvent.getDateStarted());
        } else {
            ecb.setDateInterviewed(null);
        }
        ecb.setOwnerId(ub.getId());
        ecb.setStatus(Status.AVAILABLE);
        ecb.setCompletionStatusId(1);
        ecb.setStudySubjectId(ssb.getId());
        ecb.setStudyEventId(studyEventId);
        ecb.setValidateString("");
        ecb.setValidatorAnnotations("");
        ecb = (EventCRFBean) ecdao.create(ecb);
        logger.info("CREATED EVENT CRF");
    } else {
        // there is an event CRF already, only need to update
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        ecb.setCRFVersionId(crfVersionId);
        ecb.setUpdatedDate(new Date());
        ecb.setUpdater(ub);
        ecb = (EventCRFBean) ecdao.update(ecb);
    }
    if (!ecb.isActive()) {
        throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("new_event_CRF_not_created_database_error"));
    } else {
        sEvent.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
        sEvent.setUpdater(ub);
        sEvent.setUpdatedDate(new Date());
        sedao.update(sEvent);
    }
    return ecb;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 33 with StudyEventDefinitionBean

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

the class TestRuleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String action = request.getParameter("action");
    Validator v = new Validator(request);
    if (StringUtil.isBlank(action)) {
        request.setAttribute("result", resword.getString("test_rule_default_result"));
        Integer ruleSetRuleId = fp.getInt("ruleSetRuleId");
        if (ruleSetRuleId != 0) {
            // If testing an existing ruleSetRule
            RuleSetRuleBean rsr = getRuleSetRuleDao().findById(ruleSetRuleId);
            rsr.getActions().size();
            HashMap presetValues = new HashMap();
            presetValues.put(TARGET, rsr.getRuleSetBean().getTarget().getValue());
            presetValues.put(RULE, rsr.getRuleBean().getExpression().getValue());
            presetValues.put(RULE_SET_RULE_ID, String.valueOf(ruleSetRuleId));
            fp.setPresetValues(presetValues);
            setPresetValues(presetValues);
            session.setAttribute("testRuleActions", rsr.getActions());
            session.setAttribute("testRulesTarget", rsr.getRuleSetBean().getTarget().getValue());
            request.setAttribute("ruleSetRuleId", ruleSetRuleId);
            request.setAttribute("ruleSetId", rsr.getRuleSetBean().getId());
            ItemBean item = getExpressionService().getItemBeanFromExpression(rsr.getRuleSetBean().getTarget().getValue());
            if (item != null) {
                request.setAttribute("itemName", item.getName());
                request.setAttribute("itemDefinition", item.getDescription());
            } else {
                StudyEventDefinitionBean studyEventDef = getExpressionService().getStudyEventDefinitionFromExpressionForEvents(rsr.getRuleSetBean().getTarget().getValue(), this.currentStudy);
                request.setAttribute("itemName", studyEventDef.getName());
                request.setAttribute("itemDefinition", studyEventDef.getDescription());
            }
            request.setAttribute("ruleSetRuleAvailable", true);
        } else {
            // free form testing
            putDummyActionInSession();
        }
        session.removeAttribute("testValues");
        request.setAttribute("action", "validate");
        forwardPage(Page.TEST_RULES);
    } else if (action.equals("validate")) {
        HashMap<String, String> result = validate(v);
        if (result.get("ruleValidation").equals("rule_valid")) {
            addPageMessage(resword.getString("test_rules_message_valid"));
        } else {
            addPageMessage(resword.getString("test_rules_message_invalid"));
        }
        request.setAttribute("ruleValidation", result.get("ruleValidation"));
        request.setAttribute("validate", "on");
        request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_validate_message"));
        request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
        request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
        result.remove("result");
        result.remove("ruleValidation");
        result.remove("ruleEvaluatesTo");
        result.remove("ruleValidationFailMessage");
        populateTooltip(result);
        session.setAttribute("testValues", result);
        populteFormFields(fp);
        forwardPage(Page.TEST_RULES);
    } else if (action.equals("test")) {
        HashMap<String, String> result = validate(v);
        HashMap errors = v.validate();
        if (!errors.isEmpty()) {
            setInputMessages(errors);
            if (result.get("ruleValidation").equals("rule_valid")) {
                addPageMessage(resword.getString("test_rules_message_valid"));
            } else {
                addPageMessage(resword.getString("test_rules_message_invalid"));
            }
            request.setAttribute("ruleValidation", result.get("ruleValidation"));
            request.setAttribute("validate", "on");
            request.setAttribute("ruleEvaluatesTo", resword.getString("test_rules_rule_fail_invalid_data_type") + " " + resword.getString("test_rules_rule_fail_invalid_data_type_desc"));
            request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
            request.setAttribute("action", "test");
        } else {
            if (result.get("ruleValidation").equals("rule_valid")) {
                addPageMessage(resword.getString("test_rules_message_valid"));
            } else {
                addPageMessage(resword.getString("test_rules_message_invalid"));
            }
            request.setAttribute("action", result.get("ruleValidation").equals("rule_valid") ? "test" : "validate");
            request.setAttribute("ruleValidation", result.get("ruleValidation"));
            request.setAttribute("ruleEvaluatesTo", result.get("ruleEvaluatesTo"));
            request.setAttribute("ruleValidationFailMessage", result.get("ruleValidationFailMessage"));
        }
        if (result.get("ruleValidation").equals("rule_invalid")) {
            session.setAttribute("testValues", new HashMap<String, String>());
        } else {
            session.setAttribute("testValues", result);
        }
        result.remove("result");
        result.remove("ruleValidation");
        result.remove("ruleEvaluatesTo");
        result.remove("ruleValidationFailMessage");
        populateTooltip(result);
        populteFormFields(fp);
        forwardPage(Page.TEST_RULES);
    }
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) Validator(org.akaza.openclinica.control.form.Validator)

Example 34 with StudyEventDefinitionBean

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

the class OdmController method generateStudyEventData.

private ODMcomplexTypeDefinitionStudyEventData generateStudyEventData(StudyEventBean studyEvent) {
    ODMcomplexTypeDefinitionStudyEventData studyEventData = new ODMcomplexTypeDefinitionStudyEventData();
    studyEventData.setStartDate(studyEvent.getDateStarted().toString());
    StudyEventDefinitionBean studyEventDefBean = getStudyEventDefinitionBean(studyEvent.getStudyEventDefinitionId());
    studyEventData.setEventName(studyEventDefBean.getName());
    studyEventData.setStudyEventOID(studyEventDefBean.getOid());
    studyEventData.setStudyEventRepeatKey(String.valueOf(studyEvent.getSampleOrdinal()));
    return studyEventData;
}
Also used : StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ODMcomplexTypeDefinitionStudyEventData(org.cdisc.ns.odm.v130_api.ODMcomplexTypeDefinitionStudyEventData)

Example 35 with StudyEventDefinitionBean

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

the class OdmController method getStudyEventDefinitionBean.

private StudyEventDefinitionBean getStudyEventDefinitionBean(int ID) {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
    StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) seddao.findByPK(ID);
    return studyEventDefinitionBean;
}
Also used : StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Aggregations

StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)156 ArrayList (java.util.ArrayList)107 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)86 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)65 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)63 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)62 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)56 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)56 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)52 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)52 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)50 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)50 HashMap (java.util.HashMap)49 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)49 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)48 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)48 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)45 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)45 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)42 Date (java.util.Date)37