The Complete Guide to HL7

HL7 Message Structure

HL7 Messages are used to transfer electronic data between disparate healthcare systems, each sending information about a particular event such as a patient admission. HL7 messages are in human-readable (ASCII) format, though they may require some effort to interpret.

This section describes the contents of an HL7 message and how an HL7 message is organized.

HL7 Message Structure

Contents

A
A Practical Guide to HL7 Interface Development: Building Custom Integrations for Healthcare Systems
Download the FREE Guide

What are the Components of an HL7 Message?

An HL7 message consists of one or more segments. Each segment is displayed on a different line of text. A carriage return character (\r, which is 0D in hexadecimal) separates one segment from another. 
 
Each segment consists of one or more composites, also known as fields. A pipe (|) character is used to separate one composite from another. If a composite contains other composites, these sub-composites (or sub-fields) are normally separated by caret (^) characters.

MSH|^~\&|EPIC|EPICADT|iFW|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5|
PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|
NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||
PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853


Here's a fun animated video that demonstrates exactly what an HL7 message looks like:

HL7
Play video

The following sections elaborate further on the intricacies of an HL7 message and how to read the standard. For more information about the different HL7 message types and their uses, please see our HL7 Message Types page.

HL7 Segments

In an HL7 message, each segment of the message contains one specific category of information, such as patient information or patient visit data. The name of each segment in the message is specified by the first field of the segment, which is always three characters long. Over 120 different HL7 segments are available for use in HL7 messages, this example message contains four HL7 segments: MSH, PID, NK1 and PV1. Different types of HL7 messages contain different HL7 segments.

Example HL7 Message:

MSH|^~\&|EPIC|EPICADT|iFW|SMSADT|199912271408|CHARRIS|ADT^A04|1817457|D|2.5|
PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|
NK1||ROE^MARIE^^^^|SPO||(216)123-4567||EC|||||||||||||||||||||||||||
PV1||O|168 ~219~C~PMA^^^^^^^^^||||277^ALLEN MYLASTNAME^BONNIE^^^^|||||||||| ||2688684|||||||||||||||||||||||||199912271408||||||002376853

 

The HL7 segments in this example contain the following information:

  • The MSH (Message Header) segment contains information about the message itself. This information includes the sender and receiver of the message, the type of message this is, and the date and time it was sent. Every HL7 message specifies MSH as its first segment.
  • The PID (Patient Information) segment contains demographic information about the patient, such as name, patient ID and address.
  • The NK1 (Next of Kin) segment contains contact information for the patient’s next of kin.
  • The PV1 (Patient Visit) segment contains information about the patient’s hospital stay, such as the assigned location and the referring doctor.

With HL7 messages being used to communicate all kinds of healthcare related information to a variety of disparate systems, sometimes HL7 messages need to contain customized data that cannot be included in any defined segment for its message type. To accommodate for this, the HL7 Standard enables system vendors to create a Z-segment with customized fields to transmit this data. 

By convention, all custom segments begin with the letter Z. For example, a ZPD segment could be created to contain customized patient demographics information. Z-segments can be placed anywhere in an HL7 message, however are typically located as the last segment in a message. Applications that process HL7 messages are usually configured to ignore HL7 Z-segments that they do not know how to handle.

For more information on how Iguana can support custom Z-segments, please visit iNTERFACEWARE's Help Center.

HL7 Composites

Each segment of an HL7 message consists of one or more composites (also known as fields). By default, the | (pipe) character is used to separate one composite from another.

A composite can be a primitive data type (such as a character string or a number), or can contain other composites. If a composite contains other composites, these sub-composites (or sub-fields) are normally separated by ^ characters. If a sub-composite also contains composites, these sub-sub-composites are normally separated by & characters. Sub-sub-composites must be primitive data types.

For an example of a typical composite, consider the PID segment of the sample message seen in the previous sections:

PID||0493575^^^2^ID 1|454721||DOE^JOHN^^^^|DOE^JOHN^^^^|19480203|M||B|254 MYSTREET AVE^^MYTOWN^OH^44123^USA||(216)123-4567|||M|NON|400003403~1129086|
 
In this segment, the fifth composite is the patient name, which is DOE^JOHN^^^^. (The four ^^^^ characters at the end of this composite indicates that it has a total of six sub-composites, and that only the first two of the sub-composites are defined.) In this composite, DOE represents the family name of the patient, and JOHN is the patient’s given name.

In order to be as flexible as possible and achieve a consensus, the HL7 committees were forced to define many segment fields as optional. The downside of this decision is that you cannot be certain that particular information will be present in a given message. This is one of the reasons why the same message may vary significantly from vendor to vendor.

HL7 Delimeter Characters

In HL7 messages, certain special characters separate one composite in a segment from another, or separate one sub-composite from another. These special characters are known as delimiter characters.

The following table lists the default delimiter characters used in HL7:

CHARACTER PURPOSE
0x0D Marks the end of each segment.
| Composite delimiter.
^ Sub-composite delimiter.
& Sub-sub-composite delimiter.
~ Separates repeating fields.
\
Escape character.

HL7 Message Structure: Challenges

Technically, HL7 messages come in human-readable (ASCII) format, but they are not at all easy to interpret. However, they contain a multitude of segments and fields, each carrying important healthcare information. To complicate matters further, many messages vary from vendor to vendor, making it difficult for healthcare organizations to decode and interpret.

How does Iguana help interpret HL7 messages?

If your HL7 messages contain a multitude of segments, you may find yourself in need of an easy way to interpret this information. Developed by iNTERFACEWARE, Iguana is a data integration platform that allows you to parse your message so you can instantly see its segments, fields and values. Along with parsing, Iguana can also perform other functions so you can filter and transform your HL7 messages with ease.

Get a demo: Learn how to parse HL7 messages in Iguana

Fill out the form and we'll be in touch.

Request a Free Demo