A binary resource can contain any content, whether text, image, pdf, zip archive, etc.

0. References

There are situations where it is useful or required to handle pure binary content using the same framework as other resources. Typically, this is when the binary content is referred to from other FHIR Resources. Using the same framework means that the existing servers, security arrangements, code libraries etc. can handle additional related content. Typically, Binary resources are used for handling content such as:

  • PDF Documents
  • Images
  • HL7 Structured Documents (e.g. CDA or FHIR Documents)

Binary resources behave slightly differently to all other resources on the RESTful API. Specifically, when a read request is made for the binary resource that doesn’t explicitly specify the FHIR content types “application/fhir+xml” or “application/fhir+json”, then the content should be returned using the content type stated in the resource. e.g. if the content type in the resource is “application/pdf”, then the content should be returned as a PDF directly.

The HL7 specification states that “the intent is that unless specifically requested, the FHIR XML/JSON representation is not returned”. This behaviour is implemented in the Reference Implementation and would be expected of any standard implementation.

1. Read

Return a single Binary for the specified id.

All requests SHALL contain a valid ‘Authorization’ header and SHALL contain an ‘Accept’ header. The `Accept` header indicates the format of the response the client is able to understand, this maybe be one of the following application/json+fhir or application/xml+fhir, this will return the requested resource as FHIR Binary resource.

The Binary whill be returned in a native format (i.e. not contained within a FHIR resource) if no MIME type is not specified, an appropriate MIME type is included or a wild card (*/*) is included within the request header.

Common health related MIME types are listed below:

Image/Document Type MIME Type
html text/html
pdf application/pdf
dicom application/dicom
png image/png
jpg image/jpeg
FHIR Documents application/xml+fhir or application/json+fhir

Although this page is describing a FHIR Binary endpoint, a Binary resource can be retrieved from any url. If a FHIR Binary endpoint is used then the resource SHALL be available as both a Binary resource and as a standard URL resource. The default behaviour is that of a URL resource

1.1. Response

A full set of response codes can be found here API Response Codes. FHIR Servers SHALL support the following response codes:

200 successful operation
404 resource not found
410 resource deleted

The binary is not searchable as the other API resources are, however, please refer to DocumentReference for a mechanism to gain access to Binary information through a API.

3. Example

3.1 cURL

Return a Binary resource, the format of the response body will be xml. Replace ‘baseUrl’ with the actual base Url of the FHIR Server.

curl -X GET -H 'Accept: application/json+fhir' -H 'Authorisation: BEARER [token]' -v 'https://yellow.testlab.nhs.uk/ccri-fhir/STU3/Binary/5b1e91f0ccf84d0001fffe6d'

3.2 Explore the Response

Explore the response in XML & JSON on the Reference Implementation below

Reference Implementation

Direct link Binary unstructured document download