#18. Not handling different data types for an [x] element

Many elements in FHIR resources allow different data types to be used. This is standard across most resources and is permitted for very good reasons. There is not always a single way to capture a piece of data, and some elements may genuinely need to capture data of different types.

Consuming applications can fail if they encounter a valid but unexpected data type in a FHIR resource. By fail, I mean a system crash or a generic on-screen error message.

Here are two examples that illustrate why different data types are sometimes permitted.

A ServiceRequest contains an occurrence element that is used to capture the date/time at which the requested service should occur. Three data types are allowed: dateTime, Period or Timing. The first captures a precise date and time (10:30 next Tuesday), the second an expected time period (09:00-13:00 on Monday), and the third an event that can occur multiple times (every half hour for one day).

For example: a procedure beginning at 10:30, a physiotherapy assessment that is expected to take place in the morning, or a blood pressure reading that should be taken every half hour.

Which data type is populated in these cases will depend on what the ServiceRequest is for, and also on what the data-providing application is configured and able to send.

I have seen cases where client applications failed in production because a small number of ServiceRequests contained a Period occurrence instead of the expected dateTime occurrence.

A second example is the Observation resource, where the value element can store one of many different data types. Eleven in FHIR R4, and thirteen in R5. Examples are Quantity, CodeableConcept, integer and string. By its nature, the Observation resource is expected to store diverse data in multiple different ways.

In most cases, the expected data type in an Observation will be dictated by the resource’s code element, which tells you what type of Observation it is. For example, a heart rate reading will contain a value of type Quantity, whereas a blood group will use a CodeableConcept.

What all this means for consuming applications is that they need to allow for expected data that comes in different formats – like the ServiceRequest time above. And they need to be able to manage a situation where a valid but unexpected data type is received – a blood group Observation stored as a string.

Applications should be tested against all allowed data types as defined in the FHIR standard, and not assume data types based on expectations.

---

Download my “FHIR Architecture Decisions” book

FHIR Weekly

Join 1,100+ business and technical leaders.