Skip to content

Conversation

@chibongho
Copy link
Contributor

@chibongho chibongho commented Sep 5, 2025

The isDuplicate check added to the transitionQueueEntry function was failing whenever we transition to the same queue, because the current active (un-ended) queue entry always overlaps the the new queue entry we attempt to create.

This PR fixes it by moving the isDuplicate check to after ending the current active queue entry. As the class is annotated as @Transitional, the current active queue entry should not have the end datetime set when the DuplicateQueueEntryException is thrown.

Testing done:

  • In O3, manually transition a patient to same queue (different status) to verify that the transition works.

catch (DuplicateQueueEntryException ex) {
assertNull(queueEntryService.getQueueEntryById(3).get().getEndedAt());
}
queueEntryService.transitionQueueEntry(transition);
Copy link
Member

Choose a reason for hiding this comment

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

This looks right to me (the pre-existing assertNull is not actually testing any aspect of transactionality, it is just testing whether that property was set before the exception occurred, so fine to remove that.

public void transitionQueueEntryShouldEndInitialIfNewIsNotDuplicate() {
QueueEntry queueEntry = queueEntryService.getQueueEntryById(1).get();
QueueEntry queueEntry = queueEntryService.getQueueEntryById(2).get();
assertNull(queueEntry.getEndedAt());
Copy link
Member

Choose a reason for hiding this comment

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

Why is this change needed? How is this related to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was not valid. Queue entry 1 is initialized to have a non-null endedAt datetime, so I changed it to another queue entry with no endedAt time to test that it gets ended properly after the transition.

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

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

Had a couple questions, but if it's working properly, feel free to merge.

if (isDuplicate(queueEntryToStart)) {
throw new DuplicateQueueEntryException("queue.entry.duplicate.patient");
}

Copy link
Member

Choose a reason for hiding this comment

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

Do we have tests/can we confirm that throwing this exception causes the "saveQueueEntry" listed above to be rolled back (which I think was what this fix was trying to achieve).

I would assumed it would be if the method is transactionally, but would be good to verify (which there is likely already a test for, just wanted to confirm).

Alternatively, could the isDuplicate check be changed to be smart enough to ignore the queueEntryToStop when checking for duplicates?

Copy link
Member

Choose a reason for hiding this comment

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

It is pretty difficult to test any real transactional behavior in our context-sensitive unit testing framework @mogoodrich . I don't think we really do so anywhere, across all of OpenMRS, to be honest, except in very limited cases

Copy link
Member

Choose a reason for hiding this comment

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

Fair... I guess, can we confirm manually at least that this works? Or just sanity check for me that's what is supposed to happen, correct? The PR wasn't showing enough to see whether there was a transactional annotation on the parent method (though I assume there was). It's just that if it doesn't work it defeats the whole purpose of the initial commit in the first place, if I'm understanding correctly.

Copy link
Member

Choose a reason for hiding this comment

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

@chibongho if you can manually test the webap and confirm that the original problem which was reported by @denniskigen is still fixed with these changes, i will approve this pull request. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Manually tested in RefApp version 3.6.0-SNAPSHOT with changes in PR:

  • Have a patient be put into 2 different queues ("Outpatient Consultation" and "Outpatient Triage")
  • In the O3 queues app, move entry of patient's "Outpatient Consultation" to "Outpatient Triage"

Verified that:

  • "Patient already in queue" shows in UI
  • Patient's existing queue entry (in "Outpatient Consultation") is NOT ended

@dkayiwa
Copy link
Member

dkayiwa commented Sep 8, 2025

@chibongho is it possible to also include a test reproducing the regression that was introduced?

@chibongho
Copy link
Contributor Author

@chibongho is it possible to also include a test reproducing the regression that was introduced?

@dkayiwa I just fixed that test. Turned out it was still wrong. I have verified that it passes with this fix and fails without.

@dkayiwa dkayiwa merged commit 31d34ff into main Sep 8, 2025
1 check passed
@dkayiwa dkayiwa deleted the O3-4985 branch September 8, 2025 18:21
@dkayiwa
Copy link
Member

dkayiwa commented Sep 8, 2025

Thank you so much @chibongho 👍

@denniskigen
Copy link
Member

denniskigen commented Sep 8, 2025

Thanks, all! @dkayiwa can we proceed to release a patch version of the queue module?

@dkayiwa
Copy link
Member

dkayiwa commented Sep 8, 2025

@denniskigen i already kick started the process but still flexing with the usual bamboo dances: https://ci.openmrs.org/browse/QM-QUEUE-47

@denniskigen denniskigen changed the title (fix) O3-4985 end current queue entry before checking whether it conf… (fix) O3-4985: End current queue entry when transitioning before checking for possible duplicates Sep 8, 2025
@dkayiwa
Copy link
Member

dkayiwa commented Sep 8, 2025

@denniskigen i have done the needful.

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.

6 participants