Scope
FHIR SDs
FHIR StructureDefinition storage, validation, and profile-aware exchange behavior.
Mapping Design
FHIR profile paths mapped to openEHR template fields for canonical persistence.
Bidirectional Mapping
Rules and sample-data checks for both mapping directions. Open mapping guide.
FHIR Ingest
Direct FHIR resource ingest, Bundle ingest, and governed FHIR-to-openEHR ingest boundaries.
FHIR Output
Projection of canonical compositions into FHIR resources and retrievable FHIR bundles.
Migration
Use of FHIR SDs and mappings in legacy FHIR, NDJSON, XML, and CSV migration projects.
Operations
Capability checks, validation results, troubleshooting, security, cache, and audit expectations.
How FHIR data becomes a clinical record
AMCDR exchanges data through FHIR and stores its clinical records in openEHR. A FHIR payload becomes canonical AMCDR clinical data only when an approved profile, mapping, patient context, terminology handling, and template target are available.
Mapping direction must be explicit. Inbound FHIR uses fhir_to_openehr rules and targets. Outbound FHIR uses openehr_to_fhir rules and projections. A bidirectional map is a governed artifact with both directions defined; it is not automatic inverse execution. See Mapping and Bidirectional Mapping.
When another system wants to receive FHIR resources after AMCDR changes, use the subscription pattern: a webhook or broker message carries the event identifiers, and the partner then pulls the authorized FHIR resource or projection. See Subscriptions and Outbound Delivery.
What A FHIR StructureDefinition Does
A FHIR StructureDefinition describes a FHIR resource profile: resource type, canonical URL, version, required fields, cardinality, slicing, terminology bindings, and extension rules. In AMCDR it is stored as a FHIR profile version and is used to identify the expected shape of an incoming or outgoing FHIR payload.
| Item | Meaning in AMCDR |
|---|---|
canonical_url | The profile URL placed in meta.profile or selected by implementers when validating/mapping payloads. |
resource_type | The FHIR resource family such as Patient, Observation, Composition, or Bundle. |
structure_definition | The stored JSON representation of the FHIR SD. XML uploads are parsed into the same stored structure. |
fhir_version | The FHIR version detected from the SD and checked at runtime for supported ingest/projection behaviour. |
elements | Fields exposed to designers and implementers for mappings from stable FHIR paths. |
The SD describes and validates the FHIR payload. A separate mapping connects its fields to an openEHR template or turns a stored composition into FHIR.
FHIR Profile APIs
GET /fhir/profiles
GET /fhir/profiles?resource_type=Observation&include_elements=true
GET /fhir/profiles/{profile_key}
POST /fhir/profiles
POST /fhir/profiles/import-file
GET /fhir/capabilities
PATCH /fhir/capabilities/{capability_id}
GET /fhir/validation-results
Use POST /fhir/profiles/import-file for uploaded FHIR StructureDefinition JSON or XML files. Use POST /fhir/profiles when another tool already has the StructureDefinition as JSON.
POST /fhir/profiles
Authorization: Bearer <token>
Content-Type: application/json
{
"key": "ug-lab-observation",
"name": "Uganda Laboratory Observation",
"semantic_version": "1.0.0",
"canonical_url": "https://example.org/fhir/StructureDefinition/ug-lab-observation",
"resource_type": "Observation",
"structure_definition": {
"resourceType": "StructureDefinition",
"url": "https://example.org/fhir/StructureDefinition/ug-lab-observation",
"type": "Observation",
"kind": "resource",
"version": "1.0.0"
}
}
Review and activate a FHIR profile
Importing a StructureDefinition creates a candidate capability. Import does not automatically expose a REST API, allow Bundle ingestion, or approve canonical clinical persistence. A platform administrator reviews the candidate under Platform configuration → FHIR governance and activates the permitted interactions, search parameters, Bundle behavior, projection, and template-binding requirement.
Use FHIR Capability Governance for the complete production lifecycle, role requirements, UI and API procedures, contract fields, validation and Bundle behavior, version replacement, suspension, audit evidence, operational checks, and troubleshooting.
PATCH /fhir/capabilities/2f6b6b62-4608-4b1a-b39e-28ea75a19f42
Content-Type: application/json
{
"status": "active",
"interactions": ["create", "read", "search-type"],
"search_parameters": ["_id", "patient", "subject", "encounter", "identifier", "status", "code", "date"],
"allow_bundle_ingest": true,
"allow_projection": true,
"requires_template_binding": true,
"governance_metadata": {"approval_reference": "CAB-FHIR-2026-014"}
}
When template binding is required, activation is blocked until an active FHIR-to-openEHR or bidirectional binding exists. Active capabilities are published dynamically in GET /fhir/metadata. Suspended and retired capabilities are removed from runtime resolution.
A profile does not create a new endpoint name. A StructureDefinition named UgandaLaboratoryObservation whose type is Observation continues to use /fhir/Observation. AMCDR keeps specialised native handlers for identity and operational resources; other approved resource types use the profile-driven canonical handler.
Mapping Model
A transformation map connects one or more source FHIR profiles to one or more openEHR template targets. It is versioned, referenced by mapping_key, and used for both inbound FHIR ingest and outbound FHIR projection.
GET /fhir/mappings
POST /fhir/mappings
| Mapping property | Purpose |
|---|---|
source_profile_keys | FHIR profiles accepted by this map. |
target_template_keys | openEHR templates that the mapped data creates or projects from. |
targets | Inbound rules that create canonical compositions from FHIR payloads. |
projections | Outbound rules that build FHIR resources from canonical AMCDR composition data. |
translate | Optional terminology translation through local or remote terminology services. |
Map complete field paths in Semantic Studio
Semantic Studio shows each FHIR field with its full path. This helps distinguish fields that share a label, such as coding.code, coding.system, extension.value[x], or Patient.name.given.
| FHIR path | Expected mapping behavior |
|---|---|
Procedure.code.coding[] | Repeatable coding group. Bind as a loop only when the target is also a repeatable coding group. |
Procedure.code.coding[].system | Direct value mapping to the target terminology system path. |
Procedure.code.coding[].code | Direct value mapping to the target code path. |
Procedure.code.coding[].display | Direct value mapping to the target display path. |
Patient.name[] | Repeatable name group. Bind as a loop when multiple names must be preserved. |
Patient.name[].family | Direct value mapping inside the selected name loop. |
Structural parent paths are not normally bound to scalar openEHR fields. The binding should target child value paths, while repeatable parent paths are used only to define loop context. The source and target panes can be resized when implementers need to inspect long FHIR paths or openEHR/AQL paths.
Extension paths are URL-qualified at binding time. Selecting Observation.extension[].value[x] requires the canonical extension URL; runtime selection does not depend on extension order. A loop binding over extension[] preserves correlated child values and creates repeated openEHR RM nodes when the target template cardinality permits repetition. The same governed contract reconstructs extension arrays during outbound projection.
For complete extension-contract JSON, repeatability rules, and round-trip requirements, see Mapping and Bidirectional Mapping.
Mapping Directions
| Direction | Required rule set | Runtime operation |
|---|---|---|
fhir_to_openehr | targets | POST /fhir/ingest validates FHIR and creates canonical openEHR compositions. |
openehr_to_fhir | projections | POST /fhir/project renders canonical AMCDR content as FHIR. |
bidirectional | targets and projections | The same governed mapping artifact can support both inbound and outbound operations when both directions have explicit rules, fixtures, terminology handling, and audit evidence. |
Bidirectional mapping must preserve clinical meaning, not necessarily byte-for-byte payload identity. Some openEHR values require FHIR extensions or documented loss handling. Some FHIR fields are exchange metadata and should not overwrite canonical clinical content. Production bidirectional mappings must define conflict policy and round-trip fixtures before publication.
Inbound Mapping Example
This example maps a FHIR Observation into a vital signs template. The source FHIR path is read from the incoming payload and written into canonical template field keys.
POST /fhir/mappings
Authorization: Bearer <token>
Content-Type: application/json
{
"key": "observation-vitals-to-openehr",
"name": "FHIR Observation to Vital Signs",
"semantic_version": "1.0.0",
"cardinality": "1:1",
"source_profile_keys": ["vital-signs-observation"],
"target_template_keys": ["vital_signs.v1"],
"mapping_definition": {
"targets": [
{
"template_key": "vital_signs.v1",
"name": "Vital signs",
"category": "event",
"rules": [
{
"from": {
"resourceType": "Observation",
"path": "effectiveDateTime"
},
"to": {
"kind": "context",
"key": "start_time"
}
},
{
"from": {
"resourceType": "Observation",
"path": "valueQuantity.value"
},
"to": {
"kind": "field",
"key": "body_temperature|magnitude"
}
},
{
"from": {
"resourceType": "Observation",
"path": "valueQuantity.unit"
},
"to": {
"kind": "field",
"key": "body_temperature|unit"
}
}
]
}
]
}
}
Import FHIR through an approved mapping
Use POST /fhir/ingest when incoming FHIR must be validated against a known FHIR profile and transformed into one or more canonical openEHR compositions.
Register the sending system as an integration partner before importing FHIR data. The sending system must use a scoped bearer token or API key with integration:ingest:fhir or an approved wildcard scope such as integration:ingest:*. IP allow-listing, VPN, or mTLS may be used as additional controls, but AMCDR still requires application-level authentication, route authorization, purpose-of-use context, validation, and audit.
POST /fhir/ingest
X-API-Key: <partner-api-key>
Content-Type: application/json
{
"profile_key": "vital-signs-observation",
"mapping_key": "observation-vitals-to-openehr",
"patient_id": "f59c63f3-a230-4af5-a86d-8c37f3a0897a",
"committer": "migration.fhir",
"source": {
"source_system": "legacy-emr",
"batch_id": "batch-2026-05-vitals",
"source_file": "observations.ndjson"
},
"payload": {
"resourceType": "Observation",
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8310-5",
"display": "Body temperature"
}
]
},
"subject": {
"reference": "Patient/f59c63f3-a230-4af5-a86d-8c37f3a0897a"
},
"effectiveDateTime": "2026-05-17T08:30:00Z",
"valueQuantity": {
"value": 38.2,
"unit": "Cel",
"system": "http://unitsofmeasure.org",
"code": "Cel"
}
}
}
Successful ingest returns the validation result id, the resource types found, and created composition/version identifiers. Rejected ingest returns validation issues and does not create canonical compositions.
Direct FHIR Resource Ingest
Use direct /fhir/{ResourceType} endpoints when AMCDR already supports the resource and the payload is intended for the FHIR facade/shared-record path. Use /fhir/ingest when the data must become a template-governed openEHR composition through an explicit mapping.
| Use case | Preferred API |
|---|---|
| Check server capabilities | GET /fhir/metadata |
| Create one supported FHIR resource | POST /fhir/{ResourceType} |
| Create a patient | POST /fhir/Patient |
| Create a resource with explicit patient/encounter context | POST /fhir/Observation?patient_id={uuid}&encounter_id={uuid} |
| Ingest linked resources with references | POST /fhir/Bundle |
| Profile-validated FHIR to openEHR template mapping | POST /fhir/ingest |
POST /fhir/Bundle is the preferred path when an external platform sends an SHR, IPS, referral, transfer, laboratory report, or episode package as linked FHIR resources. AMCDR resolves Patient and Encounter references, creates or links patient/EHR context where allowed, persists supported clinical resources into the shared record, and returns an acknowledgement with patient, EHR, created record, and issue details.
POST /fhir/Bundle
X-API-Key: <partner-api-key>
X-Purpose-Of-Use: TREAT
Content-Type: application/fhir+json
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"fullUrl": "urn:uuid:patient-1",
"resource": {
"resourceType": "Patient",
"identifier": [
{ "system": "https://facility.example.org/mrn", "value": "MRN-10001" }
],
"name": [{ "family": "Anywar", "given": ["Michael"] }],
"gender": "male"
}
},
{
"resource": {
"resourceType": "Observation",
"status": "final",
"subject": { "reference": "urn:uuid:patient-1" },
"code": { "coding": [{ "system": "http://loinc.org", "code": "8310-5" }] },
"valueQuantity": { "value": 37.1, "unit": "Cel" }
}
}
]
}
FHIR Output And Projection
AMCDR outputs FHIR in two ways: direct FHIR search/projection endpoints for supported resource views, and mapping-based projection from a canonical composition into a selected FHIR profile.
GET /fhir/{ResourceType}
GET /fhir/Patient/{patient_id}/$everything
POST /fhir/project
Use POST /fhir/project when a canonical composition must be rendered as a FHIR resource using a specific outbound mapping.
POST /fhir/project
Authorization: Bearer <token>
Content-Type: application/json
{
"composition_id": "36d2e5d4-620d-4b49-b2ee-9829f61d3921",
"profile_key": "vital-signs-observation",
"mapping_key": "observation-vitals-to-openehr",
"bundle": false,
"requester": "national-hie"
}
Outbound projection validates the generated FHIR payload against the selected profile and records the exchange. If the generated payload fails validation, the response status reports validation_failed and includes a validation result id for review.
FHIR Output Versus Shared Health Record Output
Use FHIR mapping when the main task is transforming one canonical composition or one source FHIR payload. Use the shared health record when the main task is a patient-wide view assembled from many templates, documents, encounters, and relationships.
| Need | Use |
|---|---|
| Project one composition into one FHIR resource/profile. | POST /fhir/project |
| Pull a FHIR patient-wide bundle. | GET /fhir/Patient/{patient_id}/$everything |
| Pull current, encounter, annual, or timeline summaries. | GET /records/patient/{patient_id}/summary/current?format=fhir or the records summary APIs. |
| Find patients with SHR or IPS data across a cohort, location, facility, or date range. | GET /records/patients/summary?profile=ips&include=index&format=fhir |
| Create IPS-style output from many templates. | Define an SHR or saved-query projection, then map the summary sections to FHIR. See Shared Health Record and IPS. |
Outbound Mapping Example
This projection builds a FHIR Observation from canonical composition field values.
{
"projections": [
{
"resourceType": "Observation",
"defaults": {
"status": "final",
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/observation-category",
"code": "vital-signs",
"display": "Vital Signs"
}
]
}
],
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8310-5",
"display": "Body temperature"
}
]
}
},
"rules": [
{
"from": { "kind": "context", "key": "start_time" },
"to": "effectiveDateTime"
},
{
"from": { "kind": "field", "key": "body_temperature|magnitude" },
"to": "valueQuantity.value"
},
{
"from": { "kind": "field", "key": "body_temperature|unit" },
"to": "valueQuantity.unit"
}
]
}
]
}
Supported FHIR Resources
The live server advertises supported operations in GET /fhir/metadata. The current FHIR facade includes these resource families for create/search/projection where implemented:
| Resource family | Typical purpose |
|---|---|
Patient | Identity and demographic exchange. Patient detail retrieval uses /fhir/Patient/{patient_id}/$everything. |
Organization, Location | Facility, unit, service location, and organisation directory exchange. |
Encounter, Composition | Care context and document exchange. |
Observation, Condition, Procedure, Immunization | Clinical facts and events. |
Medication, MedicationRequest, MedicationStatement, MedicationAdministration | Medication workflow exchange. Product master lookup is delegated to MediServe / Medication Tracker in external product-source mode. |
CarePlan, DocumentReference, Consent | Care planning, documents/media references, and consent records. |
AuditEvent, Provenance | Audit and provenance views for governed exchange. |
Bundle | Linked multi-resource ingest and response packaging. |
Medication Tracker Integration
AMCDR integrates with the Medication Tracker using standard FHIR medication workflow resources. AMCDR remains the clinical ordering and patient-context system; the Medication Tracker remains the product, formulary, batch, expiry, stock ledger, and facility supply authority.
| Workflow | Standard API | System of record |
|---|---|---|
| Check whether a drug exists | GET /fhir/Medication?q={term} | Medication Tracker master product list |
| Create a prescription/order | POST /fhir/MedicationRequest | AMCDR clinical order, mirrored to tracker pharmacy queue |
| Dispense medicine to a patient | POST /fhir/MedicationDispense | AMCDR clinical event and Medication Tracker stock ledger |
| Record ward/bedside administration | POST /fhir/MedicationAdministration | AMCDR clinical event and Medication Tracker stock ledger |
AMCDR sends the patient as a tokenised subject such as Patient/amcdr-patient:{patient_uuid}, and includes audit extensions for order id, encounter id, composition id, prescriber, dispenser/administering user, and stock reason code. Medication Tracker stores those values in ledger metadata so the stock movement remains traceable back to AMCDR.
In standard production mode, AMCDR must use AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE=external and AMCDR_MEDICATION_TRACKER_ALLOW_LOCAL_PRODUCT_CATALOG_WRITES=false. This prevents duplicate AMCDR product master rows. AMCDR stores the clinical medication order and copied tracker product identifiers for audit, not an authoritative local medication product source.
{
"resourceType": "MedicationDispense",
"status": "completed",
"subject": { "reference": "Patient/amcdr-patient:..." },
"medicationCodeableConcept": {
"coding": [{ "system": "urn:mediserv:mpl", "code": "GTIN-PARA-500" }],
"extension": [{ "url": "http://mediserv/StructureDefinition/batch-lot", "valueString": "PARA-A" }]
},
"quantity": { "value": 1, "unit": "TAB" },
"location": { "reference": "Location/6e1704f1-ecaa-5d16-82c2-ad619f22b2f1" },
"extension": [
{ "url": "urn:amcdr:reason-code", "valueString": "PATIENT_DISPENSING" },
{ "url": "urn:amcdr:order-id", "valueString": "..." },
{ "url": "urn:amcdr:dispensed-by", "valueString": "pharmacist" }
]
}
Configuration is centralised under the AMCDR medication tracker settings: AMCDR_MEDICATION_TRACKER_ENABLED, AMCDR_MEDICATION_TRACKER_BASE_URL, AMCDR_MEDICATION_TRACKER_API_KEY, AMCDR_MEDICATION_TRACKER_PRODUCT_CATALOG_MODE, AMCDR_MEDICATION_TRACKER_ALLOW_LOCAL_PRODUCT_CATALOG_WRITES, AMCDR_MEDICATION_TRACKER_DECREMENT_ON_DISPENSE, and AMCDR_MEDICATION_TRACKER_DECREMENT_ON_ADMINISTRATION.
Medication safety checks are handled by the Clinical Safety Sidecar when AMCDR_CLINICAL_SAFETY_ENABLED=true. The sidecar checks AllergyIntolerance records, active medication context, external product ingredients, formulary hooks, terminology mappings, and override policy before AMCDR stores or posts the medication action. See Medication Products and Clinical Safety.
How FHIR SDs Are Used During Migration
For migration projects, treat FHIR StructureDefinitions as the incoming contract. Each migrated source must declare which profile it claims to follow, even if the source is converted from CSV, XML, HL7v2, or NDJSON first.
- Convert source data into FHIR resources or Bundles where the migration contract requires FHIR normalization.
- Import the expected FHIR SDs into AMCDR as profiles.
- Create transformation maps from profile paths to openEHR template fields.
- Run dry-run validation on representative payloads.
- Fix missing fields, terminology mappings, patient references, and encounter references.
- Run governed
/fhir/ingestfor canonical composition creation. - Review
/fhir/validation-resultsand reconciliation reports before cutover.
Use direct /fhir/Bundle when the goal is to load supported FHIR facade resources. Use /fhir/ingest when the goal is to create canonical openEHR compositions through approved mappings.
Terminology Handling
Mappings must preserve FHIR coding details: system, code, display, and version where available. If a target template expects a different code system, use a local or remote terminology translation rule in the mapping definition.
{
"from": {
"resourceType": "Condition",
"path": "code.coding[0].code",
"system": "http://snomed.info/sct"
},
"to": {
"kind": "field",
"key": "diagnosis|code_string"
},
"translate": {
"source": "http://snomed.info/sct",
"target_system": "http://hl7.org/fhir/sid/icd-10",
"mode": "coded_text"
}
}
Official IG Validation and Cross-Bundle References
Production ingestion is guarded by the official HL7 FHIR Validator in fail-closed mode. POST /fhir/$validate validates a resource or Bundle and returns a FHIR OperationOutcome. Declared meta.profile canonicals and approved, version-pinned Implementation Guide packages are passed to the validator before MPI reconciliation, operational persistence, or openEHR mapping.
Every received FHIR resource with an id is registered under tenant + source namespace + resource type + external resource id. This registry allows a later Bundle or individual resource to resolve Patient/external-id, Encounter/external-id, medication references, Person-to-Patient links, and other FHIR references without creating a duplicate MPI identity. Use the same source_namespace on related requests. PostgreSQL row-level security and composite uniqueness prevent cross-tenant or cross-source collisions.
POST /fhir/Specimen?source_namespace=https://mpi.example.org/fhir
Content-Type: application/fhir+json
{
"resourceType": "Specimen",
"id": "specimen-1001",
"status": "available",
"type": {"text": "Blood specimen"},
"subject": {"reference": "Patient/national-patient-1001"}
}
Specimen and MedicationDispense support create, search, Bundle ingestion, validation, projection, and Semantic Studio template binding. Specimen is retained in the laboratory workflow before template approval. MedicationDispense is staged as staged_pending_template_binding. Canonical openEHR composition persistence begins only after an approved bidirectional template binding is activated; AMCDR does not install a generic clinical template for either resource.
Configure production with AMCDR_FHIR_VALIDATION_MODE=official, AMCDR_FHIR_VALIDATION_FAIL_CLOSED=true, a validator JAR or endpoint, approved package coordinates in AMCDR_FHIR_VALIDATOR_IG_PACKAGES, and a persistent validator cache. AMCDR rejects production configuration that does not meet this boundary.
Security And Audit
- All FHIR profile, mapping, ingest, projection, and direct FHIR APIs are protected by AMCDR authentication and route policies.
- Use scoped users or API keys for partner systems. Avoid using platform admin accounts for integrations.
- Protected records are filtered or denied according to protected-record policy, purpose of use, clearance, and break-glass state.
- FHIR ingest records validation results, exchange metadata, source details, mapping key, profile key, and provenance.
- Migration batches must include source file, source row or message id, batch id, source system, and checksum where available.
Troubleshooting
| Problem | Likely cause | Action |
|---|---|---|
profile_key not found | FHIR StructureDefinition was not imported or key differs. | Check GET /fhir/profiles and import the SD again if needed. |
mapping_key not found | No transformation map exists for this profile/template pair. | Create or activate the map with POST /fhir/mappings. |
| Validation rejected | Required FHIR fields, cardinality, or profile constraints failed. | Open GET /fhir/validation-results and fix the source payload or SD/mapping assumptions. |
| Composition created but field missing | The FHIR path did not resolve or the target field key is wrong. | Test with a small payload and verify source path, array handling, and template field alias. |
| Wrong code in output | Terminology translation rule missing or wrong target system. | Review mapping translate block and terminology configuration. |
| Patient context missing | FHIR subject reference did not resolve to an AMCDR patient or no patient_id was supplied. | Resolve via MPI first or pass patient_id in the ingest request. |