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

Pagination support #108

Open
bwalsh opened this issue Oct 20, 2021 · 6 comments
Open

Pagination support #108

bwalsh opened this issue Oct 20, 2021 · 6 comments

Comments

@bwalsh
Copy link

bwalsh commented Oct 20, 2021

Thanks for a great project. Enjoying working with it.

Unless I've missed it, I don't see support for:

Is this correct ?

@bwalsh
Copy link
Author

bwalsh commented Oct 20, 2021

A few more experiments reveals support for _count: just add it like any other parameter.

studies = [s for s in rs.ResearchStudy.where(struct={'_count':'1000'}).perform_resources(smart.server)]

@bwalsh
Copy link
Author

bwalsh commented Oct 26, 2021

Leaving this here in case it helps someone.

For our use case, we patched the underlying FHIRSearch.perform class to dispatch the search to multiple endpoints.
Note: the caller will need to formulate the list of api_bases
Pagination: The patch includes code to follow link results until all results are returned.

@ebrahimebrahim
Copy link

The comments here were very helpful for my project, thank you @bwalsh .

  • Including the _count parameter in the search struct is easy and works great. Thanks for pointing this out.
  • Paging can be be used manually by getting the bundle for your search via perform and then using the links in there to find the urls for the previous and next pages. In the case of the fhir server I was working with, the link to the next page showed up with the property "relation": "next". To follow the url, you can do smart.server.request_json(<url for next page>).

@anmolbhatia05
Copy link

@bwalsh @ebrahimebrahim Super helpful comments, thanks!

@bwalsh
Copy link
Author

bwalsh commented Dec 1, 2022

@anmolbhatia05 @ebrahimebrahim glad it helped

@enkaell
Copy link

enkaell commented Aug 5, 2023

I have some reservations about the current approach. We are potentially sacrificing runtime efficiency by transitioning from working with fhirclient.models.bundle.Bundle to a standard dictionary. This requires us to convert the Bundle into a dictionary or vice versa. As you can observe from my example:

bundle = Patient.where(struct={'_count': b'500'}).perform(smart.server)

bundle = smart.server.request_json(bundle.link[0].url)

while page := [page for page in bundle["link"] if "next" in page["relation"]]:
    page = smart.server.request_json(page[0]["url"])
    bundle = page

I am iterating over all pages in bundle by next link. I think there's should be another solution, otherwise raw requests are simpler and faster.

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

4 participants