@Test public void evaluate_shouldFetchAllPatientVisitsOnDate() throws Exception { List<Integer> ptIds = Arrays.asList(7, 8); Map<String, Object> paramValues = new HashMap<String, Object>(); paramValues.put("date", TestUtils.date(2012, 1, 1)); CalculationResultMap resultMap = new VisitsOnDayCalculation().evaluate(ptIds, paramValues, Context.getService(PatientCalculationService.class).createCalculationContext()); Assert.assertThat(((ListResult) resultMap.get(7)).getValues().size(), is(2)); Assert.assertThat(resultMap.get(8).isEmpty(), is(true)); }
@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); List<Patient> patientStubs = new ArrayList<Patient>(); for (Integer ptId : cohort) { patientStubs.add(new Patient(ptId)); } List<Visit> visits = Context.getVisitService().getVisits(null, patientStubs, null, null, null, endOfDay, startOfDay, null, null, true, false); CalculationResultMap ret = new CalculationResultMap(); for (Visit v : visits) { Integer ptId = v.getPatient().getId(); ListResult holder = (ListResult) ret.get(ptId); if (holder == null) { holder = new ListResult(); ret.put(ptId, holder); } holder.add(new SimpleResult(v, this)); } CalculationUtils.ensureEmptyListResults(ret, cohort); return ret; }
VisitsOnDayCalculation 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); List<Patient> patientStubs = new ArrayList<Patient>(); for (Integer ptId : cohort) { patientStubs.add(new Patient(ptId)); } List<Visit> visits = Context.getVisitService().getVisits(null, patientStubs, null, null, null, endOfDay, startOfDay, null, null, true, false); CalculationResultMap ret = new CalculationResultMap(); for (Visit v : visits) { Integer ptId = v.getPatient().getId(); ListResult holder = (ListResult) ret.get(ptId); if (holder == null) { holder = new ListResult(); ret.put(ptId, holder); } holder.add(new SimpleResult(v, this)); } CalculationUtils.ensureEmptyListResults(ret, cohort); return ret; } }
VisitsOnDayCalculation 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); List<Patient> patientStubs = new ArrayList<Patient>(); for (Integer ptId : cohort) { patientStubs.add(new Patient(ptId)); } List<Visit> visits = Context.getVisitService().getVisits(null, patientStubs, null, null, null, endOfDay, startOfDay, null, null, true, false); CalculationResultMap ret = new CalculationResultMap(); for (Visit v : visits) { Integer ptId = v.getPatient().getId(); ListResult holder = (ListResult) ret.get(ptId); if (holder == null) { holder = new ListResult(); ret.put(ptId, holder); } holder.add(new SimpleResult(v, this)); } CalculationUtils.ensureEmptyListResults(ret, cohort); return ret; }  }
VisitsOnDayCalculation 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); List<Patient> patientStubs = new ArrayList<Patient>(); for (Integer ptId : cohort) { patientStubs.add(new Patient(ptId)); } List<Visit> visits = Context.getVisitService().getVisits(null, patientStubs, null, null, null, endOfDay, startOfDay, null, null, true, false); CalculationResultMap ret = new CalculationResultMap(); for (Visit v : visits) { Integer ptId = v.getPatient().getId(); ListResult holder = (ListResult) ret.get(ptId); if (holder == null) { holder = new ListResult(); ret.put(ptId, holder); } holder.add(new SimpleResult(v, this)); } CalculationUtils.ensureEmptyListResults(ret, cohort); return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context); }
VisitsOnDayCalculation 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); List<Patient> patientStubs = new ArrayList<Patient>(); for (Integer ptId : cohort) { patientStubs.add(new Patient(ptId)); } List<Visit> visits = Context.getVisitService().getVisits(null, patientStubs, null, null, null, endOfDay, startOfDay, null, null, true, false); CalculationResultMap ret = new CalculationResultMap(); for (Visit v : visits) { Integer ptId = v.getPatient().getId(); ListResult holder = (ListResult) ret.get(ptId); if (holder == null) { holder = new ListResult(); ret.put(ptId, holder); } holder.add(new SimpleResult(v, this)); } CalculationUtils.ensureEmptyListResults(ret, cohort); return ret; }  @Override CalculationResultMap evaluate(Collection<Integer> cohort, Map<String, Object> parameterValues, PatientCalculationContext context);  }