I’ve known about FHIRPath for some time, though I must admit I haven’t paid a lot of attention to it.

Put briefly, FHIRPath is a specification that describes how to identify (and potentially extract) data from a resource using a path based syntax. From the spec:

Of particular importance is the ability to easily and precisely express conditions of basic logic, such as those found in requirements constraints (e.g. Patients must have a name), decision support (e.g. if the patient has diabetes and has not had a recent comprehensive foot exam), cohort definitions (e.g. All male patients aged 60-75), protocol descriptions (e.g. if the specimen has tested positive for the presence of sodium), and numerous other environments.

with these features:

  • Graph-traversal: FHIRPath is a graph-traversal language; authors can clearly and concisely express graph traversal on hierarchical information models (e.g. HL7 V3, FHIR, vMR, CIMI, and QDM).
  • Fluent: FHIRPath has a syntax based on the Fluent Interface pattern
  • Collection-centric: FHIRPath deals with all values as collections, allowing it to easily deal with information models with repeating elements.
  • Platform-independent: FHIRPath is a conceptual and logical specification that can be implemented in any platform.
  • Model-independent: FHIRPath deals with data as an abstract model, allowing it to be used with any information model.

The reason I’ve taken a closer look is that I’m involved in a project where we want to be able to create a testing environment for data extracted from one type of message (HL7 V2), persisted in a store and then exposed as FHIR resources. I’m aware of course of the mapping language that could potentially perform this conversion directly, but this is more of a ‘black box’ test for the outcome of such a conversion regardless of how it was done, rather than a way to actually do it.

The approach we’re taking is to create a Logical model that expresses the information we are converting in an easy to visualize way, then for each element in the model use the map to describe where it came from, and where it appears. Eventually this should lead to automated end to end testing, but it is harder than you might think! However, if you can use this to create a view where a person can easily visualize where the data comes from and check that it is correct, then that is a step forward.

Take encounters for example.

Suppose we want to check the clinicians involved in the encounter – attending, referring and consultant. In our model we’ll create them as 3 different elements (because that is easy to understand, and then map them as follows:

  HL7 v2 FHIR
Attender PV1-7 Encounter.participant where the type is ‘ATND’
Referrer PV1-8 Encounter.participant where the type is ‘REF
Consultant PV1-9 Encounter.participant where the type is ‘CON

So the question was how to express the FHIR mapping? And FHIRPath seems to fit the bill nicely. (Note that in theory I could also use if for specifying the v2 maps – but I’m not aware of an implementation for this).

I don’t intend to repeat what is in the spec – smarter folk than I have described that and you can read it for yourself – and test it online using neat tool  here which uses the Javascript implementation of FHIRPath (and, not surprisingly the same one that I decided to use – thanks Nicola!)

So the paths for our clinicians becomes:

  • Attender: Encounter.participant.where(type.coding.code=’ATND’)
  • Referrer: Encounter.participant.where(type.coding.code=’REF’)
  • Consultant: Encounter.participant.where(type.coding.code=’CON’)

Because I think it’s a very useful way of diving into (and understanding) resources (and this includes Bundles of course) I decided to implement it in various places in clinFHIR. This wasn’t without its technical challenges, as I couldn’t get the library to run in the browser, which means that I needed to create a server (nodejs) based module, and pass the resource and path to it via HTTP to be evaluated server side. This has performance implications that I’d quite like to get rid of, but it does work. The other issue is that the library is not up to date with the current spec, so not all of it will work, but I’m hopeful that there will be an update soon…

So here are the places where you can use it in clinFHIR:

In the Patient Viewer, there’s a new tab after you’ve selected the patient that allows you to run a FHIRPath expression on either a single resource or the entire bundle of data for that patient (Select the Bundle tab to the upper right, then click ‘Show all’). Here’s an example that lists the names of all Conditions in the bundle:


It’s in 2 places in the Scenario Builder. In the middle pane you can enter expressions against the bundle that holds all the resources in the scenario. Here’s an example:


And if you view a single resource, then there’s a tab that runs expressions against that resource only – like this:


And finally in the Query tool, you can examine the bundle returned by a query:



Hope you find it useful!




About David Hay
I'm an independent contractor working with a number of Organizations in the health IT space. I'm an HL7 Fellow, Chair Emeritus of HL7 New Zealand and a co-chair of the FHIR Management Group. I have a keen interest in health IT, especially health interoperability with HL7 and the FHIR standard. I'm the author of a FHIR training and design tool - clinFHIR - which is sponsored by InterSystems Ltd.

2 Responses to FHIRPath

  1. Lloyd McKenzie says:

    You probably ought to check the coding.system too, not just the code.

Leave a Reply

%d bloggers like this: