/** * @see org.openmrs.api.VisitService#getActiveVisitsByPatient(org.openmrs.Patient) */ @Override @Transactional(readOnly = true) public List<Visit> getActiveVisitsByPatient(Patient patient) throws APIException { return Context.getVisitService().getVisitsByPatient(patient, false, false); }
@Test public void getVisitsByPatient_shouldReturnEmptyListGivenNullAndFalse() { assertThat(visitService.getVisitsByPatient(null, false, false), is(empty())); }
@Test public void getVisitsByPatient_shouldReturnEmptyListGivenNull() { assertThat(visitService.getVisitsByPatient(null), is(empty())); }
private void mergeVisits(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { // move all visits, including voided ones (encounters will be handled below) //TODO: this should be a copy, not a move VisitService visitService = Context.getVisitService(); for (Visit visit : visitService.getVisitsByPatient(notPreferred, true, true)) { if (log.isDebugEnabled()) { log.debug("Merging visit " + visit.getVisitId() + " to " + preferred.getPatientId()); } visit.setPatient(preferred); Visit persisted = visitService.saveVisit(visit); mergedData.addMovedVisit(persisted.getUuid()); } }
/** * @see VisitService#getVisitsByPatient(Patient) */ @Test public void getVisitsByPatient_shouldReturnAllUnvoidedVisitsForTheSpecifiedPatient() { assertEquals(3, visitService.getVisitsByPatient(new Patient(2)).size()); }
@Test public void getVisitsByPatient_shouldReturnEmptyListGivenPatientWithNullPatientId() { Patient p = new Patient(); p.setPatientId(null); assertThat(visitService.getVisitsByPatient(p), is(empty())); }
@Test public void getVisitsByPatient_shouldReturnEmptyListGivenPatientWithNullPatientIdAndFalse() { Patient p = new Patient(); p.setPatientId(null); assertThat(visitService.getVisitsByPatient(p, false, false), is(empty())); }
@Test public void getActiveVisitsByPatient_shouldReturnAllUnvoidedVisitsForTheSpecifiedPatient() { executeDataSet(VISITS_WITH_DATES_XML); assertEquals(8, visitService.getVisitsByPatient(new Patient(2), true, false).size()); }
@Test public void getActiveVisitsByPatient_shouldReturnAllActiveVisitsForTheSpecifiedPatient() { executeDataSet(VISITS_WITH_DATES_XML); assertEquals(5, visitService.getVisitsByPatient(new Patient(2), false, true).size()); }
private boolean patientHasVoidedVisit(Patient patient, long startInMillis, long stopInMillis) { // To get voided visit from the past, both inactive AND voided visits are queried. // List<Visit> visitList = Context.getVisitService().getVisitsByPatient(patient, true, true); for (Visit visit : visitList) { if (visit.getStartDatetime() != null && visit.getStartDatetime().getTime() == startInMillis && visit.getStopDatetime() != null && visit.getStopDatetime().getTime() == stopInMillis && visit.getVoided()) { return true; } } return false; }
List<Visit> otherVisitList = Context.getVisitService().getVisitsByPatient(visit.getPatient()); for (Visit otherVisit : otherVisitList) { validateStartDatetime(visit, otherVisit, errors);
List<Visit> mergedVisits = visitService.getVisitsByPatient(merged, true, true);
@Override public void delete(Patient patient, String reason, RequestContext context) throws ResponseException { if (patient.isVoided()) { // DELETE is idempotent, so we return success here return; } VisitService visitService = Context.getVisitService(); List<Visit> visits = Context.getVisitService().getVisitsByPatient(patient); for (Visit visit : visits) { visitService.voidVisit(visit, "Patient deleted"); } super.delete(patient, reason, context); }
@Test public void shouldCreateAVisitWithEncounterAndObs() throws Exception { int originalCount = service.getAllVisits().size(); final String patientUuid = "5946f880-b197-400b-9caa-a3c661d23041"; Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); Assert.assertEquals(0, service.getVisitsByPatient(patient).size()); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\", \"encounters\": [{\"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"obs\": [{\"concept\":\"89ca642a-dab6-4f20-b712-e12ca4fc6d36\", \"value\":\"b055abd8-a420-4a11-8b98-02ee170a7b54\"}]}] }}] }"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); Assert.assertEquals(1, service.getVisitsByPatient(patient).get(0).getEncounters().size()); Iterator<Encounter> encouters = service.getVisitsByPatient(patient).get(0).getEncounters().iterator(); Assert.assertEquals(1, encouters.next().getObs().size()); }
@Test public void shouldCreateAVisitWithEncounters() throws Exception { int originalCount = service.getAllVisits().size(); final String patientUuid = "5946f880-b197-400b-9caa-a3c661d23041"; Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); Assert.assertEquals(0, service.getVisitsByPatient(patient).size()); String json = "{ \"patient\":\"5946f880-b197-400b-9caa-a3c661d23041\", \"visitType\":\"" + RestTestConstants1_9.VISIT_TYPE_UUID + "\", \"location\":\"" + RestTestConstants1_9.LOCATION_UUID + "\", \"startDatetime\":\"" + DATE_FORMAT.format(new Date()) + "\", \"encounters\": [\"6519d653-393b-4118-9c83-a3715b82d4ac\", \"eec646cb-c847-45a7-98bc-91c8c4f70add\"] }"; Object newVisit = deserialize(handle(newPostRequest(getURI(), json))); Assert.assertNotNull(PropertyUtils.getProperty(newVisit, "uuid")); Assert.assertEquals(originalCount + 1, service.getAllVisits().size()); Assert.assertEquals(2, service.getVisitsByPatient(patient).get(0).getEncounters().size()); }