Skip to content

Commit

Permalink
O3-3518 Unable to End Visits with visits.allowOverlappingVisits=false
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Jul 1, 2024
1 parent 2586624 commit dec07a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/src/main/java/org/openmrs/validator/VisitValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public void validate(Object target, Errors errors) {
if (disallowOverlappingVisits()) {
List<Visit> otherVisitList = Context.getVisitService().getVisitsByPatient(visit.getPatient());
for (Visit otherVisit : otherVisitList) {
if (visit.equals(otherVisit)) {
continue;
}
validateStartDatetime(visit, otherVisit, errors);
validateStopDatetime(visit, otherVisit, errors);
}
Expand Down
16 changes: 16 additions & 0 deletions api/src/test/java/org/openmrs/api/VisitServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@
<visit_type visit_type_id="2" name="Return TB Clinic Visit" description="Return TB Clinic Visit Description" creator="1" date_created="2005-01-01 00:00:00.0" retired="false" uuid="759799ab-c9a5-435e-b671-77773ada74e4"/>
<visit_type visit_type_id="3" name="Hospitalization" description="Hospitalization Description" creator="1" date_created="2005-01-01 00:00:00.0" retired="true" retire_reason="Some Retire Reason" uuid="759799ab-c9a5-435e-b671-77773ada74e6"/>
<visit visit_id="1" patient_id="2" visit_type_id="1" date_started="2005-01-01 00:00:00.0" location_id="1" indication_concept_id="5497" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="1e5d5d48-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="2" patient_id="2" visit_type_id="1" date_started="2005-01-01 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="4e663d66-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="3" patient_id="2" visit_type_id="2" date_started="2005-01-01 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="6f85b2a6-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="2" patient_id="2" visit_type_id="1" date_started="2005-01-02 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="4e663d66-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="3" patient_id="2" visit_type_id="2" date_started="2005-01-03 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="6f85b2a6-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="4" patient_id="6" visit_type_id="1" date_started="2005-01-01 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="7d8c1980-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="5" patient_id="6" visit_type_id="1" date_started="2005-01-01 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="0" uuid="8cfda6ae-6b78-11e0-93c3-18a905e044dc" />
<visit visit_id="6" patient_id="2" visit_type_id="1" date_started="2005-01-01 00:00:00.0" creator="1" date_created="2005-01-01 00:00:00.0" voided="1" voided_by="1" date_voided="2005-01-01 00:00:00.0" void_reason="no reason" uuid="e1428fea-6b78-11e0-93c3-18a905e044dc" />
Expand Down

0 comments on commit dec07a0

Please sign in to comment.