Missing "next" link in search bundle result

16 views
Skip to first unread message

Johanna Häusler

unread,
Jun 24, 2025, 4:22:24 AMJun 24
to HAPI FHIR
Hello,

I am running Hapi 6.10.0 in a docker with the hapi starter project (FHIR R4).

I currently face the issue that for some queries, the "next" link is missing even though more results would be present. Reproducing this on the official test system (http://hapi.fhir.org/baseR4) was not possible, mainly because the exact same query runs into a timeout.

This query returns me the desired 5 results including all "included" resources, but without a "next" link:
DiagnosticReport?_sort=date,_lastUpdated&status=registered,partial,preliminary,final,amended,corrected,appended,unknown&result:Observation.category=laboratory&result:Observation.status=corrected,final,amended&_include=DiagnosticReport:result&_include=DiagnosticReport:performer&_count=5

If I remove now the "_sort=date,_lastUpdated", then I also get 5 results including all "included" resources, but a next link is present:
DiagnosticReport?status=registered,partial,preliminary,final,amended,corrected,appended,unknown&result:Observation.category=laboratory&result:Observation.status=corrected,final,amended&_include=DiagnosticReport:result&_include=DiagnosticReport:performer&_count=5

I can tweak the query now and request 6 resources instead, then I run into the same problem again that the "next" link is missing. If the issue appears at a specific counter, all higher numbers also lead to that problem.
Tweaking the query further, without touching the _include parameters, always eventually ends up at a _counter number that runs into this problem again.

Furthermore this is a consistent behavior and 100% reproducible on my system - unfortunately I am not allowed to share the exact resources.

The only way to really get rid of the problem seems to be to remove the _include parameters from the query, then the "next" link seems to be returned correctly as far as I can tell.

I found a bug fix that sounds like it could be related to the issue: https://github.com/hapifhir/hapi-fhir/issues/5192

Is this problem already known? Has anybody an idea what could cause that issue?

Any input would be highly appreciated :)
Thanks and kind regards,
Johanna

Johanna Häusler

unread,
Jun 24, 2025, 5:55:47 AMJun 24
to HAPI FHIR
I think I found a bug here:

In the PersistedJpaSearchFirstPageBundleProvider (debugger screenshot from line 110), I want to have 5 entries (theToIndex), but the fromIndex is set to 4 with 2 remaining entries: One DiagnosticReport (match) and one Observation (included).
Already here the myIncludedResourcecount is set to 1 where only the ones from the current myResources == remaining are taken into account.

Stepping further to the ResponseBundleBuilder (debugger screenshot from line 167) we see that the actual retval contains 11 entries (5 DiagnosticReport resources (match) and 6 Observation resources (included)). The myIncludedResourceCount is still set to 1.

If we keep going to where we build the page in the ResponseBundleBuilder (debugger screenshot from line 128) we see that the myResources was properly updated to the 11 return entries, but the myIncludedResourceCount is not updated and still set to 1. With this information set, the page is built.

The actual problem arises then in the ResponsePage (debugger screenshot from line 207), where it is checked if a "next" link is present. Here we have this statement: myPageSize == myResourceList.size() + myOmittedResourceCount - myIncludedResourceCount
myPageSize = 5 - correct
myResourceList.size() = 11 - correct
myOmittedResourceCount = 0 - correct
myIncludedResourceCount = 1 - incorrect

So the calculation ends up as not equal and no "next" link is added to this page. If the myIncludedResourceCount was correctly set to 6 at the time when also the myResources was updated, then the calculation would be 5 == 5 and the next link would be added properly to the result.
ResponseBundleBuilder_L167_2.png
ResponseBundleBuilder_L128_3.png
ResponsePage_L207_4.png
PersistedJpaSearchFirstPageBundleProvider_L110_1.png

James Agnew

unread,
Jun 24, 2025, 7:37:49 AMJun 24
to Johanna Häusler, HAPI FHIR
Hi Johanna,

Version 6.10 is a fairly outdated version of HAPI FHIR - Are you able to reproduce this on the current GA version (8.2.0)?

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/c11faf42-be15-46e2-8a52-4faf06544368n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages