Skip to main content

GET Observation

Overview​

The Observation API can be used to interact with Observation records for a patient. When querying for data it must always be in the context of a single patient.

  • Retrieving or searching for Observation records is performed using a HTTP GET described below.

Observation Retrieval​

id and _id​

The Observation resource can be retrieved directly if the id of the resource is known. By appending the id to the url will cause the Observation resource to be retrieved. Unlike all other retrieval queries, the response will be a single resource as opposed to a Bundle.

GET /Observation/{id}

An alternate method for retrieval is to make use of the _id search parameter. In this case, the result will be a Bundle. If the id is present the Bundle will contain a single Observation resource, otherwise, the Bundle will be empty.

GET /Observation?_id={id}

Query Parameters​

Unless retrieving an Observation resource by the use of id the subject must always be present. The Observation can only be targeted against a single patient at any one time.

Subject​

GET /Observation?patient=Patient/{id}

When searching for NHS Numbers use the system https://fhir.nhs.uk/Id/nhs-number. For example:

GET /Observation?patient.identifier=https://fhir.nhs.uk/Id/nhs-number|1234567890

All the search examples shown below will accept the patient parameter in either form.

Code​

When searching for Observations with a specific code the query can be constructed using different combinations of the code system and the code value.

GET /Observation?patient=[value]&code=[code]
GET /Observation?patient=[value]&code=[system]|[code]
GET /Observation?patient=[value]&code=|[code]
GET /Observation?patient=[value]&code=[system]|

For example to search for a BMI observation using SNOMED then a query would look like the following:

GET /Observation?patient=[value]&code=http://snomed.info/sct|60621009
tip

For further information consult the FHIR specification at http://hl7.org/fhir/STU3/search.html#token

In addition to searching for Observations with single codes, it is possible to construct a search using a predefined ValueSet that defines a collection of codes.

GET /Observation?patient=[value]&code:in=[ValueSet url]
note

The ValueSets that are available for this function will evolve over time. Speak to Graphnet if you intend to use this capability.

Date​

To search on the date an Observation was made the following search constructs can be used.

GET /Observation?patient=[value]&date=[value]

To improve searching the API supports the use of search modifiers. The modifiers supported for date are as below:

ModifierDescription
ltReturns dates less than the search term
leReturns dates less than or equal to the search term
gtReturns dates greater than the search term
geReturns dates greater than or equal to the search term
eqReturns dates equal to the search term
GET /Observation?patient=[value]&date=lt[value]
GET /Observation?patient=[value]&date=le[value]
GET /Observation?patient=[value]&date=gt[value]
GET /Observation?patient=[value]&date=ge[value]
GET /Observation?patient=[value]&date=eq[value]

So to search for an Observation on 23rd January 2021 the query would be:

GET /Observation?patient=[value]&date=2021-01-23

To search for all Observations before the 23rd December 2020 the query would be:

GET /Observation?patient=[value]&date=lt2020-12-23
tip

For more information on using FHIR search modifiers for dates, take a look at the FHIR STU3 standard at http://hl7.org/fhir/STU3/search.html#date

Identifiers​

To search for Observations using identifiers present on the Observation record, the following search constructs can be used.

GET /Observation?patient=[value]&identifier=[system]|[code]

For example:

GET /Observation?patient=[value]&identifier=http://acme.org/obsdata|21323-123213
tip

For further information consult the FHIR specification at http://hl7.org/fhir/STU3/search.html#token

Category​

To search for Observations classified by type, the following search constructs can be used.

GET /Observation?patient=[value]&category=[code]
GET /Observation?patient=[value]&category=[system]|[code]
GET /Observation?patient=[value]&category=|[code]
GET /Observation?patient=[value]&category=[system]|

Status​

The search for Observations by status the following construct can be used.

GET /Observation?patient={id}&status=final

Encounter​

If the Observation record was recorded with information relating to the clinical encounter that it was part of, then it can be retrieved using the id of that Encounter.

GET /Observation?patient={id}&encounter={id}

_lastUpdated​

To retrieve Observations based on the last updated date of the record.

GET /Observation?patient={id}&_lastUpdated={value}

To improve searching the API supports the use of search modifiers. The modifiers supported for date are as below:

ModifierDescription
ltReturns dates less than the search term
leReturns dates less than or equal to the search term
gtReturns dates greater than the search term
geReturns dates greater than or equal to the search term
eqReturns dates equal to the search term
GET /Observation?patient=[value]&_lastUpdated=lt[value]
GET /Observation?patient=[value]&_lastUpdated=le[value]
GET /Observation?patient=[value]&_lastUpdated=gt[value]
GET /Observation?patient=[value]&_lastUpdated=ge[value]
GET /Observation?patient=[value]&_lastUpdated=eq[value]

So to search for an Observation last updated on 23rd January 2021 the query would be:

GET /Observation?patient=[value]&_lastUpdated=2021-01-23

To search for all Observations last updated before the 23rd December 2020 the query would be:

GET /Observation?patient=[value]&_lastUpdated=lt2020-12-23

_summary​

Adding the _summary=count query parameter will change the behaviour of the query to return just the count of records, rather than the records themselves.

GET /Observation?patient={id}&_summary=count

This will return a response like:

{
"resourceType": "Bundle",
"type": "searchset",
"total": 15,
"id": "df23fd8b-d30c-47c6-a2bd-64c8a24b1166"
}

This can be added to any query construct.

_format​

The API supports both XML and JSON formats. The default format is JSON. The format can be requested either using HTTP headers or via the use of the _format query parameter as per the following table.

Format ValueAPI Response Format
xmlXML
text/xmlXML
application/xmlXML
application/fhir+xmlXML
jsonJSON
text/jsonJSON
application/jsonJSON
application/fhir+jsonJSON
GET /Observation?patient={id}&_format=[format value]

For example the query below would return a response in XML format.

GET /Observation?patient={id}&_format=xml

This can be added to any query construct.

Sort Parameters​

The default sort order for Observation records is in descending date order (i.e. most current first). The following sort parameters are also available.

Date​

GET /Observation?_sort=date
GET /Observation?_sort=-date

Paging​

_count​

The parameter _count is defined as a hint to the server regarding how many resources should be returned in a single page.

For example the query below would return a Bundle with 5 records per page.

GET /Observation?patient={id}&status={code}&_count=5

Examples​

Examples of payloads in both XML and JSON formats are available from the examples section of this site.