InitialArtStartDateCalculation extends BaseEmrCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Concept arvs = Dictionary.getConcept(Dictionary.ANTIRETROVIRAL_DRUGS); CalculationResultMap allDrugOrders = allDrugOrders(arvs, cohort, context); CalculationResultMap earliestOrderDates = earliestStartDates(allDrugOrders, context); CalculationResultMap result = new CalculationResultMap(); for (Integer ptId : cohort) { Date orderDate = EmrCalculationUtils.datetimeResultForPatient(earliestOrderDates, ptId); result.put(ptId, orderDate == null ? null : new SimpleResult(orderDate, null)); } return result; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues,
	                                     PatientCalculationContext context);  }
@Test public void evaluate_shouldCalculateInitialArtStartDate() throws Exception { Concept dapsone = Dictionary.getConcept(Dictionary.DAPSONE); Concept azt = Context.getConceptService().getConcept(86663); Concept _3tc = Context.getConceptService().getConcept(78643); Concept efv = Context.getConceptService().getConcept(75523); TestUtils.saveDrugOrder(TestUtils.getPatient(6), dapsone, TestUtils.date(2011, 1, 1), null); TestUtils.saveDrugOrder(TestUtils.getPatient(7), azt, TestUtils.date(2010, 1, 1), TestUtils.date(2011, 1, 1)); TestUtils.saveDrugOrder(TestUtils.getPatient(7), _3tc, TestUtils.date(2011, 1, 1), TestUtils.date(2012, 1, 1)); TestUtils.saveDrugOrder(TestUtils.getPatient(7), efv, TestUtils.date(2011, 1, 1), TestUtils.date(2012, 1, 1)); List<Integer> cohort = Arrays.asList(6, 7, 8); CalculationResultMap resultMap = new InitialArtStartDateCalculation().evaluate(cohort, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertNull(resultMap.get(6)); Assert.assertEquals(TestUtils.date(2010, 1, 1), resultMap.get(7).getValue()); Assert.assertNull(resultMap.get(8)); }