HL7 Segment Reference Guide
Laksh Patel, Founder, HealthInterops
Laksh Patel is the Founder of HealthInterops and creator of HL7ToolBox. With more than 17 years of software engineering experience and over 5 years specializing in healthcare interoperability, he has designed and delivered more than 3,000 healthcare interfaces across hospitals, laboratories, and enterprise healthcare systems.
This article is reviewed and maintained by the HL7ToolBox Team.
TL;DR
HL7 messages are composed of segments, each representing a different type of healthcare information such as patient demographics, orders, observations, insurance, visits, or billing. Understanding the purpose of each segment is essential for anyone working with healthcare interoperability, interface engines, or HL7 integrations.
This guide explains the most commonly used HL7 segments with real-world examples, important fields, and implementation best practices.
What Are HL7 Segments?
An HL7 message consists of multiple segments, where each segment begins with a three-character identifier.
Example:
MSH|^~\&|EPIC|Hospital|LAB|Quest|202606260900||ORM^O01|12345|P|2.5.1 PID|1||MRN12345^^^Hospital^MR||Smith^John PV1|1|I|ICU^101^A ORC|NW|ORD1001 OBR|1|ORD1001||CBC^Complete Blood Count OBX|1|NM|WBC||7.8|10^9/L
Each line is a segment.
Common HL7 Segments
| Segment | Purpose |
|---|---|
| MSH | Message Header |
| EVN | Event Information |
| PID | Patient Identification |
| NK1 | Next of Kin |
| PV1 | Patient Visit |
| PV2 | Additional Visit Information |
| ORC | Common Order |
| OBR | Observation Request |
| OBX | Observation Result |
| DG1 | Diagnosis |
| PR1 | Procedures |
| AL1 | Allergy Information |
| GT1 | Guarantor |
| IN1 | Insurance |
| FT1 | Financial Transaction |
| TXA | Document Information |
MSH Segment (Message Header)
Purpose
The MSH segment is the first segment in every HL7 message.
It identifies:
- Sending application
- Receiving application
- Message type
- HL7 version
- Timestamp
- Message Control ID
Example
MSH|^~\&|EPIC|Hospital|LIS|Quest|202606260900||ORU^R01|987654|P|2.5.1
Important Fields
| Field | Description |
|---|---|
| MSH-3 | Sending Application |
| MSH-4 | Sending Facility |
| MSH-5 | Receiving Application |
| MSH-6 | Receiving Facility |
| MSH-7 | Date/Time |
| MSH-9 | Message Type |
| MSH-10 | Message Control ID |
| MSH-11 | Processing ID |
| MSH-12 | HL7 Version |
Best Practices
- Always generate a unique Message Control ID.
- Validate the HL7 version before processing.
- Use UTC or clearly documented time zones.
PID Segment (Patient Identification)
Purpose
The PID segment stores patient demographic information.
Example
PID|1||123456^^^Hospital^MR||Smith^John||19880615|M
Important Fields
| Field | Description |
|---|---|
| PID-3 | Medical Record Number (MRN) |
| PID-5 | Patient Name |
| PID-7 | Date of Birth |
| PID-8 | Sex |
| PID-11 | Address |
| PID-13 | Phone Number |
| PID-19 | SSN / National Identifier (implementation dependent) |
Best Practices
- Use PID-3 as the primary patient identifier.
- Support multiple patient identifiers where required.
- Preserve identifier assigning authority.
PV1 Segment (Patient Visit)
Purpose
The PV1 segment describes the patient's encounter or visit.
Example
PV1|1|I|ICU^101^A||||12345^Jones^David
Important Fields
| Field | Description |
|---|---|
| PV1-2 | Patient Class |
| PV1-3 | Assigned Location |
| PV1-7 | Attending Doctor |
| PV1-10 | Hospital Service |
| PV1-19 | Visit Number |
Common Patient Classes
- I = Inpatient
- O = Outpatient
- E = Emergency
NK1 Next of Kin
Purpose
Stores emergency contact information.
NK1|1|Smith^Mary|SPO
Common Fields
- Name
- Relationship
- Phone Number
- Address
ORC Common Order
Purpose
The ORC segment controls healthcare orders.
ORC|NW|ORD123456
Common Order Control Codes
- NW = New Order
- XO = Change Order
- CA = Cancel Order
- DC = Discontinue
OBR Segment (Observation Request)
Purpose
Describes the diagnostic test that has been ordered.
Example
OBR|1|ORD123|LAB456|88304^CBC
Important Fields
| Field | Description |
|---|---|
| OBR-4 | Universal Service ID |
| OBR-7 | Observation Date |
| OBR-16 | Ordering Provider |
| OBR-22 | Result Status Time |
OBX Segment (Observation Result)
Purpose
The OBX segment contains clinical observations and test results.
Example
OBX|1|NM|WBC||7.4|10^9/L|4.0-10.0|N
Important Fields
- OBX-2: Data Type
- OBX-3: Observation Identifier
- OBX-5: Observation Value
- OBX-6: Units
- OBX-7: Reference Range
- OBX-8: Abnormal Flag
- OBX-11: Result Status
Common Data Types
Best Practices
- Always validate OBX-2 before parsing OBX-5.
- Support repeating OBX segments.
- Preserve units and reference ranges.
Other Important Segments
DG1 (Diagnosis)
Stores diagnosis information including Diagnosis Code and Description.
DG1|1||I10^Essential HypertensionAL1 (Allergy)
Stores allergy information.
AL1|1|DA|PENICILLININ1 (Insurance)
Stores policy information like Company, Policy Number, Group, and Plan.
IN1|1|ABC001|BlueCrossGT1, FT1, TXA
GT1: Guarantor / responsible party.
FT1: Financial transactions (charges/payments).
TXA: Document metadata (ID, Author).
Segment Relationships
Typical Laboratory Workflow
Patient Registration
Common HL7 Segment Mistakes
Incorrect Message Header
Always verify: Sending Application, Receiving Application, Message Type, and Version.
Missing Patient Identifier
Never assume PID-3 exists. Validate before processing.
Incorrect OBX Data Type
Many parsing issues occur because OBX-2 and OBX-5 are inconsistent. Always validate the data type first.
Ignoring Repeating Segments
Segments such as OBX, NK1, AL1, DG1, IN1 can appear multiple times. Your parser should support repeating segments.
HL7 Segment Best Practices
- Validate every incoming message.
- Process segments in the expected order.
- Support optional segments.
- Handle repeating fields and repeating segments.
- Preserve unknown Z-segments.
- Log parsing errors with segment and field information.
- Use HL7 version-specific validation rules.
HL7 Segments and FHIR Mapping
| HL7 Segment | Common FHIR Resource |
|---|---|
| PID | Patient |
| PV1 | Encounter |
| NK1 | RelatedPerson |
| ORC | ServiceRequest |
| OBR | ServiceRequest / DiagnosticReport |
| OBX | Observation |
| DG1 | Condition |
| AL1 | AllergyIntolerance |
| IN1 | Coverage |
| TXA | DocumentReference |
Conclusion
HL7 segments are the building blocks of every HL7 v2 message. By understanding the purpose of segments such as MSH, PID, PV1, ORC, OBR, and OBX, developers and integration analysts can build more reliable interfaces, troubleshoot issues faster, and design scalable healthcare integrations.
Whether you're integrating laboratory systems, electronic health records, billing platforms, or radiology applications, mastering HL7 segments is one of the most valuable skills in healthcare interoperability.
Frequently Asked Questions
What is an HL7 segment?
An HL7 segment is a logical group of related data fields within an HL7 message. Each segment begins with a three-letter identifier such as MSH, PID, or OBX.
Which HL7 segment contains patient information?
The PID segment stores patient demographic and identification details, including the medical record number, patient name, date of birth, and gender.
What does the MSH segment do?
The MSH segment defines message metadata, including the sender, receiver, message type, processing ID, and HL7 version.
What is the difference between OBR and OBX?
The OBR segment describes the requested diagnostic test or procedure, while OBX segments contain the individual observation results produced by that test.
Can an HL7 message contain multiple OBX segments?
Yes. A single OBR segment is commonly followed by multiple OBX segments, each representing a different observation or laboratory result.
Which segment stores insurance information?
The IN1 segment contains insurance details such as payer information, policy number, and plan information.
Try HL7Toolbox
Practice with real HL7 messages using:
- HL7 Parser – Parse HL7 messages into a readable structure.
- HL7 Validator – Validate HL7 syntax and required fields.
- HL7 Compare Tool – Compare two HL7 messages and highlight differences.
- HL7 Viewer – Inspect messages with an easy-to-read interface.
References
- HL7 v2.x segment conventions
- Common hospital, laboratory, and billing interface mappings
- Production parsing and validation patterns for HL7 v2 messages
Editorial Review
HL7ToolBox content is written and reviewed by healthcare integration professionals with hands-on experience in HL7 v2.x, FHIR, healthcare APIs, and enterprise healthcare interfaces.