use of org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition in project openmrs-module-pihcore by PIH.
the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByAnyCoded.
@Test
public void testEvaluateByAnyCoded() throws Exception {
createDiagnosisObs();
DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
cd.setIncludeAllCodedDiagnoses(true);
EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort, hasExactlyIds(2, 6));
}
use of org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition in project openmrs-module-pihcore by PIH.
the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateSimple.
@Test
public void testEvaluateSimple() throws Exception {
DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort.size(), is(0));
assertThat((DiagnosisCohortDefinition) cohort.getDefinition(), is(cd));
createDiagnosisObs();
cd = new DiagnosisCohortDefinition();
cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort, hasExactlyIds(2, 6, 7));
cd.setOnOrAfter(DateUtil.parseDate("2013-01-02", "yyyy-MM-dd"));
cd.setOnOrBefore(DateUtil.parseDate("2013-01-02", "yyyy-MM-dd"));
cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort, hasExactlyIds(2));
}
use of org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition in project openmrs-module-pihcore by PIH.
the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByCertainty.
@Test
public void testEvaluateByCertainty() throws Exception {
createDiagnosisObs();
DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
cd.setCertainty(Diagnosis.Certainty.CONFIRMED);
cd.setCodedDiagnoses(Arrays.asList(conceptService.getConcept(9)));
EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort, hasExactlyIds(6));
}
use of org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition in project openmrs-module-pihcore by PIH.
the class DiagnosisCohortDefinitionEvaluatorTest method testEvaluateByOrder.
@Test
public void testEvaluateByOrder() throws Exception {
createDiagnosisObs();
DiagnosisCohortDefinition cd = new DiagnosisCohortDefinition();
cd.setDiagnosisOrder(Diagnosis.Order.SECONDARY);
EvaluatedCohort cohort = evaluator.evaluate(cd, new EvaluationContext());
assertThat(cohort, hasExactlyIds(2));
}
use of org.openmrs.module.pihcore.reporting.cohort.definition.DiagnosisCohortDefinition in project openmrs-module-pihcore by PIH.
the class DiagnosisCohortDefinitionEvaluator method evaluate.
@Override
public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) throws EvaluationException {
DiagnosisMetadata dmd = emrApiProperties.getDiagnosisMetadata();
DiagnosisCohortDefinition cd = (DiagnosisCohortDefinition) cohortDefinition;
if (cd.isIncludeAllCodedDiagnoses() && cd.getCodedDiagnoses() != null) {
throw new IllegalArgumentException("Cannot specify both includeAllCodedDiagnoses, and specific coded diagnoses");
}
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obsgroup");
crit.setProjection(Projections.distinct(Projections.property("person.id")));
crit.add(Restrictions.eq("voided", false));
crit.createCriteria("person").add(Restrictions.eq("voided", false));
// we're looking for an obs group whose grouping concept is VISIT DIAGNOSES (or the equivalent)
crit.add(Restrictions.eq("concept", dmd.getDiagnosisSetConcept()));
if (cd.getOnOrAfter() != null) {
crit.add(Restrictions.ge("obsDatetime", cd.getOnOrAfter()));
}
if (cd.getOnOrBefore() != null) {
crit.add(Restrictions.le("obsDatetime", DateUtil.getEndOfDayIfTimeExcluded(cd.getOnOrBefore())));
}
if (cd.getDiagnosisOrder() != null) {
DetachedCriteria orderClause = DetachedCriteria.forClass(Obs.class, "orderObs");
orderClause.add(Restrictions.eq("voided", false));
orderClause.add(Restrictions.eq("concept", dmd.getDiagnosisOrderConcept()));
orderClause.add(Restrictions.eq("valueCoded", dmd.getConceptFor(cd.getDiagnosisOrder())));
orderClause.add(Restrictions.eqProperty("obsGroup", "obsgroup.id"));
orderClause.setProjection(Projections.property("id"));
crit.add(Subqueries.exists(orderClause));
}
if (cd.getCertainty() != null) {
DetachedCriteria certaintyClause = DetachedCriteria.forClass(Obs.class, "certaintyObs");
certaintyClause.add(Restrictions.eq("voided", false));
certaintyClause.add(Restrictions.eq("concept", dmd.getDiagnosisCertaintyConcept()));
certaintyClause.add(Restrictions.eq("valueCoded", dmd.getConceptFor(cd.getCertainty())));
certaintyClause.add(Restrictions.eqProperty("obsGroup", "obsgroup.id"));
certaintyClause.setProjection(Projections.property("id"));
crit.add(Subqueries.exists(certaintyClause));
}
if (cd.isIncludeAllCodedDiagnoses()) {
// diagnoses, we can just ignore both clauses
if (!cd.isIncludeAllNonCodedDiagnoses()) {
DetachedCriteria anyCodedClause = DetachedCriteria.forClass(Obs.class, "codedDiagnosisObs");
anyCodedClause.add(Restrictions.eq("voided", false));
anyCodedClause.add(Restrictions.eq("concept", dmd.getCodedDiagnosisConcept()));
anyCodedClause.add(Restrictions.eqProperty("obsGroup", "obsgroup.id"));
anyCodedClause.setProjection(Projections.property("id"));
crit.add(Subqueries.exists(anyCodedClause));
}
} else if (cd.getCodedDiagnoses() != null || cd.getExcludeCodedDiagnoses() != null) {
if (cd.isIncludeAllNonCodedDiagnoses()) {
throw new IllegalArgumentException("Not Yet Implemented: handling both all-non-coded and specific coded diagnoses together");
}
if (!cd.isIncludeAllNonCodedDiagnoses()) {
DetachedCriteria specificCodedClause = DetachedCriteria.forClass(Obs.class, "codedDiagnosisObs");
specificCodedClause.add(Restrictions.eq("voided", false));
specificCodedClause.add(Restrictions.eq("concept", dmd.getCodedDiagnosisConcept()));
if (cd.getCodedDiagnoses() != null) {
specificCodedClause.add(Restrictions.in("valueCoded", cd.getCodedDiagnoses()));
}
if (cd.getExcludeCodedDiagnoses() != null) {
specificCodedClause.add(Restrictions.not(Restrictions.in("valueCoded", cd.getExcludeCodedDiagnoses())));
}
specificCodedClause.add(Restrictions.eqProperty("obsGroup", "obsgroup.id"));
specificCodedClause.setProjection(Projections.property("id"));
crit.add(Subqueries.exists(specificCodedClause));
}
} else if (cd.isIncludeAllNonCodedDiagnoses()) {
DetachedCriteria anyNonCodedClause = DetachedCriteria.forClass(Obs.class, "nonCodedDiagnosisObs");
anyNonCodedClause.add(Restrictions.eq("voided", false));
anyNonCodedClause.add(Restrictions.eq("concept", dmd.getNonCodedDiagnosisConcept()));
anyNonCodedClause.add(Restrictions.eqProperty("obsGroup", "obsgroup.id"));
anyNonCodedClause.setProjection(Projections.property("id"));
crit.add(Subqueries.exists(anyNonCodedClause));
}
Cohort c = new Cohort();
for (Integer i : (List<Integer>) crit.list()) {
c.addMember(i);
}
return new EvaluatedCohort(c, cohortDefinition, context);
}
Aggregations