FHIR Extensions and Primitive Data Types

If you work with FHIR you use extensions.

An extension “extends” or enhances a resource or a data element in a custom way.

They can be added to the root of a resource, like “Patient.ethnicity” in US Core. And they can be added to individual elements such as HumanName, Address or Identifier.

But did you know that you can also add an extension to a primitive data type?

Primitives are the most basic element in FHIR and usually store a single item. Here are some examples:

  • 123
  • “Darren”
  • false
  • 01/02/1974

In the Patient resource the patient’s “birthDate” and “deceased ” state are stored as primitives — a date and a boolean.

Here’s what that looks like as a JSON resource.

How do you add an extension to birthDate or to deceased?

You create a second attribute of the same name prefixed with an underscore. The underscore tells FHIR that you’re accessing the underlying base Element for the primitive data type.

All elements in FHIR inherit or descend from the base element. It contains two attributes: extension and id.

In the example below I added a “Time of year” extension to birthDate and an “Is a zombie” extension to deceasedBoolean.

I also added one more attribute to the base Element for both — an Id.

We’ve all seen and used the Id element at the FHIR resource level. You can also add an Id to every element in FHIR — even primitives such as birthDate.

This is not something most FHIR users are aware of.

When it comes to primitives, SDKs often hide the underlying base element and its two attributes from us or make it difficult to find.

More about FHIR’s base Element: http://hl7.org/fhir/R4/element.html

Discussion

---

Download my “FHIR Architecture Decisions” book

Discover more from Darren Devitt

Subscribe now to keep reading and get access to the full archive.

Continue reading