Z-segments
How a site extends HL7v2 with its own segments, events, and codes.
A Z-segment is a segment defined by a site or a vendor rather than by the standard. Its identifier begins with the letter Z, as in ZPD, because the standard reserves that letter for local definitions and never uses it for its own segments. A Z-segment carries data for which the standard has no field, such as a research-consent flag, a local bed status, or a code required by a single payer.
Because a Z-segment is defined locally, a destination can interpret it only if it has the same definition as the source. That definition is not in the standard or in the message: it is recorded in the interface's message profile, the document that specifies what the interface sends and accepts.
Reserved names
The standard reserves the letter Z for local definitions of segments, trigger events, and message types, so that local and standard identifiers never collide.
Segments
A segment whose identifier begins with Z is a local segment. The site or vendor that defines it decides its fields, their data types, and their meaning. The name often refers to the standard segment that the Z-segment supplements: a ZPD, for example, usually carries patient demographics in addition to those in PID.
Trigger events
A trigger event code that begins with Z is a local event, and it can be used with a standard message type. ADT^Z01, for example, is an administrative message for an event that the site defines.
Message types
A message type that begins with Z is a local message, with a segment structure that the site defines. Local message types are less common than Z-segments, because most local requirements can be met by adding a Z-segment to a standard message.
Codes
Local codes follow the same principle without the letter Z. A site can add values to a user-defined table and define tables of its own. In coded values, a coding system identifier of the form 99zzz marks a local coding system.
Local fields in standard segments
The standard reserves no space inside its own segments. Local data placed after the last field that the standard defines for a segment, or in an unused standard field, does not conform to the standard. It also conflicts with later versions, which add new fields at the end of existing segments. Local data belongs in a Z-segment.
Syntax
A Z-segment has the same syntax as any other segment: a three-character identifier followed by fields, components, and sub-components, separated by the message's delimiters. Only the identifier shows that the definition is local.
Example
The following admission message carries a local ZPD segment:
MSH|^~\&|SendingApp|SendingFacility|ReceivingApp|ReceivingFacility|20230630120000||ADT^A01^ADT_A01|MSG000006|P|2.5.1
EVN|A01|20230630120000
PID|1||12345^^^HOSP^MR||Doe^John||19700101|M
PV1|1|I|WARD1^101^A
ZPD|Y|20230630|RESEARCH-7781In this example, the source defines ZPD to carry a research-consent flag, the date on which consent was given, and a study identifier. The message does not contain these definitions, because HL7v2 messages are not self-describing. The destination reads ZPD according to the profile, which documents each field with its data type and table in the same form that the standard uses for PID.
Placement
Most interfaces follow two conventions. A Z-segment is placed immediately after the standard segment that it supplements, or at the end of the message, so that the standard segments keep the order that the standard defines. A Z-segment is also defined as optional, so that a source without the data can omit it.
Unknown segments
The standard instructs a destination to ignore segments that it does not expect, rather than reject the message. A source can therefore add a Z-segment without requiring every destination to change at the same time.
The same rule means that a destination without a definition for a Z-segment discards its data without reporting an error. The destination returns an acknowledgment that reports success, and the source has no indication that the Z-segment was not processed.
Governance
A Z-segment requires agreement only between the systems that exchange it. A new field in the standard requires a proposal to the responsible HL7 work group, a ballot, and a new version of the standard that both systems then adopt. Requirements within a single project are therefore usually met with a Z-segment.
Z-segments are also rarely retired. Removing one requires confirming that no system depends on it, and a Z-segment that passes through an interface engine can reach several destinations. The number of Z-segments on an interface therefore tends to grow over its lifetime.
As a result, conformance to the standard does not by itself make two systems interoperable. Each interface also depends on its Z-segments, local codes, and other local definitions, which are recorded only in its profile.
Alternatives
The standard offers several ways to carry data that might otherwise need a Z-segment.
Observations
The OBX segment carries an observation: a code in OBX-3 that identifies what was observed, and the value in OBX-5. Many local data items, such as consent flags, risk scores, and social history, can be sent as OBX segments with a local or LOINC (opens in a new tab) code. A destination that processes observations then receives the data without a new segment definition.
Notes
The NTE segment carries free-text comments about the segment that precedes it. A comment that only needs to be read by a person can be sent as a note.
Alternate codes
A composite coded value can carry an alternate code next to its primary code, in a second coding system. A site that needs to send its own code for a concept can send it as the alternate code of a standard one, as described in Coded values.
Standard fields
Later versions of the standard add fields to existing segments. A requirement that once needed a Z-segment may have a standard field in a later version, so the newest definition of a segment is worth checking before a Z-segment is defined.
These mechanisms cover many local requirements, but not all of them, so Z-segments remain necessary for data that has no standard representation.
Trade-offs
The reserved letter lets HL7v2 accommodate local requirements without a change to the standard, at the cost of agreements that exist outside it:
- Flexibility. A site can add the data it needs on its own schedule, without waiting for a new version of the standard.
- No collisions. Local identifiers cannot conflict with standard ones, or with those of later versions.
- Bilateral agreement. Each Z-segment is understood only by the systems that share its definition. A message that depends on one cannot be sent to a system that lacks that definition.
- Silent loss. A destination that does not recognize a Z-segment ignores it and reports success, so errors in Z-segments are less likely to be noticed than errors in standard segments.
- Documentation. The definition exists only in the profile. If the profile is not maintained, the Z-segment stays in use without a current definition.
A message profile reduces these costs by defining the Z-segments of an interface together with its constraints on standard segments, so that both can be checked in the same way.
Further reading
- Message structure — the rules that Z-segments share with every other segment.
- Tables — user-defined tables and local coding systems.
- Conformance — how a profile documents local extensions.