microsoft / microsoft/fhir-server
ExpressionParser.ParseInclude() for parameter value 'MedicationRequest:patient' returns SearchParameter not following the R4 and R5 spec
Nobody has claimed this yet.
- Dominant language
- TSQL
- Stars
- 1.4k
- Forks
- 592
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 41
Description
**Describe the bug**
ExpressionParser.ParseInclude() for parameter value 'MedicationRequest:patient' returns SearchParameter not following the R4 and R5 spec.
The expression.SearchParameter.TargetResourceType includes { Group, Patient } types.
However the spec specifies that 'MedicationRequest:patient' is of type Patient.
The likely reason for that is that MedicationRequest:subject is of type (Group | Patient) and MedicationRequest:patient is a subset of it.

[MedicationRequest (R5)](http://hl7.org/fhir/2020Sep/medicationrequest.html)
[MedicationRequest (R4)](http://hl7.org/fhir/medication.html)
This creates an issue in the _revinclude:iterate (WIP) implementation, which requires specifying target type in case there is more than one possible type. Otherwise throws BadRequest.
**To Reproduce**
Steps to reproduce the behavior:
1. run query: "MedicationRequest?_include:MedicationRequest:patient"
2. Debug and stop on this line in SearchOptionsFactory.cs:
var expression = _expressionParser.ParseInclude(parsedIncludeResourceType.ToString(), p.Item2, reversed, true);
3. See that expression.SearchParameter.TargetResourceTypes is of length 2 (Group, Patient) instead of Patient.
**Expected behavior**
The parsed expression.SearchParameter.TargetResourceTypes is of length 2 instead of 1
**Actual behavior**
expression.SearchParameter.TargetResourceTypes is of length 2 (Group, Patient) instead of Patient.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in SearchOptionsFactory.cs at the ParseInclude call shown in the report, then trace ExpressionParser.ParseInclude for the MedicationRequest:patient value. Reproduce the MedicationRequest?_include:MedicationRequest:patient query and verify that the resulting TargetResourceTypes contains only Patient, matching the R4 and R5 references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100