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.
from zato.hl7v2 import SGH
sgh = SGH()
sgh.set_id_sgh = '1'
sgh.segment_group_name = 'ORDER'How to construct and work with real-world SGH segments.
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'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'Opens a segment group using only the sequence number
from zato.hl7v2.v2_9 import SGH
sgh = SGH()
sgh.set_id_sgh = '3'Step-by-step guides for working with HL7 v2 in Zato.
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.
Complete list of fields in the SGH segment, HL7 v2.9.
| # | Python name | Datatype | Usage | Repeatable | Table |
|---|---|---|---|---|---|
| 1 | set_id_sgh | SI | Required | No | - |
| 2 | segment_group_name | ST | Optional | No | - |
Get started with Zato and connect your systems in minutes.