Skip to content

Commit

Permalink
Cover edge case where multiple dispositions have the exact same datet…
Browse files Browse the repository at this point in the history
…ime, favoring the one with the later obsId. Add same constraint to existing awaiting admission query.
  • Loading branch information
mseaton committed Jul 11, 2024
1 parent a059657 commit 1e153da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,6 @@ public void shouldFindVisitEvenIfPatientHasMoreRecentVisitNoteWithoutAdmissionDi
.encounterType(emrApiProperties.getVisitNoteEncounterType())
.visit(visit)
.save();
testDataManager.obs()
.person(patient)
.encounter(secondVisitNoteEncounter)
.concept(dispositionDescriptor.getDispositionConcept())
.value(emrConceptService.getConcept("org.openmrs.module.emrapi:Death"))
.save();

VisitQueryResult result = visitQueryService.evaluate(query, null);
assertThat(result.getMemberIds().size(), is(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ where
where laterDispoObs.encounter.visit = visit
and laterDispoObs.voided = false
and laterDispoObs.concept = :dispositionConcept
and laterDispoObs.obsDatetime > dispo.obsDatetime
and (
laterDispoObs.obsDatetime > dispo.obsDatetime or
(laterDispoObs.obsDatetime = dispo.obsDatetime and laterDispoObs.obsId > dispo.obsId)
)
) = 0
and (
select count(*)
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/resources/hql/visits_awaiting_admission.hql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ where
and (:visitIds is null or visit.visitId in :visitIds)
and person.dead = false
and visit.stopDatetime is null
and (
select count(*)
from Obs as laterDispoObs
where laterDispoObs.encounter.visit = visit
and laterDispoObs.voided = false
and laterDispoObs.concept = :dispositionConcept
and (
laterDispoObs.obsDatetime > dispo.obsDatetime or
(laterDispoObs.obsDatetime = dispo.obsDatetime and laterDispoObs.obsId > dispo.obsId)
)
) = 0
and (
select count(*)
from Encounter as admission
Expand Down

0 comments on commit 1e153da

Please sign in to comment.