Marks the beginning of a batch of HL7 messages, carrying batch encoding characters, sending and receiving application and facility, batch creation date and time, and batch control identifier. It is used when multiple HL7 messages are grouped into a single transmission file, commonly in batch-mode interfaces between lab systems, reference labs, billing systems, and clearinghouses. BHS is always paired with a closing BTS segment.
from zato.hl7v2.v2_9 import BHS
from zato.hl7v2.v2_9 import HD, CWE
bhs = BHS()
bhs.batch_field_separator = '|'
bhs.batch_encoding_characters = '^~\\&'
bhs.batch_sending_application = HD(
namespace_id='WELLAPP',
universal_id='Wellness Hub',
universal_id_type='DNS',
)
bhs.batch_sending_facility = HD(
namespace_id='CLIN01',
universal_id='Main Clinic',
universal_id_type='DNS',
)
bhs.security_classification_tag = CWE(
identifier='WELL',
text='Wellness data',
name_of_coding_system='HL70952',
)How to construct and work with real-world BHS segments.
Full batch header with HD routing, identifiers, security CWE tags, and restriction text
from zato.hl7v2.v2_9 import BHS
from zato.hl7v2.v2_9 import CWE, HD
bhs = BHS()
bhs.batch_field_separator = '|'
bhs.batch_encoding_characters = '^~\\&'
bhs.batch_sending_application = HD(
namespace_id='WELLAPP',
universal_id='Wellness Hub',
universal_id_type='DNS',
)
bhs.batch_sending_facility = HD(
namespace_id='CLIN01',
universal_id='Main Clinic',
universal_id_type='DNS',
)
bhs.batch_receiving_application = HD(
namespace_id='HISAPP',
universal_id='HIS',
universal_id_type='DNS',
)
bhs.batch_receiving_facility = HD(
namespace_id='HUB02',
universal_id='Wellness Hub',
universal_id_type='DNS',
)
bhs.batch_creation_date_time = '20260404120000'
bhs.batch_security = 'TLS'
bhs.batch_name_id_type = 'SCREEN'
bhs.batch_comment = 'Wellness screening batch'
bhs.batch_control_id = 'BATCH-2026-001'
bhs.reference_batch_control_id = 'REF-2025-999'
bhs.batch_sending_network_address = HD(
namespace_id='NETSEND',
universal_id='dns',
universal_id_type='DNS',
)
bhs.batch_receiving_network_address = HD(
namespace_id='NETRECV',
universal_id='dns',
universal_id_type='DNS',
)
bhs.security_classification_tag = CWE(
identifier='WELL',
text='Wellness data',
name_of_coding_system='HL70952',
)
bhs.security_handling_instructions = [
CWE(
identifier='HANDLE',
text='Standard handling',
name_of_coding_system='HL70953',
),
CWE(
identifier='LOCK',
text='Secure channel',
name_of_coding_system='HL70953',
),
]
bhs.special_access_restriction_instructions = [
'INTERNAL',
'EXTERNAL',
]Compact header with routing HD rows and trailing empty fields
from zato.hl7v2.v2_9 import BHS
from zato.hl7v2.v2_9 import HD
bhs = BHS()
bhs.batch_field_separator = '|'
bhs.batch_encoding_characters = '^~\\&'
bhs.batch_sending_application = HD(
namespace_id='FITAPP',
universal_id='Fitness',
universal_id_type='DNS',
)
bhs.batch_sending_facility = HD(
namespace_id='GYM01',
universal_id='Studio',
universal_id_type='DNS',
)Receiving partners, batch label, and control identifiers filled in
from zato.hl7v2.v2_9 import BHS
from zato.hl7v2.v2_9 import HD
bhs = BHS()
bhs.batch_field_separator = '|'
bhs.batch_encoding_characters = '^~\\&'
bhs.batch_sending_application = HD(
namespace_id='NUTRI',
universal_id='Coach App',
universal_id_type='DNS',
)
bhs.batch_sending_facility = HD(
namespace_id='KITCHEN',
universal_id='Demo Kitchen',
universal_id_type='DNS',
)
bhs.batch_receiving_application = HD(
namespace_id='HUB',
universal_id='Data Hub',
universal_id_type='DNS',
)
bhs.batch_receiving_facility = HD(
namespace_id='LAB',
universal_id='Assessment Lab',
universal_id_type='DNS',
)
bhs.batch_creation_date_time = '20260405120000'
bhs.batch_name_id_type = 'NUTRI'
bhs.batch_comment = 'Coaching intake batch'
bhs.batch_control_id = 'NUT-BATCH-88'
bhs.reference_batch_control_id = 'PREV-REF-01'Step-by-step guides for working with HL7 v2 in Zato.
BHS opens a batch and BTS closes it with counts and optional totals. Messages between them are usually delimited MSH segments your profile defines for wellness or fitness traffic.
batch_field_separator and batch_encoding_characters describe how to read the rest of the batch payload, similar in purpose to MSH-1 and MSH-2 on a message.
Use HD for batch sending and receiving application and facility, plus optional network addresses when partners exchange DNS-style endpoints:
from zato.hl7v2.v2_9 import BHS, HD
bhs = BHS()
bhs.batch_field_separator = '|'
bhs.batch_encoding_characters = '^~\\&'
bhs.batch_sending_application = HD(
namespace_id='WELLAPP',
universal_id='Wellness Hub',
universal_id_type='DNS',
)Field 16 repeats as CWE values from HL70953 so receivers know how to handle the batch contents. Assign a list of CWE rows in Python when more than one applies.
Yes. Field 17 is ST with repetition, so ER7 uses ~ between tokens and Python accepts a list of short restriction strings.
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 BHS segment, HL7 v2.9.
| # | Python name | Datatype | Usage | Repeatable | Table |
|---|---|---|---|---|---|
| 1 | batch_field_separator | ST | Required | No | - |
| 2 | batch_encoding_characters | ST | Required | No | - |
| 3 | batch_sending_application | HD | Optional | No | - |
| 4 | batch_sending_facility | HD | Optional | No | - |
| 5 | batch_receiving_application | HD | Optional | No | - |
| 6 | batch_receiving_facility | HD | Optional | No | - |
| 7 | batch_creation_date_time | DTM | Optional | No | - |
| 8 | batch_security | ST | Optional | No | - |
| 9 | batch_name_id_type | ST | Optional | No | - |
| 10 | batch_comment | ST | Optional | No | - |
| 11 | batch_control_id | ST | Optional | No | - |
| 12 | reference_batch_control_id | ST | Optional | No | - |
| 13 | batch_sending_network_address | HD | Optional | No | - |
| 14 | batch_receiving_network_address | HD | Optional | No | - |
| 15 | security_classification_tag | CWE | Optional | No | HL70952 |
| 16 | security_handling_instructions | CWE | Optional | Yes | HL70953 |
| 17 | special_access_restriction_instructions | ST | Optional | Yes | - |
Get started with Zato and connect your systems in minutes.