On this page:

12.2Using FHIRPath

 

Realtime Export uses FHIRPath as its evaluation engine, which is likely to be unfamiliar to many people. While the official documentation is excellent, this page will serve as a set of examples that can be used in Realtime Export

For all of the following examples, we will be applying the FHIRPath expressions to this example Patient.

{
   "resourceType":"Patient",
   "id":"123",
   "meta":{
      "versionId":"1",
      "lastUpdated":"2020-09-15T18:38:07.182+00:00"
   },
   "identifier":[
      {
         "system": "http://example.org/mrn",
         "value": "123"
      },
      {
         "system": "http://example.org/person-id",
         "value": "456"
      }
   ],
   "gender":"male",
   "name":[
      {
         "family":"Scott",
         "given":[
            "Michael",
            "Gary"
         ]
      },
      {
         "family":"Levinson",
         "given":[
            "Astrid"
         ]
      }
   ],
   "address":[
      {
         "use":"home",
         "line":[
            "#4 Privet Drive",
            "Under the staircase"
         ],
         "city":"Little Whinging",
         "district":"Surrey",
         "postalCode":"ABC 123"
      }
   ]
}

Basics

The first thing to know is that all FHIRPath expressions always return collections of elements. For example, this expression:

Patient.name.given

Will return

["Michael", "Gary", "Astrid"]

This makes intuitive sense, as there are 3 given name elements. However, even if there were a single element, it would return it wrapped in a collection like this:

["Michael"]

For Realtime Export, the FHIRPath expressions must resolve to a single element. Refer to Collection Subsetting below for methods to mitigate this limitation.

12.2.1Collection Subsetting

 

first() method

Patient.name.given.first()
> ["Michael"]

last() method

Patient.name.given.last()
> ["Astrid"]

Index slicing

Patient.name.given[0]
> ["Michael"]
Patient.name.given[1]
> ["Gary"]

There are more methods which can handle subsetting, which are documented here.

12.2.2Self-referral

 

Occasionally you will need to refer to the full content of a previous given FHIRPath expression. For occasions like this, you can use the $this expression, which will cause the element to evaluate to itself. Consider the following snippet, which has a child transformer on each line of an address.

{
   "childTables": [
      {
         "fhirPath": "line",
         "tableName": "rte_patient_address_line",
         "childTransformer": {
            "columns": [
               {
                  "columnName": "line",
                  "fhirPath": "$this",
                  "columnType": "STRING"
               }
            ]
         }
      }
   ]
}

12.2.3Conditionals

 

In FHIR, often times you will be faced with a high cardinality element, but what do you do when you need a specific element in the collection, which you cannot safely index by its position in the list? In this case, FHIRPath supports use of the .where() function, which allows you to conditionally select from a collection:

Patient.identifier.where(system='http://example.org/mrn').value > ["123"]