@Test public void evaluate_shouldReturnHivPatientsNotScreenedForTb() throws Exception { // Get HIV Program and TB screening encounter type Program hivProgram = MetadataUtils.getProgram(Metadata.HIV_PROGRAM); EncounterType screeningEncType = MetadataUtils.getEncounterType(Metadata.TB_SCREENING_ENCOUNTER_TYPE); // Enroll patients #6 and #7 PatientService ps = Context.getPatientService(); TestUtils.enrollInProgram(ps.getPatient(6), hivProgram, TestUtils.date(2011, 1, 1)); TestUtils.enrollInProgram(ps.getPatient(7), hivProgram, TestUtils.date(2011, 1, 1)); // Screen patient #6 for TB a year later TestUtils.saveEncounter(ps.getPatient(6), screeningEncType, TestUtils.date(2012, 1, 1)); Context.flushSession(); List<Integer> cohort = Arrays.asList(6, 7, 8); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class) .evaluate(cohort, new NeverScreenedForTbCalculation()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertNull(resultMap.get(8)); // not in HIV program }