Storing files in a FHIR server

How do you store a file in FHIR?

A photo uploaded by a Patient. A PDF report written by a surgeon after a procedure. A document or image added to a QuestionnaireResponse.

Before you go looking for which resource or element to store it in ask yourself if your FHIR server is the right place.

If it’s an image captured during a procedure, it properly belongs in your DICOM server.

If you’re planning to store a lot of files, space and costs could quickly become an issue and an external storage location might be better.

If you’ve decided the file needs to go into your FHIR server, where is the best place to put it?

Start with the Attachment element.

Attachment can be used to store either the file itself or a link to that file if it’s stored elsewhere. Here are some FHIR resources that contain Attachments:

  • DocumentReference
  • Media
  • Communication
  • DiagnosticReport
  • QuestionnaireResponse

But let’s say you’re building a screen displaying QuestionnaireResponse results and one of your questions involves the user uploading a photo. You make a GET request that returns 20 QuestionnaireResponse resources and each one contains an answer with a file Attachment.

The last thing you want to see in those Attachments is a 10 megabyte image file, as the page load time would be crippling.

This is where the Binary resource becomes useful.

A Binary resource contains only the raw data in a file — nothing more.

By storing the file contents in a Binary resource, and linking to that resource from the Attachment.url of your QuestionnaireResponse, the GET request used to populate your screen returns all the required data apart from the file itself.

The file can be retrieved individually when required using the link to the Binary resource contained in the Attachment.

Some FHIR resources insist on the raw file staying with the resource itself — Provenance.signature for example. But in most other cases a link to a Binary resource can be used, separating the file from the resource that references it.

More about the Binary resource: https://hl7.org/fhir/R4/binary.html

More about the Attachment element: http://hl7.org/fhir/R4/datatypes.html#attachment

Discussion

---

Download my “FHIR Architecture Decisions” book

FHIR Weekly

Join 1,100+ business and technical leaders.

Discover more from Darren Devitt

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

Continue reading