Search in sources :

Example 21 with EvaluatedCohort

use of org.openmrs.module.reporting.cohort.EvaluatedCohort in project openmrs-module-pihcore by PIH.

the class PersonAuditInfoCohortDefinitionEvaluator method evaluate.

@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {
    PersonAuditInfoCohortDefinition cd = (PersonAuditInfoCohortDefinition) cohortDefinition;
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Patient.class);
    crit.setProjection(Projections.property("id"));
    if (!cd.isIncludeVoided()) {
        crit.add(Restrictions.eq("voided", false));
    }
    if (cd.getCreatedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateCreated", cd.getCreatedOnOrAfter()));
    }
    if (cd.getCreatedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateCreated", DateUtil.getEndOfDayIfTimeExcluded(cd.getCreatedOnOrBefore())));
    }
    if (cd.getCreatedByUsers() != null) {
        crit.add(Restrictions.in("creator", cd.getCreatedByUsers()));
    }
    if (cd.getChangedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateChanged", cd.getChangedOnOrAfter()));
    }
    if (cd.getChangedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateChanged", DateUtil.getEndOfDayIfTimeExcluded(cd.getChangedOnOrBefore())));
    }
    if (cd.getChangedByUsers() != null) {
        crit.add(Restrictions.in("changedBy", cd.getChangedByUsers()));
    }
    if (cd.getVoidedOnOrAfter() != null) {
        crit.add(Restrictions.ge("dateVoided", cd.getVoidedOnOrAfter()));
    }
    if (cd.getVoidedOnOrBefore() != null) {
        crit.add(Restrictions.le("dateVoided", DateUtil.getEndOfDayIfTimeExcluded(cd.getVoidedOnOrBefore())));
    }
    if (cd.getVoidedByUsers() != null) {
        crit.add(Restrictions.in("voidedBy", cd.getVoidedByUsers()));
    }
    Cohort c = new Cohort();
    for (Integer personId : (List<Integer>) crit.list()) {
        c.addMember(personId);
    }
    return new EvaluatedCohort(c, cohortDefinition, context);
}
Also used : Cohort(org.openmrs.Cohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) EvaluatedCohort(org.openmrs.module.reporting.cohort.EvaluatedCohort) List(java.util.List) PersonAuditInfoCohortDefinition(org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition) Criteria(org.hibernate.Criteria)

Example 22 with EvaluatedCohort

use of org.openmrs.module.reporting.cohort.EvaluatedCohort in project openmrs-module-pihcore by PIH.

the class LastDispositionBeforeExitCohortDefinitionEvaluatorTest method testEvaluate.

@Test
public void testEvaluate() throws Exception {
    Location mensInternalMedicine = locationService.getLocation("Sal Gason");
    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 23 with EvaluatedCohort

use of org.openmrs.module.reporting.cohort.EvaluatedCohort 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) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Example 24 with EvaluatedCohort

use of org.openmrs.module.reporting.cohort.EvaluatedCohort 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) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Example 25 with EvaluatedCohort

use of org.openmrs.module.reporting.cohort.EvaluatedCohort in project openmrs-module-pihcore by PIH.

the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByAnyNonCoded.

@Test
public void testEvaluateByAnyNonCoded() throws Exception {
    createDiagnosisObs();
    DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
    cd.setIncludeAllNonCodedDiagnoses(true);
    EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
    assertThat(cohort, hasExactlyIds(2, 7));
}
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) Test(org.junit.Test) PihCoreContextSensitiveTest(org.openmrs.module.pihcore.PihCoreContextSensitiveTest)

Aggregations

EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)26 Test (org.junit.Test)18 EvaluationContext (org.openmrs.module.reporting.evaluation.EvaluationContext)18 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)12 Date (java.util.Date)8 Cohort (org.openmrs.Cohort)8 Location (org.openmrs.Location)8 DiagnosisCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition)8 List (java.util.List)7 BaseInpatientReportTest (org.openmrs.module.pihcore.reporting.BaseInpatientReportTest)6 PersonAuditInfoCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.PersonAuditInfoCohortDefinition)6 SQLQuery (org.hibernate.SQLQuery)5 InpatientLocationCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientLocationCohortDefinition)3 InpatientTransferCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.InpatientTransferCohortDefinition)3 Criteria (org.hibernate.Criteria)2 Concept (org.openmrs.Concept)2 EncounterType (org.openmrs.EncounterType)2 AdmissionSoonAfterExitCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.AdmissionSoonAfterExitCohortDefinition)2 LastDispositionBeforeExitCohortDefinition (org.openmrs.module.pihcore.reporting.cohort.definition.LastDispositionBeforeExitCohortDefinition)2 Parameter (org.openmrs.module.reporting.evaluation.parameter.Parameter)2