ConditionCohortDefinitionEvaluator implements CohortDefinitionEvaluator { @Override public EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context) { ConditionCohortDefinition cd = (ConditionCohortDefinition) cohortDefinition; HqlQueryBuilder query = new HqlQueryBuilder(); query.select("c.patient.patientId") .from(Condition.class, "c") .wherePatientIn("c.patient.patientId", context) .whereEqual("c.condition.coded", cd.getConditionCoded()) .whereEqual("c.condition.nonCoded", cd.getConditionNonCoded()) .whereGreaterOrEqualTo("c.dateCreated", cd.getCreatedOnOrAfter()) .whereLessOrEqualTo("c.dateCreated", cd.getCreatedOnOrBefore()) .whereGreaterOrEqualTo("c.onsetDate", cd.getOnsetDateOnOrAfter()) .whereLessOrEqualTo("c.onsetDate", cd.getOnsetDateOnOrBefore()) .whereGreaterOrEqualTo("c.endDate", cd.getEndDateOnOrAfter()) .whereLessOrEqualTo("c.endDate", cd.getEndDateOnOrBefore()) .whereGreaterOrEqualTo("c.endDate", cd.getActiveOnDate()) .whereLessOrEqualTo("c.onsetDate", cd.getActiveOnDate()); List<Integer> patientIds = evaluationService.evaluateToList(query, Integer.class, context); Cohort cohort = new Cohort(patientIds); return new EvaluatedCohort(cohort, cd, context); }  @Override EvaluatedCohort evaluate(CohortDefinition cohortDefinition, EvaluationContext context);  }
@Test public void evaluateShouldReturnAllPatients() throws Exception { Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertTrue(cohort.contains(3)); Assert.assertTrue(cohort.contains(4)); Assert.assertTrue(cohort.contains(5)); Assert.assertEquals(5, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithConcept() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertTrue(cohort.contains(3)); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(4, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithConceptAndNonCodedValue() throws Exception { cd.setConditionNonCoded("NON-CODED-CONDITION"); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(4)); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(2, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithCreatedOnOrAfter() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setCreatedOnOrAfter(DateUtil.getDateTime(2014, 03, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertTrue(cohort.contains(3)); Assert.assertEquals(3, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithOnSetDateOnOrAfter() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setOnsetDateOnOrAfter(DateUtil.getDateTime(2014, 03, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertTrue(cohort.contains(3)); Assert.assertEquals(3, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithEndDateOnOrAfter() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setEndDateOnOrAfter(DateUtil.getDateTime(2016, 05, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertTrue(cohort.contains(3)); Assert.assertEquals(3, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithCreatedOnOrBefore() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setCreatedOnOrBefore(DateUtil.getDateTime(2014, 03, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(3)); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(2, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithOnSetDateOnOrBefore() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setOnsetDateOnOrBefore(DateUtil.getDateTime(2014, 03, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(3)); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(2, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithEndDateOnOrBefore() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setEndDateOnOrBefore(DateUtil.getDateTime(2016, 05, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(1, cohort.size()); }
@Test public void evaluateShouldFilterPatientsBetweenDateRanges() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setCreatedOnOrAfter(DateUtil.getDateTime(2014, 02, 12)); cd.setCreatedOnOrBefore(DateUtil.getDateTime(2014, 04, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(3)); Assert.assertEquals(1, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithActiveOnDate() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setConditionCoded(concept); cd.setActiveOnDate(DateUtil.getDateTime(2014, 04, 12)); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(3)); Assert.assertTrue(cohort.contains(4)); Assert.assertEquals(2, cohort.size()); }
@Test public void evaluateShouldFilterPatientsWithAllParams() throws Exception { Concept concept = Context.getConceptService().getConcept(409); cd.setCreatedOnOrAfter(DateUtil.getDateTime(2015, 01, 10)); cd.setCreatedOnOrBefore(DateUtil.getDateTime(2015, 01, 14)); cd.setConditionCoded(concept); cd.setConditionNonCoded("NON-CODED-CONDITION2"); Cohort cohort = Context.getService(CohortDefinitionService.class).evaluate(cd, null); Assert.assertTrue(cohort.contains(1)); Assert.assertTrue(cohort.contains(2)); Assert.assertEquals(2, cohort.size()); }