Integration

Demographics, MPI, PIX/PDQ

Manage patient identity, demographic records, PIX/PDQ exchange, duplicate review, and merges through the MPI.

What Demographics Means In AMCDR

Demographics connects a person to their patient record, EHR and known identifiers. It also records links to external identities and the access rules that apply when someone searches for or requests those records.

Resolve the patient and EHR before recording care or exchanging clinical data. Clinical records are stored in openEHR compositions.

For the durable cross-organisation identifier, identity assurance, and NIN verification lifecycle, see Enterprise Master Patient Index.

How identity stays consistent: the internal MPI is authoritative for identity matching, duplicates, merges and national identifiers. Every patient-identity write first calls the shared MPI resolution/upsert boundary and then generates a new openEHR PartyVersion. openEHR PERSON and FHIR Patient are interoperable views of the same resolved identity, not independent demographic stores.

Mandatory Identity Reconciliation

Inbound surfaceRequired behavior
openEHR PERSONResolve/upsert MPI first, then create the PERSON PartyVersion projection.
Internal FHIR Patient create/updateResolve/update the MPI patient and regenerate the openEHR demographic projection.
PIX feedResolve the patient identity before applying the feed and projecting demographics.
SHR /fhir/Patient, FHIR Bundle and /fhir/ingestUse the same MPI gateway; profile or bundle ingestion cannot bypass identity reconciliation.
Client registration and deprecated patient registration/clients and /patients converge on the same MPI identity and PartyVersion.
Portable-form subject create/updateResolve through MPI before the runtime receives patient/EHR context.
FHIR PersonAllowed only after Person.link.target resolves to an existing or same-Bundle Patient. A standalone Person cannot create an MPI identity.

Exact identifier/MRN evidence is followed through merge chains. Conflicting authoritative evidence or ambiguous matches return 409 Conflict; AMCDR does not silently merge uncertain people. FHIR identifiers are namespaced by their source where supplied so unrelated systems cannot accidentally share an identifier domain.

Demographics to clinical record
PersonName, DOB, sex, contact
->
PatientClinical subject
->
EHRopenEHR container
->
Visit / encounterCare context
->
CompositionTemplate-governed content

Core Data Model

ObjectPurposeImportant Fields
PersonHuman demographic identity.given_name, family_name, date_of_birth, sex_at_birth, active, extra.
PatientClinical care subject linked to one person.person_id, mrn, status, merged_into_id, primary_ehr_id.
PartyIdentifierIdentifiers for a person or organisation.system, value, use. Examples: MRN, national ID, passport, refugee ID, UNHCR ID, temporary ID, external MPI ID.
Address and TelecomContact points used for care, MPI matching, and reporting.Address lines, city, country, phone, email, contact use.
Party / VersionedPartyopenEHR-style demographic party projection and version history.Party payload, identities, contacts, roles, relationships, external identity bindings, federation events.
PartyRelationship and PartyLinkRelationships between people or patient records.Mother-child, guardian, merged identity, duplicate, care relationship, referral or other link types.
PatientCoverageInsurance, self-pay, guarantor, authorization, and verification status.Payer, plan, policy number, subscriber, priority, dates, verification status.
PatientSecurityLabelProtected/VIP classification inherited by search, exports, FHIR, AQL, and workspace access.Classification, active state, reason, expiry, metadata.

Client Registry Versus Patient Registration

Use the client registry to search for, verify, import, link or protect a person before opening or creating their patient record. Patient registration is the clinical handoff that resolves to an existing client whenever possible, creates the patient/EHR when required, and starts the registration workflow.

SurfaceMain JobShould It Create Duplicates?
Client registryFind or create demographic identity, identifiers, protected classification, external MPI links, and duplicate review candidates.No. It searches and reconciles first.
Patient registrationCreate or select the clinical patient subject, create the EHR, and place the person into a registration/visit workflow.No. It resolves to the existing client/patient when a match exists.
FHIR Patient create/updateInteroperability-facing identity write.No. MPI reconciliation is mandatory, not optional.

Governed Administrative Addresses

Patient Registration uses AmyTerm-backed cascading address selectors when a governed national hierarchy is available. Selecting the country changes the hierarchy; selecting a parent limits the next field to its direct children. The bundled hierarchies are Uganda (district/city through parish/ward), Zambia (province through ward), and Zimbabwe (province through ward).

Every selected unit retains its terminology system, code, hierarchy level, and display in Address.details.administrative_areas. The compatibility state and city columns retain the relevant displays for existing consumers. The source authorities do not publish a governed village layer in these packages, so street, village, or locality remains free text unless an organisation imports a locally governed AmyTerm extension. Polling stations and enumeration areas must not be substituted for villages.

Registration fields and template bindings

The Client Registry registration UI is a bound registration profile rather than an independent demographics form. Each field declares an operational foundation target, a companion composition path, and the openEHR RM value type used when AMCDR projects the registration artifact.

Write targetWhat is storedPurpose
Foundation recordsPerson, Patient, PartyIdentifier, Telecom, security labels, EHR, EHR status, EHR access, and openEHR demographic Party projection.Operational identity, MPI, search, access control, FHIR Patient output, and patient context.
Registration artifactClient registry registration composition with submitted field values, semantic binding metadata, provenance, audit details, and searchable indexes.Longitudinal audit, openEHR query, registration evidence, and implementation traceability.

The foundation record remains the source of truth for identity and MPI operations. The companion artifact uses the AMCDR registration profile key amcdr.client_registry.registration.v1. A missing published clinical template must not block identity creation.

The shipped MPI registration OPT is stored in source control at examples/opt/amcdr_client_registration_mpi.opt. It appears in Semantic Studio and template selection only after it has been inserted into the database-backed Template Repository. Register it through the template upload API or run python scripts/bootstrap_registration_templates.py. On VPS deployments, run the same bootstrap inside the backend container with the production compose files. The runtime repository key is amcdr.client_registry.registration.v1; the OPT internal template_id remains amcdr-client-registration-mpi.v1.

The Patient Registration workflow and the Client Registry workspace both use this same repository key for registration evidence. In the Patient Registration wizard, the stepwise UI remains the workflow surface, while the submitted new-client payload includes a registration_artifact object so /clients can create the patient, create the EHR, and store the registration evidence composition after the EHR exists.

Registration Acknowledgement

Registration capture can be template-driven, but no openEHR composition is committed until a patient identity and EHR exist. The controlled sequence is pre-commit capture, duplicate resolution, patient identity creation, EHR creation, EHR status and access creation, then optional registration composition creation.

POST /patients and POST /clients return 201 Created with a JSON acknowledgement. The acknowledgement includes the patient identifier, EHR identifier, created resource summary, and links that clients can use for follow-up workflow or audit display.

HTTP/1.1 201 Created
Location: /clients/{patient_id}
X-AMCDR-EHR-Location: /openehr/v1/ehr/{ehr_id}

{
  "acknowledgement": "client-registration-created",
  "created": true,
  "patient_id": "{patient_id}",
  "ehr_id": "{ehr_id}",
  "created_resources": {
    "client_identity": true,
    "patient_identity": true,
    "ehr": true,
    "ehr_status": true,
    "ehr_access": true,
    "registration_composition": true
  },
  "links": {
    "client": "/clients/{patient_id}",
    "patient": "/patients/{patient_id}",
    "ehr": "/openehr/v1/ehr/{ehr_id}",
    "registration_composition": "/openehr/v1/ehr/{ehr_id}/composition/{composition_id}"
  }
}

Patient And Party APIs

These are the primary demographics APIs. They are authenticated backend routes. Nginx deployments expose them as /backend/... when that proxy pattern is configured.

GET  /patients?q={name-or-identifier}&limit=50
POST /patients
GET  /patients/{patient_id}/coverages
POST /patients/{patient_id}/coverages
GET  /patients/{patient_id}/party

GET  /payers
POST /payers

GET  /parties
POST /parties
GET  /parties/examples
GET  /parties/examples/{example_kind}
GET  /parties/{party_id}
PUT  /parties/{party_id}
GET  /parties/{party_id}/versions
GET  /parties/{party_id}/extract
GET  /parties/{party_id}/relationships
POST /parties/{party_id}/relationships
GET  /parties/organisation/{organisation_id}

Create A Patient

POST /patients creates a Person, Patient, identifiers, addresses, telecoms, coverages, EHR, EHR status, default EHR access, and an open registration workflow task. It also synchronizes the openEHR demographic party projection.

POST /patients
Content-Type: application/json

{
  "given_name": "Amina",
  "family_name": "Okello",
  "date_of_birth": "1992-04-17",
  "sex_at_birth": "female",
  "mrn": "MRN-000123",
  "identifiers": [
    {"system": "urn:national-id:ug", "value": "CM920417001", "use": "official"},
    {"system": "urn:unhcr", "value": "UGA-RF-102938", "use": "secondary"}
  ],
  "telecoms": [
    {"system": "phone", "value": "+256700000000", "use": "mobile"}
  ],
  "addresses": [
    {"line1": "Zone 4", "city": "Arua", "country": "UG"}
  ],
  "extra": {
    "patient_type": "REFUGEE_PATIENT",
    "identity_status": "PARTIALLY_VERIFIED"
  }
}

Search Behaviour

GET /patients searches by name, MRN, identifier system/value, patient id, and person id. Results include identifiers and coverage summaries. When protected-record controls are enabled, broad search filters protected patients out unless the caller has the correct clearance or uses the required exact search pattern. When protected-record controls are disabled, patient search uses a short cache and invalidates after demographics changes.

GET /patients?q=MRN-000123&limit=10
GET /patients?q=UGA-RF-102938&limit=10
GET /patients?q=Amina%20Okello&limit=10

Internal MPI

The internal MPI compares local patient records and creates reviewable match candidates. It scores MRN, identifiers, names, date of birth, sex, telecoms, and address. Strong identifier systems raise a candidate score floor so refugee IDs, passport numbers, national IDs, humanitarian identifiers, or other configured identifiers carry more weight.

When exact inbound identifiers resolve to different MPI patients, AMCDR returns 409 Conflict and creates a durable MPI resolution task rather than selecting one patient. For an atomic FHIR transaction, AMCDR rolls back the clinical transaction first, commits the steward task separately, and returns its identifier in the FHIR OperationOutcome. The task appears under Operations → MPI reconciliation → Review Queue. Approval merges only when both records describe the same person; rejection keeps them separate. The source system replays the original transaction after the identity decision and any required source correction.

Each open MPI resolution task is also a durable shell notification. Super administrators and authorized MPI, identity, governance, or platform stewards see it in the top-right Tasks counter before anyone claims it. The counter refreshes while the application is open and routes directly to MPI reconciliation when identity work is pending. The workflow API continues to enforce tenant and queue visibility, so the notification does not reveal unauthorized patient or task data.

GET  /mpi/internal/policy
POST /mpi/internal/policy
POST /mpi/internal/candidates
POST /mpi/internal/merge
POST /mpi/internal/merge/approve
POST /mpi/internal/merge/reject
POST /mpi/internal/unmerge
GET  /mpi/internal/links/{patient_id}
POST /mpi/internal/links

MPI Service Facade

Use /mpi as the MPI entry point for applications and integrations that must remain independent of whether AMCDR is using its internal MPI or a configured external MPI. Routed requests support internal, external, and auto modes. Auto mode uses a selected or first active external MPI server when available, otherwise it falls back to AMCDR internal MPI.

GET  /mpi/capability
POST /mpi/pdq/search
POST /mpi/pix/query
POST /mpi/pix/feed
POST /mpi/fhir/patient/search
GET  /mpi/fhir/patient/{patient_id}?mode=internal|external&server_key={key}
POST /mpi/fhir/patient
PUT  /mpi/fhir/patient/{patient_id}

The internal implementation provides PDQ-style local demographic search, PIX-style identifier cross-reference, controlled PIX feed create/update, and FHIR Patient read/search/write over the AMCDR Client Registry. External mode delegates to configured PDQ/PIX/FHIR Patient connectors and records integration audit events.

POST /mpi/pdq/search
Content-Type: application/json

{
  "mode": "internal",
  "criteria": {
    "family_name": "Okello",
    "given_name": "Amina",
    "date_of_birth": "1992-04-17"
  },
  "limit": 20
}
POST /mpi/pix/query
Content-Type: application/json

{
  "mode": "auto",
  "identifier": "MRN-000123",
  "assigning_authority": "urn:facility-mrn:amcdr",
  "target_domains": ["urn:national-id", "urn:insurance-id"]
}
POST /mpi/pix/feed
Content-Type: application/json

{
  "mode": "internal",
  "source_identifier": "MRN-000123",
  "source_assigning_authority": "urn:facility-mrn:amcdr",
  "patient_resource": {
    "resourceType": "Patient",
    "identifier": [
      {"system": "urn:facility-mrn:amcdr", "value": "MRN-000123"}
    ],
    "name": [{"family": "Okello", "given": ["Amina"]}],
    "birthDate": "1992-04-17",
    "gender": "female"
  }
}
ActionWhat Happens
Candidate searchCompares one patient against other non-merged patients and returns candidates above the review threshold.
Merge requestCreates an internal MPI review task. Merges are not silently accepted from a standard user action.
Approve mergeRequires an MPI review role such as mpi_admin, governance_admin, platform_admin, or super admin. It merges demographics, EHR-linked content, and patient references according to the manifest.
Reject mergeCloses the review and leaves the two records separate.
UnmergeUses the merge event manifest to reverse a completed merge when policy allows it.

Governed Merge Correction And Reversal

A rejected review remains part of the audit record but does not permanently prevent a later merge. When new evidence establishes that both records describe the same person, submit a new review request. AMCDR preserves both the prior rejection and the later decision.

A completed merge is corrected only through the openEHR Admin workflow. The UI exposes the same workflow under Operations → MPI reconciliation → Merge correction and reversal. It lists merge operations, opens a read-only safety preview, supports composition-by-composition attribution, and executes the approved correction.

MethodRoutePurpose
GET/openehr/v1/admin/ehr/mergeList completed and reversed merge operations with patient, status and paging filters.
GET/openehr/v1/admin/ehr/merge/{merge_event_id}/reversal-previewValidate manifest safety and list post-merge compositions requiring attribution.
POST/openehr/v1/admin/ehr/merge/{merge_event_id}/reverseRestore both MPI patients/EHRs and apply the approved record attribution.

The preview fails closed when reversal is disabled, the merge is no longer completed, the source MPI patient or EHR no longer points to the recorded survivor, either EHR is missing, copied demographics or survivorship fields changed after the merge, or the surviving EHR DIRECTORY changed after the merge. The preview does not modify clinical or identity data.

GET /openehr/v1/admin/ehr/merge/{merge_event_id}/reversal-preview
Authorization: Bearer ${ACCESS_TOKEN}

Every composition created after the merge must be classified. Select compositions belonging to the restored source patient. Unselected compositions remain with the survivor and require explicit acknowledgement. The expected count prevents execution if records changed after preview.

POST /openehr/v1/admin/ehr/merge/{merge_event_id}/reverse
Authorization: Bearer ${ACCESS_TOKEN}
Content-Type: application/json

{
  "reason": "Identity audit correction approved under case MPI-2026-0081.",
  "source_composition_ids": [
    "55555555-5555-4555-8555-555555555555"
  ],
  "expected_post_merge_composition_count": 2,
  "acknowledge_unassigned_post_merge_records": true
}

Successful reversal restores the original MPI merge pointer, patient/EHR state, demographic survivorship, merge link and openEHR demographic Party versions. Selected compositions move with their versions, contributions, audit references, item tags and FHIR registry attribution. Patient, FHIR and composition caches are invalidated after commit. Shared contributions cannot be split: AMCDR requires governance to classify the complete contribution and never redistributes ambiguous records automatically.

Internal MPI Examples

POST /mpi/internal/candidates
Content-Type: application/json

{
  "patient_id": "b84b0829-cfa9-4214-b59b-9d3df289de22",
  "persist_results": true
}
POST /mpi/internal/merge
Content-Type: application/json

{
  "source_patient_id": "duplicate-patient-id",
  "target_patient_id": "surviving-patient-id",
  "reason": "Same national ID and date of birth",
  "actor_ref": "user:mpi.reviewer"
}

When to use PDQ and PIX

QueryMeaningUse In AMCDR
PDQ / PDQmPatient Demographics Query. Search an external MPI for possible people using demographics such as name, birth date, sex, phone, or identifier.Use before creating a local patient, during migration, or when a user cannot find a patient locally.
PIX / PIXm QueryPatient Identifier Cross-reference. Ask an external MPI which identifiers belong to the same person across domains.Use when AMCDR has one identifier and needs another domain's identifier, such as national MPI ID, facility MRN, or insurance ID.
PIX FeedSend a patient identity update to an external MPI.Use when AMCDR is allowed to register or update identity data in the external MPI.

External MPI Configuration

External MPI servers are configured in backend/connectors.yaml or the path set by AMCDR_CONNECTORS_CONFIG_PATH. The browser does not receive MPI credentials. AMCDR backend adapters call the external MPI and audit integration events.

mpi_servers:
  - key: mpi-main
    name: Enterprise MPI
    base_url: https://mpi.example.org/fhir
    active: true
    protocols:
      - pdqm
      - pixm
      - fhir
    field_mappings:
      pdq_parameter_map:
        given_name: given
        family_name: family
        date_of_birth: birthdate
      pix_identifier_systems:
        - urn:national-id
        - urn:facility-mrn
    endpoints:
      pdq_search:
        path: /Patient
        method: GET
        response_mode: json
      pix_query:
        path: /Patient/$ihe-pix
        method: GET
        response_mode: json
      pix_feed:
        path: /Patient
        method: POST
        response_mode: json
      fhir_patient:
        path: /Patient
        method: GET
        response_mode: json
    auth:
      auth_type: oauth2_client_credentials
      token_url: https://auth.example.org/realms/mpi/protocol/openid-connect/token
      client_id: amcdr
      client_secret_env: AMCDR_MPI_CLIENT_SECRET

External MPI APIs

GET  /integrations/mpi/servers
GET  /integrations/mpi/servers/{server_key}
POST /integrations/mpi/{server_key}/pdq/search
POST /integrations/mpi/{server_key}/pix/query
POST /integrations/mpi/{server_key}/pix/feed
POST /integrations/mpi/{server_key}/fhir/patient/search
GET  /integrations/mpi/{server_key}/fhir/patient/{patient_id}
POST /integrations/mpi/{server_key}/fhir/patient
PUT  /integrations/mpi/{server_key}/fhir/patient/{patient_id}
POST /integrations/mpi/{server_key}/transform/local-to-fhir
POST /integrations/mpi/{server_key}/transform/fhir-to-local
POST /integrations/mpi/{server_key}/transform/party-to-fhir
POST /integrations/mpi/{server_key}/transform/fhir-to-party
POST /integrations/mpi/{server_key}/fhir/party
PUT  /integrations/mpi/{server_key}/fhir/party/{patient_id}
POST /integrations/mpi/{server_key}/fhir/party/import

PDQ Search Example

PDQ is used before local patient creation. The response returns FHIR Bundle entries and normalized party_candidates when the external MPI provides match data for review or import.

POST /integrations/mpi/mpi-main/pdq/search
Content-Type: application/json

{
  "criteria": {
    "given_name": "Amina",
    "family_name": "Okello",
    "date_of_birth": "1992-04-17",
    "sex": "female",
    "identifier": "UGA-RF-102938"
  }
}

PIX Query Example

PIX is used when one identifier is known and other identity domains are needed. AMCDR sends the identifier and target domains to the configured external MPI and normalizes returned identifiers as federated identifiers and party candidates.

POST /integrations/mpi/mpi-main/pix/query
Content-Type: application/json

{
  "identifier": "MRN-000123",
  "assigning_authority": "urn:facility-mrn:amcdr",
  "target_domains": [
    "urn:national-id",
    "urn:insurance-id",
    "urn:unhcr"
  ]
}

PIX Feed Example

Use PIX feed only when AMCDR is authorized to update the external identity registry. The patient resource uses a standard FHIR Patient payload.

POST /integrations/mpi/mpi-main/pix/feed
Content-Type: application/json

{
  "source_identifier": "MRN-000123",
  "source_assigning_authority": "urn:facility-mrn:amcdr",
  "patient_resource": {
    "resourceType": "Patient",
    "identifier": [
      {"system": "urn:facility-mrn:amcdr", "value": "MRN-000123"}
    ],
    "name": [
      {"family": "Okello", "given": ["Amina"]}
    ],
    "birthDate": "1992-04-17",
    "gender": "female"
  }
}

FHIR Patient Exchange

FHIR Patient APIs are available in two places. The /fhir/Patient facade writes through the internal MPI. The /integrations/mpi/{server_key}/fhir/patient routes call an external MPI or FHIR server through backend connector configuration. Inbound identities still reconcile locally before becoming AMCDR patients.

# Create or update through the MPI-authoritative FHIR facade
POST /fhir/Patient
PUT  /fhir/Patient/{patient_id}

# Apply Person demographics only to its linked Patient
POST /fhir/Person

# Ingest identities through bundle/profile/SHR boundaries
POST /fhir/Bundle
POST /fhir/ingest

# Pull a governed patient-wide FHIR bundle from AMCDR
GET /fhir/Patient/{patient_id}/$everything

# Search an external FHIR/MPI server
POST /integrations/mpi/mpi-main/fhir/patient/search

# Transform local demographics to the external FHIR Patient shape
POST /integrations/mpi/mpi-main/transform/local-to-fhir

Foreigners, Refugees, Unknown Persons, And Undocumented People

AMCDR preserves uncertainty instead of inventing false identity data. Use temporary identifiers, refugee or humanitarian identifiers, passport or foreign national identifiers, camp/settlement identifiers, emergency temporary identities, and review tasks. The internal MPI compares these identifiers, but uncertain matches must go to review.

ScenarioRecommended Demographic Handling
Foreign nationalUse passport, country-of-origin, visa or foreign national identifier systems; keep local MRN separate.
Refugee or humanitarian caseUse UNHCR/refugee registration, camp/settlement, humanitarian agency reference, household or family tracing reference.
Unknown emergency patientCreate a temporary identity with temporary MRN and identity_status such as TEMPORARY or REVIEW_PENDING; reconcile later through MPI review.
Newborn before final namingUse newborn temporary identity, facility birth number, mother link, birth order, birth date/time, sex, and birth event context.
Unknown deceased personUse temporary deceased identity, mortuary or facility case number, location found, estimated age, sex, and reconciliation task.

Protected Demographics

Protected-record labels apply before clinical workflows. A protected patient can be hidden from broad search, require exact identifier search, require clearance, require purpose of use, or require break-glass access. This applies to demographics, EHRs, encounters, compositions, FHIR output, AQL, exports, dashboards, and subscriptions.

See Protected Records for VIP, sealed, protected minor, witness-protected, and break-glass workflow details.

Operational Flows

FlowRecommended Steps
Register known local patientSearch /patients, run internal MPI candidates if needed, create patient only when no match exists, verify party/coverage/EHR, open visit.
Register from external MPIRun PDQ, review candidates, use PIX to collect cross-domain identifiers, import party or create local patient, link external identifiers.
Merge duplicatesRun internal candidates, request merge, have MPI reviewer approve or reject, audit merge event and change manifest.
Migration importNormalize identifiers, run MPI checks, import FHIR Patient or party payloads, then create clinical compositions only after patient/EHR context is resolved.
External identity updateUse PIX feed or external FHIR Patient update only if the governance agreement allows AMCDR to update the external MPI.

Events And Subscriptions

Demographic and MPI actions emit reviewable and subscribable events. Examples include coverage.created, integration.mpi.pdq.search, integration.mpi.pix.query, integration.mpi.pix.feed, integration.mpi.fhir.patient.create, integration.mpi.fhir.patient.update, and integration.mpi.fhir.party.import.

GET /triggers/events?event_type=integration.mpi.pdq.search&limit=20
GET /triggers/events?event_type=coverage.created&limit=20

Use Subscriptions and Outbound Delivery when another system needs a webhook or broker notification after an MPI or demographics event.

Implementation Rules