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);
}
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()));
}
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));
}
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));
}
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));
}
Aggregations