HL7 v2 & integration
HL7 v2 in 15 minutes
Segments, fields, delimiters and the message types that still carry most of Australia's hospital and pathology traffic.
HL7 version 2 is from the late 1980s and is still everywhere. Patient administration systems, pathology labs, radiology and GP software exchange v2 messages all day. In Australia, pathology messaging follows AS 4700.2, which is based on HL7 v2.4. Expect to translate v2 into FHIR for years to come.
Anatomy of a message#
MSH|^~\&|FHIRLAB|SYNTHEA|OIE|LAB|20261126101500||ADT^A04^ADT_A01|MSG20261126101500123|P|2.5
EVN|A04|20261126101500
PID|1||922fb35e-148d-9e82^^^SYNTHEA^MR||McClure^Agnes||19870314|F|||12 Example Street^^Brisbane^QLD^4000
PV1|1|O- Segment
- One line, ending with a carriage return (
\r, not\n). The first three letters name it:MSH,PID,PV1. - Field
- Separated by
|. They're counted from 1 after the segment name, soPID-5is the fifth field:McClure^Agnes. - Component
- Separated by
^.PID-5.1=McClure(family name),PID-5.2=Agnes(given name). - Repetition
- Separated by
~.PID-3often repeats:MRN^^^HOSP^MR~8003608833357361^^^AUSHIC^NI. - Subcomponent
- Separated by
&. It's rare, but common in assigning authorities:^^^HOSP&1.2.3&ISO^MR.
MSH is counted differently
In MSH, the field separator | itself is MSH-1, and the encoding characters ^~\& are MSH-2. So MSH-9 (message type) is the 9th field when you count that way, which is one off from naive splitting.
Escape sequences#
| Sequence | Means |
|---|---|
\F\ |
\| |
\S\ |
^ |
\R\ |
~ |
\T\ |
& |
\E\ |
\ |
\.br\ |
line break (in text fields) |
\X0D\ |
hexadecimal character |
Segments you'll meet constantly#
| Segment | Carries |
|---|---|
MSH |
Header: sender, receiver, time, message type (MSH-9), control id (MSH-10), processing id (MSH-11), version (MSH-12) |
EVN |
Event type and time |
PID |
Patient identity: identifiers (PID-3), name (PID-5), DOB (PID-7), sex (PID-8), address (PID-11), phone (PID-13) |
NK1 |
Next of kin |
PV1 |
Visit: class (PV1-2: I inpatient, O outpatient, E emergency), location (PV1-3), attending doctor (PV1-7), visit number (PV1-19) |
AL1 / DG1 |
Allergies / diagnoses |
ORC / OBR |
Order control / observation request (the test ordered) |
OBX |
One observation result: value type (OBX-2), code (OBX-3), value (OBX-5), units (OBX-6), range (OBX-7), flag (OBX-8), status (OBX-11) |
NTE |
Free-text notes |
MSA / ERR |
Acknowledgment / error details |
Message types#
| Type^Event | Meaning | Typical FHIR result |
|---|---|---|
ADT^A01 |
Admit inpatient | Encounter (in-progress) + Patient upsert |
ADT^A02 |
Transfer | Encounter.location changes |
ADT^A03 |
Discharge | Encounter finished, period.end set |
ADT^A04 |
Register outpatient or ED | Patient upsert + Encounter |
ADT^A08 |
Update patient info | Patient conditional update |
ADT^A11 / A13 |
Cancel admit / cancel discharge | Encounter status reverted or entered-in-error |
ADT^A28 / A31 |
Add / update person (no visit) | Patient upsert |
ADT^A40 |
Merge patients | Patient.link replaced-by, plus moving references |
ORM^O01 / OML^O21 |
Order | ServiceRequest |
ORU^R01 |
Results | DiagnosticReport + Observations |
SIU^S12 |
Booking | Appointment |
MDM^T02 |
Document | DocumentReference |
The structure isn't the event
ADT^A04^ADT_A01 means event A04 using the A01 message structure. Many events share structures, and parsers pick a layout based on MSH-9.3.