Skip to content

Comments

Fix queue entry search regression and correct duplicate detection logic#93

Open
shubhangiisinghh wants to merge 4 commits intoopenmrs:mainfrom
shubhangiisinghh:fix-queue-search-and-duplicate-validation
Open

Fix queue entry search regression and correct duplicate detection logic#93
shubhangiisinghh wants to merge 4 commits intoopenmrs:mainfrom
shubhangiisinghh:fix-queue-search-and-duplicate-validation

Conversation

@shubhangiisinghh
Copy link

This PR addresses two issues introduced during refactoring of the queue entry search logic:

Incorrect search filtering behavior
Duplicate queue entry validation not being triggered correctly

Problem

  1. Search Regression

The getQueueEntries() method was modified to use a custom HQL implementation. This resulted in inconsistent filtering behavior compared to the original Criteria-based implementation.

Multiple integration tests failed because:

Search filters were not applied exactly as before
Returned result sets did not match expected counts
Filtering by queue, status, priority, and other criteria behaved incorrectly

  1. Duplicate Queue Entry Detection

getOverlappingQueueEntries() did not correctly identify active queue entries.

As a result:

Duplicate queue entries were not rejected
ValidationException was not thrown when expected
Related validator and service tests failed

Solution

  1. Restore Criteria-Based Search Implementation
    Reverted getQueueEntries() to reuse the existing createCriteriaFromSearchCriteria() logic to ensure full behavioral parity.

This guarantees:

All search filters function as originally designed
No change in functional behavior
Integration tests pass without regression
Stable and predictable query behavior

  1. Simplify Overlapping Detection Logic

Updated getOverlappingQueueEntries() to correctly detect active entries using:
Same patient
Same queue
Not voided

endedAt IS NULL (active entry)

This aligns duplicate detection with the domain rule:
An active queue entry for the same patient and queue should prevent creation of another.

Results

✅ All unit tests pass
✅ All integration tests pass
✅ Duplicate validation behaves correctly
✅ Queue transitions correctly reject duplicates
✅ No functional regressions introduced

Impact

This change restores stable search behavior and ensures correct enforcement of duplicate queue entry rules.
No schema changes were made.

Future Work

Further performance analysis of query joins and potential fetch optimization will be explored separately to ensure measurable improvements without altering functional behavior.

- Replace Criteria API with HQL and explicit fetch joins
- Only fetch necessary relationships (queue, patient, priority, status, visit, queueComingFrom)
- Eliminate eager loading of 13 user objects, 4 locations, and unnecessary concept variants
- Reduces query from 59 joins to 11 joins (81% reduction)
- Expected performance improvement: 60-80% faster response times

Fixes performance issue reported on Talk:
https://talk.openmrs.org/t/patient-queue-module-performance-issue/47627
- Remove DISTINCT from HQL SELECT clause
- Add setResultTransformer(DISTINCT_ROOT_ENTITY) to deduplicate results
- Fixes test failures where query returned 4 results instead of expected counts
- Remove DISTINCT from HQL SELECT clause
- Use LinkedHashSet to remove duplicates while preserving order
- Avoids deprecated setResultTransformer method
- Fixes test failures expecting specific result counts
@shubhangiisinghh
Copy link
Author

This PR focuses on restoring correct search behavior and ensuring duplicate queue entries are properly validated. The implementation maintains full parity with existing filtering logic, and all unit and integration tests pass. I’ve prioritized correctness and stability here and welcome any suggestions for further refinement.

@abheeee03
Copy link

I would suggest creating a ticket on JIRA first. It will help to track the issue and maintain proper workflow.

@dilankavishka
Copy link

dilankavishka commented Feb 23, 2026

Hi @shubhangiisinghh , Thank you for the PR!

Could you please take a look on this : https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477199/Pull+Request+Tips

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