IsTransferOutCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); CalculationResultMap inHivProgram = Calculations.activeEnrollment(hivProgram, cohort, context); CalculationResultMap transferOutDate = calculate(new TransferOutDateCalculation(), cohort, context); CalculationResultMap result = new CalculationResultMap(); for (Integer ptId : cohort) { boolean isTransferOut = false; Date dateTo = EmrCalculationUtils.datetimeResultForPatient(transferOutDate, ptId); if (dateTo != null) { isTransferOut = true; } if(inHivProgram.containsKey(ptId)){ isTransferOut = false; } result.put(ptId, new BooleanResult(isTransferOut, this, context)); } return result; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
										 PatientCalculationContext context);  }
@Test public void evaluate_shouldCalculateIsTransferOutCalculation() throws Exception { Concept reasonForDiscontinue = Dictionary.getConcept(Dictionary.REASON_FOR_PROGRAM_DISCONTINUATION); Concept transferOut = Dictionary.getConcept(Dictionary.TRANSFERRED_OUT); Concept died = Dictionary.getConcept(Dictionary.DIED); Concept unknown = Dictionary.getConcept(Dictionary.UNKNOWN); Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); TestUtils.enrollInProgram(TestUtils.getPatient(2), hivProgram, TestUtils.date(2014, 3, 1)); TestUtils.saveObs(TestUtils.getPatient(2), reasonForDiscontinue, transferOut, TestUtils.date(2014, 3, 30)); TestUtils.saveObs(TestUtils.getPatient(7), reasonForDiscontinue, died, TestUtils.date(2014, 3, 10)); TestUtils.saveObs(TestUtils.getPatient(8), reasonForDiscontinue, transferOut, TestUtils.date(2014, 3, 10)); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8, 999); CalculationResultMap resultMap = new IsTransferOutCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(2).getValue()); Assert.assertFalse((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }