HL7 Formatter
Turn the HL7 from a ticket, an email or a log back into something an engine accepts, or lay it out field by field to read.
HL7 message
Formatted HL7
Paste your HL7 message on the leftabove and the result shows up here.
Or drop a file on this box, , or .
Why an HL7 message needs formatting
HL7 v2 is picky about layout. Each segment ends with a carriage return, the segment ID sits at the very start of the line, and nothing else belongs between segments. A message that went through a log viewer, an email client or a ticket system rarely looks like that any more: there is a timestamp line on top, every segment is indented, a long NTE has been wrapped onto a second line, and the line ends are whatever the last program liked. This HL7 formatter puts it back the way an interface engine expects.
In Wire layout you get one segment per line with the line ends you pick: \r as the HL7 v2 standard asks for, \n for a text file or a test fixture, or \r\n for Windows tools. MLLP framing bytes and a byte order mark are removed, so are blank lines, text before the first MSH and spaces in front of segments. A line that is not a segment is joined to the one above it, which repairs the wrapping that mail programs do on long lines (RFC 3676 describes how they flow text). Field values are never touched, so the result parses to the same fields as your input.
Pretty layout is for reading, not for sending: each field goes on its own line with its position and name (PID-5 Patient name Delgado^Rosa^M), empty fields are left out and a blank line separates messages. It is handy for a code review or for explaining a message in a document. The work happens in your browser and the message is not uploaded. To get the fields as JSON instead, use HL7 to JSON and browse the result in the JSON parser online.
How to format an HL7 message
Paste the message
Paste it as you found it, log line and all, upload a file, or drop one on the tool. Sample loads an appointment booking (SIU^S12) copied from a support ticket, with a log line on top, indented segments and a wrapped note.
Pick the layout and line ends
Wire keeps the message ready to send; Pretty spells out every field. The status line under the output says what was changed: blank lines removed, spaces trimmed, wrapped lines joined (with their line numbers, so you can check them). This wrapped note:
NTE|1|P|Patient asked for a morning slot. Bring the glucose log from the last two weeks and the
list of current medicines. comes out as one segment:
NTE|1|P|Patient asked for a morning slot. Bring the glucose log from the last two weeks and the list of current medicines. Copy or download
Copy and Download use the line ends you picked, even though the editor shows each segment on its own line. Download saves message.hl7 in Wire layout and message.txt in Pretty layout.
What people use the HL7 formatter for
Replaying a message from a ticket
Someone pasted the failing message into a ticket and the tracker indented it and wrapped it. Format it here with \r line ends and you can resend it through the engine's test channel.
Test fixtures in a repository
Store messages with \n line ends so diffs in code review stay readable, then convert back to \r in the test helper. Libraries like python-hl7 expect segments split on \r, which is a common surprise.
Reading a long segment
A PV1 with fifty fields is hard to read on one line. Pretty layout lists the filled fields with their names, so you can see at once that the attending doctor is in PV1-7 and the visit number in PV1-19.
Fixing line ends after a file transfer
A file that went through a Windows share or an FTP transfer in text mode may come back with \r\n or bare \n. Pick the line ends the receiver wants; the newline differences between systems are the usual cause.
Frequently Asked Questions
Does formatting change any field values?
No. Fields are kept exactly as written, escape sequences included. Two things can change the text at the edges, and both are options: Trim line ends removes spaces at the very end of a segment (turn it off if a trailing space matters), and Join wrapped lines puts a broken line back on the segment above it. Every joined line is listed in the status line.
How does it decide that a line was wrapped?
A line that does not start with a segment ID HL7 defines (or a Z-segment) followed by the field separator is taken as the rest of the line above. Three capitals are not enough on their own: an IN1 wrapped at a space often goes on with HMO|IC-1.31|..., and HMO is not a segment, so that line is joined when the segment above still has room for its fields. A line that looks like a mistyped segment ID, such as pid|1|..., is kept on its own line instead, and so is any line when Join wrapped lines is off. The space at the wrap point is kept when it was at the end of the upper line or the start of the lower one.
Why does the editor show separate lines when I picked \r?
The editor always shows one segment per line so you can read it. The line ends you picked are used for Copy and Download, which take the formatted text directly, not the editor's display.
What are the MLLP bytes it removes?
Messages sent over TCP with the Minimal Lower Layer Protocol are wrapped in a start byte (0x0B) and an end sequence (0x1C followed by a carriage return). They show up as odd characters when a message is copied from a network capture. They are not part of the message, so the formatter drops them.
Can I format several messages at once?
Yes. Each MSH starts a new message and they stay in order; batch headers and trailers (FHS, BHS, BTS, FTS) are kept. Up to 2 MB of text is formatted in the browser.
Does the formatter check whether the message is valid?
Only far enough to find the segments. To check dates, required MSH fields and the segments a message type needs, paste the result into the HL7 validator.
Related tools
Check the message, read it as a table, or compare two versions.