How can you get the latest observation by patient and concept ID from REST Web Services Module?

Application Name: Platform Version Number: 2.0

Background: I’m trying to get the latest observation by patient UUID and Concept UUID using the REST Web Services API.

I’m testing on int02 and have two vitals encounters where I collect the “Temperature ©” concept (id/UUID: 5088/5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) for the “Darius Manual Test” patient (patient UUID: 10c20de9-4606-40b1-b2a9-b7ba53410120)

The following CURL request returns two observations for this concept:

curl -X GET --header 'Accept: application/json' -u admin:Admin123 'http://int 02.openmrs.org/openmrs/ws/rest/v1/obs?patient=10c20de9-4606-40b1-b2a9-b7ba53410 120&concept=5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'

Response:

{ "results": [{ "uuid": "d292c562-a7b4-4709-a6f7-c627eef35169", "display": "Temperature (C): 37.0", "links": [{ "rel": "self", "uri": "http://int02.openmrs.org/openmrs/ws/rest/v1/obs/d292c562-a7b4-4709-a6f7-c627eef35169" }] }, { "uuid": "9acdab1f-ab33-4cc3-b606-58b95c1d62a2", "display": "Temperature (C): 40.0", "links": [{ "rel": "self", "uri": "http://int02.openmrs.org/openmrs/ws/rest/v1/obs/9acdab1f-ab33-4cc3-b606-58b95c1d62a2" }] }] }

I would like to return the latest observation only.

Questions:

  1. Is the order of observations guaranteed to return the latest observation always? For example, if I add &limit=1&startIndex=1 will I always get the latest observation?
  2. If the answer to number 1 is ‘no’ is there a url parameter I can use to get the latest observation? (I know bahmni uses &scope=latest, but I don’t know if this is available in OpenMRS)

Thanks! Craig

Hi @craigappl, Question 1: Yes Adding &limit=1 or &limit=1&startIndex=0 would give the desired result. Please refer “Limiting the number of results, and paging” section in OpenMRS WIKI