Skip to content

Conversation

@chibongho
Copy link
Contributor

…er patient merge

Previously, on patient merge, we change all bed assignments from the non-preferred patient to the preferred patient. This causes problems with multiple active bed assignment on the same patient.

This PR changes it so that if both the preferred and non-preferred patients has active bed assignments, we void the assignment to the non-preferred patient. (If only one of them has a bed assignment, it will still be reassigned to the preferred patient).

Note:
I tested this manually via the Ward App and it seemed to do the right thing in the DB. However, there is a bug (fix pending PR) where the backend returns voided bed assignments. Marking this PR as draft for now, and I'll do another manual test after that PR is merged in.

for (BedPatientAssignment bpa : bpaList) {
bpa.setPatient(preferred);
// ensure there is at most one active bed assignment per patient
if(preferredPatientHasBedAssigned && bpa.getEndDatetime() == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem sufficient. Don't we need to ensure that it also doesn't overlap with the preferred patient's bed assignment, even if it has already ended? i.e. it can't have a endDateTime > the startDateTime of the preferred assignment, right?

bpa.setVoidReason("Merging into patient " + preferred.getId());
bpa.setVoidedBy(Context.getAuthenticatedUser());

Encounter e = bpa.getEncounter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this class should do anything with encounters, should it? Isn't there already a merge function that handles either merging or voiding encounters, and ensuring the appropriate / preferred patient is set on it, etc?

@chibongho
Copy link
Contributor Author

Closing this. Superceded by openmrs/openmrs-module-bedmanagement#99.

@chibongho chibongho closed this Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants