HL7 v2 is a legacy healthcare messaging standard that uses a proprietary, pipe-and-hat (|^~\&) delimited format to encode clinical and administrative events into discrete message segments. Unlike modern API-based standards, it operates over a Lower Layer Protocol (often Minimal Lower Layer Protocol, or MLLP) using TCP/IP sockets, wrapping each message with start and end block characters to ensure message boundary integrity during transmission.
Glossary
HL7 v2

What is HL7 v2?
HL7 v2 is a widely implemented, pipe-and-hat delimited messaging standard that defines the structure and encoding rules for the electronic exchange of clinical and administrative data between hospital information systems.
Each HL7 v2 message is composed of segments (e.g., MSH for message header, PID for patient identification, OBR for observation request), which are further decomposed into fields, components, and sub-components separated by the defined delimiter characters. A trigger event, such as an admission (A01) or lab result (R01), initiates message generation, and the standard's inherent flexibility—allowing extensive Z-segments for custom local definitions—has driven its near-universal adoption in hospital ADT and orders workflows despite its lack of a formal information model.
Key Characteristics of HL7 v2
HL7 v2 is a widely implemented messaging standard that defines a pipe-and-hat delimited format for the electronic exchange of clinical and administrative data. Its design prioritizes flexibility and backward compatibility, making it the dominant protocol in hospital information systems despite its age.
Pipe-and-Hat Encoding
HL7 v2 messages use a non-XML, delimited format where fields are separated by pipes (|), components by carets (^), sub-components by ampersands (&), and repetitions by tildes (~). This compact, positional syntax was designed to minimize bandwidth on legacy serial connections. For example, a patient name segment might appear as PID||12345^5^M11^ADT1^MR^UH|. Parsing requires strict adherence to the segment-specific grammar defined in the standard.
Trigger Events and Message Types
Communication in HL7 v2 is driven by trigger events—real-world occurrences like a patient admission (A01), discharge (A03), or lab order (ORM^O01). Each trigger event maps to a specific message type that defines the required and optional segments. This event-driven architecture ensures that data flows automatically in response to clinical workflow state changes, reducing manual data entry.
Z-Segments for Customization
A defining feature of HL7 v2 is its extensibility through Z-segments. Vendors and healthcare organizations can define custom segments (e.g., ZPD for custom patient demographics) to transmit data not covered by the standard. While this flexibility drove widespread adoption, it also created a major interoperability challenge: Z-segments are site-specific and require custom mapping in interface engines like Mirth Connect to normalize data across systems.
Acknowledgment Protocol
HL7 v2 implements a robust application-level acknowledgment (ACK) mechanism to ensure reliable delivery. A receiving system must return an acknowledgment message confirming successful processing. The standard defines multiple acknowledgment codes:
- AA: Application Accept
- AE: Application Error
- AR: Application Reject This protocol is critical for patient safety, ensuring that a lab order or pharmacy request was not lost in transit.
Version Compatibility
The standard has evolved through versions, with v2.5.1 and v2.7 being the most common in production. A key design principle is backward compatibility: a v2.7 system can parse a v2.3 message. However, forward compatibility is not guaranteed. Interface engines must often handle multiple versions simultaneously, translating between them to bridge legacy ADT systems and modern clinical applications.
Segment-Based Structure
Every HL7 v2 message is composed of a hierarchical sequence of segments, each identified by a three-character code. Key segments include:
- MSH: Message Header (control information)
- PID: Patient Identification
- PV1: Patient Visit
- OBR: Observation Request
- OBX: Observation Result Each segment occupies a separate line and contains a defined sequence of fields, making the message human-readable but structurally rigid.
HL7 v2 vs. FHIR vs. CDA
A technical comparison of the three foundational HL7 standards for clinical data exchange, covering their messaging paradigms, transport mechanisms, and implementation complexity.
| Feature | HL7 v2 | FHIR (R4/R5) | CDA (C-CDA) |
|---|---|---|---|
Messaging Paradigm | Event-driven, unsolicited messages | RESTful API with discrete resources | Persistent clinical document |
Data Format | Pipe-and-hat delimited (ER7) | JSON, XML, Turtle (RDF) | XML only |
Transport Protocol | MLLP over TCP/IP | HTTPS (REST) | XDS.b, Direct Messaging, SMTP |
Granularity | Segments and fields | Discrete resources (Patient, Observation) | Whole document (header + body) |
Human Readability | |||
Semantic Interoperability | Implicit via Z-segments and lookup tables | Explicit via coded elements and terminology bindings | Explicit via structured templates and value sets |
Query Capability | Limited (QBP/RSP messages) | Rich (search parameters, chaining, _include) | Document-level (XDS.b registry queries) |
Stateless Architecture |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the HL7 Version 2 messaging standard, its structure, and its role in modern healthcare data exchange.
HL7 Version 2 (v2) is a legacy healthcare messaging standard that defines a pipe-and-hat delimited format for the electronic exchange of clinical and administrative data between hospital information systems. It works by transmitting discrete, event-driven messages—such as patient admissions, laboratory orders, or observation results—over a TCP/IP connection using Minimal Lower Layer Protocol (MLLP). Each message is composed of segments (e.g., MSH for message header, PID for patient identification, OBR for observation request), which are further broken down into fields, components, and sub-components separated by pipe (|), caret (^), and ampersand (&) characters respectively. The standard is not a plug-and-play data model; it is a flexible framework with numerous optional fields and Z-segments for vendor-specific customization, which necessitates rigorous conformance profiling between trading partners to ensure semantic interoperability.
Related Terms
Mastering HL7 v2 requires understanding the surrounding ecosystem of integration engines, data transformation patterns, and complementary standards that enable seamless clinical data exchange.
Canonical Data Model
A design pattern that defines a single, standard, application-independent data format to which all incoming HL7 v2 messages are translated. Instead of building point-to-point mappings between every system pair, each interface only needs to map to and from the canonical model.
- Drastically reduces mapping complexity from O(n²) to O(n)
- Provides a consistent semantic layer across the enterprise
- Simplifies onboarding of new systems
Data Mapping
The process of defining field-level correspondences between a source HL7 v2 segment and a target system's schema. A mapper must understand that PID-3 in an ADT message maps to the patient identifier field in the receiving EHR.
- Handles code set translation (e.g., local codes to LOINC)
- Manages structural transformation (v2 segments to XML or JSON)
- Requires deep knowledge of both sending and receiving system data dictionaries
Guaranteed Delivery
A message queuing mechanism ensuring no clinical message is ever lost in transit. When an interface engine receives an HL7 v2 message, it persists the message to disk and only deletes it after the receiving system sends a positive ACK (acknowledgment) message.
- Protects against network failures and system downtime
- Uses sequence numbering to detect gaps
- Critical for patient safety in lab result and medication order workflows
Hub-and-Spoke Model
An integration architecture where all clinical applications connect to a central interface engine rather than directly to each other. The engine receives HL7 v2 messages from any source, applies routing rules, and delivers transformed data to the appropriate destination.
- Replaces brittle point-to-point interfaces
- Centralizes monitoring, logging, and error handling
- Simplifies compliance auditing with a single data flow map

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us