The Path
Module 2 · Reading an HL7 v2 message·14 min
Data types
Text, number, date, code, identifier, name, address: how each value is built.
19850312: a number? a code? a date? In an HL7 message, nothing tells you at a glance. The standard does: every field has a data type. The type sets the format of the value and, for composite types, the list of its components.
Here is Marie Dubois’s admission, with a fuller identity than usual.
The patient record system tells the sleep lab that Marie Dubois has arrived, with her identifier, name, date of birth, address and two ways to reach her.
Click PID-3, PID-5, PID-7, PID-11 and PID-13: the panel shows the type of each one. We take them apart right below.
Simple or composite
There are two families:
- simple types: one single value, no
^. A piece of text, a number, a date, a code. - composite types: several components separated by
^, each with its own type.
Handy detail: the component of a composite type is often a simple type itself. You keep meeting the same building blocks.
Simple types
| Type | Name | What it holds | Example |
|---|---|---|---|
ST |
string | short text, meant for under 200 characters | Polysomnography |
TX |
text | text meant for display; each repetition is a new line | a report |
FT |
formatted text | like TX, plus formatting commands |
\.br\ for a line break |
NM |
numeric | digits, optional leading sign, optional decimal point | 28.5 |
SI |
sequence ID | a non-negative integer, 4 digits at most | PID-1 = 1 |
DT |
date | YYYY[MM[DD]] |
19850312 |
TM |
time | HH[MM[SS]], optional time zone |
0830 |
DTM |
date/time | YYYYMMDDHHMMSS, variable precision, optional time zone |
20260627083000 |
ID |
code from an HL7 table | a value from a table fixed by HL7 | P in MSH-11 |
IS |
code from a user table | a value from a table the site can adapt | F in PID-8 |
The composite types you will meet everywhere
| Type | Name | Main components | Where to see it |
|---|---|---|---|
TS |
time stamp | date/time ^ precision (legacy) |
MSH-7, PID-7 |
CE |
coded element | code ^ text ^ coding system, then an alternate |
OBX-3, OBX-6 |
CWE |
coded with exceptions | the 6 of CE, plus version and original text |
OBX-5 when OBX-2 = CWE, newer segments |
CX |
identifier | number ^ check digit ^ check digit scheme ^ authority ^ type |
PID-3 |
XPN |
person name | family ^ given ^ middle names ^ suffix ^ prefix ^ degree ^ name type |
PID-5 |
XAD |
address | street ^ other designation ^ city ^ state ^ postal code ^ country ^ type |
PID-11 |
XTN |
telecom number | legacy number ^ use ^ equipment ^ email ^ country ^ area ^ number |
PID-13 |
HD |
hierarchic designator | short name ^ universal ID ^ ID type |
MSH-3, MSH-4 |
EI |
entity identifier | identifier ^ short name ^ universal ID ^ type |
OBR-3 |
CQ |
composite quantity | number ^ unit |
quantities with a unit |
No need to learn this table by heart. Four examples on Marie Dubois are enough to build the reflex.
Example 1: TS, the date that states its own precision
PID-7 is 19850312. The TS type reads digits left to right: year, month, day, hour, minute, second. The number of digits sets the precision.
1985: the year only.198503: March 1985.19850312: March 12, 1985, no time.20260627090000+0200(inMSH-7): June 27, 2026 at 9:00:00, two hours ahead of UTC.
Without a time zone, the one declared in MSH-7 applies. If MSH-7 has none either, the time is the sender’s local time. The second component of TS, which used a letter to state the precision, is kept only for backward compatibility.
Example 2: CX, an identifier that says where it comes from
PID-3 is 1024^^^LELEUX^MR. Count the components:
1024: the number itself;- empty: the check digit;
- empty: the check digit scheme;
LELEUX: the authority that assigned the number;MR: the identifier type, here a medical record number (table 0203).
That is why you see three ^ in a row: components 2 and 3 are empty, but they still count. And that is why the authority matters: 1024 only means something inside the Leleux Clinic system. Another hospital almost certainly has a patient 1024 too.
Example 3: XPN, a name in parts
PID-5 is DUBOIS^Marie^^^^^L.
- component 1,
DUBOIS: family name; - component 2,
Marie: given name; - components 3 to 6, empty: middle names, suffix, prefix (such as
DR), degree; - component 7,
L: the name type, here the legal name (table 0200).
The first component is a composite type itself. A family name with a prefix, such as a “de” or a “van”, can be split there into subcomponents, separated by &.
In real life, the ampersand you will meet most often sits elsewhere: in the assigning authority of PID-3. That 4th component is of type HD, like MSH-3, and its three parts become subcomponents: 1024^^^LELEUX&2.999.1&ISO^MR. You read the short name LELEUX, a universal ID (here an example OID) and its type, ISO.
Example 4: XAD and XTN, address and contacts
PID-11 is Rue de la Sante 12^^Bruxelles^^1000^BEL^H: the street, an empty other designation, the city, an empty state or province, the postal code, the country as a three-letter ISO code (BEL), then the address type (H, home).
PID-13 shows an XTN that repeats with ~:
^PRN^PH^^32^2^0000000: first component empty (the legacy free-text number, kept for backward compatibility), usePRN(primary residence), equipmentPH(telephone), then country code, area code and number;^NET^Internet^marie.dubois@example.com: useNET(network address), equipmentInternet, then the email address in the 4th component.
ID or IS: who owns the list?
Both are codes drawn from a table. The difference is who owns the table:
ID: an HL7 table. The values are the standard’s. Example: the components ofMSH-9.IS: a user table. HL7 may suggest values, but each site can adapt them.
A common surprise: in 2.5.1, administrative sex PID-8 is an IS. Later versions moved it to CWE.
CE, CWE, TS, DTM: what changes after 2.5.1
In 2.5.1, coded fields mostly use CE and time stamps use TS. But the 2.5.1 standard already flags CE as kept for backward compatibility only: CWE and CNE have existed since 2.3.1. Later versions move fields over to CWE and CNE, and TS to DTM. Good news: the first six components of CWE are the ones of CE, and a TS starts with a DTM. So a 2.5.1 message reads almost unchanged in a later version.
The type of a result: OBX-2
In a result, OBX-5 can hold a number, a piece of text or a code. OBX-2 announces which. Click OBX-2 on each OBX line: NM for the AHI, ST for the conclusion.
A sleep study report. The lab sends the hospital record an AHI of 28.5/h, flagged “high”: moderate sleep apnea.
And in FHIR?
Each composite type has a counterpart, according to the official v2-to-FHIR mapping guide:
| HL7 v2 | FHIR |
|---|---|
CX |
Identifier |
XPN |
HumanName |
XAD |
Address |
XTN |
ContactPoint |
CE, CWE |
CodeableConcept |
TS, DTM |
dateTime |
Watch the date format: 19850312 becomes 1985-03-12 in FHIR.
Check your understanding
1 of 5PID-7 is 198503. What does that tell you about the date of birth?
+50 XPPass the quiz (4 correct answers) to complete the lesson.
Reviewed and checked on 27 September 2026