HL7 v2 & integration
Send test messages
Use the lab's HL7 sender to turn a Synthea patient into an ADT^A04 and send it to the engine.
~/fhir-lab/hl7/send-adt picks a Synthea patient, builds a valid HL7 v2.5 ADT^A04 with hl7apy, wraps it in MLLP, sends it to the engine and prints the ACK.
Use it#
cd ~/fhir-lab/hl7
./send-adt --dry-run # build and print, don't send
./send-adt # random patient to localhost:6661
./send-adt --port 6662 # another channel
./send-adt /synthea/Agnes294_Laree109_McClure239_922fb35e-148d-9e82-7e65-bfa05e3b3515.jsonThe Synthea output folder is mounted at /synthea inside the container, so name a specific bundle by its /synthea/... path.
MSH|^~\&|FHIRLAB|SYNTHEA|OIE|LAB|20261126101500||ADT^A04^ADT_A01|MSG20261126101500123|P|2.5
EVN|A04|20261126101500
PID|1||922fb35e-148d-9e82-7e65-bfa05e3b3515^^^SYNTHEA^MR||McClure^Agnes||19870314|F|||...
PV1|1|O
--- ACK ---
MSH|^~\&|OIE|LAB|FHIRLAB|SYNTHEA|...||ACK^A04^ACK|...|P|2.5
MSA|AA|MSG20261126101500123What it maps#
| v2 field | From the Synthea Patient |
|---|---|
PID-3 |
The MR identifier (or the resource id), assigning authority SYNTHEA |
PID-5 |
name[0].family ^ name[0].given[0], with Synthea's digits removed |
PID-7 |
birthDate with the dashes removed |
PID-8 |
gender → M / F / U |
PID-11 |
address[0] line ^^ city ^ state ^ postcode |
PV1-2 |
Always O (outpatient) |
Delimiter characters are removed from every field, so a name like O'Brien|x can't break the message.
Change it#
The source is send_adt.py, and it runs in the fhirlab-hl7 image (Python 3.13 + hl7apy 1.3.5). The script is mounted into the container, so edits take effect on the next run. Rebuild the image only if you change the Python packages:
docker build -t fhirlab-hl7 ~/fhir-lab/hl7Good exercises: send an A08 with a changed address, an A03 discharge, a message with a deliberate error (a missing PID-3, or a bad date), and a burst of 50 messages in a loop.