LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects
https://linuxforhealth.github.io/FHIR
Apache License 2.0
330 stars 157 forks source link

Add method to fhir-client that will load subsequent pages of search request #2458

Open csandersdev opened 3 years ago

csandersdev commented 3 years ago

Is your feature request related to a problem? Please describe. In the FHIR client API, it isn't obvious how to retrieve the next page of results after processing the initial bundle returned by a search request.

Describe the solution you'd like I would like for there to be an API (e.g. loadPage) that takes in a bundle and returns a new bundle that is the result of traversing the "next" link in the input.

Describe alternatives you've considered It is possible to retrieve the next link by retrieving the link from the source bundle and then using getWebTarget().path( linkURL ).request().get(), but it requires you to first retrieve the Link and then to use the low-level JAX-RS client APIs to make the request. It would be clearer and easier for client applications if there was an API directly on the client that provided this function. This is something that the HAPI client provides in their API.

Acceptance Criteria

  1. GIVEN the client has executed a search request AND the bundle that is returned has a next link THEN client application can invoke client.loadPage(bundle) and get the next page of results

lmsurpre commented 3 years ago

I think it should support following any of the links in a bundle response...or at least the standard ones.

Something like: client.previous(Bundle) client.next(Bundle) and maybe client.self(Bundle)

I could imagine having client.first(Bundle) and client.last(Bundle) as well, although I don't think we send those links in our responses.

Alternatively, these could take a list of links instead of the whole Bundle. then you'd call it like client.next(bundle.getLink())

Alternatively, for something a little more versatile, we could support following whatever Bundle.Link the user passes: client.loadPage(bundle.getLink(), "next") client.load(bundle.getLink(), "next") client.follow(bundle.getLink(), "next") client.resolve(bundle.getLink(), "next") or force the client to pick out the specific link: client.loadPage(Bundle.Link) client.load(Bundle.Link) client.follow(Bundle.Link) client.resolve(Bundle.Link)

Or, something like this could be much more generic/powerful: client.resolve(Uri) client.fetch(Uri) client.dereference(Uri)

lmsurpre commented 3 years ago

We should ensure this works with our new history endpoint as well, maybe in conjunction with https://github.com/IBM/FHIR/issues/2686