CommonCohortLibrary { public CohortDefinition enrolled(Program... programs) { ProgramEnrollmentCohortDefinition cd = new ProgramEnrollmentCohortDefinition(); cd.setName("enrolled in program between dates"); cd.addParameter(new Parameter("enrolledOnOrAfter", "After Date", Date.class)); cd.addParameter(new Parameter("enrolledOnOrBefore", "Before Date", Date.class)); if (programs.length > 0) { cd.setPrograms(Arrays.asList(programs)); } 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 enrolled() throws Exception { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); TestUtils.enrollInProgram(Context.getPatientService().getPatient(2), hivProgram, TestUtils.date(2012, 5, 31)); TestUtils.enrollInProgram(Context.getPatientService().getPatient(6), hivProgram, TestUtils.date(2012, 6, 1)); TestUtils.enrollInProgram(Context.getPatientService().getPatient(7), hivProgram, TestUtils.date(2012, 6, 30)); TestUtils.enrollInProgram(Context.getPatientService().getPatient(8), hivProgram, TestUtils.date(2012, 7, 1)); CohortDefinition cd = commonCohortLibrary.enrolled(hivProgram); context.addParameterValue("enrolledOnOrAfter", TestUtils.date(2012, 6, 1)); EvaluatedCohort evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(6, 7, 8), evaluated); cd = commonCohortLibrary.enrolled(hivProgram); context.addParameterValue("enrolledOnOrBefore", TestUtils.date(2012, 6, 30)); context.addParameterValue("enrolledOnOrAfter", null); evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(2, 6, 7), evaluated); cd = commonCohortLibrary.enrolled(hivProgram); context.addParameterValue("enrolledOnOrAfter", TestUtils.date(2012, 6, 1)); context.addParameterValue("enrolledOnOrBefore", TestUtils.date(2012, 6, 30)); evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(6, 7), evaluated); }