The Path
Module 2 · Reading an HL7 v2 message·11 min
Field paths
PID-3(2).1, OBX(3)-5: how to point at one exact value, in the standard and in an engine.
“Check PID-3.” Easy, as long as PID-3 holds a single identifier. The day it holds two, and the message lines up four OBX segments, you have to say which one and which part. A field path is the full address of one value, with no room for doubt.
Here is Marie Dubois’s sleep study result. She has two identifiers: her record number at the clinic and her number at the sleep lab. The lab sends four measurements.
The sleep lab sends four results from the night to the hospital record. PID-3 repeats: one identifier from the clinic, one from the lab.
Level 1: segment and field
You already know PID-3: the segment code, a hyphen, the field number. The standard turns this into a rule. The same field name can exist in several segments, so you always quote the segment together with the position. Never “the Patient Identifier List field” on its own.
Level 2: component and subcomponent
To go inside a field, add the component number: PID-3.1 is the identifier itself, PID-3.4 the authority that assigned it, PID-3.5 its type (MR for a medical record number, PI for a patient internal identifier).
If that component is split again by &, add the subcomponent. PID-3.4.2 would be the second piece of the authority. In the first repetition, LELEUX has no pieces: you need the second repetition, which you will learn to address next.
You will also see PID-3-1, with a hyphen. The 2.5.1 standard itself writes MSH-9.1 in one place and MSH-9-2 in another. Same address, two spellings.
Level 3: the repetition
PID-3 holds two identifiers split by a ~. PID-3.1 is no longer enough: which one? Add the repetition number in parentheses, right after the field: PID-3(2).1 is PSG-7781.
The 2.5.1 standard does not define a notation for repetitions. This course uses parentheses and counts from 1, like fields. Some tools write [2], others count from 0. More on that below.
Level 4: the segment occurrence
The message has four OBX segments. Plain OBX-5 is ambiguous. Number the segment occurrence in parentheses, attached to the code: OBX(3)-5 is the value of the third OBX, which is 24.1.
| You want | Path | Value |
|---|---|---|
| the number of the 1st identifier | PID-3.1 |
1024 |
| the number of the 2nd identifier | PID-3(2).1 |
PSG-7781 |
| the authority’s universal ID, 2nd identifier | PID-3(2).4.2 |
leleux.example |
| the value of the 3rd result | OBX(3)-5 |
24.1 |
| the patient’s given name | PID-5.2 |
Marie |
Your turn: click and name the path
Three challenges. Write each path from memory, then click to check: the panel shows the full path of the field, and every repetition with its components.
- The value of the second
OBX. - The identifier type
PI, in the part after the~. - The domain
leleux.example.
The same result. Click a field, then write its full path: occurrence, field, repetition, component.
Show the answers
OBX(2)-5, value84.PID-3(2).5, valuePI.PID-3(2).4.2: second repetition, component 4, subcomponent 2.
In HAPI: the Terser path
HAPI, an open source Java library for HL7 v2, reads messages through short paths with its Terser class. Its documentation sets the syntax: SEGMENT-field(repetition)-component-subcomponent, all with hyphens.
Two rules change everything:
- repetitions count from 0: fields, segments and groups alike;
- fields, components and subcomponents count from 1.
| Course notation | Terser path |
|---|---|
PID-3.1 |
/.PID-3-1 |
PID-3(2).1 |
/.PID-3(1)-1 |
PID-3(2).4.2 |
/.PID-3(1)-4-2 |
OBX(3)-5 |
/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(2)/OBX-5 |
The last path walks through the groups of the ORU_R01 structure. Each OBX lives in its own OBSERVATION group. So the third OBX is repetition (2) of the group, not OBX(2). A leading / starts from the root of the message. A . before a name tells Terser to search the message for that segment.
In an interface engine
Every engine has its own mapping syntax: dots, brackets, hyphens, sometimes a scripting language. Take Mirth Connect, which turns the message into XML and reads it in JavaScript:
| Course notation | Mirth Connect |
|---|---|
PID-3.1 |
msg['PID']['PID.3'][0]['PID.3.1'] |
PID-3(2).1 |
msg['PID']['PID.3'][1]['PID.3.1'] |
Repetitions count from 0, in square brackets. Components keep their names, PID.3.1, counted from 1. And one more spelling: the standard itself uses dots in queries, such as @PID.5.1 in a QPD. The QBP queries lesson shows it in context.
Before you copy a path from a spec into an engine, ask its documentation three questions:
- What separator goes between field, component and subcomponent?
- Do repetitions and occurrences count from 0 or 1?
- With no repetition number, does the path return the first one or all of them?
And in FHIR?
FHIR points at an element with a dotted path: Patient.identifier.value. To filter, it has a standard language, FHIRPath: Patient.identifier.where(system = 'https://leleux.example/record').value picks an identifier by its system rather than its position. Same habit as at the sleep lab.
Check your understanding
1 of 5Marie Dubois’s PID-3 is 1024^^^LELEUX^MR~PSG-7781^^^SLEEPLAB&leleux.example&DNS^PI. Using the course notation, write the path that points at PSG-7781.
+50 XPPass the quiz (4 correct answers) to complete the lesson.
Reviewed and checked on 28 September 2026