NHS Digital FHIR Implementation Guide (Retired - 2.1.50)

This guidance is under active development by NHS Digital and content may be added or updated on a regular basis.

NHSDigital-MessageHeader

Conformance url
https://fhir.nhs.uk/StructureDefinition/NHSDigital-MessageHeader


with MessageHeader

idΣ0..1string
metaΣ0..1Meta
implicitRulesΣ ?!0..1uri
language0..1codeBinding
text0..1Narrative
contained0..*Resource
replacementOfS I0..1Extension(Identifier)
modifierExtension?! I0..*Extension
id0..1string
extensionI0..*Extension
systemΣ1..1uri
versionΣ0..1string
codeΣ1..1code
displayΣ0..1string
userSelectedΣ0..1boolean
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
nameΣ0..1string
targetΣ I0..1Reference(Device)
endpointΣ1..1url
id0..1string
receiverLocalPartI0..1Extension(Reference(NHSDigitalHealthcareService | NHSDigitalPractitionerRole | NHSDigitalPractitioner))
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
senderLocalPartI0..1Extension(Reference(NHSDigitalHealthcareService | NHSDigitalPractitionerRole | NHSDigitalPractitioner))
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
entererΣ I0..1Reference(NHSDigitalPractitionerRole | NHSDigitalPractitioner)
id0..1string
extensionI0..*Extension
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
nameΣ0..1string
softwareΣ0..1string
versionΣ0..1string
contactΣ I0..1ContactPoint
endpointΣ1..1url
id0..1string
extensionI0..*Extension
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
extensionI0..*Extension
id0..1string
extensionI0..*Extension
systemΣ1..1uri
versionΣ0..1string
codeΣ1..1code
displayΣ0..1string
userSelectedΣ0..1boolean
textΣ0..1string
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
identifierΣ1..1id
codeΣ1..1codeBinding
detailsΣ I0..1Reference(OperationOutcome)
id0..1string
extensionI0..*Extension
referenceΣ I1..1string
typeΣ0..1uriBinding
identifierΣ0..1Identifier
displayΣ0..1string
definitionΣ0..1canonical(MessageDefinition)

from MessageHeader

idΣ0..1string
metaΣ0..1Meta
implicitRulesΣ ?!0..1uri
language0..1codeBinding
text0..1Narrative
contained0..*Resource
replacementOfS I0..1Extension(Identifier)
modifierExtension?! I0..*Extension
id0..1string
extensionI0..*Extension
systemΣ1..1uri
versionΣ0..1string
codeΣ1..1code
displayΣ0..1string
userSelectedΣ0..1boolean
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
nameΣ0..1string
targetΣ I0..1Reference(Device)
endpointΣ1..1url
id0..1string
receiverLocalPartI0..1Extension(Reference(NHSDigitalHealthcareService | NHSDigitalPractitionerRole | NHSDigitalPractitioner))
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
senderLocalPartI0..1Extension(Reference(NHSDigitalHealthcareService | NHSDigitalPractitionerRole | NHSDigitalPractitioner))
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
entererΣ I0..1Reference(NHSDigitalPractitionerRole | NHSDigitalPractitioner)
id0..1string
extensionI0..*Extension
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
nameΣ0..1string
softwareΣ0..1string
versionΣ0..1string
contactΣ I0..1ContactPoint
endpointΣ1..1url
id0..1string
extensionI0..*Extension
referenceΣ I0..1string
typeΣ0..1uriBinding
id0..1string
extensionI0..*Extension
useΣ ?!0..1codeBinding
typeΣ0..1CodeableConceptBinding
systemΣ1..1uri
valueΣ1..1string
periodΣ I0..1Period
assignerΣ I0..1Reference(Organization)
displayΣ0..1string
id0..1string
extensionI0..*Extension
id0..1string
extensionI0..*Extension
systemΣ1..1uri
versionΣ0..1string
codeΣ1..1code
displayΣ0..1string
userSelectedΣ0..1boolean
textΣ0..1string
id0..1string
extensionI0..*Extension
modifierExtensionΣ ?! I0..*Extension
identifierΣ1..1id
codeΣ1..1codeBinding
detailsΣ I0..1Reference(OperationOutcome)
id0..1string
extensionI0..*Extension
referenceΣ I1..1string
typeΣ0..1uriBinding
identifierΣ0..1Identifier
displayΣ0..1string
definitionΣ0..1canonical(MessageDefinition)

keyhumanseverityexpression
nhsd-11replacementOf extension is required for update messageswarningevent.code.where(substring($this.length()-6) = 'update').exists().not() or (event.code.where(substring($this.length()-6) = 'update').exists() and extension('https://fhir.nhs.uk/StructureDefinition/Extension-replacementOf').exists())


The header for a FHIR Message exchange that is either requesting or responding to an action. The reference(s) that are the subject of the action as well as other information related to the action are typically transmitted in a bundle in which the MessageHeader resource instance is the first resource in the bundle.

Messaging middleware systems are expected to use this MessageHeader resource to route, deliver and handle messages correctly.

This profile is not tied to any specific transport/API requirement or clinical requirement. Intermediaries are not expected to perform detailed routing on clinical content. Some clinical information will be required for routing purposes and this will be held within eventCoding and reason sections as discussed in the Message Event section below. In circumstances where more detailed information is required for routing this MUST be carried in the relevant FHIR Resource in the payload only. For example, document types should be recorded in FHIR DocumentReference.type and health service/specialty type can be recorded in FHIR Encounter.serviceType or DocumentReference.context.practiceSetting.

Systems involved in NHSDigital/UKCore messaging are expected to support this profile only, extensions or derived profiles are permitted but they may only have limited (internal) scope and will not be supported outside of this scope (e.g. externally). This resource SHOULD NOT be profiled to further define the contents of the resources and FHIR MessageDefinition MUST be used instead.

eventCoding

The main message type is held in the mandatory eventCoding section which can be subdivided by the optional reason codes.

The ValueSet set for eventCoding is NHSDigital-Message-Events Every code MUST have a corresponding MessageDefinition.

For example the event code dispense-notification has a MessageDefintion of https://fhir.nhs.uk/MessageDefinition/pharmacy-dispense. This definition lists the profiles and cardinality of the resources in the message. eventCoding and MessageDefintion define the structure of the message.

"eventCoding": {
  "system": "https://fhir.nhs.uk/CodeSystem/message-event",
  "code": "dispense-notification",
  "display": "Dispense Notification"
}

reason

The ValueSet set for reason is Message-Reason-Codes. reason can be used to subdivide eventCoding. In the example below, cancel is used to indicate the specific reason for the event prescription-order-update. The physical cancellation would be the status=cancelled in the MedicationRequest reason, the reason is a hint.

"reason": {
  "coding":  [
    {
      "system": "https://fhir.nhs.uk/CodeSystem/message-reason-prescription",
      "code": "cancel",
      "display": "Cancel"
    }
  ]
}

status (extension)

A code from the message-status-vs ValueSet

replacementOf (extension)

If the message is an update or replaceOf a previous message, then this extension should reference the replaced FHIR Message (Bundle.identifier).

"extension": [
    {
        "url": "https://fhir.nhs.uk/StructureDefinition/Extension-replacementOf",
        "valueIdentifier": {
            "system": "https://tools.ietf.org/html/rfc4122",
            "value": "334a3195-1f6c-497a-8efe-d272ca9c4e38"
        }
    }
],

identifiers and message timings

FHIR messages have two identifiers: the messageIdentifier of the Message (Bundle.identifier) and a messageId (Bundle.id) which is used in each transport channel . The messageId should be unique within a each message channel/stream. Whenever a message is resent, the messageIdentifier of the Bundle remains the same, but the messageId may change. The response message has its own unique messageIdentifier, the messageIdentifier of the request message can be referenced in the MessageHeader.response.identifier element.

The Bundle.identifier, the messageIdentifier, MUST have a UUID value.

Systems may chose to map X-Request-ID header to the Bundle.id, messageId. If both are supplied to a $process-messge endpoint it is recommended they hold the same values.

MessageHeader can hold previous and extra messageId's in the ExtensionMessageHeadermessageId

messageIDs

In addition, a FHIR Message Bundle has two important timestamps:

The time of sending the message is captured in the timestamp element The last time the message was updated (e.g. by storing or modification) is captured in the meta.lastUpdated element.

{
    "resourceType": "Bundle",
    "id": "884cfa4f-7a56-4be5-9592-783ef4f3992a",
    "meta": {
        "lastUpdated": "2020-11-02T01:43:30+00:00"
      },
    "identifier": {
        "system": "https://tools.ietf.org/html/rfc4122",
        "value": "ad945a29-85f8-439a-b590-6789719adc16"
    },
    "type": "message",
    "timestamp": "2020-11-02T01:43:30+00:00",
    "entry": [
        {
            "fullUrl": "urn:uuid:311316d3-1de0-4f7c-8109-c950ead1c717",
            "resource": {
                "resourceType": "MessageHeader",
                "extension": [
                    {
                        "url": "https://fhir.nhs.uk/StructureDefinition/Extension-Spine-MessageHeader-messageId",
                        "valueIdentifier": {
                            "system": "https://fhir.nhs.uk/Id/prescription-order-number",
                            "value": "DC2C66-A1B2C3-23407B"
                        }
                    }
                ]

From (source and sender) and To (destination)

The From is contained in both the sender and source elements and the To is contained in the destination array. One source, sender and at least one destination MUST be present.

Messages may be sent over multiple transmission legs (i.e. the first leg uses http and the second MESH). The contents of elements SHOULD reflect the current leg only.

  • destination.endpoint
  • source.endpoint
  • MessageHeader.extension(messageId)

Endpoints MUST point to valid endpoint uri's on each leg of the messages journey, they may not refer to inaccessible endpoints on other legs. See also the destination section below.

destination

Lists all the destinations where message is be delivered to.

The recipient of a message takes the responsibility of delivering to all the destination.endpoints. Similarly the sender MUST NOT include destination's the recipient can not deliver to, these destinations MUST be removed from the message. Additional rules for endpoint can be found in the source section below.

sender

The current requirement in NHS Digital API's is to rely on the Access Tokens and Audit (JWT) for sender details.

For use outside of NHS Digital it is recommended this is populated with either the Organisation ODS code or the Practitioner's professional code.

"sender": {
    "identifier": {
        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
        "value": "VNE51"
   },
    "display": "The Simple Pharmacy"
}

source

source.endpoint is required and MUST indicate the address where replies are to be sent.

For responses to be received via http this will be the address of the $process-message endpoint. E.g.

https://fhir.hospitaltrust.nhs.uk/$process-message

For MESH this will follow ITK2.2 MESH Transport Requirements for ITK Routing. E.g. the MESH Endpoint for Organisation B80310

urn:nhs-uk:addressing:ods:B80310

Local Part/Addressing (sender and/or destination.receiver)

When exchanging messages between organisations, local references SHOULD NOT be used for sender and destination.receiver references. Local references can make use of the Extension ExtensionMessageHeaderLocalPart. Messages between Organisations should be directed to the Organisation. The receiving organisation will take responsibility for delivering to the local address. Sending organisations are not expected to be able to deliver to local entities in another organisation/domain/facility.

This concept is similar to email addresses local-part@domain and also HL7 version 2 combination of Sending/Receiving Application | Sennding/Receiving Facility in the MSH segment.

In the example below, the destination is a clinic (A99968) which part of NHS Trust (RBA). Note also the destination endpoint is for the NHS Trust, who will route the message as required.

"destination": [
    {
        "endpoint": "urn:nhs-uk:addressing:ods:RBA",
        "receiver": {
          "extension": [
              {
                  "url": "https://fhir.nhs.uk/StructureDefinition/Extension-MessageHeader-LocalPart",
                  "valueReference": {
                        "identifier": {
                        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                        "value": "A99968"
                    }
                }

              }
          ],
            "identifier": {
                "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                "value": "RBA"
            },
            "display": "TAUNTON AND SOMERSET NHS FOUNDATION TRUST"
        }
    }
],

example - Prescription, Pharmacy known

nominatedPharmacy

In the example below, the prescriber Taunton and Somerset Foundation Trust (RBA), is sending a message to The Simple Pharmacy (VNE51). The destination.receiver and sender are references to these organisations.

This message is to be sent via the Electronic Prescription Service, the http address of EPS is held in destination.endpoint. Replies to this message can only be received by MESH and the source.endpoint is the MESH address of the sending organisation.

"destination": [
    {
        "endpoint": "https://sandbox.api.service.nhs.uk/electronic-prescriptions/$post-message",
        "receiver": {
            "identifier": {
                "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                "value": "VNE51"
            },
            "display": "The Simple Pharmacy"
        }
    }
],
"sender": {
    "identifier": {
        "extension": [
            {
                "url": "https://fhir.nhs.uk/StructureDefinition/Extension-MessageHeader-LocalPart",
                "valueReference": {
                        "identifier": {
                        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                        "value": "A99968"
                    }
                }
            }
        ],
        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
        "value": "RBA"
    },
    "display": "TAUNTON AND SOMERSET NHS FOUNDATION TRUST"
},
"source": {
    "endpoint": "urn:nhs-uk:addressing:ods:RBA"
}

EPS will now send this message to the pharmacy. This message is collected by the pharmacy using MESH and so the destination.endpoint is now the MESH address of the pharmacy. Replies to this message are sent to EPS and so the source.endpoint is now the http address of the EPS $process-message endpoint.

"destination": [
    {
        "endpoint": "urn:nhs-uk:addressing:ods:VNE51",
        "receiver": {
            "identifier": {
                "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                "value": "VNE51"
            },
            "display": "The Simple Pharmacy"
        }
    }
],
"sender": {
    "extension": [
            {
                "url": "https://fhir.nhs.uk/StructureDefinition/Extension-MessageHeader-LocalPart",
                "valueReference": {
                        "identifier": {
                        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                        "value": "A99968"
                    }
                }

            }
        ],
    "identifier": {
        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
        "value": "RBA"
    },
    "display": "TAUNTON AND SOMERSET NHS FOUNDATION TRUST"
},
"source": {
    "endpoint": "https://sandbox.api.service.nhs.uk/electronic-prescriptions/$post-message"
}

example - Prescription, Pharmacy not known

noNominatedPharmacy

In this example the destination is not known and the message is sent to NHS Digital (X26).

"destination": [
    {
        "endpoint": "https://sandbox.api.service.nhs.uk/electronic-prescriptions/$post-message",
        "receiver": {
            "identifier": {
                "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                "value": "X26"
            },
            "display": "NHS Digital"
        }
    }
],
"sender": {
    "extension": [
            {
                "url": "https://fhir.nhs.uk/StructureDefinition/Extension-MessageHeader-LocalPart",
                "valueReference": {
                        "identifier": {
                        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                        "value": "A99968"
                    }
                }
            }
        ],
    "identifier": {
        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
        "value": "RBA"
    },
    "display": "TAUNTON AND SOMERSET NHS FOUNDATION TRUST"
},
"source": {
    "endpoint": "urn:nhs-uk:addressing:ods:RBA"
}

The pharmacy the patient selects to dispense the medication will contact EPS and set themselves as the destination of the prescription. This action changes the destination.receiver of the message, like the previous example the source.endpoint now reflects the EPS http address. Resulting in the following section in the message sent to the pharmacy.

"destination": [
    {
        "endpoint": "urn:nhs-uk:addressing:ods:VNE51",
        "receiver": {
            "identifier": {
                "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                "value": "VNE51"
            },
            "display": "The Simple Pharmacy"
        }
    }
],
"sender": {
    "extension": [
            {
                "url": "https://fhir.nhs.uk/StructureDefinition/Extension-MessageHeader-LocalPart",
                "valueReference": {
                        "identifier": {
                        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
                        "value": "A99968"
                    }
                }
            }
        ],
    "identifier": {
        "system": "https://fhir.nhs.uk/Id/ods-organization-code",
        "value": "RBA"
    },
    "display": "TAUNTON AND SOMERSET NHS FOUNDATION TRUST"
},
"source": {
    "endpoint": "https://sandbox.api.service.nhs.uk/electronic-prescriptions/$post-message"
}

author

If present, this SHOULD be an identifier reference to a Practitioner or PractitionerRole. Internal references to resources should NOT be used.

"author": {
    "type": "PractitionerRole",
    "identifier": {
        "system": "https://fhir.nhs.uk/Id/sds-role-profile-id",
        "value": "100102238986"
    },
    "display": "DR ALI"
},

response

If the message is a response to a previous message, the response.identifier MUST match the previous request messages Bundle.identifier Correlation-ID.

"response": {
    "identifier": "ad945a29-85f8-439a-b590-6789719adc16",
    "code": "ok"
}

focus

The focus element of the MessageHeader specifies the content of the message. The MessageHeader is followed by other resources depending on the type of request. For example, a request to book an appointment may contain the Patient to book the appointment for, the Practitioner to book the appointment with and the actual Appointment that is requested.


MessageBundle


The focus section SHOULD match the focus section of the corresponding MessageDefinition

MessageDefinition.focus extract

"focus":  [
        {
            "code": "MedicationRequest",
            "profile": "https://fhir.nhs.uk/StructureDefinition/DM-MedicationRequest",
            "min": 1,
            "max": "4"
        },
        {
            "code": "Patient",
            "profile": "https://fhir.nhs.uk/StructureDefinition/DM-Patient",
            "min": 1,
            "max": "1"
        },
        {
            "code": "CommunicationRequest",
            "profile": "https://fhir.nhs.uk/StructureDefinition/DM-CommunicationRequest",
            "min": 0,
            "max": "*"
        }
    ]

Corresponding MessageHeader.focus (Note: type is not required and is included for illustration purposes)

"focus": [
    {
        "type": "Patient",
        "reference": "urn:uuid:78d3c2eb-009e-4ec8-a358-b042954aa9b2"
    },
    {
        "type": "MedicationRequest",
        "reference": "urn:uuid:a54219b8-f741-4c47-b662-e4f8dfa49ab6"
    },
    {
        "type": "CommunicationRequest",
        "reference": "urn:uuid:28828C55-8FA7-42D7-916F-FCF076E0C10E"
    }
]

back to top