Did you get pagination in FHIR right on your first try?

If it was your team’s first FHIR project, chances are you didn’t.

Many devs new to FHIR come with experience of regular databases. They think FHIR works the same way.

They’ll try constructing their own query URL for Next and Previous, then start pulling their hair out when it doesn’t work.

Confession: I was that guy!

So how do you do pagination when you want to populate a screen filled with query results from a FHIR server?

1 – Get that first page of results:

/Encounter/?_count=20&_total=accurate

2 – Read the returned bundle’s ‘Link’ URLs for ‘self’, ‘next’ and ‘previous’.

3 – Use these URLs to build your Next and Previous links.

4 – Save the ‘total’ and use it to calculate and populate your resource counts. (21-40 of 361)

That’s it.

But not always!!

The above will only work if the FHIR server implements the total resource count, and populates the self, next and previous attributes. Many don’t.

More: https://www.hl7.org/fhir/http.html#paging

Discussion

---

Sign up to “The Tuesday FHIR Sessions” and receive an email every Tuesday where I go deep on a single FHIR topic.