Inferensys

Glossary

HL7 v2

HL7 v2 is a widely implemented 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.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
LEGACY HEALTHCARE MESSAGING STANDARD

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.

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.

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.

LEGACY INTEROPERABILITY STANDARD

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.

01

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.

02

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.

03

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.

04

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.
05

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.

06

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.
HEALTHCARE INTEROPERABILITY STANDARDS COMPARISON

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.

FeatureHL7 v2FHIR (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

HL7 V2 INTEROPERABILITY

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.

Prasad Kumkar

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.