HL7 Message Structure

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.

What are the Components of an HL7 Message?

An HL7 message consists of one or more segments. Each segment appears on a different line of text and is separated by a carriage return character (\r, hexadecimal 0D). Each segment consists of one or more composites (fields) separated by a pipe (|) character. If a composite contains other composites, those sub-composites (sub-fields) are separated by carets (^).

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

Watch an animated video demonstrating what an HL7 message looks like:

The following sections explain the intricacies of an HL7 message and how to interpret it. For more information on different HL7 message types, see the HL7 Message Types page.

HL7 Segments

Each segment in an HL7 message contains a specific category of information, such as patient demographics or visit data. The first field of each segment identifies its type (three characters long). There are over 120 HL7 segment types; this example contains four: MSH, PID, NK1, and PV1.

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 segments above contain:

  • MSH (Message Header): Message metadata such as sender, receiver, type, and timestamp. Always the first segment.
  • PID (Patient Information): Demographic details including name, ID, and address.
  • NK1 (Next of Kin): Contact details for the patient’s next of kin.
  • PV1 (Patient Visit): Information about the patient’s hospital stay, such as location and 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 Help Center.

HL7 Composites

Each segment is composed of composites (fields) separated by pipes (|). A composite may contain sub-composites separated by carets (^), and sub-sub-composites separated by ampersands (&). Sub-sub-composites must be primitive data types.

For example, from the PID segment:

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|

The fifth composite is the patient name: 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 Delimiter 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?

Iguana, developed by iNTERFACEWARE, provides an intuitive way to parse, view, and manipulate HL7 messages. It lets users see all segments, fields, and values instantly, and also perform transformations and filtering with ease.

 


References:

The all-in-one integration platform by iNTERFACEWARE.
G2 - Healthcare Integration Engines
Rated 4.5/5
4.5/5 on G2
Capterra - Integration Software
Rated 4.8/5
4.8/5 on Capterra
KLAS - Integration Engines
KLAS Rated*
93.6/100
*Average performance score from 2017-2022 in the 'Best of KLAS' report
iNTERFACEWARE Inc.
© iNTERFACEWARE Inc.
Privacy | Terms of Service | MSA
General Inquiries
iNTERFACEWARE Inc.
2 Bloor Street East, Suite 3500
Toronto, Ontario   M4W 1A8   Canada
contact@interfaceware.com
1-888-824-6785
Follow Us: