TbCohortLibrary { public CohortDefinition testedForHivAndInTbProgram() { Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); CompositionCohortDefinition cd = new CompositionCohortDefinition(); cd.addParameter(new Parameter("onOrAfter", "After Date", Date.class)); cd.addParameter(new Parameter("onOrBefore", "Before Date", Date.class)); cd.addSearch("inTbProgram", ReportUtils.map(commonCohorts.enrolled(tbProgram), "enrolledOnOrBefore=${onOrBefore}")); cd.addSearch("hivTested", ReportUtils.map(hivCohortLibrary.testedForHiv(), "onOrAfter=${onOrAfter},onOrBefore=${onOrBefore}")); cd.setCompositionString("inTbProgram AND hivTested"); return cd; }  CohortDefinition enrolled(); CohortDefinition screenedForTb(); CohortDefinition currentlyOnCareAndScreenedInTheLastVisit(); CohortDefinition screenedForTbAndNotOnTbTreatment(); CohortDefinition screenedForTbAndHivPositive(); CohortDefinition screenedForTbUsingICF(); CohortDefinition died(); CohortDefinition startedTbTreatmentBetweenDates(); CohortDefinition started12MonthsAgo(); CohortDefinition diedAndStarted12MonthsAgo(); CohortDefinition completedTreatment(); CohortDefinition defaulted(); CohortDefinition inTbAndHivProgramsAndOnCtxProphylaxis(); CohortDefinition testedForHivAndInTbProgram(); CohortDefinition testedHivPositiveAndInTbProgram(); CohortDefinition tbRetreatments(); CohortDefinition extraPulmonaryTbPatients(); CohortDefinition pulmonaryTbPatients(); CohortDefinition smearNegativePatients(); CohortDefinition smearPositivePatients(); CohortDefinition pulmonaryTbSmearNegative(); CohortDefinition pulmonaryTbSmearPositive(); CohortDefinition tbNewDetectedCases(); CohortDefinition pulmonaryTbSmearNotDone(); CohortDefinition ptbSmearNotDoneResultsAtMonths(); CohortDefinition startedTbTreatmentResultsAtMonths(Integer months); CohortDefinition completedInitialTreatment(); CohortDefinition totalEnrolledPtbSmearNotDoneResultsAtMonths(int highMonths, int leastMonths  ); CohortDefinition ptbSmearNotDoneResults2MonthsFinalizedInitialtreatment(); CohortDefinition ptbSmearNotDoneResults2MonthsDied(); CohortDefinition ptbSmearNotDoneResults2MonthsAbsconded(); CohortDefinition ptbSmearNotDoneResults2MonthsTransferredOut(); CohortDefinition ptbSmearNotDoneResults2MonthsTotalEvaluated(); CohortDefinition totalEnrolled8Months(int highMonths, int leastMonths ); CohortDefinition totalEnrolled8MonthsHivPositive(); CohortDefinition totalEnrolled8MonthsHivNegative(); CohortDefinition totalEnrolled8MonthsHivTestNotDone(); CohortDefinition totalEnrolled8MonthsHivPositiveNegativeTestNotDone(); CohortDefinition totalEnrolled8MonthsHivPositiveOnCpt(); CohortDefinition totalEnrolled8MonthsHivPositiveOnArt(); CohortDefinition finalizedInitialTreatmentResults8monthsHivPositive(); CohortDefinition diedResults8monthsHivPositive(); CohortDefinition abscondedResults8monthsHivPositive(); CohortDefinition transferredOutResults8monthsHivPositive(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivPositive(); CohortDefinition finalizedInitialTreatmentTotalEnrolled8MonthsHivNegative(); CohortDefinition diedTotalEnrolled8MonthsHivNegative(); CohortDefinition abscondedTotalEnrolled8MonthsHivNegative(); CohortDefinition transferredOutTotalEnrolled8MonthsHivNegative(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivNegative(); CohortDefinition finalizedInitialTreatmentTotalEnrolled8MonthsHivTestNotDone(); CohortDefinition diedTotalEnrolled8MonthsHivTestNotDone(); CohortDefinition abscondedTotalEnrolled8MonthsHivTestNotDone(); CohortDefinition transferredOutTotalEnrolled8MonthsHivTestNotDone(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivTestNotDone(); CohortDefinition finalizedInitialTreatmentTotalEnrolled8MonthsHivPositiveNegativeTestNotDone(); CohortDefinition diedTotalEnrolled8MonthsHivPositiveNegativeTestNotDone(); CohortDefinition abscondedTotalEnrolled8MonthsHivPositiveNegativeTestNotDone(); CohortDefinition transferredOutTotalEnrolled8MonthsHivPositiveNegativeTestNotDone(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivPositiveNegativeTestNotDone(); CohortDefinition finalizedInitialTreatmentTotalEnrolled8MonthsHivPositiveOnCpt(); CohortDefinition diedTotalEnrolled8MonthsHivPositiveOnCpt(); CohortDefinition abscondedTotalEnrolled8MonthsHivPositiveOnCpt(); CohortDefinition transferredOutTotalEnrolled8MonthsHivPositiveOnCpt(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivPositiveOnCpt(); CohortDefinition finalizedInitialTreatmentTotalEnrolled8MonthsHivPositiveOnArt(); CohortDefinition diedTotalEnrolled8MonthsHivPositiveOnArt(); CohortDefinition abscondedTotalEnrolled8MonthsHivPositiveOnArt(); CohortDefinition transferOutTotalEnrolled8MonthsHivPositiveOnArt(); CohortDefinition finalizedInitialTreatmentDiedAbscondedTransferredOutResults8monthsHivPositiveOnArt(); CohortDefinition newSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(int highMonths, int leastMonths); CohortDefinition finalizedInitialTreatmentNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(); CohortDefinition diedNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(); CohortDefinition abscondedNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(); CohortDefinition transferOutNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(); CohortDefinition transferOutAbscondedDiedFinalizedInitialTreatmentNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults2Months(); CohortDefinition newSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(int highMonths, int leastMonths); CohortDefinition treatmentCompletedNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition diedNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition outOfControlNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition transferOutNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition becameSmearPositiveNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition transferOutOutOfControlDiedCompletedTreatmentNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition extraPulmonaryTbResultsAt2Months(int highMonths, int leastMonths); CohortDefinition finalizedInitialTreatmentExtraPulmonaryTbResultsAt2Months(); CohortDefinition diedExtraPulmonaryTbResultsAt2Months(); CohortDefinition abscondedExtraPulmonaryTbResultsAt2Months(); CohortDefinition transferredOutExtraPulmonaryTbResultsAt2Months(); CohortDefinition transferOutAbscondedDiedCompletedTreatmentNewSputumSmearNegative12to15MonthsEarlierPulmonaryTbResults8Months(); CohortDefinition extraPulmonaryTbResultsAt8Months(int highMonths, int leastMonths); CohortDefinition treatmentCompleteExtraPulmonaryTbResultsAt8Months(); CohortDefinition diedExtraPulmonaryTbResultsAt8Months(); CohortDefinition outOfControlExtraPulmonaryTbResultsAt8Months(); CohortDefinition transferredOutExtraPulmonaryTbResultsAt8Months(); CohortDefinition transferOutOutOfControlDiedCompletedTreatmentExtraPulmonaryTbResultsAt8Months();  }
@Test public void testedForHivAndInTbProgram_shouldReturnPatientsWhoTestedForHivAndInTbProgram() throws Exception { Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Concept hivStatus = Dictionary.getConcept(Dictionary.HIV_STATUS); Concept hivInfected = Dictionary.getConcept(Dictionary.HIV_INFECTED); Concept positive = Dictionary.getConcept(Dictionary.POSITIVE); Concept negative = Dictionary.getConcept(Dictionary.NEGATIVE); TestUtils.enrollInProgram(TestUtils.getPatient(2), tbProgram, TestUtils.date(2012, 6, 10)); TestUtils.enrollInProgram(TestUtils.getPatient(6), hivProgram, TestUtils.date(2011, 5, 10)); TestUtils.enrollInProgram(TestUtils.getPatient(7), tbProgram, TestUtils.date(2012, 6, 8)); TestUtils.enrollInProgram(TestUtils.getPatient(8), tbProgram, TestUtils.date(2012, 6, 10)); TestUtils.saveObs(TestUtils.getPatient(6), hivStatus, negative, TestUtils.date(2012, 6, 11)); TestUtils.saveObs(TestUtils.getPatient(7), hivInfected, positive, TestUtils.date(2012, 6, 14)); TestUtils.saveObs(TestUtils.getPatient(2), hivInfected, positive, TestUtils.date(2012, 6, 19)); TestUtils.saveObs(TestUtils.getPatient(8), hivInfected, negative, TestUtils.date(2012, 6, 17)); CohortDefinition cd = tbCohortLibrary.testedForHivAndInTbProgram(); 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(2,7,8), evaluated); }