TbSuspectCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Set<Integer> alive = Filters.alive(cohort, context); Set<Integer> inTbProgram = Filters.inProgram(tbProgram, cohort, context); Concept tbSuspect = Dictionary.getConcept(Dictionary.DISEASE_SUSPECTED); CalculationResultMap lastTbDiseaseStatus = Calculations.lastObs(Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS), alive, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { Boolean isTBSuspectNotInProgram = false; ObsResult obsResultTbDiseaseStatus = (ObsResult)lastTbDiseaseStatus.get(ptId); if (obsResultTbDiseaseStatus != null) { if (obsResultTbDiseaseStatus.getValue().getValueCoded().equals(tbSuspect)) { if ( ! inTbProgram.contains(ptId)) { isTBSuspectNotInProgram = true; } } } ret.put(ptId, new BooleanResult(isTBSuspectNotInProgram, this, context)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
			PatientCalculationContext context);  }
@Test public void evaluate_shouldDetermineWhetherPatientIsTbSuspectAndNotEnrolledInTBProgram() { Program tbProgram = MetadataUtils.existing(Program.class, TbMetadata._Program.TB); Concept tbDiseaseStatus = Dictionary.getConcept(Dictionary.TUBERCULOSIS_DISEASE_STATUS); Concept tbSuspect = Dictionary.getConcept(Dictionary.DISEASE_SUSPECTED); Concept onTbTreatment = Dictionary.getConcept(Dictionary.ON_TREATMENT_FOR_DISEASE); TestUtils.enrollInProgram(TestUtils.getPatient(6), tbProgram, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(6), tbDiseaseStatus, tbSuspect, TestUtils.date(2012, 5, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(7), tbProgram, TestUtils.date(2012, 1, 1),TestUtils.date(2012, 6, 1)); TestUtils.saveObs(TestUtils.getPatient(7), tbDiseaseStatus, tbSuspect, TestUtils.date(2012, 5, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(8), tbProgram, TestUtils.date(2012, 1, 1)); TestUtils.saveObs(TestUtils.getPatient(8), tbDiseaseStatus, onTbTreatment, TestUtils.date(2012, 5, 1)); List<Integer> cohort = Arrays.asList(6,7,8); CalculationResultMap resultMap = Context.getService(PatientCalculationService.class).evaluate(cohort, new TbSuspectCalculation()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); }