microsoft / microsoft/fhir-server

ImagingStudy API Returns Fewer Records Than Requested When Using _include

Open
#5,649 3 comments 0 reactions 0 assignees View on GitHub
Question
Dominant language
TSQL
Stars
1.4k
Forks
592
Avg merge
2d 7h
Merged PRs (30d)
41

Description

**Question**
We are encountering an issue with the ImagingStudy FHIR search API. The request includes _count to specify the number of ImagingStudy resources to be returned, along with _include parameters to fetch related resources and _elements to limit the returned fields.

https://test.com/ImagingStudy?_include=ImagingStudy:subject&_include=ImagingStudy:referrer&_total=accurate&_sort=-_lastUpdated&_elements=id,identifier,subject,name,gender,birthDate,modality,description,status,started,numberOfInstances,reasonReference,referrer,extension,location,resultsInterpreter&_count=10

**Observed behavior:**

When _count=10, the response contains only 5 total resources, including both ImagingStudy and the included resources. As a result, fewer ImagingStudy records are returned than expected.
When _count=20, only 10 ImagingStudy records are returned.
When _count=50, only 25 ImagingStudy records are returned.

It appears that the effective number of ImagingStudy resources returned is approximately half of the requested _count, while the remaining entries are the included subject and referrer resources.

**Expected behavior:**
The API should return the requested number of ImagingStudy resources as specified by _count, along with the corresponding included resources (subject and referrer) and the requested elements. This behavior was working correctly previously but has recently changed without any modifications to the request.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the ImagingStudy search request from the issue with _count and both _include parameters, then trace how search pagination counts primary and included resources. Done means the response contains the requested number of ImagingStudy resources while still returning the corresponding included resources and requested elements.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.