Skip to content

BED-17: Queries for BedPatientAssignment should account for the voided field#90

Closed
jwnasambu wants to merge 53 commits intoopenmrs:masterfrom
jwnasambu:BED-17
Closed

BED-17: Queries for BedPatientAssignment should account for the voided field#90
jwnasambu wants to merge 53 commits intoopenmrs:masterfrom
jwnasambu:BED-17

Conversation

@jwnasambu
Copy link
Copy Markdown
Contributor

@jwnasambu jwnasambu commented Oct 2, 2025

Description of what I changed
Updated BedPatientAssignment queries in BedManagementDaoImpl to exclude voided records.

Issue I worked on
https://openmrs.atlassian.net/browse/BED-17

@jwnasambu jwnasambu changed the title Bed 17 Bed 17: Queries for BedPatientAssignment should account for the voided field Oct 2, 2025
@chibongho
Copy link
Copy Markdown
Contributor

Code looks good. Can you include what you did to test this change @jwnasambu?

@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Oct 7, 2025

@jwnasambu can you update the ticket with the link to your pull request as advised at? https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477199/Pull+Request+Tips

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa I have updated the ticket with the link to my pull request.

@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Oct 10, 2025

Do you mind also adding some tests?

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa, @chibongho, I’m really sorry for overlooking the requested changes. I’ve just noticed them now I think it might have been due to fatigue. Please allow me to fix them over the weekend.

@jwnasambu
Copy link
Copy Markdown
Contributor Author

jwnasambu commented Oct 12, 2025

Do you mind also adding some tests?

Sorry for the delayed update. @chibongho , @dkayiwa I have implemented the proposed changes.

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.*;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Oct 12, 2025

I thought that you would create two new tests where one demonstrates what is returned when the voided flag is set and the other when the voided flag is not set.

@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa feel free to review my PR please!

@jwnasambu jwnasambu requested a review from dkayiwa October 13, 2025 11:55
@dkayiwa
Copy link
Copy Markdown
Member

dkayiwa commented Oct 14, 2025

@jwnasambu when committing, can you always include the ticket id in the commit message as advised at? https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477199/Pull+Request+Tips

@@ -67,8 +67,8 @@ public Bed getBedByUuid(String uuid) {
public Bed getBedByPatient(Patient patient) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have the getBedByPatient method called/not mocked, in a test?

@@ -89,7 +89,7 @@ public Location getWardForBed(Bed bed) {
@Override
public BedPatientAssignment getBedPatientAssignmentByUuid(String uuid) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have the getBedPatientAssignmentByUuid method called/not mocked, in a test?

@@ -129,8 +129,9 @@ public List<BedPatientAssignment> getBedPatientAssignmentByVisit(String visitUui
public List<BedPatientAssignment> getCurrentAssignmentsByBed(Bed bed) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have the getCurrentAssignmentsByBed method called/not mocked, in a test?

@@ -139,7 +140,8 @@ public Bed getLatestBedByVisit(String visitUuid) {
Session session = sessionFactory.getCurrentSession();
Bed bed = (Bed) session
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have the getLatestBedByVisit method called/not mocked, in a test?

bedManagementService = new BedManagementServiceImpl();
bedManagementService.setDao(bedManagementDao);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we discard these formatting changes?


defaultLocation = Context.getLocationService()
.getLocationByUuid("8d6c993e-c2cc-11de-8d13-0010c6dffd0f");
assertNotNull("Default location should not be null", defaultLocation);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think we need this assertion because we are sure that we have this location in the test dataset.

defaultEncounterType = Context.getEncounterService()
.getEncounterType("Scheduled");

assertNotNull("Default encounter type should not be null", defaultEncounterType);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.


private Visit getTestVisit(Patient patient) {
List<Visit> visits = Context.getVisitService().getVisitsByPatient(patient);
if (visits.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need to test if visits is empty when you are dealing with visits in a known test dataset file?

private Encounter getTestEncounter(Patient patient) {
List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient);

if (encounters.isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.


Encounter encounter = encounters.get(0);

if (encounter.getEncounterType() == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To make these tests simpler, you can fetch a visit or encounter from the test dataset file, which you know is not null and has all the expected properties filled in.

@jwnasambu jwnasambu requested a review from dkayiwa November 25, 2025 22:10
}

private Encounter getTestEncounter(Patient patient) {
return Context.getEncounterService().getEncountersByPatient(patient).get(0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can make this test more efficient by directly fetching this encounter with EncounterService.getEncounter(id)

}

private Visit getTestVisit(Patient patient) {
return Context.getVisitService().getVisitsByPatient(patient).get(0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can make this test more efficient by directly fetching this encounter with VisitService.getVisit(id)

@jwnasambu jwnasambu requested a review from dkayiwa November 25, 2025 23:07
}

private Visit getTestVisit(Patient patient) {
List<Visit> visits = Context.getVisitService().getVisitsByPatient(patient);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What i mean is Context.getVisitService().getVisit(visitId)

}

private Encounter getTestEncounter(Patient patient) {
List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What i mean is Context.getEncounterService().getEncounter(encounterId)

@jwnasambu jwnasambu requested a review from dkayiwa November 26, 2025 08:54
@jwnasambu
Copy link
Copy Markdown
Contributor Author

@dkayiwa Kindly feel free to review my PR at your convinient time please!


private Bed createBed(String bedNumber) {
BedType bedType = new BedType();
bedType.setName("Test BedType");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't we just load this bed from the test dataset?


private Visit getTestVisit(Patient patient, Integer visitId) {
Visit visit = Context.getVisitService().getVisit(visitId);
assertNotNull(visit);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we know that this visit exists in the test dataset, then we do not need to assertNotNull.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In fact we do not need a method for this. The caller should just do Context.getVisitService().getVisit(visitId)


private Encounter getTestEncounter(Patient patient, Integer encounterId) {
Encounter encounter = Context.getEncounterService().getEncounter(encounterId);
assertNotNull(encounter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.


BedPatientAssignment assignment = new BedPatientAssignment();
assignment.setBed(bed);
assignment.setPatient(patient);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of doing all this, just have this data in the test dataset file and then it gets loaded as expected.

BedPatientAssignment assignment = new BedPatientAssignment();
assignment.setBed(bed);
assignment.setPatient(patient);
assignment.setEncounter(encounter);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review @dkayiwa. I am fixing the issue now.

<person person_id="678" gender="" birthdate="1975-06-30" birthdate_estimated="false" dead="false" creator="1" date_created="2005-01-01 00:00:00.0" changed_by="1" date_changed="2007-09-20 21:54:12.0" voided="false" void_reason="" uuid="6adb7c42-cfd2-4301-b53b-ff17c5654dd7"/>

<encounter encounter_id="1001" visit_id="1001" encounter_type="2" patient_id="1001" location_id="1" form_id="1" encounter_datetime="2008-08-01 00:00:00.0" creator="1" date_created="2008-08-18 14:09:05.0" voided="false" uuid="12345678-393b-4118-9c83-a3715b82d4de"/>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a patient with the ID 1001??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the point out. Though still fixing the change format issues with the help of Daniel

@chibongho
Copy link
Copy Markdown
Contributor

Sorry @jwnasambu , I'm taking over this ticket as we need it soon for an upcoming release. New PR here: #102. Closing this one.

@chibongho chibongho closed this Jan 6, 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.

4 participants