Skip to content

Message flow

How a message travels from the event that creates it to the acknowledgment that answers it.

An HL7v2 exchange moves a message between two systems: the source, which sends it, and the destination, which receives and processes it. When an appointment is booked in the electronic health record (EHR), for example, the EHR is the source and the departmental scheduling system is the destination.

The steps of an exchange are the same for every message and every pair of systems. A system can therefore exchange messages with systems from other vendors without agreeing on a separate procedure for each interface, which is one of the foundations of HL7v2's interoperability.

A system can be the source of one message and the destination of another. A laboratory system, for example, is the destination of an order that it receives and the source of the result that it sends back.

Steps

An exchange has six steps:

  1. An event occurs in the source.
  2. The source generates a message.
  3. The source transmits the message to the destination.
  4. The destination receives the message.
  5. The destination processes the message.
  6. The destination returns an acknowledgment that reports the outcome.

Event

HL7v2 is event-driven. An exchange begins with an event: something that happens in the source system and that other systems need to know about, such as a patient admission, a laboratory order, or a discharge. The source sends a message as soon as the event occurs, without waiting for another system to request it, and each destination processes the message independently. In the example, the event is the booking of an appointment in the EHR.

Request-based interfaces

Request-based interfaces work the other way: a system asks for specific data when it needs it, as with an HL7v2 query or a request to a FHIR server.

The event itself occurs outside HL7v2. The standard does not define how a system records an admission or an order; it defines how the system reports the event, as a message that names the event with a trigger event code, such as A01 for an admission.

Generation

The source creates a message that represents the event, following the HL7v2 specification. The specification defines the structure that a message can have: the message type and trigger event determine which segments the message can contain, and each segment defines its fields. The specification also defines how this structure is adapted to each interface, through message profiles: a profile that the source and the destination agree on specifies which optional segments and fields the source populates, which codes it sends, and any local extensions. The specification does not constrain how the source produces the message, only what the result must contain.

In the example, the EHR generates an SIU^S12 message: message type SIU (scheduling information) with trigger event S12 (a new appointment booking). The message carries the appointment (SCH), the patient (PID), and the resources booked for the appointment: the service (AIS) and the location (AIL).

Example SIU^S12 message
MSH|^~\&|SendingApp|SendingFacility|ReceivingApp|ReceivingFacility|20230630120000||SIU^S12^SIU_S12|MSG000002|P|2.8|
SCH|1|12345|||20230701^20230702||1^60^Mins||||^^^Hospital^Bed^100||||||||12345678|John Doe|
PID|1||1234567890^^^MRN^MRN~9876543210^^^SSN^SSN||Doe^John^M^^^||19700101|M|||123 Main St^Anytown^CA^12345||555-123-4567|||S|||||||||||||||||||12345678|
RGS|1|
AIS|1|^^^Appointment^Appointment||202307011000^202307011100^R||||||12345^Smith^Jane^^Dr.||||||||||||||||
AIL|1|1|^^^Appointment Location^Appointment Location||||Hospital^100 Main St^Anytown^CA^12345|

Transmission

The source sends the message to the destination. The most common transport is MLLP, which carries messages over a TCP network connection and marks where each message starts and ends. Messages can also travel over HTTP, through message queues, or as files.

In most hospitals, the source and the destination are not connected directly, and use instead an intermediary system to handle the message routing, named an interface engine. The interface engine receives the message from the EHR and forwards it to the scheduling system, and to any other system that needs appointment messages.

Reception

The destination receives the message and checks it before using it: that the message is well formed, that its message type is one the destination supports, and that it contains the data the destination requires. In the example, the scheduling system reads the appointment, patient, and resource segments from the SIU^S12 message.

At this point, the source has no confirmation that the message arrived or was processed. For more information about how the source receives confirmation, see the Acknowledgment section.

Enhanced mode

In enhanced mode, the destination can send a commit acknowledgment as soon as it has stored the message, before processing it. The acknowledgment that reports the processing outcome follows later.

Processing

Processing, like the event, takes place outside HL7v2. The standard defines what a message means, but not what the destination does with it. Most destination systems process a message by updating their own records: in the example, the scheduling system creates the appointment in its calendar. Other messages cause a destination to update a patient record, start a workflow, or raise an alert.

Acknowledgment

The destination shall return an acknowledgment, a short message that reports to the source what happened to its message. The acknowledgment states one of three outcomes: the destination processed the message, the message contained an error, or the destination rejected the message, for example because it does not support that kind of message. The acknowledgment also refers to the original message by its unique identifier, the control ID, so that the source can match each acknowledgment to the message it sent.

Example ACK message
MSH|^~\&|ReceivingApp|ReceivingFacility|SendingApp|SendingFacility|20230630121000||ACK^S12^ACK|MSG000002A|P|2.8|
MSA|AA|MSG000002|

In the example, the scheduling system acknowledges message MSG000002 with the code AA, which reports that it processed the message. Acknowledgments describes the outcome codes and the acknowledgment message in detail.

Failures

The steps above describe a successful exchange. An interface also needs to handle three common failures.

  • No acknowledgment. If the connection fails or the destination stops responding, the source receives no acknowledgment within its timeout, and it shall resend the message. The destination can therefore receive the same message twice. Because the resent message carries the same control ID as the original, the destination can recognize the duplicate.

  • Negative acknowledgment. An acknowledgment that reports an error or a rejection means that the message was not processed. The interface design, not the standard, defines what happens next: the message can be queued for review, corrected and resent, or discarded.

  • Loss after acknowledgment. A destination that acknowledges a message before storing it can fail between the two steps. The source does not resend the message, because it received an acknowledgment, and the message is lost. HL7v2's enhanced acknowledgment mode addresses this case.