Schedule a demo
Segment

Patient identification

Carries core patient demographics such as medical record number, name, date of birth, sex, address, and phone number. It appears in ADT, ORM, ORU, DFT, SIU, and virtually all other message types, making it the cornerstone of patient identification across the enterprise. EHRs, registration systems, lab systems, and billing systems all send and consume PID data to identify and match patients.

31fields
2required
v2.9HL7 version
pid.py
from zato.hl7v2 import PID, XPN

pid = PID()
pid.patient_name = XPN(
    family_name='Smith',
    given_name='John'
)
pid.date_time_of_birth = '19850315'
pid.administrative_sex = 'M'

Build PID segments in Python

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

1

New patient registration with name, ID, and date of birth

Registers a new patient with a medical record number, full name, date of birth, and home address for a routine wellness visit

from zato.hl7v2.v2_9 import PID
from zato.hl7v2.v2_9 import CWE, CX, XAD, XPN

pid = PID()
pid.set_id_pid = '1'
pid.patient_identifier_list = CX(id_number='MRN-78432')
pid.patient_name = XPN(
    family_name='GARCIA',
    given_name='MARIA'
)
pid.date_time_of_birth = '19900515'
pid.administrative_sex = CWE(
    identifier='F',
    text='Female',
    name_of_coding_system='HL70001'
)
pid.patient_address = XAD(
    street_address='350 Sunrise Blvd',
    city='Austin',
    state_or_province='TX',
    zip_or_postal_code='73301'
)
2

Patient with language preference and marital status

Captures a patient's primary language and marital status alongside basic demographics for a preventive care visit

from zato.hl7v2.v2_9 import PID
from zato.hl7v2.v2_9 import CWE, CX, XPN

pid = PID()
pid.set_id_pid = '2'
pid.patient_identifier_list = CX(id_number='WEL-55210')
pid.patient_name = XPN(
    family_name='CHEN',
    given_name='LIANG'
)
pid.date_time_of_birth = '19850220'
pid.administrative_sex = CWE(
    identifier='M',
    text='Male',
    name_of_coding_system='HL70001'
)
pid.primary_language = CWE(
    identifier='en',
    text='English',
    name_of_coding_system='ISO639-2'
)
pid.marital_status = CWE(
    identifier='M',
    text='Married',
    name_of_coding_system='HL70002'
)
3

Patient with multiple identifiers and mother's maiden name

Records a patient with a medical record number, full name, mother's maiden name, and date of birth for identity verification

from zato.hl7v2.v2_9 import PID
from zato.hl7v2.v2_9 import CWE, CX, XAD, XPN

pid = PID()
pid.set_id_pid = '3'
pid.patient_identifier_list = CX(id_number='ACC-90124')
pid.patient_name = XPN(
    family_name='PATEL',
    given_name='ANANYA'
)
pid.mothers_maiden_name = XPN(
    family_name='SHARMA',
    given_name='PRIYA'
)
pid.date_time_of_birth = '19920810'
pid.administrative_sex = CWE(
    identifier='F',
    text='Female',
    name_of_coding_system='HL70001'
)
pid.patient_address = XAD(
    street_address='22 Meadow Lane',
    city='Denver',
    state_or_province='CO',
    zip_or_postal_code='80202'
)

Learn by building

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

Frequently asked questions

PID contains core patient demographics - name, date of birth, sex, address, phone numbers, and identifiers like MRN and SSN. It appears in virtually every HL7v2 message type.

Configure an MLLP channel and access the PID segment from the parsed message:

msg = HL7Message.parse(raw_data)
name = msg.pid.patient_name
dob = msg.pid.date_time_of_birth
mrn = msg.pid.patient_identifier_list

Use semantic Python names instead of positional notation:

# Instead of PID.5, use:
pid.patient_name

# Subcomponents work too:
pid.patient_name.family_name
pid.patient_name.given_name

# Instead of PID.7, use:
pid.date_time_of_birth

PID.3 (patient_identifier_list) is a repeating field. Access individual identifiers by index or iterate:

from zato.hl7v2.v2_9 import PID, CX

pid = PID()
pid.patient_identifier_list = [
    CX(),
    CX(),
]
pid.patient_identifier_list.id_number = 'MRN-78432'
pid.patient_identifier_list[1].id_number = 'SSN-555667788'

for ident in pid.patient_identifier_list:
    print(ident.id_number)

Yes, you can map PID fields to a FHIR Patient resource:

from zato.fhir.r4_0_1 import Patient, HumanName

hn = HumanName()
hn.family = pid.patient_name.family_name
hn.given = [pid.patient_name.given_name]

patient = Patient()
patient.name = [hn]
patient.birthDate = pid.date_time_of_birth

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.

PID field reference

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

#Python nameDatatypeUsageRepeatableTable
1set_id_pidSIOptionalNo-
3patient_identifier_listCXRequiredYes-
5patient_nameXPNRequiredYesHL70200
6mothers_maiden_nameXPNOptionalYes-
7date_time_of_birthDTMOptionalNo-
8administrative_sexCWEOptionalNoHL70001
10raceCWEOptionalYesHL70005
11patient_addressXADOptionalYes-
15primary_languageCWEOptionalNoHL70296
16marital_statusCWEOptionalNoHL70002
17religionCWEOptionalNoHL70006
18patient_account_numberCXOptionalNoHL70061
21mothers_identifierCXOptionalYesHL70061
22ethnic_groupCWEOptionalYesHL70189
23birth_placeSTOptionalNo-
24multiple_birth_indicatorIDOptionalNoHL70136
25birth_orderNMOptionalNo-
26citizenshipCWEOptionalYesHL70171
27veterans_military_statusCWEOptionalNoHL70172
29patient_death_date_and_timeDTMOptionalNo-
30patient_death_indicatorIDOptionalNoHL70136
31identity_unknown_indicatorIDOptionalNoHL70136
32identity_reliability_codeCWEOptionalYesHL70445
33last_update_date_timeDTMOptionalNo-
34last_update_facilityHDOptionalNo-
35taxonomic_classification_codeCWEOptionalNo-
36breed_codeCWEOptionalNoHL70447
37strainSTOptionalNo-
38production_class_codeCWEOptionalNoHL70429
39tribal_citizenshipCWEOptionalYesHL70171
40patient_telecommunication_informationXTNOptionalYes-

Ready to build integrations?

Get started with Zato and connect your systems in minutes.

Open source In Python