Integration

openEHR API Reference

Look up AMCDR openEHR endpoints for EHRs, definitions, queries, demographics, administration, and simplified formats.

Purpose

Use this reference to manage templates, create EHRs, write compositions and run queries through the openEHR APIs. It also covers TDS/TDD, FLAT JSON and STRUCTURED JSON composition formats.

Canonical JSON/XML, FLAT, STRUCTURED, TDD XML, and template-data-definition JSON use the same /openehr/v1/ehr/{ehr_id}/composition resource. Content-Type selects the submitted representation and Accept selects the returned representation without introducing a second create, update, read, or delete API.

Getting started: upload or manage templates, create or resolve an EHR, write compositions, then query governed clinical records through AQL or saved-query APIs.
Active standard: the public /openehr/v1 contract follows the openEHR ITS-REST 1.1.0 names and HTTP behavior. See openEHR ITS-REST 1.1.0 for the release-level implementation and maturity notes.
Request examples: Swagger publishes each capability once under openEHR EHR, Query, Definition, Demographic, or Admin. Every published operation includes a ready-to-adapt cURL example; write operations also show a representative request body and required openEHR headers.
Finding AMCDR extensions: composition projections and reversible lifecycle extensions are grouped under openEHR EHR. Irreversible single and AQL-selected batch composition hard deletion is grouped under openEHR Admin. Product extensions are explicitly marked x-amcdr-api-boundary: product-extension and are not presented as normative ITS-REST operations.

1.1.0 API Additions

CapabilityPrimary routeImportant behavior
SMART app platform/.well-known/smart-configuration and /smart/*Discovery, governed app registry, one-time patient/EHR launches, grants, scope enforcement, audit and readiness. See SMART on openEHR.
Demographic resources/openehr/v1/demographic/...PARTY CRUD, VERSIONED_PARTY, contribution and ITEM_TAG operations. PERSON writes resolve through the MPI and create a PartyVersion.
Admin EHR deletionDELETE /openehr/v1/admin/ehr/{ehr_id}Irreversible, super-admin only; preserves MPI identity and clears its EHR reference.
Admin selected/all deletionDELETE /openehr/v1/admin/ehr/allRepeated ehr_id selects EHRs; omitting it selects every EHR visible to the deployment.
Governed EHR merge/openehr/v1/admin/ehr/.../mergeRequest, status, survivor resolution, operation details, approval, rejection and reversal; MPI-governed AMCDR extension.
Admin all-template retirementDELETE /openehr/v1/admin/template/allTenant-scoped dry-run and count-confirmed execution; hard deletion is disabled in production.
System options and heartbeatOPTIONS /openehr/v1, GET /openehr/v1/system/heartbeatConformance discovery plus a dependency-free operational heartbeat extension.
Template examplesGET /openehr/v1/definition/template/adl1.4/{template_id}/exampleSpecification-defined example sub-resource; ADL2 equivalent is also available.
ITEM_TAGEHR, EHR_STATUS, COMPOSITION and Demographic tag routesRead, replace, filter and delete-by-key operations use standard item-tag headers.
Stored query resolution/openehr/v1/definition/query/{qualified_query_name}/{version}Qualified names, versions and query execution resolve correctly even when the stored query is named aql.

Common Request Rules

HeaderUseExample
AuthorizationBearer token or platform session credential.Bearer eyJ...
Content-TypeRequest body format.application/json, application/xml, application/openehr.wt+json
AcceptExpected response format.application/json, application/xml
PreferResponse body preference for writes.return=representation or return=minimal
If-MatchVersion-safe update precondition where the operation defines it.W/"{version_uid}"
openehr-versionStandard version/lifecycle commit metadata.lifecycle_state.code_string="532"
openehr-audit-detailsStandard change audit, committer and optional source system.change_type.code_string="251",system_id="hospital.example"
openehr-template-idTemplate reference where the operation accepts it.vital-signs.v1
openehr-item-tagResource ITEM_TAG values.key="record-class";value="primary"
openehr-version-item-tagVersion ITEM_TAG values.key="review";value="complete"
openehr-ehr-idStandard EHR context header where specified.87284370-...

Header names follow the openEHR contract and remain case-insensitive under HTTP. Writes default to Prefer: return=minimal. AMCDR applies role, tenant, organisation, environment, template-access, protected-record, and audit policies before returning clinical data.

Definition API

The Definition API manages clinical templates. The OPT defines their structure and constraints. TDS XSD, TDD examples, flat examples, structured examples, and mapping documentation are derived from the managed template.

Upload an OPT template

POST /openehr/v1/definition/template/adl1.4
Content-Type: application/xml
Prefer: return=representation

<template xmlns="http://schemas.openehr.org/v1">
  ...
</template>

Example response:

{
  "template_id": "KDS_Diagnose",
  "concept": "Diagnose",
  "lifecycle_state": "uploaded",
  "links": {
    "definition": "/openehr/v1/definition/template/adl1.4/KDS_Diagnose",
    "opt": "/templates/KDS_Diagnose/exports/opt",
    "tds": "/templates/KDS_Diagnose/exports/tds"
  }
}

List all templates in the CDR

GET /openehr/v1/definition/template/adl1.4?view=summary&offset=0&fetch=50
Accept: application/json

The default view=summary returns a public template catalogue without repository UUIDs, lifecycle controls, deletion state, or other AMCDR administration fields. Optional template_id, version, and concept filters narrow the catalogue; offset and fetch provide paging. Use view=details when repository governance information is required. Use GET /openehr/v1/definition/template/adl2 for the corresponding ADL 2 catalogue.

Example response:

[
  {
    "template_id": "KDS_Diagnose",
    "name": "Diagnose",
    "version": "1.0.0",
    "concept": "Diagnose",
    "archetype_id": "openEHR-EHR-COMPOSITION.encounter.v1",
    "created_timestamp": "2026-04-18T03:31:16.759670+00:00"
  }
]

Detailed repository inventory remains available on the same operation:

GET /openehr/v1/definition/template/adl1.4?view=details&offset=0&fetch=50
Accept: application/json

Read a template definition

GET /openehr/v1/definition/template/adl1.4/KDS_Diagnose
Accept: application/xml

Generate a sample composition

The template identifier is a required path parameter. The standard openEHR representation selector is the Accept header. Swagger also exposes an optional format query selector for convenient testing; when supplied, it takes precedence over Accept.

GET /openehr/v1/definition/template/adl1.4/KDS_Diagnose/example?type=input&detail_level=required&format=flat_json
Accept: application/openehr.wt.flat+json
formatRepresentationStandard Accept value
canonical_jsonCanonical RM COMPOSITION JSONapplication/json
canonical_xmlCanonical RM COMPOSITION XMLapplication/xml
flat_jsonopenEHR FLAT JSONapplication/openehr.wt.flat+json
structured_jsonopenEHR STRUCTURED JSONapplication/openehr.wt.structured+json
tddAMCDR TDD XML composition instanceapplication/xml; format=tdd
template_data_definition_jsonAMCDR template-data-definition JSONapplication/json; format=template_data_definition_json

The standard type values are input and output. The standard detail_level values are required, medium, and complete. The ADL 2 route provides the same controls at /openehr/v1/definition/template/adl2/{template_id}/example.

Download template exports

RoutePurpose
GET /templates/{templateKey}/exports/optDownload the authoritative OPT.
GET /templates/{templateKey}/exports/tdsDownload the generated Template Data Structure XSD for mapping tools.
GET /templates/{templateKey}/examples/tddDownload a sample TDD XML instance.
GET /templates/{templateKey}/examples/flatDownload a flat JSON composition example.
GET /templates/{templateKey}/examples/structuredDownload a structured JSON composition example.
GET /templates/KDS_Diagnose/exports/tds
Accept: application/xml

Example response headers:

HTTP/1.1 200 OK
Content-Type: application/xml
Content-Disposition: attachment; filename="KDS_Diagnose_TDS.xsd"

Define and execute saved queries

Saved queries are reviewed, versioned query definitions. Internal users create and version them through the workbench API; partner systems execute reviewed queries through the outbound integration API.

POST /workbench/queries
Content-Type: application/json

{
  "key": "recent-lab-results",
  "name": "Recent laboratory results",
  "query_type": "query",
  "aql_text": "SELECT c FROM EHR e CONTAINS COMPOSITION c[kds-laborbericht] FETCH 100",
  "parameters_schema": {
    "type": "object",
    "properties": {
      "ehr_id": { "type": "string" }
    }
  }
}
POST /integration/outbound/saved-queries/recent-lab-results/execute
Content-Type: application/json

{
  "params": {
    "ehr_id": "118194d5-1efe-42fc-8ee8-2e11b74782a2"
  }
}

Privileged EHR catalogue

openEHR ITS-REST resolves an individual EHR using its identifier or subject reference; it does not define a collection operation for enumerating every EHR. AMCDR therefore publishes the following tenant-scoped operation as an explicitly marked Admin extension. It requires super-administrator authorization.

GET /openehr/v1/admin/ehr?limit=50&offset=0
Accept: application/openehr+json

The response contains items, total, returned, limit, and offset. Results are ordered newest first. Use the canonical GET /openehr/v1/ehr?subject_id=...&subject_namespace=... operation when resolving one EHR by subject.

EHR API

The EHR API manages EHR containers, EHR status, directories, folders, compositions, versions, and contributions. Clinical data must be persisted as governed openEHR compositions.

Governed EHR merge

POST /openehr/v1/admin/ehr/{target_ehr_id}/merge
Content-Type: application/json

{
  "source_ehr_id": "11111111-1111-4111-8111-111111111111",
  "reason": "Duplicate EHR confirmed by MPI governance case MPI-2026-0042."
}

The response contains the review task ID. Use GET /openehr/v1/admin/ehr/{ehr_id}/merge-status, GET /openehr/v1/admin/ehr/{ehr_id}/merged-into, or GET /openehr/v1/admin/ehr/merge/{operation_id} to inspect progress, the surviving EHR and complete operation provenance. Authorized MPI governance reviewers approve or reject through the operation-specific Admin endpoints. Completed operations can be reversed from the recorded manifest when no conflicting later DIRECTORY change exists.

DIRECTORY

The versioned DIRECTORY is managed through GET, POST, PUT and DELETE /openehr/v1/ehr/{ehr_id}/directory. Updates and deletion use the current weak ETag in If-Match; version UID, time and nested path retrieval are supported.

Create an EHR

POST /openehr/v1/ehr
Content-Type: application/json
Prefer: return=representation

{
  "_type": "EHR_STATUS",
  "subject": {
    "external_ref": {
      "id": { "value": "MRN-UG-2026-0002" },
      "namespace": "AMCDR-MRN",
      "type": "PERSON"
    }
  },
  "is_queryable": true,
  "is_modifiable": true
}

Example response:

{
  "ehr_id": {
    "value": "118194d5-1efe-42fc-8ee8-2e11b74782a2"
  },
  "ehr_status": {
    "subject": {
      "external_ref": {
        "id": { "value": "MRN-UG-2026-0002" }
      }
    },
    "is_queryable": true,
    "is_modifiable": true
  }
}

Read EHR metadata

GET /openehr/v1/ehr/118194d5-1efe-42fc-8ee8-2e11b74782a2
Accept: application/json

Read or update EHR status

GET /openehr/v1/ehr/{ehr_id}/ehr_status
PUT /openehr/v1/ehr/{ehr_id}/ehr_status
If-Match: "{version_uid}"

Read or update directory and folders

GET /openehr/v1/ehr/{ehr_id}/directory
PUT /openehr/v1/ehr/{ehr_id}/directory
Content-Type: application/json

Create an openEHR composition

POST /openehr/v1/ehr/{ehr_id}/composition
Content-Type: application/json
Prefer: return=representation

{
  "_type": "COMPOSITION",
  "archetype_details": {
    "template_id": { "value": "KDS_Diagnose" }
  },
  "name": { "value": "Diagnosis" },
  "language": {
    "terminology_id": { "value": "ISO_639-1" },
    "code_string": "en"
  },
  "territory": {
    "terminology_id": { "value": "ISO_3166-1" },
    "code_string": "UG"
  },
  "category": {
    "value": "event",
    "defining_code": {
      "terminology_id": { "value": "openehr" },
      "code_string": "433"
    }
  },
  "content": []
}

Example response:

{
  "uid": {
    "value": "7d1d1c1b-6a0b-47e6-9f3d-50b1a7a25a8b::amcdr::1"
  },
  "template_id": "KDS_Diagnose",
  "ehr_id": "118194d5-1efe-42fc-8ee8-2e11b74782a2",
  "lifecycle_state": "complete"
}

Create a composition using simplified formats

Use the same canonical composition resource for every supported representation. FLAT JSON is suitable for compact template-path submissions from forms, ETL jobs, and partner systems. STRUCTURED JSON preserves an openEHR-shaped composition envelope.

POST /openehr/v1/ehr/118194d5-1efe-42fc-8ee8-2e11b74782a2/composition
Content-Type: application/openehr.wt.flat+json
openehr-template-id: vital-signs
Prefer: return=representation

{
  "vital_signs/context/start_time": "2026-06-16T09:30:00+03:00",
  "vital_signs/body_temperature/temperature|magnitude": 37.1,
  "vital_signs/body_temperature/temperature|unit": "Cel"
}
POST /openehr/v1/ehr/118194d5-1efe-42fc-8ee8-2e11b74782a2/composition
Content-Type: application/openehr.wt.structured+json
openehr-template-id: vital-signs
Prefer: return=representation

{
  "name": { "value": "Vital signs" },
  "language": {
    "terminology_id": { "value": "ISO_639-1" },
    "code_string": "en"
  },
  "territory": {
    "terminology_id": { "value": "ISO_3166-1" },
    "code_string": "UG"
  },
  "content": []
}
POST /openehr/v1/ehr/118194d5-1efe-42fc-8ee8-2e11b74782a2/composition
Content-Type: application/xml; format=tdd
openehr-template-id: vital-signs
Prefer: return=representation

<vital-signs xmlns="http://schemas.oceanehr.com/templates">
  <temperature>37.1</temperature>
</vital-signs>

TDS and TDD are different artifacts: TDS is the XSD schema. Retrieve it with GET /openehr/v1/definition/template/adl1.4/{template_id}/schema?format=tds. TDD is the XML composition instance that can be sampled, submitted, updated, or retrieved.

Read and export compositions

RoutePurpose
GET /openehr/v1/ehr/{ehr_id}/compositionReturn the current compositions belonging to one EHR. Use format for canonical, FLAT, STRUCTURED, TDD, template-data-definition, or workspace-summary output and use limit/offset for paging.
GET /openehr/v1/ehr/{ehr_id}/composition/{uid_based_id}Read one composition; use Accept for canonical JSON/XML, FLAT, STRUCTURED, TDD XML, or template-data-definition JSON.
PUT /openehr/v1/ehr/{ehr_id}/composition/{uid_based_id}Update a composition using If-Match and the selected representation media type.
DELETE /openehr/v1/ehr/{ehr_id}/composition/{uid_based_id}Create the standard deleted version where policy permits.
POST /openehr/v1/admin/ehr/{ehr_id}/composition/{uid_based_id}/{restore|expire|revoke|supersede}Apply a privileged records-governance transition. The authenticated super-administrator is recorded as the actor.
DELETE /openehr/v1/admin/ehr/{ehr_id}/composition/{uid_based_id}Permanently delete one composition under super-administrator governance.
POST /openehr/v1/admin/composition/hard-delete-batchPreview or execute an AQL-selected or UUID-selected permanent-deletion batch.

The standard EHR-scoped DELETE is the sole published logical-delete operation. Standard PUT is the normal clinical correction and versioning operation. Explicit restoration, expiry, revocation and administrative supersession are governed Admin extensions; physical deletion remains irreversible. Legacy /compositions* compatibility handlers are not published for integration use.

Lifecycle events and deleted-composition webhooks

RoutePurpose
GET /triggers/eventsSearch immutable lifecycle events by event type, target, actor, reason and time range.
GET /triggers/events/activityReturn authoritative time-bounded totals, groupings, pagination, item details and deletion tombstones across openEHR and platform resources.
GET /triggers/events/deleted-compositionsPoll logical- and hard-deletion events together with retained tombstone metadata.
GET, POST /triggers/subscriptionsList or create governed webhook and broker subscriptions, including composition.logical_deleted and composition.hard_deleted.
GET /triggers/deliveriesInspect webhook delivery status and attempts.
POST /triggers/deliveries/{delivery_id}/retryRetry an approved failed webhook delivery.

Swagger groups these routes under Lifecycle & Webhooks. Access requires the deployment's authenticated platform or integration authorization and is not duplicated beneath the openEHR routes.

Create and read contributions

POST /openehr/v1/ehr/{ehr_id}/contribution
Content-Type: application/json

{
  "versions": [
    {
      "commit_audit": {
        "change_type": { "value": "creation" }
      },
      "data": {
        "_type": "COMPOSITION",
        "name": { "value": "Laboratory report" }
      }
    }
  ]
}
GET /openehr/v1/ehr/{ehr_id}/contribution/{contribution_id}

Query API

The Query API executes Archetype Query Language (AQL) against governed openEHR records. AMCDR accepts standard openEHR query routes and AMCDR records query routes for shared-health-record clients.

Execute AQL with POST

POST /openehr/v1/query/aql?fetch=50&offset=0
Content-Type: application/json

{
  "q": "SELECT c FROM EHR e CONTAINS COMPOSITION c[kds-laborbericht] FETCH 10",
  "query_parameters": {}
}

Example response:

{
  "meta": {
    "href": "/openehr/v1/query/aql",
    "type": "RESULTSET",
    "executed_aql": "SELECT c FROM EHR e CONTAINS COMPOSITION c[kds-laborbericht] FETCH 10"
  },
  "q": "SELECT c FROM EHR e CONTAINS COMPOSITION c[kds-laborbericht] FETCH 10",
  "columns": [
    { "name": "c", "path": "/composition" }
  ],
  "rows": [
    [
      {
        "uid": { "value": "7d1d1c1b-6a0b-47e6-9f3d-50b1a7a25a8b::amcdr::1" },
        "name": { "value": "Laboratory report" }
      }
    ]
  ]
}

Execute AQL with GET

GET /openehr/v1/query/aql?q=SELECT%20c%20FROM%20EHR%20e%20CONTAINS%20COMPOSITION%20c%20FETCH%205
Accept: application/json

Common query examples

-- Retrieve EHR ids and external subject ids
SELECT
  e/ehr_id/value,
  e/ehr_status/subject/external_ref/id/value
FROM EHR e
FETCH 100
-- Retrieve compositions for one template
SELECT
  c
FROM EHR e
  CONTAINS COMPOSITION c[kds-laborbericht]
TOP 10
-- Retrieve composition ids
SELECT
  c/uid/value
FROM EHR e
  CONTAINS COMPOSITION c
FETCH 100
-- Aggregate by template id
SELECT
  c/archetype_details/template_id/value AS template_id,
  COUNT(*) AS total
FROM EHR e
  CONTAINS COMPOSITION c
GROUP BY c/archetype_details/template_id/value
ORDER BY total DESC
FETCH 20
-- Retrieve feeder audit provenance
SELECT
  e/ehr_id/value,
  c,
  c/feeder_audit AS Feeder_Audit
FROM EHR e[ehr_id/value='118194d5-1efe-42fc-8ee8-2e11b74782a2']
  CONTAINS FEEDER_AUDIT f
WHERE
  f/feeder_audit/originating_system_item_ids/id='Observation/6115aed3-8b17-42ce-97d5-67e25b02a702/_history/1'
  AND f/feeder_audit/originating_system_item_ids/type='fhir_logical_id'
FETCH 10
Paging rule: if an AQL request omits LIMIT, FETCH, or TOP, AMCDR applies an internal default limit of 1000 rows. Explicit limits such as FETCH 5 or LIMIT 100000 override that default subject to policy.

Errors

Errors should be explicit, recoverable, and safe to expose to integration clients without leaking protected patient data.

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "aql_syntax_error",
  "message": "Unexpected token near SELECT",
  "details": {
    "line": 1,
    "column": 8
  }
}
HTTP/1.1 403 Forbidden
Content-Type: application/json

{
  "error": "access_denied",
  "message": "The caller is not authorized to access this EHR or template."
}
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{
  "error": "composition_validation_failed",
  "message": "The submitted payload does not satisfy the selected template.",
  "validation_errors": [
    {
      "path": "/content[0]/data/items[0]/value",
      "message": "Required value is missing."
    }
  ]
}

Operational Sequence

Definition API EHR API Composition write Query API Saved query delivery
  1. Upload or manage the OPT through the Definition API or Semantic Studio.
  2. Generate or download TDS and example payloads when mapping tools need a structure contract.
  3. Create or resolve the patient EHR before writing clinical data.
  4. Submit compositions using openEHR JSON/XML, TDD XML, FLAT JSON, or STRUCTURED JSON.
  5. Retrieve clinical records using EHR reads, AQL queries, saved queries, SHR projections, or IPS projections according to partner authorization.