ScheduledVisitOnDayCalculation extends AbstractPatientCalculation { @Override public CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context) { Date date = (Date) parameterValues.get("date"); if (date == null) { date = new Date(); } Date startOfDay = DateUtil.getStartOfDay(date); Date endOfDay = DateUtil.getEndOfDay(date); Concept returnVisitDate = Dictionary.getConcept(Dictionary.RETURN_VISIT_DATE); DateObsCohortDefinition cd = new DateObsCohortDefinition(); cd.setTimeModifier(TimeModifier.ANY); cd.setQuestion(returnVisitDate); cd.setOperator1(RangeComparator.GREATER_EQUAL); cd.setValue1(startOfDay); cd.setOperator2(RangeComparator.LESS_EQUAL); cd.setValue2(endOfDay); EvaluatedCohort withScheduledVisit = CalculationUtils.evaluateWithReporting(cd, cohort, null, context); CalculationResultMap ret = new CalculationResultMap(); for (Integer ptId : cohort) { ret.put(ptId, new BooleanResult(withScheduledVisit.contains(ptId), this)); } return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }
@Test public void evaluate_shouldCalculateForSpecifiedDate() throws Exception { List<Integer> ptIds = Arrays.asList(6, 7, 8); Map<String, Object> paramValues = new HashMap<String, Object>(); paramValues.put("date", TestUtils.date(2012, 1, 1)); CalculationResultMap resultMap = new ScheduledVisitOnDayCalculation().evaluate(ptIds, paramValues, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertTrue((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); }
@Test public void evaluate_shouldCalculateForTodayWithoutDateParam() throws Exception { List<Integer> ptIds = Arrays.asList(6, 7, 8); Map<String, Object> paramValues = new HashMap<String, Object>(); CalculationResultMap resultMap = new ScheduledVisitOnDayCalculation().evaluate(ptIds, paramValues, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertFalse((Boolean) resultMap.get(6).getValue()); Assert.assertFalse((Boolean) resultMap.get(7).getValue()); Assert.assertFalse((Boolean) resultMap.get(8).getValue()); }