Total Record count values

Hello,

If I use the following call it gives me a total of 15040:

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_revinclude=OrganizationAffiliation:primary-organization&_summary=count

If I use the following then the total field has a value of 15075:

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_revinclude=OrganizationAffiliation:primary-organization&_count=100&_offset=15000

I’m looking for the total number of elements in the entry array.
I think 15075 is the more accurate figure?

If so is it possible to obtain the 15075 value without paging through all the ‘next’ links until we get to the last page? As an example if I use the following there is no total field:

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_revinclude=OrganizationAffiliation:primary-organization&_count=100&_offset=14900

As side note: It’s really useful that the APIs provide previous and next links.

Thanks

Hi

The total of 15040, returned by your first API call, is the correct count for the number of organisations with the role RO177.

We can prove that by checking the response from your second API call:

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_revinclude=OrganizationAffiliation:primary-organization&_count=100&_offset=15000

Search in the response text for the string https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization/ and you will find that it appears 40 times. We have started from offset 15000 with this API call so 15000 + 40 = 15040.

The reason why a searchset total of 15075 appears in the response is because 35 OrganizationAffiliation records have come back in the response too (because of the _revinclude).

Search in the response text for the string https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/OrganizationAffiliation/ and you will see it appears 35 times.

This 15075 total is the 15040 count of Organization records with RO177 plus 35 OrganizationAffiliation records that are associated with the final 40 Organization records.

I am liaising further with our technical team to investigate why the searchset total is not present within all of the queries (i.e. when you change the offset). I will update you asap.

Thanks

Hi as140

I’ve been provided with some further information re searchset totals and counts:

Why the searchset total does not always appear

There is always a trade off for APIs in terms of speed vs. scope … there is cost to calculating the total number of possible results and the default behaviour is not to provide a total.

You can override this by adding an additional parameter _total=accurate (see https://hl7.org/fhir/R4/search.html#return)

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_revinclude=OrganizationAffiliation:primary-organization&_count=100&_total=accurate

Why changing the Offset changes the Total

This is a characteristic of the _revinclude … e.g. the total reported is the total of all the Organizations that match the search criteria + the OrganizationAffiliations included for the Organizations returned in the specific offset.

The total number of Organizations that match the search criteria is the same regardless of the offset (15040) … but the OrganizationAffiliations will vary depending on the Organizations in the current search offset window e.g. for the offset of 14989 it is 48 giving a total of 15088 (15040 + 48) … but for an offset of 15000 it is 35 giving a total of 15075 (15040 + 35).

The entries array is a searchset Bundle and the entries array size will vary by offset

A quick way of finding the total count from a search is to specify _count=0

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_count=0

or just _summary=count

https://sandbox.api.service.nhs.uk/organisation-data-terminology-api/fhir/Organization?roleCode=RO177&_summary=count

Many thanks, ODS

Thank you for your help and the detailed information.