Skip to content
The Path

Module 2 · Reading an HL7 v2 message·11 min

Structure, optionality and repetition

What is required, what repeats, and how to read a message structure.

An HL7 v2 message is not a random pile of lines. Each message type follows a blueprint: which segments, in which order, which are required, which repeat. That blueprint has a name, and the message itself states it.

Look at MSH-9 in this sleep lab result: it has three components.

The sleep lab sends two tests from the same night: the polysomnography and the oximetry.

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

MSH-9.3: the name of the blueprint

MSH-9 holds three pieces: ORU^R01^ORU_R01.

  • MSH-9.1, ORU: the message type (an observation result);
  • MSH-9.2, R01: the trigger event;
  • MSH-9.3, ORU_R01: the message structure, meaning the blueprint to follow.

Why a third piece? Because several events share the same blueprint. In v2.5.1, the ADT_A01 structure is used by events A01 (admit), A04 (register), A08 (update) and A13. So an update is written ADT^A08^ADT_A01. The receiver reads MSH-9.3 and knows right away which blueprint applies.

Special case: for a general acknowledgment, MSH-9.3 is always ACK.

Abstract syntax: brackets and braces

The standard describes each blueprint with a compact notation, the abstract message syntax. A handful of signs is enough.

Notation Meaning
SEG the segment is required, once
[ SEG ] optional: zero or one time
{ SEG } repeating: one or more times
[{ SEG }] optional and repeating: zero, one or many times
< A | B > a choice: one or the other

The signs also apply to a group of segments. A group travels as a block and has an uppercase name, like OBSERVATION.

Here is the v2.5.1 ORU_R01 structure, simplified (rare segments removed):

MSH
{                              PATIENT_RESULT
  [ PID [PD1] [{NTE}]          PATIENT
    [ PV1 [PV2] ]              VISIT
  ]
  {                            ORDER_OBSERVATION
    [ORC]
    OBR [{NTE}]
    [{ OBX [{NTE}] }]          OBSERVATION
  }
}
[DSC]

Read it from the outside in:

  • MSH is required, once.
  • The PATIENT group is optional. Inside it, PID is required. The PV1 visit is itself optional.
  • The ORDER_OBSERVATION group repeats: one block per test, always starting with an OBR.
  • Each OBX can be followed by its own NTE comments.

Go back to the message above. You will find two OBR blocks, each with its OBX segments, and one NTE attached to the first OBX. The blueprint shows in the message.

Notice the OBX|1 under the second OBR: numbering starts again at 1. That is expected, OBX-1 counts observations within each test, not across the whole message.

At field level: R, O, C, X, B, W

Segments have a blueprint, and so do fields. For each segment, the standard gives an OPT (optionality) column:

Code Meaning Example in v2.5.1
R required PID-3 (patient identifiers), PV1-2 (patient class)
O optional PID-8 (administrative sex)
C conditional: depends on the event or on another field OBX-2, required unless OBX-11 is X
X not used with this trigger event depends on the event
B kept for backward compatibility with older versions PID-2, in practice replaced by PID-3
W withdrawn: the position still exists, but the field must no longer be filled depends on the version

An RP/# column says whether the field repeats: blank or N for no, Y for any number, a number for a maximum. PID-3 and PID-5 are marked Y: a patient can have several identifiers, separated by ~.

Conformance profiles: RE and cardinality

The standard leaves a lot optional. For a real interface, you tighten it in a conformance profile: a document stating what a given sender actually sends. Two tools show up there.

  • RE, “required but may be empty”: the sender must be able to fill the field and sends it whenever it has the data. If it does not, it leaves it empty, and the receiver must not raise an error.
  • Cardinality [min..max]: [1..1] exactly once, [0..1] at most once, [0..*] as many as you like.

Why the receiver must be tolerant

The standard gives the receiver three rules:

  1. ignore segments, fields and repetitions that are present but not expected;
  2. treat a segment that is expected but missing as a segment with empty fields;
  3. treat a field that is expected but missing as not valued.

These rules let versions live side by side. A 2.5.1 sender can send a field an older receiver does not know, without breaking anything.

And in FHIR?

FHIR keeps the same idea of cardinality, on every element of a resource. Patient.name is marked 0..*: optional, repeating. The structure is no longer a sequence of segments, but the question stays the same: what is required, what repeats?

Check your understanding

1 of 5

In a message structure, what does [{ OBX }] mean?

+50 XPPass the quiz (4 correct answers) to complete the lesson.

Reviewed and checked on 27 September 2026