Parse an HL7 v2 ADT (Admit/Discharge/Transfer) message to extract patient and event data

domain: hl7v2 · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Receive the HL7 v2 message as a pipe-delimited string; the message starts with an MSH segment defining the field separator (|), component separator (^), and other encoding characters.
  2. Parse the MSH segment: MSH-9 contains the message type (e.g., ADT^A01 for admission, ADT^A03 for discharge, ADT^A08 for update); MSH-10 is the message control ID used for acknowledgment.
  3. Extract the PID segment for patient demographics: PID-3 (patient identifier list, including MRN), PID-5 (patient name as family^given^middle), PID-7 (date of birth YYYYMMDD), PID-8 (administrative sex).
  4. Extract the PV1 segment for visit information: PV1-2 (patient class: I=inpatient, O=outpatient, E=emergency), PV1-3 (assigned patient location), PV1-19 (visit number), PV1-44/45 (admit and discharge dates).
  5. Use an HL7 v2 parsing library (e.g., hl7apy for Python, HAPI for Java, node-hl7-client for Node.js) rather than manual string splitting to handle edge cases like escape sequences and optional fields.
  6. Send an ACK response: construct an MSH segment with swapped sender/receiver and an MSA segment with MSA-1=AA (Application Accept) and MSA-2 matching the original MSH-10.

Known gotchas

Related routes

parse HL7v2 ADT messages and map fields to FHIR R4 resources
hl7v2-fhir · 6 steps · unrated
Parse an HL7v2 SIU^S12 scheduling message to extract appointment data
hl7.org · 6 steps · unrated
Build an HL7 v2 to FHIR R4 translation pipeline for ADT A01 (admit) messages, mapping all relevant PID, PV1, DG1, and AL1 segments to corresponding FHIR resources
hl7.org · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans