LastCd4PercentageCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { return Calculations.lastObs(Dictionary.getConcept(Dictionary.CD4_PERCENT), cohort, context); }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }
@Test public void evaluate_shouldCalculateLastCD4() throws Exception { Concept cd4Percent = Dictionary.getConcept(Dictionary.CD4_PERCENT); TestUtils.saveObs(TestUtils.getPatient(7), cd4Percent, 20d, TestUtils.date(2012, 12, 1)); TestUtils.saveObs(TestUtils.getPatient(7), cd4Percent, 30d, TestUtils.date(2010, 11, 1)); List<Integer> ptIds = Arrays.asList(6, 7); CalculationResultMap resultMap = new LastCd4PercentageCalculation().evaluate(ptIds, null, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertNull(resultMap.get(6)); Assert.assertEquals(new Double(20d), ((Obs) resultMap.get(7).getValue()).getValueNumeric()); }