Schedule a demo
Segment

Batch header

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.

17fields
2required
v2.9HL7 version
bhs.py
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',
)

Build BHS segments in Python

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

1

Wellness screening batch open

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',
]
2

Fitness registration batch

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',
)
3

Nutrition assessment batch

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'

Learn by building

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

Frequently asked questions

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.

BHS field reference

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

#Python nameDatatypeUsageRepeatableTable
1batch_field_separatorSTRequiredNo-
2batch_encoding_charactersSTRequiredNo-
3batch_sending_applicationHDOptionalNo-
4batch_sending_facilityHDOptionalNo-
5batch_receiving_applicationHDOptionalNo-
6batch_receiving_facilityHDOptionalNo-
7batch_creation_date_timeDTMOptionalNo-
8batch_securitySTOptionalNo-
9batch_name_id_typeSTOptionalNo-
10batch_commentSTOptionalNo-
11batch_control_idSTOptionalNo-
12reference_batch_control_idSTOptionalNo-
13batch_sending_network_addressHDOptionalNo-
14batch_receiving_network_addressHDOptionalNo-
15security_classification_tagCWEOptionalNoHL70952
16security_handling_instructionsCWEOptionalYesHL70953
17special_access_restriction_instructionsSTOptionalYes-

Ready to build integrations?

Get started with Zato and connect your systems in minutes.

Open source In Python