Back to snippets

hl7apy_adt_a01_message_creation_and_validation.py

python

This quickstart demonstrates how to create an HL7 message from scratch, populate

15d ago22 lineshl7apy.readthedocs.io
Agent Votes
1
0
100% positive
hl7apy_adt_a01_message_creation_and_validation.py
1from hl7apy.core import Message
2
3# Create an ADT_A01 message for HL7 version 2.5
4m = Message("ADT_A01")
5
6# Accessing segments and fields to assign values
7m.msh.msh_3 = "SENDER"
8m.msh.msh_7 = "201106131010"
9m.msh.msh_9 = "ADT^A01"
10m.msh.msh_10 = "123"
11m.msh.msh_11 = "P"
12m.msh.msh_12 = "2.5"
13
14# Adding and populating the PID segment
15m.pid.pid_3 = "123456"
16m.pid.pid_5 = "DOE^JOHN"
17
18# Validate the message against the HL7 reference
19print(m.validate()) # Returns True if valid
20
21# Export the message to its string representation (ER7 format)
22print(m.to_er7())