CommonCohortLibrary { public CohortDefinition hasEncounter(EncounterType... types) { EncounterCohortDefinition cd = new EncounterCohortDefinition(); cd.setName("has encounter between dates"); cd.setTimeQualifier(TimeQualifier.ANY); cd.addParameter(new Parameter("onOrBefore", "Before Date", Date.class)); cd.addParameter(new Parameter("onOrAfter", "After Date", Date.class)); if (types.length > 0) { cd.setEncounterTypeList(Arrays.asList(types)); } return cd; }  CohortDefinition females(); CohortDefinition males(); CohortDefinition agedAtMost(int maxAge); CohortDefinition agedAtLeast(int minAge); CohortDefinition agedAtLeastAgedAtMost(int minAge, int maxAge); CohortDefinition femalesAgedAtLeast18(); CohortDefinition hasEncounter(EncounterType... types); CohortDefinition hasObs(Concept question, Concept... answers); CohortDefinition transferredIn(); CohortDefinition transferredOut(); CohortDefinition enrolled(Program... programs); CohortDefinition enrolledExcludingTransfers(Program... programs); CohortDefinition enrolledExcludingTransfersOnDate(Program... programs); CohortDefinition pregnant(); CohortDefinition inProgram(Program program); CohortDefinition medicationDispensed(Concept... concepts); CohortDefinition compltedProgram(); CohortDefinition deceasedPatients(); CohortDefinition markedAsDeadButNotDeceased();  }
@Test public void hasEncounter() throws Exception { EncounterType registrationType = MetadataUtils.existing(EncounterType.class, CommonMetadata._EncounterType.REGISTRATION); EncounterType triageType = MetadataUtils.existing(EncounterType.class, CommonMetadata._EncounterType.TRIAGE); TestUtils.saveEncounter(Context.getPatientService().getPatient(6), registrationType, TestUtils.date(2012, 6, 1)); TestUtils.saveEncounter(Context.getPatientService().getPatient(7), registrationType, TestUtils.date(2012, 7, 1)); TestUtils.saveEncounter(Context.getPatientService().getPatient(8), triageType, TestUtils.date(2012, 6, 1)); CohortDefinition cd = commonCohortLibrary.hasEncounter(registrationType); context.addParameterValue("onOrAfter", TestUtils.date(2012, 6, 1)); context.addParameterValue("onOrBefore", TestUtils.date(2012, 6, 30)); EvaluatedCohort evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(6), evaluated); }