What the federation provides
An authorized application sends one patient-scoped AQL query to the National Federation Gateway. The Gateway resolves identity and record location outside AQL, asks eligible Regional Federation Agents to query their local AMCDR by local ehr_id, and returns one result. Clinical compositions remain in their controlling CDR.
| Component | Responsibility | Clinical storage |
|---|---|---|
| National Federation Gateway | Standard Query API facade, AMMPI resolution, locator and consent gate, fan-out, combined results, provenance, follow-up routing and central audit. | None |
| Regional Federation Agent | Gateway authentication, signed clinician context, local policy/consent, EHR resolution, AMCDR connector and regional audit. | None |
| AMMPI and record locator | Canonical patient identity and patient-to-node metadata. | No clinical payloads |
| PCM | National policy, consent and signed decision context. | Policy metadata only |
| AMCDR/openEHR CDR | EHRs, versions, compositions, contributions, templates and final source-side access decision. | Authoritative clinical content |
End-to-end query sequence
- The authenticated client calls
GET|POST /openehr/v1/query/aqlon the National Gateway. - The Gateway treats
e/ehr_status/subject/external_ref/id/valueas a facade patient-resolution predicate only. - AMMPI resolves the input to the canonical patient, and the locator supplies candidate nodes for an undirected query.
- National consent and policy remove denied nodes before local resolution or query.
- Each Regional Agent resolves the canonical patient through local AMCDR
GET /openehr/v1/ehr?subject_id=.... - The Gateway sends standard AQL containing only
e/ehr_id/value = '<local-ehr-id>'. - The Agent validates signed clinician context, repeats local controls and calls local AMCDR
POST /openehr/v1/query/aql. - The Gateway combines rows, adds only selected provenance and applies global DISTINCT/ORDER.
Client request
POST /openehr/v1/query/aql
Authorization: Bearer <credential from the trusted identity boundary>
X-User-ID: clinician-123
X-User-Roles: doctor
X-Organisation: hospital-a
X-Facility: facility-a
X-Purpose-Of-Use: TREAT
X-Correlation-ID: 3fbc49a7-09b0-49ab-8890-09912e9faf80
Content-Type: application/json
{
"q": "SELECT e/ehr_status/subject/external_ref/id/value AS patient_id, c/uid/value AS composition_id FROM EHR e CONTAINS COMPOSITION c WHERE e/ehr_status/subject/external_ref/id/value = $patient_id ORDER BY composition_id",
"query_parameters": {"patient_id": "MPI-000123"}
}
The local CDR does not need the national ID in EHR_STATUS.subject. When the subject is selected, the Gateway re-injects the original resolution input into every row.
Directed queries and provenance
SELECT
p/id AS endpoint_id,
p/system_id AS system_id,
p/organisation AS organisation,
c/uid/value AS composition_id
FROM ENDPOINT p ["hospital-a", "hospital-b"]
CONTAINS EHR e
CONTAINS COMPOSITION c
WHERE e/ehr_status/subject/external_ref/id/value = 'MPI-000123'
FROM ORGANISATION p ["regional-health-authority-a"] expands an organisation to its registered endpoints. IDs in directives are stable registry identifiers, never URLs. Endpoint columns appear only when selected, and an alias collision is renamed deterministically.
Undirected aggregates are blocked because cross-node correctness cannot be assumed. An aggregate is permitted only when an endpoint- or organisation-directed query resolves to one endpoint.
Result and failure semantics
| Case | Behavior |
|---|---|
| Normal result | {q, columns, rows, meta}; no hidden endpoint columns. |
| Default duplicate handling | Rows pass through. Use endpoint provenance, SELECT DISTINCT or explicit ?dedup=version. |
| Global ordering | ORDER BY runs over the combined result after fan-out and deduplication. |
| Patient found nowhere | HTTP 200, empty rows and meta.resolution_status=not-found. |
| Some nodes fail | HTTP 200 when at least one succeeds; meta.partial=true and every endpoint outcome remains visible. |
| All targeted nodes time out | HTTP 504 with the normal metadata envelope. |
| Invalid or unsafe facade AQL | HTTP 400 before any node query. |
| Unknown directed endpoint | HTTP 404. |
Endpoint statuses include active, offline, time-out, not-resolved, consent-denied and excluded. LIMIT/OFFSET remain node-local and are not stable cross-node pagination.
Follow-up reads and writes
The facade forwards governed composition, versioned-composition and contribution operations under /openehr/v1/ehr/{ehr_id}/.... It selects the owner by the creating_system_id in the OBJECT_VERSION_ID, then an explicit ?endpoint= or X-AMCDR-Endpoint-ID, then ask-all for reads only.
Versioned writes must route to one controlling CDR. New objects must name one endpoint. Ambiguous writes fail with HTTP 400, and openEHR UIDs are never changed.
Register and configure a node
1. Prepare AMCDR
- Verify
/health,/openehr/v1/metadata, EHR lookup and AQL with a least-privilege service account. - Create a dedicated non-interactive integration identity, give it only the
integration_modelerrole and required tenant/organisation membership, and issue a separate expiring API key for the Regional Agent. Never use an administrator's browser token. - Enable final AMCDR policy/PCM decision-token verification.
- Record the stable CDR
system_id.
2. Configure the Regional Agent
AMCDR_RFA_DEPLOYMENT_ENVIRONMENT=production
AMCDR_RFA_NODE_ID=hospital-a
AMCDR_RFA_GATEWAY_TOKEN=<random-agent-token>
AMCDR_RFA_CLIENT_CONTEXT_SECRET=<random-secret-at-least-32-bytes>
AMCDR_RFA_CLIENT_CONTEXT_REQUIRED=true
AMCDR_RFA_LOCAL_CDR_BASE_URL=https://amcdr-a.internal.example.org
AMCDR_RFA_ALLOW_RUNTIME_CONNECTOR_CONFIGURATION=false
AMCDR_RFA_AMCDR_API_KEY=<dedicated-expiring-amcdr-integration-key>
AMCDR_RFA_AMCDR_API_KEY_HEADER=X-API-Key
AMCDR_RFA_AMCDR_VERIFY_TLS=true
AMCDR_RFA_PCM_REQUIRED=true
AMCDR_RFA_AMMPI_REQUIRED=true
3. Configure the National Gateway
AMCDR_NFG_DEPLOYMENT_ENVIRONMENT=production
AMCDR_NFG_FEDERATION_TOKEN=<random-client-api-token>
AMCDR_NFG_REGIONAL_GATEWAY_TOKEN=<same-agent-token>
AMCDR_NFG_REGIONAL_CLIENT_CONTEXT_SECRET=<same-signed-context-secret>
AMCDR_NFG_REGIONAL_VERIFY_TLS=true
AMCDR_NFG_FEDERATION_AQL_ENABLED=true
AMCDR_NFG_PCM_REQUIRED=true
AMCDR_NFG_AMMPI_REQUIRED=true
Place the public National Gateway behind the approved OIDC, national-PKI, mTLS or service-mesh identity boundary. Both processes fail production startup when SQLite, short/development/placeholder credentials, unsafe PCM/AMMPI authentication, unsafe TLS, optional configured PCM/AMMPI or unsigned forwarded clinician context are detected.
4. Register the node
{
"id": "hospital-a",
"name": "Hospital A Regional Agent",
"region": "central",
"organisation": "regional-health-authority-a",
"base_url": "https://regional-agent-a.example.org",
"cdr_base_url": "https://amcdr-a.example.org/openehr/v1",
"system_id": "amcdr-a.example.org",
"creating_system_ids": ["legacy-cdr-a.example.org"],
"connection_type_code": "openehr-rest-query",
"certificate_fingerprint": "sha256:<fingerprint>",
"supported_capabilities": ["federation-aql-node", "openehr-rest-query", "ips-2.0.1"],
"status": "active"
}
Use the National Gateway Nodes UI or POST /federation/nodes. Each endpoint has exactly one managing organisation. Locator lifecycle events should include local_ehr_id when known.
Authentication and access checks
The configured identity provider or gateway authenticates the client. The National Gateway authenticates onward and signs a short-lived X-AMCDR-Client-Context containing clinician ID, roles, organisation, facility, purpose, correlation, audience and scope. The Regional Agent validates it and compares every field to the forwarded request before local resolution or query.
National consent determines which nodes may receive the query. Each Regional Agent checks local policy and consent, and AMCDR makes the final access decision.
Acceptance tests
| Track | Verify |
|---|---|
| Transparency | A plain standard patient AQL returns single-CDR-shaped rows with no implicit endpoint fields. |
| Identity scope | Nodes receive local ehr_id and never the facade subject predicate. |
| Directed routing | Endpoint/organisation targeting, not-resolved members and single-node aggregate. |
| Partial results | Active, not-resolved, consent-denied, timeout and upstream-error outcomes. |
| Combined rows | Default duplicate pass-through, global DISTINCT/ORDER and version dedup. |
| Ownership | Follow-up read/write by creating-system ID, no UID mutation, ambiguous write rejection. |
| Security | Signed context accepted; missing, expired, tampered or mismatched context rejected; source-side consent denial retained. |
| Identity lifecycle | AMMPI merge/survivor resolution changes subsequent routing correctly. |
Monitoring and troubleshooting
Scrape /metrics and monitor 4xx/5xx/504 rates, latency, active nodes, locator/audit volume, outbox growth, database health and broker lag. Alert on zero active nodes, sustained partial responses, signed-context failures and replay backlog.
| Symptom | Check |
|---|---|
| 401 at National Gateway | Client credential and trusted identity boundary. |
| 401/403 at Regional Agent | Gateway token; signed-context signature, issuer, audience, scope, expiry, clock and exact claim match. |
not-found | AMMPI canonical identity and locator lifecycle ingestion. |
not-resolved | Local patient-to-EHR link and the AMCDR EHR lookup operation. |
| Node rejects query | Confirm an ehr_id predicate and no subject predicate reached the node. |
| Follow-up write rejected | Controlling system/creating-system registry or explicit endpoint for a new object. |
| 504 | Regional TLS/network, Agent health, AMCDR latency and timeout settings. |