Skip to main content

SQL on FHIR functions

The following functions are defined in the SQL on FHIR specification as additional FHIRPath functions for use within views. They produce keys that can be used to join the rows of one view to the rows of another.

The notation used to describe the type signature of each function is as follows:

[input type] -> [function name]([argument name]: [argument type], ...): [return type]

getResourceKey​

Resource -> getResourceKey() : String

Returns a key for the resource, in the form [type]/[id], e.g. Patient/123. The version of the resource is not part of the key.

Example:

getResourceKey()

getReferenceKey​

collection<Reference> -> getReferenceKey(type?: TypeSpecifier) : collection<String>

For each Reference in the input collection, returns a key that is equal to the getResourceKey() value of the resource that it refers to.

If a type is given, only references to resources of exactly that type produce a key. For example, getReferenceKey(Person) returns an empty collection for a reference to RelatedPerson/r1.

The key is derived from Reference.reference:

ReferenceKeyJoins to getResourceKey()
Patient/123Patient/123Yes
Patient/123/_history/2Patient/123Yes
http://example.org/fhir/Patient/123Empty collectionNo
#p1 (contained resource)Empty collectionNo
urn:uuid:9d0a6e7c-...Empty collectionNo
Not present (identifier only)Empty collectionNo

A version-specific reference joins to whichever version of the resource is present in the data. The version named in the reference is not checked.

Only relative references produce a key, as absolute, contained and URN references can never equal a resource key. A reference whose id or version contains characters outside the FHIR id character set (A-Z, a-z, 0-9, - and .) also produces an empty collection.

Example:

subject.getReferenceKey(Patient)