Total Record/count FHIR endpoint / List data pagination implementation approach


We have a requirement to paginate list data in the OHRI widgets / tables that display it. We are experimenting an implementation approach but this requires that we know the total count/number of records before hand in order to paginate. Looked around the FHIR documentation but can’t seem to see any endpoint that returns the total count of say the Encounter Resource given certain filter criteria.

Do we have any such endpoint? Secondly, any ideas on implementation approaches to paginate list data in the micro-frontends?

@samuel34 @ssmusoke @alaboso @eudson @vineeth68 @dkayiwa @ibacher

Is it fair to assume filter criteria are simple and are indexed in the database. Returning a total count for arbitrary criteria, complex filters, or criteria that include data that aren’t indexed would not perform well in existing systems that have hundreds of thousands or millions of encounters.

1 Like

Yes, all FHIR search endpoints return paginated list data. Probably, we haven’t done a good job documenting. Get more insights from the initial implementation here.

Things(GPs configuration) to take note of:

  1. Paging default - Sets the default page size
  2. Paging maximum - Sets the maximum page size

For example; A paginated list of vital data. From the first request, you will be able to know the total size of resources, and links (next & prev)



            "display":"Resource encoded in summary mode"
      //Omitted entries

Most of the microfrontend widgets don’t utilize backend paging.

1 Like

As a general principle, we haven’t documented things where we’re just conforming to the FHIR spec. As @corneliouzbett pointed out, there is a total element in all search bundles. While not strictly required by the spec, it is returned for all searches for OpenMRS. If you want to know just the total, you can run the query with ?_summary=count as noted in the FHIR search document.

By default, the FHIR2 API returns 10 results (this can be changed via the fhir2.paging.default). You can request more resources by using the _count=... search parameter (also documented in the FHIR search documentation) up to the value of the fhir2.paging.maximum global property (which defaults to 100).

This is a very important consideration and the FHIR2 search API can easily be abused to create a pathological query.

Strictly speaking, most frontend widgets are unaware that they are only using paged results and don’t properly handle things :slight_smile:.

1 Like

@ibacher @corneliouzbett noted with thanks