HL7 Segment Reference Guide

Published

June 26, 2026

Last Updated

June 26, 2026

Reading Time

12 min

Author

Laksh Patel
LP

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.

17+ Years Software Development5+ Years Healthcare Integration3,000+ Healthcare Interfaces Delivered

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

SegmentPurpose
MSHMessage Header
EVNEvent Information
PIDPatient Identification
NK1Next of Kin
PV1Patient Visit
PV2Additional Visit Information
ORCCommon Order
OBRObservation Request
OBXObservation Result
DG1Diagnosis
PR1Procedures
AL1Allergy Information
GT1Guarantor
IN1Insurance
FT1Financial Transaction
TXADocument 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

FieldDescription
MSH-3Sending Application
MSH-4Sending Facility
MSH-5Receiving Application
MSH-6Receiving Facility
MSH-7Date/Time
MSH-9Message Type
MSH-10Message Control ID
MSH-11Processing ID
MSH-12HL7 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

FieldDescription
PID-3Medical Record Number (MRN)
PID-5Patient Name
PID-7Date of Birth
PID-8Sex
PID-11Address
PID-13Phone Number
PID-19SSN / 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

FieldDescription
PV1-2Patient Class
PV1-3Assigned Location
PV1-7Attending Doctor
PV1-10Hospital Service
PV1-19Visit 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

FieldDescription
OBR-4Universal Service ID
OBR-7Observation Date
OBR-16Ordering Provider
OBR-22Result 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

STTXNMCECWESNDTTMED

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 Hypertension

AL1 (Allergy)

Stores allergy information.

AL1|1|DA|PENICILLIN

IN1 (Insurance)

Stores policy information like Company, Policy Number, Group, and Plan.

IN1|1|ABC001|BlueCross

GT1, FT1, TXA

GT1: Guarantor / responsible party.
FT1: Financial transactions (charges/payments).
TXA: Document metadata (ID, Author).

Segment Relationships

Typical Laboratory Workflow

MSH
PID
PV1
ORC
OBR
OBX
OBX
OBX

Patient Registration

MSH
EVN
PID
NK1
PV1
GT1
IN1

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 SegmentCommon FHIR Resource
PIDPatient
PV1Encounter
NK1RelatedPerson
ORCServiceRequest
OBRServiceRequest / DiagnosticReport
OBXObservation
DG1Condition
AL1AllergyIntolerance
IN1Coverage
TXADocumentReference

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.