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

Implement _revinclude on Search API #1947

Closed
ellykits opened this issue Apr 3, 2023 · 0 comments · Fixed by #1978
Closed

Implement _revinclude on Search API #1947

ellykits opened this issue Apr 3, 2023 · 0 comments · Fixed by #1978
Assignees
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue type:enhancement New feature or request

Comments

@ellykits
Copy link
Collaborator

ellykits commented Apr 3, 2023

Is your feature request related to a problem? Please describe.
Implement _revinclude on the client Search API. This should cause the search response to include resources (that have a relationship to the primary resources) in the returned result.

Describe the solution you'd like
Implement a new function (Search#include) like the Search#has function in the search DSL that should cause the search response to include resources that have a relationship with the primary resource in the returned search result.

Describe alternatives you've considered
None that is related to using existing functionality on the search DSL. I however contemplated running two queries i.e. run a query to fetch the primary resources, then run a custom SQL query (not supported) that uses SQL UNION against the ReferenceIndexEntity table to fetch the accompanying resources for each of the primary resource. The example below fetches accompanying resources (Tasks, Conditions and CarePlan) for the Patient referenced with id Patient/fee261ad-4e90-4054-9cd3-906a60362c59.

NOTE: The custom query in this proposal CANNOT work with the current Search API as the functionality for running custom queries does not exist

SELECT re.serializedResource
FROM ReferenceIndexEntity ref
INNER JOIN ResourceEntity re on ref.resourceUuid = re.resourceUuid
WHERE ref.resourceType = 'Task'
  AND index_name = 'subject'
  AND index_value = 'Patient/fee261ad-4e90-4054-9cd3-906a60362c59'
UNION  ALL
SELECT re.serializedResource
FROM ReferenceIndexEntity ref
INNER JOIN ResourceEntity re on ref.resourceUuid = re.resourceUuid
WHERE ref.resourceType = 'Condition'
  AND index_name = 'subject'
  AND index_value = 'Patient/fee261ad-4e90-4054-9cd3-906a60362c59'
UNION  ALL
SELECT re.serializedResource
FROM ReferenceIndexEntity ref
INNER JOIN ResourceEntity re on ref.resourceUuid = re.resourceUuid
WHERE ref.resourceType = 'CarePlan'
  AND index_name = 'subject'
  AND index_value = 'Patient/fee261ad-4e90-4054-9cd3-906a60362c59';

Additional context
The implementation for this function should be close to Search#has for instance in this example:
Fetch all Patients with Condition Diabetes, Search#has would return just the Patient resources with the Condition, whereas the new function should also include the Conditions in the result.
See Search parameter's _revinclude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:medium Medium effort - 3 to 5 days P1 High priority issue type:enhancement New feature or request
Projects
Status: Complete
4 participants