diff --git a/api/src/main/java/org/openmrs/validator/VisitValidator.java b/api/src/main/java/org/openmrs/validator/VisitValidator.java index 41674b204c3c..e0a312171f69 100644 --- a/api/src/main/java/org/openmrs/validator/VisitValidator.java +++ b/api/src/main/java/org/openmrs/validator/VisitValidator.java @@ -109,6 +109,9 @@ public void validate(Object target, Errors errors) { if (disallowOverlappingVisits()) { List otherVisitList = Context.getVisitService().getVisitsByPatient(visit.getPatient()); for (Visit otherVisit : otherVisitList) { + if (visit.equals(otherVisit)) { + continue; + } validateStartDatetime(visit, otherVisit, errors); validateStopDatetime(visit, otherVisit, errors); } diff --git a/api/src/test/java/org/openmrs/api/VisitServiceTest.java b/api/src/test/java/org/openmrs/api/VisitServiceTest.java index d66ffce97e74..65514ce74cba 100644 --- a/api/src/test/java/org/openmrs/api/VisitServiceTest.java +++ b/api/src/test/java/org/openmrs/api/VisitServiceTest.java @@ -781,6 +781,22 @@ public void endVisit_shouldFailIfValidationErrorsAreFound() { assertThrows(APIException.class, () -> visitService.endVisit(visit, cal.getTime())); } + /** + * @see VisitService#endVisit(Visit,Date) + */ + @Test + public void endVisit_shouldNotFailIfAllowOverlappingVisitsIsFalse() { + + Context.getAdministrationService().setGlobalProperty("visits.allowOverlappingVisits", "false"); + + Visit visit = visitService.getVisit(1); + assertNull(visit.getStopDatetime()); + + visitService.endVisit(visit, null); + + assertNotNull(visit.getStopDatetime()); + } + /** * @see VisitService#purgeVisit(Visit) */ diff --git a/api/src/test/resources/org/openmrs/include/standardTestDataset.xml b/api/src/test/resources/org/openmrs/include/standardTestDataset.xml index 6af982e5c0a9..c7f58371d138 100644 --- a/api/src/test/resources/org/openmrs/include/standardTestDataset.xml +++ b/api/src/test/resources/org/openmrs/include/standardTestDataset.xml @@ -440,8 +440,8 @@ - - + +