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

Bundle.total not returned on searchset with parameter _count=x #701

Closed
MatthewThomasTiani opened this issue Jun 19, 2024 · 1 comment
Closed

Comments

@MatthewThomasTiani
Copy link

MatthewThomasTiani commented Jun 19, 2024

Hi,

We are testing this fhir server on version 7.2.0 and have found that when a SEARCH interaction is sent including the query parameter '_count' then there is no Bundle.total value returned in the response.

Here is the request parameters without the _count
----------------------------REQUEST--------------------------- queryString= http:https://visuapps3:8080/SpiritFhirServer/fhir/Observation?patient=http:https://visuapps3:8081/SpiritPIXFhir/r4/Patient/Q0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ&category=laboratory&_revinclude=Provenance:target&_format=json method=GET HEADERS: Accept-Charset: utf-8, Accept: application/fhir+json;q=1.0, application/json+fhir;q=0.9, User-Agent: HAPI-FHIR/5.7.9 (FHIR Client; FHIR 4.0.1/R4; apache), Accept-Encoding: gzip, X-Forwarded-prefix: SpiritQEDMFhir/r4, PARAMETERS: patient=http:https://visuapps3:8081/SpiritPIXFhir/r4/Patient/Q0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ category=laboratory _revinclude=Provenance:target _format=json

This returns:
{ "resourceType": "Bundle", "id": "93d1774d-02b9-4049-a4bf-c672e633bb31", "meta": { "lastUpdated": "2024-06-19T08:50:37.982+01:00" }, "type": "searchset", "total": 16, "link": [ { "relation": "self", "url": "http:https://visuapps3:8080/SpiritQEDMFhir/r4/Observation?_format=json&_revinclude=Provenance%3Atarget&category=laboratory&patient=http%3A%2F%2Fvisuapps3%3A8081%2FSpiritPIXFhir%2Fr4%2FPatient%2FQ0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ" } ], "entry": [ { "fullUrl": "http:https://visuapps3:8080/SpiritQEDMFhir/r4/Observation/46376027-5f7d-45fa-9158-5ef8f2de59b9",

All working as expected...

Now with the addition of the _count parameter
----------------------------REQUEST--------------------------- queryString= http:https://visuapps3:8080/SpiritFhirServer/fhir/Observation?patient=http:https://visuapps3:8081/SpiritPIXFhir/r4/Patient/Q0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ&_count=10&category=laboratory&_revinclude=Provenance:target&_format=json method=GET HEADERS: Accept-Charset: utf-8, Accept: application/fhir+json;q=1.0, application/json+fhir;q=0.9, User-Agent: HAPI-FHIR/5.7.9 (FHIR Client; FHIR 4.0.1/R4; apache), Accept-Encoding: gzip, X-Forwarded-prefix: SpiritQEDMFhir/r4, PARAMETERS: patient=http:https://visuapps3:8081/SpiritPIXFhir/r4/Patient/Q0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ _count=10 category=laboratory _revinclude=Provenance:target _format=json
This returns:
`--------------------------RESPONSE--------------------------
status= 200
HEADERS:
date: Wed, 19 Jun 2024 10:33:34 GMT,
x-request-id: h7QvWZieFyfg7Ips,
last-modified: Wed, 19 Jun 2024 10:33:34 GMT,
transfer-encoding: chunked,
x-powered-by: HAPI FHIR 7.2.0 REST Server (FHIR Server; FHIR 4.0.1/R4),
content-type: application/fhir+json; charset=UTF-8,
connection: keep-alive,

{
"resourceType": "Bundle",
"id": "9becca21-9c11-44f4-a372-4c57ee222b99",
"meta": {
"lastUpdated": "2024-06-19T11:33:34.270+01:00"
},
"type": "searchset",
"link": [ {
"relation": "self",
"url": "http:https://visuapps3:8080/SpiritQEDMFhir/r4/Observation?_count=10&_format=json&_revinclude=Provenance%3Atarget&category=laboratory&patient=http%3A%2F%2Fvisuapps3%3A8081%2FSpiritPIXFhir%2Fr4%2FPatient%2FQ0RSLjE3MTUyNzAzMjI0NDA4JjEuMy42LjEuNC4xLjIxMzY3LjEzLjIwLjIwMDAuMQ"
}, {
"relation": "next",
"url": "http:https://visuapps3:8080/SpiritQEDMFhir/r4?_getpages=9becca21-9c11-44f4-a372-4c57ee222b99&_getpagesoffset=10&_count=10&_format=json&_pretty=true&_bundletype=searchset"
} ],
"entry": [ {
"fullUrl": "http:https://visuapps3:8080/SpiritQEDMFhir/r4/Observation/2d304508-39a8-4b3c-8294-9eab511cc313"`

From the FHIR specification it suggests that there should always be a Bundle.total on a '"type": "searchset"' - http:https://hl7.org/fhir/R4/bundle.html

Any help would be appreciated

@jamesagnew
Copy link
Contributor

The Bundle.total is not included unless the server knows it.

If you perform a search with _count the server will not try to fetch more data than it needs, and if it does not exhaust the available search results from the DB it may not know the total by the time it's done loading the first page. If your search for Patient?name=smith matches 40 Patients for example, and your default page size is 50 then a search with no count will fetch all 40 and the server knows the total by the end of fetching the first page. On the other hand, if you specify a count of 10, the server will fetch 10 and it won't know how many more pages are available when it returns the first page. If you keep paging through the results, eventually it will exhaust the available results and the total will show up.

You can force a COUNT query by specifying _total=accurate , which will affect performance negatively on large resultsets so think about whether you really need the count before doing this.

(Note also: Please don't use GitHub issues to ask questions about HAPI FHIR. See Getting Help for more information on where to ask for help)

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

No branches or pull requests

2 participants