microsoft / microsoft/fhir-server
Support recursive _include:iterate and _revinclude:iterate queries
- Dominant language
- TSQL
- Stars
- 1.4k
- Forks
- 592
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 41
Description
**User story**
As a user, I want to recursively iterate results so that there's no need to use multiple _include/_revinclude search parameters in order to iterate circular references.
According to the spec, recursive calls allow recursively iterating over circular references.
For example:
* Observation?_include:iterate=Observation:derived-from --> here derived-from is a reference of type Observation
* Organization?_revinclude:iterate=Organization:partof --> similarly, partof is a reference of type Observation
* CareTeam?_include=CareTeam:participant&_include:iterate=Patient:general-practitioner --> Here, there's a 'hidden' recursion since CareTeam:participant can reference multiple resource types, including CareTeam.
A question was submitted on the chat.fhir.org discussion: https://chat.fhir.org/#narrow/stream/179166-implementers/topic/_include.3Aiterate.20recursive.20iteration/near/211691246
The recursive implementation can be handled similarly. to the way multiple result sets are implemented, using a recursive call to the Visit and writing the include limit cte.
**Acceptance criteria**
1. When I do _include/_revinclude:iterate on circular references, the results are included recursively and the correct results are returned. The search parameter can be at any part of the search query.
2. The recursion depth is limited to avoid performance issues
3. Each recursive iteration result should be limited by a configurable MaxCount (preferably, use the same Include limit)
Contributor guide
Research direction
Start by locating the Visit path and the existing multiple-result-set implementation, then trace how the include limit CTE is written. Check how _include and _revinclude parameters are processed, including circular references and search parameters appearing anywhere in the query. Done means recursive results are returned with bounded recursion and each iteration respects the configurable MaxCount/include limit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql
- Domain
- api, backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100