The Path
Module 2 · Reading an HL7 v2 message·12 min
Anatomy of a message
Segments, fields, components, repetitions. We dissect a real message top to bottom.
An HL7 v2 message is just text. No tags like XML, no curly braces like JSON. Once you know three or four splitting rules, you can read any message. We will go through them one by one, from the biggest piece to the smallest.
Here is the message we are taking apart: the result of one night at the Leleux Clinic sleep lab.
A sleep study report. The lab sends the hospital record an AHI of 28.5/h, flagged “high”: moderate sleep apnea.
1. A message is made of lines: segments
Each line is a segment. It always starts with a three-letter code that says what it carries:
MSH: the header. Who sends, to whom, when, which kind of message.PID: the patient. Name, date of birth, identifiers.OBR: the requested test, here a polysomnography.OBX: a result. A measurement, a value.
Spot those codes in the message above. Click the color legend, or click a segment code directly.
2. Each segment is made of fields, split by bars
Inside a segment, values are separated by a vertical bar |. Each piece is a field. Fields are numbered in order: the fifth field of the PID segment is written PID-5, and it holds the patient name.
This SEGMENT-number notation is the address of any piece of information in a message. When a colleague says “check PID-3”, they are giving you exact coordinates.
A sleep study report. The lab sends the hospital record an AHI of 28.5/h, flagged “high”: moderate sleep apnea.
Two bars in a row, ||, simply mean a field is empty. It still exists: you still have to count it.
3. A field can be split further
Some fields hold several pieces. A name separates family name and given name with a caret ^: these are components. So DUBOIS^Marie reads “Marie Dubois”. We write PID-5.1 for the family name and PID-5.2 for the given name. Depending on the tool, you will also see PID.5.1 or PID-5-1: same address.
Two more levels exist:
- repetitions, separated by a tilde
~, when a field holds several values of the same kind (two phone numbers, for instance); - subcomponents, separated by an ampersand
&, when a component itself has to be split.
Try it: this short message gives Marie two phone numbers in PID-13. Click the field and look at the repetition.
The same patient, with a home number and a mobile number in one field.
The five characters that split everything
| Character | Name | Role |
|---|---|---|
| |
vertical bar | separates fields |
^ |
caret | separates the components of a field |
~ |
tilde | separates repetitions of a field |
\ |
backslash | starts an escape sequence |
& |
ampersand | separates subcomponents |
The neat 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 tells you how to split it.
How to read a message in practice
Top to bottom, left to right. Start with MSH to know what it is about, then PID to know who it is about, then the clinical segments for the content.
Check your understanding
1 of 4In an HL7 v2 message, what is one line?
+50 XPPass the quiz (3 correct answers) to complete the lesson.
Reviewed and checked on 27 September 2026