GETtting all results from REST API returns empty array

For some reason REST calls for fetching all results return empty array, ie

/openmrs/ws/rest/v1/patient?q=John

correctly returns one patient, John Max, but when I call

/openmrs/ws/rest/v1/person

It returns nothing.

This is by design. The underlying Java API doesn’t actually support getting all patients at once because we thought it would perform badly, overload the server, and encourage bad patterns of data access at any scale.

(Conceivably it would be worth adding a paged version of that call though.)

You can get the IDs of all patients using the reporting and reportingrest modules (though I don’t think this is really documented anywhere).

Ok, so I believe the wiki needs an update: https://wiki.openmrs.org/display/docs/REST+Web+Service+Resources+in+OpenMRS+1.9#RESTWebServiceResourcesinOpenMRS1.9-Patient

In general, almost all other sections describe the api call without any parameters as “fetching all results”.

Good point.

Hopefully those who are working on documentation of our REST web services this summer will note this conversation!

Ok, but is there any ‘easy’ way to modify that behaviour?

I’m writing R package to do some analytics on my data, which require importing data of all patients from OpenMRS.

The REST API should either return an error (e.g., HTTP 400 Bad Request) or return all resources paginated. Returning an empty set is misleading/confusing.

Pagination

We should have a standard mechanism for paging results that can easily be used by modules extending the REST API with new resources, so clients get consistent behavior across all resources.

The server should have a max number for any resource. It would be preferable for consistency to have a max number that applied across all resources (e.g., 100). While we could support the ability for clients to define smaller page sizes, they should be able to override the server’s max page size.

1 Like