HL7 v2 Message Parser
Split a pipe-delimited HL7 v2 message into segments and fields.
Overview
The HL7 v2 parser breaks down a pipe-delimited Health Level 7 v2 message into its segments, fields, components, and subcomponents. Paste an ADT, ORM, ORU, or any other v2 message and see the MSH header, patient demographics, and observation segments laid out for inspection.
Healthcare integration engineers and interface analysts use an hl7 parser when diagnosing routing problems, validating a vendor's outbound feed, or reverse-engineering a sample message. It saves the eye-watering work of counting pipes by hand.
How it works
HL7 v2 messages use a four-level hierarchy with character separators encoded in the MSH-2 field: | for fields, ^ for components, & for subcomponents, ~ for repetitions, and \ for escapes. The parser reads MSH first to pick up the actual separators (some interfaces use custom characters), then splits every subsequent segment accordingly.
Each segment is identified by its three-letter type code (MSH, PID, OBR, OBX, etc.) and field positions are numbered starting at 1 — except for MSH where position 1 is the field separator itself. The output shows each piece with both its HL7 path (e.g. PID-5.1) and a human-readable description from the v2.5 dictionary.
Examples
Input (one line):
MSH|^~\&|EPIC|HOSP|LAB|HOSP|20240115||ADT^A01|123|P|2.5
Output:
MSH-3 Sending Application EPIC
MSH-4 Sending Facility HOSP
MSH-5 Receiving Application LAB
MSH-7 Date/Time 20240115
MSH-9 Message Type ADT^A01 (Admit/visit notification)
MSH-10 Message Control ID 123
MSH-12 Version 2.5
PID|1||MRN123||Doe^John^A||19800115|M
Output:
PID-3 Patient ID MRN123
PID-5.1 Family Name Doe
PID-5.2 Given Name John
PID-7 Birth Date 19800115
PID-8 Sex M
FAQ
Does it support HL7 v3 or FHIR?
No — v2 only. HL7 v3 uses XML and FHIR uses JSON/XML resources; both are entirely different specifications and need their own parsers.
Is the message validated against a schema?
The parser splits structure but doesn't validate cardinality or required-field rules. For full validation, run the message through an HL7 conformance profile tool with the relevant message specification.
How are escape sequences handled?
The encoding characters (\F\, \S\, \T\, \R\, \E\) are decoded back to the literal separator characters when displaying field values, so escaped pipes and carets appear correctly in the output.