Batching GET Requests in FHIR

How do you get a total count for every resource type in your FHIR server?

Without making 145 GET requests.

I was looking into this last week for one of my own FHIR servers. Curiosity more than anything else, but I could see a genuine business case as well.

Maybe you’re using an off-the-shelf FHIR server and you haven’t locked down resources you’re not using. Maybe you’re worried that some resources are creeping into transaction bundles that shouldn’t be there.

Some unexpected Basic resources filled with extensions?

As cringe worthy as that sounds, it’s not unusual. Developers have a habit of using what they can.

So I looked into batching GET requests inside a single bundle and POSTing it to my server. I knew this was possible but I’d never done it before.

Here’s an example of two GET requests in a bundle.

Total counts for Patient and Encounter. I posted this to the HAPI test server and got a bundle back containing two bundles with a count for each one.

660,980 and 177,516 respectively.

I then wrote a few lines of code to generate a batch Bundle with 145 GET requests.

Here’s the bundle if you want to try it out on your own server.

I sent a POST request — with Bundle — to the HAPI and Firely test servers, as well as to my own Azure server.

All servers returned a correct response. A Bundle containing 145 Bundles, each with a count for the specific resource type.

  • 10 seconds for the HAPI server, with its millions of Observations
  • Under 1 second for the smaller Firely and Azure servers.

Far quicker than making 145 GET requests!

Discussion

---

Ways to Work With Me

Discover more from Darren Devitt

Subscribe now to keep reading and get access to the full archive.

Continue reading