KenyaEmrServiceImpl extends BaseOpenmrsService implements KenyaEmrService { @Override public List<Visit> getVisitsByPatientAndDay(Patient patient, Date date) { Date startOfDay = OpenmrsUtil.firstSecondOfDay(date); Date endOfDay = OpenmrsUtil.getLastMomentOfDay(date); List<Visit> visits = Context.getVisitService().getVisits(null, Collections.singleton(patient), null, null, null, endOfDay, startOfDay, null, null, true, false); Collections.reverse(visits); return visits; }  void setKenyaEmrDAO(KenyaEmrDAO dao); @Override boolean isSetupRequired(); @Override void setDefaultLocation(Location location); @Override Location getDefaultLocation(); @Override String getDefaultLocationMflCode(); @Override Location getLocationByMflCode(String mflCode); @Override String getNextHivUniquePatientNumber(String comment); @Override List<Visit> getVisitsByPatientAndDay(Patient patient, Date date); @Override void setupMrnIdentifierSource(String startFrom); @Override void setupHivUniqueIdentifierSource(String startFrom); @Override List<Object> executeSqlQuery(String query, Map<String, Object> substitutions); @Override List<Object> executeHqlQuery(String query, Map<String, Object> substitutions);  }
@Test public void getVisitsByPatientAndDay_shouldGetVisitsOnDayWithPatient() { Patient patient = Context.getPatientService().getPatient(7); VisitType outpatientType = MetadataUtils.existing(VisitType.class, CommonMetadata._VisitType.OUTPATIENT); Visit visit1 = TestUtils.saveVisit(patient, outpatientType, TestUtils.date(2012, 1, 1, 10, 0, 0), TestUtils.date(2012, 1, 1, 11, 0, 0)); Visit visit2 = TestUtils.saveVisit(patient, outpatientType, TestUtils.date(2012, 1, 1, 12, 0, 0), null); List<Visit> visits = service.getVisitsByPatientAndDay(patient, TestUtils.date(2011, 12, 31)); Assert.assertEquals(0, visits.size()); visits = service.getVisitsByPatientAndDay(patient, TestUtils.date(2012, 1, 1)); Assert.assertEquals(2, visits.size()); Assert.assertEquals(visit1, visits.get(0)); Assert.assertEquals(visit2, visits.get(1)); visits = service.getVisitsByPatientAndDay(patient, TestUtils.date(2012, 1, 2)); Assert.assertEquals(1, visits.size()); Assert.assertEquals(visit2, visits.get(0)); }