Schedule a demo
Segment

Patient visit

Contains details about a specific patient encounter or visit, including patient class (inpatient, outpatient, emergency), assigned location (nursing unit, room, bed), attending and admitting physicians, and admit/discharge dates. It is present in virtually all ADT messages, orders, results, and billing transactions, and is critical for associating clinical and financial data with a specific encounter.

52fields
1required
v2.9HL7 version
pv1.py
from zato.hl7v2 import PV1

pv1 = PV1()
pv1.patient_class = 'E'
pv1.hospital_service = 'MED'
pv1.patient_type = 'ER'
pv1.admit_date_time = '20260315120000'

Build PV1 segments in Python

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

1

Walk-in registration

Patient registered at the front desk with attending physician

from zato.hl7v2.v2_9 import PV1
from zato.hl7v2.v2_9 import CWE, XCN

pv1 = PV1()
pv1.set_id_pv1 = '1'
pv1.patient_class = CWE(identifier='E')
pv1.assigned_patient_location.point_of_care = 'ER'
pv1.assigned_patient_location.room = '101'
pv1.assigned_patient_location.bed = 'A'
pv1.attending_doctor = XCN(
    person_identifier='0001',
    family_name='DOC',
    given_name='MARY',
    suffix='MD'
)
pv1.hospital_service = CWE(identifier='MED')
pv1.admit_date_time = '20240315120000'
2

Inpatient stay

Patient checked in to a medical ward with visit number and financial class

from zato.hl7v2.v2_9 import PV1
from zato.hl7v2.v2_9 import CWE, XCN, CX

pv1 = PV1()
pv1.set_id_pv1 = '1'
pv1.patient_class = CWE(identifier='I')
pv1.assigned_patient_location.point_of_care = '4N'
pv1.assigned_patient_location.room = '402'
pv1.assigned_patient_location.bed = 'B'
pv1.attending_doctor = XCN(
    person_identifier='5678',
    family_name='SMITH',
    given_name='ANNA',
    suffix='MD'
)
pv1.hospital_service = CWE(identifier='SUR')
pv1.visit_number = CX(id_number='V12345')
3

Outpatient visit

Outpatient clinic visit with discharge date

from zato.hl7v2.v2_9 import PV1
from zato.hl7v2.v2_9 import CWE, XCN

pv1 = PV1()
pv1.set_id_pv1 = '1'
pv1.patient_class = CWE(identifier='O')
pv1.assigned_patient_location.point_of_care = 'CLINIC'
pv1.assigned_patient_location.room = '200'
pv1.attending_doctor = XCN(
    person_identifier='9999',
    family_name='JONES',
    given_name='ROBERT',
    suffix='MD'
)
pv1.hospital_service = CWE(identifier='GEN')
pv1.admit_date_time = '20240401090000'
pv1.discharge_date_time = '20240401103000'

Learn by building

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

Frequently asked questions

PV1 describes a patient visit or encounter - the location, attending physician, admission type, hospital service, financial class, and admission/discharge dates. It appears in virtually every ADT message and most order and result messages.

Parse the message and access the PV1 segment directly:

from zato.hl7v2 import HL7Message

msg = HL7Message.parse(raw_data)

location = msg.pv1.assigned_patient_location
ward = location.point_of_care
room = location.room

service = msg.pv1.hospital_service

Use semantic Python names instead of positional notation:

from zato.hl7v2.v2_9 import PV1, CWE

pv1 = PV1()
# Instead of PV1.2, use:
pv1.patient_class = CWE(identifier='I')

# Instead of PV1.3, use:
pv1.assigned_patient_location.point_of_care = 'ICU'
pv1.assigned_patient_location.room = '301'

The attending_doctor field uses the XCN (extended composite name) datatype:

from zato.hl7v2.v2_9 import PV1, XCN

pv1 = PV1()
pv1.attending_doctor = XCN(
    person_identifier='12345',
    family_name='Smith',
    given_name='John',
    suffix='MD'
)

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.

PV1 field reference

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

#Python nameDatatypeUsageRepeatableTable
1set_id_pv1SIOptionalNo-
2patient_classCWERequiredNoHL70004
3assigned_patient_locationPLOptionalNo-
4admission_typeCWEOptionalNoHL70007
5preadmit_numberCXOptionalNo-
6prior_patient_locationPLOptionalNo-
7attending_doctorXCNOptionalYesHL70010
8referring_doctorXCNOptionalYesHL70010
9consulting_doctorXCNOptionalYes-
10hospital_serviceCWEOptionalNoHL70069
11temporary_locationPLOptionalNo-
12preadmit_test_indicatorCWEOptionalNoHL70087
13re_admission_indicatorCWEOptionalNoHL70092
14admit_sourceCWEOptionalNoHL70023
15ambulatory_statusCWEOptionalYesHL70009
16vip_indicatorCWEOptionalNoHL70099
17admitting_doctorXCNOptionalYesHL70010
18patient_typeCWEOptionalNoHL70018
19visit_numberCXOptionalNo-
20financial_classFCOptionalYesHL70064
21charge_price_indicatorCWEOptionalNoHL70032
22courtesy_codeCWEOptionalNoHL70045
23credit_ratingCWEOptionalNoHL70046
24contract_codeCWEOptionalYesHL70044
25contract_effective_dateDTOptionalYes-
26contract_amountNMOptionalYes-
27contract_periodNMOptionalYes-
28interest_codeCWEOptionalNoHL70073
29transfer_to_bad_debt_codeCWEOptionalNoHL70110
30transfer_to_bad_debt_dateDTOptionalNo-
31bad_debt_agency_codeCWEOptionalNoHL70021
32bad_debt_transfer_amountNMOptionalNo-
33bad_debt_recovery_amountNMOptionalNo-
34delete_account_indicatorCWEOptionalNoHL70111
35delete_account_dateDTOptionalNo-
36discharge_dispositionCWEOptionalNoHL70112
37discharged_to_locationDLDOptionalNoHL70113
38diet_typeCWEOptionalNoHL70114
39servicing_facilityCWEOptionalNoHL70115
41account_statusCWEOptionalNoHL70117
42pending_locationPLOptionalNo-
43prior_temporary_locationPLOptionalNo-
44admit_date_timeDTMOptionalNo-
45discharge_date_timeDTMOptionalNo-
46current_patient_balanceNMOptionalNo-
47total_chargesNMOptionalNo-
48total_adjustmentsNMOptionalNo-
49total_paymentsNMOptionalNo-
50alternate_visit_idCXOptionalYesHL70203
51visit_indicatorCWEOptionalNoHL70326
53service_episode_descriptionSTOptionalNo-
54service_episode_identifierCXOptionalNo-

Ready to build integrations?

Get started with Zato and connect your systems in minutes.

Open source In Python