Skip to content

Step 2

Anatomy of a message

Segments, fields, components, delimiters. We dissect a real message top to bottom.

An HL7 v2 message is just text. No tags, no braces, nothing scary. Once you know the three or four splitting rules, you can read any message. Let's take them one at a time, from the biggest piece to the smallest.

1. The message is made of lines: the segments

Each line is a segment. It always starts with a three-letter code that announces what it carries:

  • MSH: the header. Who sends, to whom, when, what kind of message.
  • PID: the patient. Name, date of birth, identifiers.
  • OBX: a result. One measurement, one value.

Spot these codes in the message below. Click the color legend, or a segment directly.

A sleep study report. The lab sends the hospital record an AHI of 28.5/h, flagged “high”: severe sleep apnea.

ORU^R01· Observation result (unsolicited)
||||||||||
|||||||||||
|||||||
|||||||||||||||||||||||
|||||||||||
|||||||||||
|||||||||||

2. Each segment is made of fields, separated by bars

Inside a segment, values are separated by a vertical bar |. Each piece is afield. We number them in order: the fifth field of the PID segment is writtenPID-5, and it is the patient's name.

This SEGMENT-number notation is the address of any piece of information in a message. When someone says "look at PID-3", they are giving you exact coordinates.

3. A field can be split even finer

Some fields hold several pieces. A name, for example, separates family and given name with a caret^: these are components. So DUBOIS^Marie reads as "Marie Dubois". Other separators exist for repetitions and even finer levels.

The five characters that split everything

CharacterRole
|Separates fields
^Separates the components of a field
~Separates the repetitions of a field
\Escapes a special character
&Separates subcomponents

The elegant part: these characters are not hard-coded. They are declared at the very start of the message, in MSH-1 (the bar) and MSH-2(^~\&). The message itself tells you how to split it.

How you actually read a message

Top to bottom, left to right. Start with MSH to know what it is, then PIDto know who it is about, then the clinical segments for the content. That's it.