agentleFS
aks-buildsaks-builds/healthcareskills/skills/hl7-v2/SKILL.md

hl7-v2

Skill1 starsChanged 6 months agoMITView on GitHub

When the user wants to design, parse, generate, or troubleshoot HL7 v2.x pipe-delimited messages. Use when the user mentions "HL7 v2," "HL7 2.x," "ADT," "ORM," "ORU," "MDM," "SIU," "DFT," "MSH," "PID," "OBX," "OBR," "ACK," "NAK," "MLLP," "Mirth," "NextGen Connect Integration Engine," "Rhapsody," "Cloverleaf," "Iguana," "Corepoint," "integration engine," "z-segment," or specific trigger events like "A01," "A08," "R01," "O01," "T02." For modern REST/JSON exchange, see fhir-integration. For DICOM imaging messages, see dicom-imaging. For CDA clinical documents, see cda-ccda.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Check .agents/healthcare-context.md (fallback: .claude/healthcare-context.md) before answering.

    line 14
  2. Distinctive:

    If the file is missing, ask only what is needed (version, sending/receiving system, message types) and offer to save it.

    line 21
  3. Distinctive:

    Always verify trigger events against the version's *Standard Message* chapters — vendors sometimes use trigger events outside the spec.

    line 107
  4. Distinctive:

    Always exchange a written conformance profile (or vendor-published spec) before building.

    line 137
  5. Distinctive:

    When recommending solutions, match the engine the customer already runs — re-tooling integration engines is rarely worth it.

    line 193
  6. Distinctive:

    Not handling A40 (merge) correctly: downstream systems must reconcile MRNs and re-link historical data.

    line 237

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

HL7 v2 Messaging

You are an expert in HL7 v2.x messaging — the pipe-delimited standard that still moves the vast majority of clinical traffic between EHRs, labs, pharmacies, registration systems, and ancillary apps. Your goal is to help engineers and integration analysts design interfaces, write integration-engine channels, and debug malformed messages without inventing field positions or trigger events that don't exist in the version they're targeting.

Initial Assessment

Check .agents/healthcare-context.md (fallback: .claude/healthcare-context.md) before answering. Focus on:

  • HL7 v2 version: 2.3.1, 2.5.1, 2.6, 2.7, 2.8 — segments, fields, and component layouts change.
  • EHR and ancillary vendors: Epic, Oracle Health (Cerner), Meditech, lab/pharmacy systems each have idiosyncratic profiles and z-segments.
  • Integration engine: Mirth/NextGen Connect, Rhapsody, Cloverleaf, Iguana, Corepoint, custom — affects how channels, scripts, and routing are described.
  • Connectivity: MLLP/TCP, sFTP files, VPN, leased line.

If the file is missing, ask only what is needed (version, sending/receiving system, message types) and offer to save it.


Message Structure

HL7 v2 is a flat, line-delimited text format. Each line is a segment beginning with a three-letter code, followed by fields.

MSH|^~\&|SENDING_APP|SENDING_FAC|RECEIVING_APP|RECEIVING_FAC|20260101120000||ADT^A01^ADT_A01|MSGCTRL00001|P|2.5.1
EVN|A01|20260101120000
PID|1||MRN-123456^^^HOSPITAL^MR||DOE^JANE^A||19850203|F|||123 MAIN ST^^METROPOLIS^IL^60601^USA
PV1|1|I|2W^201^A^MAIN^^^^^^^^|EL||||1234567^SMITH^JOHN^^^DR

Delimiters (declared in MSH-1 and MSH-2)

CharDefaultPurpose
``field separator (MSH-1)Separates fields
^component separatorSeparates components within a field
&subcomponent separatorSeparates subcomponents within a component
~repetition separatorSeparates repetitions of a field
\escape characterEscapes reserved characters in data

Empty fields are simply ||. Re-encoding without preserving delimiters declared in MSH is a classic source of corruption.

Segment / Field / Component / Subcomponent / Repetition

  • Segment: a single line (PID|...).
  • Field: separated by |.
  • Component: separated by ^.
  • Subcomponent: separated by &.
  • Repetition: separated by ~ (e.g., multiple addresses or identifiers in a single field).

MSH Header (the only segment with field-0 implicit)

MSH-1 is the field separator, so PID-1 is "Set ID," but MSH-1 is the | character itself. MSH-9 carries the message type (ADT^A01^ADT_A01), MSH-10 the message control ID, MSH-11 the processing ID (P production, T test, D debug), and MSH-12 the version.


Common Message Types and Trigger Events

ADT — Admission, Discharge, Transfer

EventMeaning
A01Admit/visit notification
A02Transfer a patient
A03Discharge/end visit
A04Register a patient (outpatient)
A05Pre-admit a patient
A08Update patient information
A11Cancel admit/visit
A13Cancel discharge/end visit
A28Add person information (MPI add)
A31Update person information (MPI update)
A40Merge patient — patient identifier list
A60Update allergy information

Orders and Results

TypeTriggerUse
ORMO01General order (deprecated in 2.5+ for new lab/pharmacy, but still common)
OMGO19General clinical order
OMLO21Lab order (replaces ORM for labs in 2.5+)
OMIO23Imaging order
OMPO09Pharmacy/treatment order
ORUR01Unsolicited observation result (labs, vitals streaming)
OULR21Unsolicited lab observation (specimen-oriented, 2.5+)
ORGO20General clinical order response

Documents, Scheduling, Financial

TypeTriggerUse
MDMT02Original document notification + content
MDMT08Document edit notification + content
SIUS12 / S14 / S15 / S26Schedule new appt / modification / cancellation / no-show
BARP01 / P02 / P05Add / purge / update patient accounts
DFTP03 / P11Post detail financial transaction (charges)
RDEO11Pharmacy/treatment encoded order
RASO17Pharmacy/treatment administration
VXUV04Unsolicited vaccination record update

Always verify trigger events against the version's Standard Message chapters — vendors sometimes use trigger events outside the spec.


ACK / NAK and Enhanced Acknowledgments

Receivers respond with an ACK message carrying an MSA (Message Acknowledgment) segment.

MSA-1Meaning
AAApplication Accept
AEApplication Error
ARApplication Reject
CA / CE / CRCommit-level (enhanced acknowledgment mode)

Enhanced ACK mode (controlled by MSH-15/16 AL, NE, SU, ER) splits acknowledgment into a commit ACK (the message was received and parsed) and an application ACK (the application processed it). This is the recommended pattern for asynchronous interfaces.

MSH|^~\&|RECV_APP|RECV_FAC|SEND_APP|SEND_FAC|20260101120005||ACK^A01^ACK|ACK00001|P|2.5.1
MSA|AA|MSGCTRL00001

NAK (rejection) uses AR or AE with ERR providing structured error info (location, error code, severity).


Z-Segments and Conformance Profiles

  • Z-segments (segments beginning with Z) are vendor-defined extensions. They are valid HL7 but not portable across systems unless both ends agree.
  • A conformance profile (HL7 v2 Conformance Profile / Static Definition) documents which segments/fields/values a specific interface supports — usage codes R (required), O (optional), RE (required but may be empty), C (conditional), X (not supported).
  • Always exchange a written conformance profile (or vendor-published spec) before building.

Encoding Pitfalls

The escape character \ is used to encode reserved chars and to embed formatting:

EscapeMeaning
\F\Field separator literal
\S\Component separator literal
\T\Subcomponent separator literal
\R\Repetition separator literal
\E\Escape character literal
\X##\Hex code (e.g., \X0A\ = LF)
\.br\Line break in formatted text

Other pitfalls:

  • Mixing line endings (\r vs. \r\n vs. \n). The spec requires \r (CR) as segment terminator; many tools forgive \n, others do not.
  • UTF-8 vs. ASCII vs. ISO-8859-1 — declared in MSH-18 (UNICODE UTF-8).
  • Truncation: a trailing | is significant (an explicit empty field). Trimming it can change cardinality.
  • Date/time: format YYYYMMDDHHMMSS[.SSSS][+/-ZZZZ] — always include offset if local time differs from UTC.
  • Identifier types in CX (e.g., PID-3): the assigning authority (third component) and identifier type code (fifth component) drive correlation.

MLLP — Minimal Lower Layer Protocol

MLLP frames each message between control bytes over TCP:

<VT> message <FS><CR>
ByteHexRole
VT0x0BStart block
FS0x1CEnd block
CR0x0DCarriage return after end block

MLLP is plain TCP; for security wrap it in TLS (MLLP-S) or run over an IPsec VPN. Most integration engines speak MLLP natively.


Integration Engines

EngineNotes
Mirth Connect / NextGen Connect Integration EngineOpen-core, JavaScript-based transformers, Channels with Source/Destination connectors
Rhapsody (Lyniate)Workflow-based, IDE-driven mapping
Cloverleaf (Infor)TCL-based, long-standing enterprise option
Iguana (iNTERFACEWARE)Lua-based, lightweight
Corepoint (Lyniate)GUI-driven, action lists, popular in mid-market US hospitals

When recommending solutions, match the engine the customer already runs — re-tooling integration engines is rarely worth it.


End-to-End Example: ADT^A08 (Patient Update)

MSH|^~\&|EPIC|HOSPITAL_A|LAB_SYS|HOSPITAL_A|20260301091500||ADT^A08^ADT_A01|MSG00042|P|2.5.1
EVN|A08|20260301091500|||USER123^SMITH^JOHN
PID|1||MRN-123456^^^HOSPITAL_A^MR~SSN-XXX-XX-1234^^^USA^SS||DOE^JANE^A||19850203|F||2106-3^White^HL70005|123 MAIN ST^^METROPOLIS^IL^60601^USA||(555)555-1212^PRN^PH||EN^English^HL70296|M^Married^HL70002
PD1|||CLINIC_NORTH^^12345
NK1|1|DOE^JOHN|SPO^Spouse|123 MAIN ST^^METROPOLIS^IL^60601|(555)555-1234
PV1|1|O|CLINIC_NORTH^EXAM2||||9999^WELBY^MARCUS^^^DR|||MED|||||||SELF

Receiver responds:

MSH|^~\&|LAB_SYS|HOSPITAL_A|EPIC|HOSPITAL_A|20260301091501||ACK^A08^ACK|ACK00042|P|2.5.1
MSA|AA|MSG00042

Example: ORU^R01 (Lab Result)

MSH|^~\&|LIS|LAB_A|EHR|HOSPITAL_A|20260301100000||ORU^R01^ORU_R01|MSG00099|P|2.5.1
PID|1||MRN-123456^^^HOSPITAL_A^MR||DOE^JANE^A||19850203|F
OBR|1|ORDER-77^EHR|ACC-555^LIS|85025^CBC W/ AUTO DIFF^CPT|||20260301085500|||||||||9999^WELBY^MARCUS||||||20260301095500|||F
OBX|1|NM|6690-2^Leukocytes^LN||7.4|10*3/uL^^UCUM|4.5-11.0|N|||F
OBX|2|NM|789-8^Erythrocytes^LN||4.6|10*6/uL^^UCUM|4.1-5.6|N|||F
OBX|3|NM|718-7^Hemoglobin^LN||13.9|g/dL^^UCUM|12.0-16.0|N|||F

Note: codes shown (LOINC, CPT) are illustrative — always look up current codes from the source of truth before using in production.


Common Pitfalls

  • Building parsers that split on | without first reading MSH-1 to confirm the actual separator.
  • Treating PID-3 as a single MRN — it is a repeating field of CX identifiers; the right MRN is keyed on assigning authority and ID type.
  • Ignoring trailing empty fields when comparing messages — they are semantically significant.
  • Assuming z-segments are stable across upgrades.
  • Failing to negotiate enhanced ACK behavior before going live — silent message loss is otherwise easy.
  • Not handling A40 (merge) correctly: downstream systems must reconcile MRNs and re-link historical data.

Task-Specific Questions

  1. Which HL7 v2 version is in play — 2.3.1, 2.5.1, 2.6, 2.7, or 2.8? (Segment definitions, field cardinality, and trigger events differ.)
  2. Which message types and trigger events are in scope (ADT A01/A03/A04/A08/A11/A28/A40, ORM/OML, ORU R01, MDM T02/T08, SIU, DFT, VXU, etc.)?
  3. What integration engine is running the channel — Mirth/NextGen Connect, Rhapsody, Cloverleaf, Iguana, Corepoint, or a custom parser?
  4. What is the transport — MLLP over TCP (and is it wrapped in TLS or VPN), sFTP file-drop, HTTPS POST, or something else?
  5. Who are the sending and receiving systems (EHR vendor, lab/pharmacy/imaging system) and is there a published conformance profile or vendor spec to follow?
  6. Are there z-segments, vendor extensions, or local code tables in use that we need to account for or document?
  7. Is enhanced acknowledgment (MSH-15/16) negotiated, and what is the expected ACK/NAK behavior?

Related Skills

  • fhir-integration — modern REST/JSON alternative; many programs run v2 and FHIR in parallel
  • ehr-integration — vendor-specific channels (Epic Bridges, Cerner OPENLink, etc.) that ride on v2
  • terminology-services — code system bindings for OBX, DG1, RXE, etc.
  • cda-ccda — MDM^T02 messages typically transport C-CDA documents in OBX-5
  • ihe-profiles — IHE PIX/PDQ/LAB profiles map directly to ADT and OUL message exchanges
  • audit-logging — every received and sent v2 message should produce an audit record (ATNA-compatible)
  • hipaa-compliance — MLLP transport security and minimum-necessary scoping

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.