Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Feat) Implementation of _has parameter for patients #545

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

icrc-jofrancisco
Copy link

Description of what I changed

This feature extends the functionality of the _has parameter to support chained searches.

Users can now perform complex queries to retrieve resources based on specific relationships.
For now, only support for the groups/members relationship has been added. In the future, new resource types may be supported.

For example, the following query can be used to search for Patients resources who are members of a specific group

GET /openmrs/ws/fhir2/R4/Patient?_has:Group:member:id=<GROUP_ID>

several groups can be combined, not returning duplicate records:
GET /openmrs/ws/fhir2/R4/Patient?_has:Group:member:id=<GROUP_ID_1>,<GROUP_ID_2>

Example:

GroupA

  • Patient1
  • Patient2

GroupB

  • Patient3

GroupC

  • Patient1
  • Patient3

GET /openmrs/ws/fhir2/R4/Patient?_has:Group:member:id=<GROUP_A>
_returns Patient1, Patient2

GET /openmrs/ws/fhir2/R4/Patient?_has:Group:member:id=<GROUP_A>,<GROUP_B>
returns Patient1, Patient2, Patient3

GET /openmrs/ws/fhir2/R4/Patient?_has:Group:member:id=<GROUP_A>,<GROUP_C>
returns Patient1, Patient2, Patient3

HL7 FHIR documentation: section 3.2.1.6.6 Reverse Chaining

Issue I worked on

N/A

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

    Thanks,
    CC: @ibacher @denniskigen @icrc-psousa

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 84.84848% with 5 lines in your changes missing coverage. Please review.

Project coverage is 77.91%. Comparing base (c7f2ec2) to head (055c60d).
Report is 6 commits behind head on master.

Files Patch % Lines
.../module/fhir2/api/dao/impl/FhirPatientDaoImpl.java 78.26% 0 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #545      +/-   ##
============================================
+ Coverage     77.84%   77.91%   +0.06%     
- Complexity     2683     2719      +36     
============================================
  Files           239      239              
  Lines          7452     7537      +85     
  Branches        901      922      +21     
============================================
+ Hits           5801     5872      +71     
  Misses         1115     1115              
- Partials        536      550      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@delphinepas
Copy link

@denniskigen @ibacher would it be possible for you to review this PR ? Thank you cc @icrc-jofrancisco @icrc-fdeniger @gracepotma

@gracepotma gracepotma requested review from dkayiwa and removed request for denniskigen October 11, 2024 14:08
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Couple of small things. Also, changes like this require:

  1. A WebTest showing that the parameters passed to REST are processed correctly
  2. An integration test showing the whole thing works

In addition to the above, we should have a data-level test where the cohort has more than one member (ideally something like 4).

Comment on lines 166 to 173
private List<Integer> getGroupMemberIds(String groupId) {
Cohort cohort = groupDao.get(groupId);
if (cohort != null) {
return cohort.getMemberships().stream().map(CohortMembership::getPatientId).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we reformulate this as a subquery?

switch (hasParam.getTargetResourceType()) {
case FhirConstants.GROUP:
switch (hasParam.getReferenceFieldName()) {
case FhirConstants.INCLUDE_MEMBER_PARAM:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also have some sort of check for the :id part mentioned in the PR comments?

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