HL7 Diff

See what really changed between two messages, field by field, instead of squinting at two long pipe-delimited lines.

Message A (before)

Message B (after)

Comparing HL7 messages field by field

Two HL7 messages that should be the same rarely are, and a line-based diff is little help: each segment is one long line, so a changed room number marks the whole PV1 as different and leaves you to count pipes. This HL7 diff compares the messages the way they are built. Segments are lined up by segment ID and occurrence (first OBX with first OBX, second with second), and each field is compared component by component, so the result says PV1-3.2 (room): 308 → 312.

Every line of the result has the field position and its name from the HL7 v2.5.1 definitions. Repetitions are compared one by one (PID-3(2).1), a segment that only one side has is shown whole, and values are compared after escape sequences are decoded, so a hex escape such as \X41\ and the letter it stands for count as equal. Trailing empty components do not count either: Lindqvist^Henrik^ and Lindqvist^Henrik are the same name.

MSH-7 (message date/time) and MSH-10 (control ID) change on every message by design, so they are left out unless you turn Ignore MSH-7 and MSH-10 off. The comparison runs in your browser and neither message is uploaded. When you need a plain text compare for something that is not HL7, GNU diff does that job; to look at either message as data, convert it with HL7 to JSON and open it in the JSON parser.

How to compare two HL7 messages

1

Paste both messages

Put the earlier or expected message on the left and the other on the right. Sample loads an inpatient update (ADT^A08) as it was sent at 07:15 and again at 08:30, after a bed move, a new address and an added allergy.

2

Read the differences

The comparison runs as soon as both sides hold a message. Changed values show old and new, added and removed values show the one that exists. For example, these two PV1 locations:

PV1|1|I|3N^308^A^STJUDE_REGIONAL
PV1|1|I|3N^312^B^STJUDE_REGIONAL

give two changes:

~ PV1-3.2 (Assigned patient location: room): 308 -> 312
~ PV1-3.3 (Assigned patient location: bed): A -> B
3

Copy the result

Copy puts the differences on your clipboard as text, one line per field, ready for a ticket or a review comment. Turn on Show unchanged when you want the full field list for context.

When an HL7 diff is the quickest answer

Engine upgrade or route change

Run the same message through the old and the new route and compare the outputs. Any mapping that changed shows up with its field name, and the timestamps and control IDs that always differ stay out of the way.

Inbound versus outbound

Compare what the sender sent with what your engine passed on to the receiver, to see which transformations the channel really applied.

Duplicate or corrected messages

Two ADT^A08 updates a few minutes apart, or an ORU sent again with result status C: the diff shows whether anything clinical changed or only the header did. Result status codes are listed in HL7 table 0085.

Checking a test fixture

When a test fails on a message comparison, paste the expected and the actual message here. It is easier to read than the assertion error, and a library such as python-hl7 can then assert on the exact field that changed.

Frequently Asked Questions

How are segments matched when one message has an extra OBX?

By segment ID and occurrence: the first OBX on the left with the first OBX on the right, and so on. If an OBX was inserted in the middle, the OBX segments after it are compared with their new neighbours and the last one shows as added. Read the result from the top and the shift is usually obvious from the OBX-1 set IDs.

Why are MSH-7 and MSH-10 ignored?

MSH-7 is the time the message was created and MSH-10 its unique control ID, so they differ between any two messages. Leaving them out keeps the result to the changes that matter. Turn off Ignore MSH-7 and MSH-10 if you want them compared, for example when checking that a resend kept the original control ID.

Can I compare two batches?

Yes. Messages are compared in order (first with first, second with second), and each line of the result is labelled with its message number. Batch headers and trailers are compared too. Each side can be up to 2 MB.

Does it matter if the two messages use different separators?

Values are compared after they are split with each message's own separators and escape sequences are decoded, so a message using # as the field separator can be compared with one using |. MSH-1 and MSH-2 will of course show as changed.

Are the messages sent to a server?

No. Both messages are parsed and compared in your browser. If you need to share the result with someone outside your team, run the messages through the HL7 anonymizer first.

Is there a JSON version of this?

For JSON documents use the JSON diff, which works the same way by key instead of by field.

Related tools

Tidy the messages first, check them, or read one field by field.