Search in sources :

Example 21 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByCoded.

@Test
public void testEvaluateByCoded() throws Exception {
    createDiagnosisObs();
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    cd.setCodedDiagnoses(Arrays.asList(conceptService.getConcept(9)));
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(6));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 22 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByCodedExclusions.

@Test
public void testEvaluateByCodedExclusions() throws Exception {
    createDiagnosisObs();
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    cd.setExcludeCodedDiagnoses(Arrays.asList(conceptService.getConcept(9)));
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    // everyone with a coded diagnosis that isn't concept 9
    assertThat(cohort, hasExactlyIds(2));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) DiagnosisCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 23 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class InpatientTransferCohortDefinitionEvaluatorTest method testEvaluateTransferOut.

@Test
public void testEvaluateTransferOut() throws Exception {
    Location womensInternalMedicine = Metadata.lookup(MirebalaisLocations.WOMENS_INTERNAL_MEDICINE);
    Date startDate = DateUtil.parseDate("2013-10-03 00:00:00", "yyyy-MM-dd HH:mm:ss");
    Date endDate = DateUtil.parseDate("2013-10-03 23:59:59", "yyyy-MM-dd HH:mm:ss");
    InpatientTransferCohortDefinition definition = new InpatientTransferCohortDefinition();
    definition.setOnOrAfter(startDate);
    definition.setOnOrBefore(endDate);
    definition.setOutOfWard(womensInternalMedicine);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient5.getId()));
}
Also used : EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) InpatientTransferCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 24 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class LastDispositionBeforeExitCohortDefinitionEvaluatorTest method testEvaluate.

@Test
public void testEvaluate() throws Exception {
    Location mensInternalMedicine = Metadata.lookup(MirebalaisLocations.MENS_INTERNAL_MEDICINE);
    Date startDate = DateUtil.parseDate("2013-10-03 00:00:00", "yyyy-MM-dd HH:mm:ss");
    Date endDate = DateUtil.parseDate("2013-10-03 23:59:59", "yyyy-MM-dd HH:mm:ss");
    Concept discharged = conceptService.getConceptByMapping("DISCHARGED", "PIH");
    LastDispositionBeforeExitCohortDefinition definition = new LastDispositionBeforeExitCohortDefinition();
    definition.setExitFromWard(mensInternalMedicine);
    definition.setExitOnOrAfter(startDate);
    definition.setExitOnOrBefore(endDate);
    definition.addDisposition(discharged);
    EvaluatedCohort result = cohortDefinitionService.evaluate(definition, new EvaluationContext());
    assertThat(result, isCohortWithExactlyIds(patient4.getId()));
}
Also used : Concept(org.openmrs.Concept) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) LastDispositionBeforeExitCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) Date(java.util.Date) Location(org.openmrs.Location) BaseInpatientReportTest(org.openmrs.module.pihcore.reporting.BaseInpatientReportTest) Test(org.junit.Test)

Example 25 with EvaluationContext

use of org.openmrs.module.reporting.evaluation.EvaluationContext in project openmrs-module-pihcore by PIH.

the class ActiveVisitsAjaxController method getActiveVisits.

@RequestMapping(value = "/module/pihcore/reports/ajax/activeVisitsList.form", method = RequestMethod.GET, headers = "Accept=application/json")
public void getActiveVisits(@RequestParam(value = "patientIds", required = false) Integer[] patientIds, HttpServletResponse response) throws EvaluationException, IOException {
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    AllDefinitionLibraries definitionLibraries = Context.getRegisteredComponents(AllDefinitionLibraries.class).get(0);
    EvaluationContext context = new EvaluationContext();
    Cohort c = null;
    if (patientIds != null && patientIds.length > 0) {
        if (patientIds[0] == null) {
            // there are no patients with last encounter at this specific location
            return;
        }
        c = new Cohort("active", "Patients with active visits", patientIds);
    }
    DataSet result = null;
    PatientDataSetDefinition dsd = new PatientDataSetDefinition();
    VisitCohortDefinition visitCohortDefinition = new VisitCohortDefinition();
    visitCohortDefinition.setActive(true);
    if (c != null) {
        context.setBaseCohort(c);
    }
    dsd.addRowFilter(visitCohortDefinition, null);
    dsd.addColumn("patientId", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.patientId"), "");
    dsd.addColumn("familyName", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.preferredName.familyName"), "");
    dsd.addColumn("givenName", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.preferredName.givenName"), "");
    dsd.addColumn("zlEmrId", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.preferredZlEmrId.identifier"), "");
    dsd.addColumn("firstCheckinLocation", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.checkin.location"), "");
    dsd.addColumn("checkinDateTime", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.checkin.encounterDatetime"), "");
    dsd.addColumn("lastEncounterType", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.type"), "");
    dsd.addColumn("lastEncounterLocation", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.location"), "");
    dsd.addColumn("lastEncounterDateTime", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.encounterDatetime"), "");
    dsd.addColumn("visitUuid", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.visit.uuid"), "");
    result = dsdService.evaluate(dsd, context);
    String json = toJson(DataSetUtil.simplify(result));
    PrintWriter out = response.getWriter();
    out.print(json);
}
Also used : Cohort(org.openmrs.Cohort) DataSet(org.openmrs.module.reporting.dataset.DataSet) PatientDataDefinition(org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition) PatientDataSetDefinition(org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition) AllDefinitionLibraries(org.openmrs.module.reporting.definition.library.AllDefinitionLibraries) EvaluationContext(org.openmrs.module.reporting.evaluation.EvaluationContext) VisitCohortDefinition(org.openmrs.module.reporting.cohort.definition.VisitCohortDefinition) PrintWriter(java.io.PrintWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)25 Test (org.junit.Test)22 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)18 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12 Date (java.util.Date)7 DiagnosisCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition)7 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)6 Location (org.openmrs.Location)5 PersonAuditInfoCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition)5 SimpleDataSet (org.openmrs.module.reporting.dataset.SimpleDataSet)4 DataSetDefinition (org.openmrs.module.reporting.dataset.definition.DataSetDefinition)4 DataSetRow (org.openmrs.module.reporting.dataset.DataSetRow)3 InpatientLocationCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientLocationCohortDefinition)2 InpatientTransferCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition)2 PatientDataDefinition (org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition)2 DataSet (org.openmrs.module.reporting.dataset.DataSet)2 Parameter (org.openmrs.module.reporting.evaluation.parameter.Parameter)2 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1