Schedule a demo
Healthcare/HL7 v2

HL7 v2 in Python

Parse, validate, and transform HL7 v2 messages with typed Python classes. Every segment, field, and datatype from v2.9 at your fingertips.

215
Message types
191
Segments
33
Datatypes
v2.9
HL7 version
hl7v2_service.py

Pythonic by design

Parse incoming messages or build new ones from scratch, all with typed Python classes.

Everything for HL7 v2

Parse, validate, transform, and exchange HL7 v2 messages, all in Python.

Semantic field access
Use msg.pid.patient_name instead of PID.5. Access any field by meaning, not position. Subcomponents work the same way.
All v2.9 segments
Every v2.9 segment as a typed Python class with full autocompletion and type checking.
Built-in validation
Validate field lengths, cardinality, required fields, datatypes, and terminology bindings.
MLLP channels
Receive and send HL7 v2 messages over MLLP with automatic acknowledgments. Zato handles the framing protocol so you focus on business logic.
Batch processing
Process multiple messages in batch and file wrappers with BHS/BTS and FHS/FTS segments.
JSON serialization
Convert messages to and from JSON with to_dict, from_dict, to_json, and from_json.

Learn by building

Step-by-step guides for HL7 v2 integration patterns.

HL7 v2 developer guides

In-depth documentation for working with HL7 v2 messages in Python.

Frequently asked questions

Zato supports HL7 v2.9, which is backward compatible with earlier versions including v2.3, v2.5, and v2.7. All standard segments and their datatypes are available as typed Python classes.

Configure an MLLP channel in Zato to listen for incoming HL7v2 messages. Your Python service receives parsed message objects automatically:

from zato.hl7v2 import HL7Message

msg = HL7Message.parse(raw_data)
patient = msg.pid.patient_name

Use HL7Message.parse() with the raw ER7 string:

from zato.hl7v2 import HL7Message

msg = HL7Message.parse(raw_data)
name = msg.pid.patient_name.family_name
mrn = msg.pid.patient_identifier_list

Yes, use semantic Python names instead of positional notation:

# Instead of PID.5, use:
msg.pid.patient_name

# Instead of PID.3, use:
msg.pid.patient_identifier_list

# Subcomponents work too:
msg.pid.patient_name.family_name

Yes, Zato has built-in MLLP support for sending and receiving HL7v2 messages. MLLP channels handle the framing protocol automatically, so you only work with parsed message objects in your Python code.

Yes, validate field lengths, cardinality, required fields, and datatype conformance:

from zato.hl7v2 import validate_message

result = validate_message(raw_data)
for error in result.errors:
    print(error.message)

Use parse_batch and parse_file to process multiple messages wrapped in BHS/BTS and FHS/FTS segments. Each message in the batch is parsed individually.

Yes, Zato supports transforming HL7v2 messages and segments to FHIR resources. You can map fields between standards and build FHIR bundles from HL7v2 messages.

All message types

Every HL7 message structure, grouped by domain.

Admissions, registration, and billing 42

ADT^A01 Admit / visit notification ADT^A02 Transfer a patient ADT^A03 Discharge / end visit ADT^A05 Pre-admit a patient ADT^A06 Change an outpatient to an inpatient ADT^A09 Patient departing - tracking ADT^A12 Cancel transfer ADT^A15 Pending transfer ADT^A16 Pending discharge ADT^A17 Swap patients ADT^A20 Bed status update ADT^A21 Patient goes on a leave of absence ADT^A24 Link patient information ADT^A37 Unlink patient information ADT^A38 Cancel pre-admit ADT^A39 Merge person - patient ID ADT^A43 Move patient information - patient identifier list ADT^A44 Move account information - patient account number ADT^A45 Move visit information - visit number ADT^A50 Change visit number ADT^A52 Cancel leave of absence for a patient ADT^A54 Change attending doctor ADT^A60 Update allergy information ADT^A61 Change consulting doctor BAR^P01 Add patient accounts BAR^P02 Purge patient accounts BAR^P05 Update account BAR^P06 End account BAR^P10 Transmit ambulance patient census BAR^P12 Update diagnosis / procedure DFT^P03 Post detail financial transaction DFT^P11 Post detail financial transaction - expanded EHC^E01 Submit health care services invoice EHC^E02 Cancel health care services invoice EHC^E04 Re-assess health care services invoice request EHC^E10 Edit / adjudication results EHC^E12 Request additional information EHC^E13 Additional information response EHC^E15 Payment / remittance advice EHC^E20 Submit authorization request EHC^E21 Cancel authorization request EHC^E24 Authorization response

Orders and order responses 34

OMG^O19 General clinical order OML^O21 Laboratory order OML^O33 Laboratory order for multiple orders related to a single specimen OML^O35 Laboratory order for multiple orders related to a single container of a specimen OML^O39 Specimen shipment centric laboratory order OML^O59 Laboratory order for additional work up OMP^O09 Pharmacy / treatment order OMI^O23 Imaging order OMB^O27 Blood product order OMD^O03 Dietary order OMN^O07 Non-stock requisition order OMS^O05 Stock requisition order OMQ^O57 General order message with document payload OPL^O37 Population / location-based laboratory order OPR^O38 Population / location-based laboratory order acknowledgment OSU^O51 Order status update OSU^O52 Order status update acknowledgment ORG^O20 General clinical order acknowledgment ORL^O22 General laboratory order response to any OML ORL^O34 Laboratory order response - multiple order per specimen ORL^O36 Laboratory order response - multiple order per container ORL^O40 Specimen shipment centric laboratory order acknowledgment ORL^O53 Laboratory general order response (to any OML) ORL^O54 Laboratory order response - multiple orders per specimen (to OML_O33) ORL^O55 Laboratory order response - multiple orders per container (to OML_O35) ORL^O56 Specimen shipment centric laboratory order acknowledgment (to OML_O39) RCV^O59 Laboratory order for additional work up response ORP^O10 Pharmacy / treatment order acknowledgment ORI^O24 Imaging order acknowledgment ORB^O28 Blood product order acknowledgment ORD^O04 Dietary order acknowledgment ORN^O08 Non-stock requisition order acknowledgment ORS^O06 Stock requisition order acknowledgment ORX^O58 General order message with document payload acknowledgment

Queries, responses, and master files 53

QBP^E03 Query health care services invoice status QBP^E22 Query authorization information QBP^O33 Query for order status QBP^O34 Query for order status - order based QBP^Q11 Query by parameter QBP^Q13 Query by parameter - tabular response QBP^Q15 Query by parameter - display response QBP^Q21 Get related clinical observations QBP^Qnn Query by parameter - site defined QBP^Z73 Query for information about donor eligibility QCN^J01 Cancel query / grant continuation QSB^Q16 Create subscription QVR^Q17 Query for previous events RDY^K15 Display response in response to QBP_Q15 RDY^Z80 Dispense information RSP^E03 Response to query health care services invoice status RSP^E22 Response to query authorization information RSP^K11 Segment pattern response RSP^K21 Get person demographics response RSP^K22 Find candidates response RSP^K23 Get corresponding identifiers response RSP^K25 Personnel information by segment response RSP^K31 Dispense history response RSP^K32 Find candidates including visit information response RSP^O33 Order status response RSP^O34 Order status response - order based RSP^Z82 Dispense history response RSP^Z84 Who am I response RSP^Z86 Pharmacy information comprehensive response RSP^Z88 Dispense information response RSP^Z90 Lab results history response RSP^Znn Segment pattern response - site defined RTB^K13 Tabular response RTB^Knn Tabular response - site defined RTB^Z74 Information about phone calls response MFK^M01 Master file acknowledgment MFN^M02 Master file - staff practitioner MFN^M04 Master file - charge description MFN^M05 Patient location master file MFN^M06 Clinical study with phases and schedules master file MFN^M07 Clinical study without phases but with schedules master file MFN^M08 Test / observation (numeric) master file MFN^M09 Test / observation (categorical) master file MFN^M10 Test / observation batteries master file MFN^M11 Test / calculated observations master file MFN^M12 Master file notification message MFN^M13 Master file notification - general MFN^M15 Inventory item master file notification MFN^M16 Master file notification - inventory item enhanced MFN^M17 DRG master file MFN^M18 Master file notification - test / observation (payer) MFN^M19 Contract master file MFN^Znn Master file notification - site defined

All segments

Every HL7 segment, grouped by domain.

Master files, scheduling, and specialty 51

MFI Master file identification MFE Master file entry MFA Master file acknowledgment OM1 General segment OM2 Numeric observation OM3 Categorical service / test / observation OM4 Observations that require specimens OM5 Observation batteries (sets) OM6 Observations calculated from other observations OM7 Additional basic attributes OMC Observation map component CDM Charge description master CM0 Clinical study master CM1 Clinical study phase master CM2 Clinical study schedule master CDO Clinical study data object DMI DRG master file information PM1 Payer master file MCP Master file coverage policy LOC Location identification LCH Location characteristic LDP Location department LCC Location charge code LRL Location relationship STF Staff identification PRA Practitioner detail ORG Practitioner org unit AFF Professional affiliation LAN Language detail EDU Educational detail CER Certificate detail SCH Scheduling activity information AIS Appointment information - service AIG Appointment information - general resource AIL Appointment information - location resource AIP Appointment information - personnel resource APR Appointment preferences ARQ Appointment request RF1 Referral information AUT Authorization information PRD Provider data CTD Contact data CSR Clinical study registration CSP Clinical study phase CSS Clinical study data schedule segment CTI Clinical trial identification TXA Transcription document header SCD Anti-microbial cycle data SDD Sterilization device data SLT Sterilization lot STZ Sterilization parameter

Ready to build HL7 v2 integrations?

Get started with Zato and connect your healthcare systems in minutes.

Open source In Python