Moh731CohortLibrary { public CohortDefinition currentlyInCare() { EncounterType hivEnroll = MetadataUtils.existing(EncounterType.class, HivMetadata._EncounterType.HIV_ENROLLMENT); EncounterType hivConsult = MetadataUtils.existing(EncounterType.class, HivMetadata._EncounterType.HIV_CONSULTATION); CalculationCohortDefinition nextAppointment = new CalculationCohortDefinition(new NextOfVisitHigherThanContextCalculation()); nextAppointment.setName("Have date of next visit"); nextAppointment.addParameter(new Parameter("onDate", "On Date", Date.class)); CalculationCohortDefinition ctxFromAListOfMedicationOrders = new CalculationCohortDefinition(new CtxFromAListOfMedicationOrdersCalculation()); ctxFromAListOfMedicationOrders.setName("ctxFromAListOfMedicationOrders"); ctxFromAListOfMedicationOrders.addParameter(new Parameter("OnDate", "On Date", Date.class)); CompositionCohortDefinition cd = new CompositionCohortDefinition(); cd.addParameter(new Parameter("onDate", "On Date", Date.class)); cd.addSearch("recentEncounter", ReportUtils.map(commonCohorts.hasEncounter(hivEnroll, hivConsult), "onOrAfter=${onDate-90d},onOrBefore=${onDate}")); cd.addSearch("appointmentHigher", ReportUtils.map(nextAppointment, "onDate=${onDate}")); cd.addSearch("hasCtx", ReportUtils.map(ctxFromAListOfMedicationOrders, "onDate=${onDate}")); cd.addSearch("inHivProgram", ReportUtils.map(hivCohortLibrary.enrolled(), "enrolledOnOrBefore=${onDate}")); cd.addSearch("ltfDeadTo", ReportUtils.map(hivCohortLibrary.transferredOutDeadAndLtf(), "onOrBefore=${onDate}")); cd.setCompositionString("((recentEncounter OR appointmentHigher OR hasCtx) AND inHivProgram) AND NOT ltfDeadTo"); return cd; }  CohortDefinition currentlyInCare(); CohortDefinition missedAppointment(); CohortDefinition revisitsArt(); CohortDefinition hasAppointmentDateAndStartedArt(); CohortDefinition currentlyOnArt(); CohortDefinition onOriginalFirstLineAt12Months(); CohortDefinition onAlternateFirstLineAt12Months(); CohortDefinition onSecondLineAt12Months(); CohortDefinition onTherapyAt12Months();  }
@Test public void currentlyInCare() throws Exception { EncounterType triage = MetadataUtils.existing(EncounterType.class, CommonMetadata._EncounterType.TRIAGE); EncounterType hivConsult = MetadataUtils.existing(EncounterType.class, HivMetadata._EncounterType.HIV_CONSULTATION); Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram,PERIOD_END); TestUtils.enrollInProgram(TestUtils.getPatient(8), hivProgram, PERIOD_END); TestUtils.saveEncounter(TestUtils.getPatient(2), triage, TestUtils.date(2012, 6, 15)); TestUtils.saveEncounter(TestUtils.getPatient(6), hivConsult, TestUtils.date(2012, 3, 31)); TestUtils.saveEncounter(TestUtils.getPatient(6), hivConsult, TestUtils.date(2012, 7, 1)); TestUtils.saveEncounter(TestUtils.getPatient(7), hivConsult, TestUtils.date(2012, 4, 1)); TestUtils.saveEncounter(TestUtils.getPatient(8), hivConsult, TestUtils.date(2012, 6, 30)); CohortDefinition cd = moh731Cohorts.currentlyInCare(); context.addParameterValue("onDate", PERIOD_END); EvaluatedCohort evaluated = Context.getService(CohortDefinitionService.class).evaluate(cd, context); ReportingTestUtils.assertCohortEquals(Arrays.asList(7, 8), evaluated); }