Schedule a demo
Segment

Segment group header

Marks the beginning of a logical segment group within an HL7 v2 message. It carries a set identifier and an optional group name, allowing sending and receiving systems to delimit repeating or nested groups of segments. SGH is paired with SGT (Segment Group Trailer) to bracket the enclosed segments, enabling parsers to handle variable-length groups without ambiguity.

2fields
1required
v2.9HL7 version
sgh.py
from zato.hl7v2 import SGH

sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'ORDER'

Build SGH segments in Python

How to construct and work with real-world SGH segments.

1

Order group start

Opens a named order group with a sequence identifier

from zato.hl7v2.v2_9 import SGH

sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'ORDER'
2

Observation group start

Opens a group for observation result segments

from zato.hl7v2.v2_9 import SGH

sgh = SGH()
sgh.set_id_sgh = '2'
sgh.segment_group_name = 'OBSERVATION'
3

Unnamed group start

Opens a segment group using only the sequence number

from zato.hl7v2.v2_9 import SGH

sgh = SGH()
sgh.set_id_sgh = '3'

Learn by building

Step-by-step guides for working with HL7 v2 in Zato.

Frequently asked questions

SGH marks the start of a logical segment group in an HL7 v2 message. It lets senders and receivers bracket related segments into named, repeatable groups so parsers can identify group boundaries without relying on segment order alone.

SGH opens a group and SGT closes it. Every SGH should have a matching SGT with the same set identifier. The segments between the pair form the group content:

from zato.hl7v2.v2_9 import SGH, SGT

sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'ORDER'

sgt = SGT()
sgt.set_id_sgt = '1'
sgt.segment_group_name = 'ORDER'

No, it is optional. When omitted, the group is identified solely by its set_id_sgh. Named groups improve readability and are useful when multiple group types appear in the same message:

from zato.hl7v2.v2_9 import SGH

sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'PATIENT'

Yes, groups can nest by using different set identifiers. An inner SGH/SGT pair with a higher set_id can appear inside an outer pair, creating hierarchical groupings within the message.

Instantiate SGH and set its fields:

from zato.hl7v2.v2_9 import SGH

sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'RESULT'

Zato connects to any system that speaks HL7v2 over MLLP or FHIR over REST. This includes Epic, Cerner, Meditech, Allscripts, and other EHR platforms.

Yes, Zato has built-in MLLP support for sending and receiving HL7v2 messages. MLLP channels handle the framing protocol automatically.

Zato supports HL7 v2.9, which is backward compatible with earlier versions including v2.3, v2.5, and v2.7. Standard segments and datatypes are available as typed Python classes.

Yes. Zato handles both HL7v2 and FHIR natively, so you can parse v2 messages and build FHIR resources with IG-specific extensions in the same service. Typed Python classes are available for both protocols, including extensions from US Core, UK Core, Da Vinci, and other Implementation Guides.

SGH field reference

Complete list of fields in the SGH segment, HL7 v2.9.

#Python nameDatatypeUsageRepeatableTable
1set_id_sghSIRequiredNo-
2segment_group_nameSTOptionalNo-

Ready to build integrations?

Get started with Zato and connect your systems in minutes.

Open source In Python