Schedule a demo
Segment

Merge patient information

Carries the prior patient identifiers (such as MRN, account number, and visit number) that are being merged into the surviving record identified in the PID segment. It is used in ADT merge events (A34, A40, A41, A44, and others) sent by the MPI or registration system to all downstream systems so they can consolidate duplicate patient records.

5fields
1required
v2.9HL7 version
mrg.py
from zato.hl7v2 import MRG

mrg = MRG()
mrg.prior_patient_identifier_list = '12345'
mrg.prior_patient_name = 'SMITH^JOHN'

Build MRG segments in Python

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

1

Record consolidation

Merging duplicate records for a wellness patient into a single identifier

from zato.hl7v2.v2_9 import MRG
from zato.hl7v2.v2_9 import CX, XPN

mrg = MRG()
mrg.prior_patient_identifier_list = CX(
    id_number='12345',
    assigning_authority='WELLNESS'
)
mrg.prior_patient_account_number = CX(id_number='98765')
mrg.prior_patient_name = XPN(
    family_name='SMITH',
    given_name='JOHN',
    middle_name='A'
)
2

Account transfer

Transferring a patient to a new account after a routine visit update

from zato.hl7v2.v2_9 import MRG
from zato.hl7v2.v2_9 import CX, XPN

mrg = MRG()
mrg.prior_patient_identifier_list = CX(
    id_number='67890',
    assigning_authority='GREENVALLEY'
)
mrg.prior_patient_account_number = CX(id_number='55001')
mrg.prior_visit_number = CX(id_number='V2024001')
mrg.prior_patient_name = XPN(
    family_name='JONES',
    given_name='MARY'
)
3

Name update

Updating patient name after a legal name change on file

from zato.hl7v2.v2_9 import MRG
from zato.hl7v2.v2_9 import CX, XPN

mrg = MRG()
mrg.prior_patient_identifier_list = CX(
    id_number='24680',
    assigning_authority='LAKESIDE'
)
mrg.prior_patient_name = XPN(
    family_name='BROWN',
    given_name='SARAH',
    middle_name='L'
)

Learn by building

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

Frequently asked questions

MRG carries the prior patient identifiers, account numbers, visit numbers, and names needed when merging duplicate records or transferring a patient to a new account. It appears in ADT merge and move messages alongside PID to indicate which prior identifiers are being retired.

Create an MRG segment and read its fields directly:

from zato.hl7v2.v2_9 import MRG, CX, XPN

mrg = MRG()
mrg.prior_patient_identifier_list = CX(
    id_number='12345',
    assigning_authority='WELLNESS'
)
mrg.prior_patient_name = XPN(
    family_name='SMITH', given_name='JOHN')
mrg.prior_patient_account_number = CX(
    id_number='98765')

prior_id = mrg.prior_patient_identifier_list
prior_name = mrg.prior_patient_name
prior_acct = mrg.prior_patient_account_number

Positions 2 (prior alternate patient ID) and 4 (prior patient ID) were withdrawn in HL7 v2.9. The fields are retained as gaps to preserve the positional numbering of all subsequent fields. This is standard HL7v2 practice for deprecated fields.

The prior_patient_identifier_list field uses the CX (extended composite ID) datatype:

from zato.hl7v2.v2_9 import MRG, CX

mrg = MRG()
mrg.prior_patient_identifier_list = CX(
    id_number='12345',
    assigning_authority='WELLNESS'
)

The prior_patient_name field uses the XPN (extended person name) datatype:

from zato.hl7v2.v2_9 import MRG, XPN

mrg = MRG()
mrg.prior_patient_name = XPN(
    family_name='SMITH',
    given_name='JOHN',
    middle_name='A'
)

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.

MRG field reference

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

#Python nameDatatypeUsageRepeatableTable
1prior_patient_identifier_listCXRequiredYesHL70061
3prior_patient_account_numberCXOptionalNoHL70061
5prior_visit_numberCXOptionalNoHL70061
6prior_alternate_visit_idCXOptionalYesHL70061
7prior_patient_nameXPNOptionalYesHL70200

Ready to build integrations?

Get started with Zato and connect your systems in minutes.

Open source In Python