HL7

What Is HL7 Parsing? A Complete Technical Guide

Everything healthcare integration engineers need to know about HL7 v2 message structure, segment decoding, and clinical data pipeline design.

Disclaimer: This guide is provided by Efneze for educational and technical reference purposes only. HL7®, FHIR®, and related standards are trademarks of Health Level Seven International. Efnezeis not affiliated with or endorsed by Health Level Seven International. For official requirements, always refer to the applicable official specification and your organization's implementation guidance.

What Is HL7?

HL7 (Health Level Seven International) is a non-profit organization that develops international standards for the exchange of health information. The "Seven" refers to the seventh layer of the OSI model (application layer), reflecting the focus on healthcare application interoperability.

HL7 v2 is the most-deployed healthcare messaging standard in the world. Despite being developed in the late 1980s, it remains the operational backbone of clinical data exchange in US hospitals — Epic, Cerner, Meditech, and virtually every other EHR vendor generates HL7 v2 interfaces.

HL7 v2 Message Structure

An HL7 v2 message is a plain-text, pipe-delimited format. Each message consists of one or more segments separated by carriage returns. The structure follows these rules:

  • Segment separator: Carriage return (\r)
  • Field separator: Pipe (|)
  • Component separator: Caret (^)
  • Subcomponent separator: Ampersand (&)
  • Repetition separator: Tilde (~)
  • Escape character: Backslash (\)

Anatomy of an HL7 ADT^A01 Message

An ADT (Admission, Discharge, Transfer) message is the most common HL7 message type. Here is a minimal admission message:

MSH|^~\&|EPIC|MAIN_HOSPITAL|ADT_SYSTEM|EXT|20240115140000||ADT^A01|MSG12345|P|2.5.1

EVN||20240115140000

PID|||MRN12345^^^MAIN_HOSPITAL^MR||DOE^JOHN^A||19800322|M|||123 MAIN ST^^BOSTON^MA^02101||6175551234

PV1||I|4N^401^A^MAIN_HOSPITAL|||12345^SMITH^MARY^A^MD|||MED||||A|||12345^SMITH^MARY^A^MD|INP||||||||||||||||||MAIN_HOSPITAL|V12345|20240115140000

HL7 Parsing in Healthcare ETL Pipelines

In production healthcare environments, HL7 parsing is the first step in a clinical data ingestion pipeline. The typical architecture involves:

  1. HL7 Listener: An integration engine (Mirth Connect, Rhapsody) receives HL7 messages via MLLP (Minimal Lower Layer Protocol) over TCP.
  2. Message Routing: Messages are inspected at MSH-9 (message type) and routed to appropriate processing channels.
  3. Field Extraction: Specific fields are extracted — PID-5 for patient name, PID-7 for date of birth, PID-3 for MRN.
  4. Transformation: Data is normalized (date formats, terminology codes, name structures) and mapped to target schemas.
  5. Storage/Forwarding: Transformed data is stored in a database, forwarded to a FHIR server, or published to a message queue (Kafka, SQS).

Common HL7 Parsing Challenges

  • Z-Segments: Vendor-specific custom segments (Z-segments) not in the standard specification require custom parsing logic per site.
  • Encoding variations: Different systems use different field separators or escape characters — always inspect MSH-1 and MSH-2.
  • Repeated fields: PID-3 (Patient ID) often contains multiple identifiers separated by ~ — all must be parsed and handled.
  • Missing optional segments: Not all message types include all segments. Parsers must handle missing NK1, DG1, or IN1 gracefully.
  • Legacy encoding issues: Older systems may send Windows-1252 or Latin-1 encoded messages instead of UTF-8.

Try the Free HL7 Parser

Paste any HL7 message and quickly see the decoded segment structure.

Open HL7 Parser →

Frequently Asked Questions

Is HL7 v2 still used in healthcare?

Yes. HL7 v2 remains the dominant messaging standard in US hospital systems. Despite FHIR's growth, over 95% of US hospitals still use HL7 v2 for operational interoperability — ADT feeds, lab results, pharmacy orders, and scheduling. Most healthcare systems run both simultaneously.

What tool do I use to parse HL7 messages?

Integration engines like Mirth Connect, Rhapsody, or Azure APIM handle HL7 parsing in production environments. For development and analysis, browser-based parsers like the ${Brand.name} HL7 Parser let you decode messages quickly without installing software.

What is the difference between HL7 v2 and v3?

HL7 v2 uses pipe-delimited text; it is simple, widely implemented, and event-driven. HL7 v3 used XML-based Clinical Document Architecture (CDA) and was complex to implement, leading to low adoption. FHIR (sometimes called v4) replaced both with a RESTful JSON approach.