Skip to content
The Path

Module 5 · The integrator’s job·9 min

Z-segments

Extending a message without breaking the standard: rules, good uses and traps.

Sooner or later a vendor will tell you: “That data does not exist in HL7, we send it in a Z-segment.” Sometimes they are right. Often a standard field would have done the job. This lesson gives you the exact rules of the standard, and the reflex to have before you accept a Z-segment.

You met ZSL in the lesson on interface specifications. There, you read it. Here, it goes on trial.

Here is Marie Dubois’s polysomnography result as the sleep lab software sends it. Click ZSL-4, the 480 on the last line.

Validation

  • ZSL ZSL is a Z-segment, specific to this interface. It must be described in the specification.

The sleep lab software adds a local ZSL segment with the recording context.

ORU^R01^ORU_R01· Observation result (unsolicited)
||||||||||
||||||||
|||||||
|||||||||||
||||||

Validation flags ZSL as a local segment, and that is all a generic tool can say about it. Without the vendor’s specification, 480 is just a number.

What the letter Z reserves

Chapter 2 of v2.5.1 reserves the letter Z for everything local. HL7 commits to never defining a code starting with Z for:

  • segments (ZSL, ZPI);
  • message types and trigger events (a Z01 event, for instance).

A segment ID is always three characters long, so a Z-segment is Z followed by two characters. Pick a name that means something: ZSL for “Sleep Lab” beats ZZ1.

The exact rules for local extension

Section 2.11 of chapter 2 separates what is allowed, what is ill-advised and what is forbidden.

Practice The standard’s verdict
Adding a Z-segment to an HL7 message Allowed. The trigger event can stay the same if the intent of the message is unchanged
Creating a Z message Allowed. It must start with MSH and use HL7 segments where possible
Placing a Z-segment inside a segment group Allowed
Locally adding an HL7 segment (an extra NTE) where the structure does not provide for it Ill-advised: HL7 may move it in a future version
Adding custom fields at the end of an HL7 segment Not forbidden, but ill-advised: risk of collision with future official fields
Turning segments into a group, or ungrouping a group Forbidden
Changing the type of an existing component (NM to ST) Forbidden
Adding components at the end of a data type (a Z data type) Allowed, but “particularly ill-advised” in the standard’s words
Assigning a local table to a Z field, or to an HL7 field of type CWE Allowed

A local Z acknowledgment has a rule too: MSH, then MSA, an optional SFT and a conditional ERR. And the standard slips in a piece of advice at the top of the section: read the conformance profiles first, they often make the extension unnecessary.

Where to put the segment

The standard does not fix a position. In practice, you place the Z-segment right after the segment it complements, inside the same group. Here ZSL follows the OBX of the test it describes. A Z-segment dumped at the end of the message, far from its context, forces the receiver to guess which test it belongs to when the message holds several.

Document it like an official segment

A Z-segment with no written definition is debt. Describe it in the specification with the same columns as the standard: position, length, type, usage, repetition, table. Compared with the version in the specifications lesson, each field gains a type and a usage, and there is a sixth field: the technologist.

Field Type Usage Content
ZSL-1 SI R Sequence number
ZSL-2 IS R Recording type, local table (e.g. ZSL0001): PSG, PG
ZSL-3 CE RE Montage used, local code
ZSL-4 NM RE Total recording time, in minutes
ZSL-5 EI RE Device identifier
ZSL-6 XCN RE Technologist who scored the night

Tables for Z fields are local. The standard explicitly allows this, as long as they are published with the specification. Watch the data type: in 2.5.1, ID is reserved for HL7 tables. A local table goes in an IS, or in a CWE if you want to send both the code and its label.

Before you create one: the alternatives

Now read that table again with a critical eye. Almost every row already has a home in HL7 v2.5.1:

  • the test type is already in OBR-4 (PSG);
  • the recording time is a measurement: a numeric OBX with its unit;
  • the device has its own field, OBX-18 (Equipment Instance Identifier);
  • so does the technologist, OBX-16 (Responsible Observer);
  • the montage describes the method: OBX-17 (Observation Method);
  • a free comment would go in an NTE, allowed after each OBX.

Here is the same content with no Z-segment. Click OBX-16, then OBX-18 in the second OBX.

No issues found.

The duration becomes an OBX, the technologist and the device take their standard fields.

ORU^R01^ORU_R01· Observation result (unsolicited)
||||||||||
||||||||
|||||||
|||||||||||
||||||||||||||||||

Any HL7 receiver can now read the duration, its unit, who validated it and which device produced it. The Z-segment no longer has a reason to exist.

The risks of a Z-segment

  • Silent loss: a receiver that ignores unexpected segments, as the standard tells it to, drops the ZSL with no error. The data is gone and nobody notices.
  • Vendor lock-in: the content only exists in their document. Changing software means remapping everything.
  • Engine cost: each Z-segment needs its own parsing and transformation rule.
  • FHIR conversion: a Z-segment has no planned mapping, so you will have to define an extension.

And in FHIR?

FHIR planned for extension from day one. Local data becomes an extension, identified by a URL and described by a published StructureDefinition. Same spirit as Z, with one big difference: the definition travels with an identifier any system can look up.

Check your understanding

1 of 5

A vendor wants to add three custom fields at the end of the PID segment, as PID-40, PID-41 and PID-42. What does the standard say?

+50 XPPass the quiz (4 correct answers) to complete the lesson.

Reviewed and checked on 28 September 2026