IsTransferInCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Set<Integer> inHivProgram = Filters.inProgram(hivProgram, cohort, context); CalculationResultMap transferInDate = calculate(new TransferInDateCalculation(), cohort, context); CalculationResultMap result = new CalculationResultMap(); for (Integer ptId : cohort) { boolean isTransferIn = false; Date transferInDateValue = EmrCalculationUtils.datetimeResultForPatient(transferInDate, ptId); if (inHivProgram.contains(ptId) && transferInDateValue != null ) { isTransferIn = true; } result.put(ptId, new BooleanResult(isTransferIn, this, context)); } return result; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
										 PatientCalculationContext context);  }
@Test public void evaluate_shouldCalculateIsTransferInCalculation() throws Exception { Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); Concept transferInStatus = Dictionary.getConcept(Dictionary.TRANSFER_IN); Concept yes = Dictionary.getConcept(Dictionary.YES); Concept no = Dictionary.getConcept(Dictionary.NO); TestUtils.enrollInProgram(TestUtils.getPatient(2), hivProgram, TestUtils.date(2014, 3, 1)); TestUtils.enrollInProgram(TestUtils.getPatient(7), hivProgram, TestUtils.date(2014, 3, 1)); TestUtils.saveObs(TestUtils.getPatient(2), transferInStatus, yes, TestUtils.date(2014, 3, 1)); TestUtils.saveObs(TestUtils.getPatient(7), transferInStatus, yes, TestUtils.date(2014, 3, 10)); TestUtils.saveObs(TestUtils.getPatient(8), transferInStatus, no, TestUtils.date(2014, 3, 10)); List<Integer> ptIds = Arrays.asList(2, 6, 7, 8, 999); CalculationResultMap resultMap = new IsTransferInCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertTrue((Boolean) resultMap.get(2).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); Assert.assertFalse((Boolean) resultMap.get(999).getValue()); }