Construct the HL7v2 ORU^R01 message with required segments: MSH (message header), PID (patient identification), OBR (observation request), and one or more OBX (observation result) segments encoding each lab value with LOINC codes in OBX-3 and result values with UCUM units in OBX-6
Wrap the message in MLLP framing: prepend the vertical-tab byte (0x0B) and append the field-separator byte (0x1C) followed by a carriage return (0x0D)
Open a TCP socket connection to the receiving system on its configured MLLP port (commonly 2575 or a site-specific port) and send the framed message bytes
Read the response bytes from the socket, strip the MLLP envelope, and parse the returned ACK message to check MSA-1 for AA (application accept), AE (application error), or AR (application reject)
On AE or AR, log the MSA-3 error text and the ERR segment details, then implement retry logic with back-off appropriate to your operational SLA
Close the TCP socket; for high-volume interfaces consider connection pooling rather than opening a new socket per message
Known gotchas
MLLP is a raw TCP protocol — firewalls and load balancers that do not understand MLLP framing will corrupt messages; verify network path supports persistent TCP connections
HL7v2 field encoding characters (|, ^, ~, \, &) must be escaped in data values; unescaped pipe characters in a patient name will break segment parsing on the receiver
OBX-11 (observation result status) must be set correctly (F for final, P for preliminary) — receivers often use this to decide whether to display or suppress a result
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp