Integration

Mapping and Bidirectional Mapping

Configure incoming and outgoing mappings, terminology translation, validation, and version history.

Purpose

Use this guide to build and check mappings in Semantic Studio. It covers FHIR imports, openEHR-to-FHIR exports, rules for both directions, and the reviews required before a mapping is used in production.

Mappings connect the clinical record to forms, workflows and exchange formats. The openEHR composition remains the source clinical record.

Mapping Surfaces

Mapping surfaceDirectionExpected use
Template to formopenEHR template -> form fieldsCreates user-facing capture surfaces from approved clinical templates.
Template to foundation projectionopenEHR template -> operational foundationUpdates rebuildable operational state such as encounter, movement, relationship, queue, visibility, reporting, or safety facts.
FHIR inbound mappingFHIR -> openEHRValidates an incoming FHIR payload and creates one or more template-governed openEHR compositions.
FHIR outbound projectionopenEHR -> FHIRProjects canonical AMCDR content into a governed FHIR resource or Bundle for external systems.
Bidirectional mappingFHIR <-> openEHRDeclares that both inbound and outbound directions are intentionally governed, versioned, tested, and audited.
Terminology mappingCode system -> code systemTranslates or normalizes codes while preserving system, code, display, version, and provenance.

Direction Terms

AMCDR uses direction labels in two related places. Template FHIR bindings use runtime FHIR direction names. Universal mapping governance may also use source/target direction labels when a mapping is not limited to FHIR.

LabelMeaningRuntime implication
fhir_to_openehrInbound FHIR mapping.FHIR payload is validated, transformed through targets, and committed as canonical openEHR content when all required context is present.
openehr_to_fhirOutbound FHIR projection.Canonical AMCDR/openEHR content is transformed through projections into FHIR output.
bidirectionalBoth directions are governed.The mapping can be selected for inbound or outbound operations, but inverse logic is not assumed unless explicit rules exist for both directions.
SOURCE_TO_TARGETUniversal mapping source is transformed into target.Used by the broader mapping registry for non-FHIR or multi-model transformations.
TARGET_TO_SOURCEUniversal mapping target is transformed back to source.Used when the declared target model is the operational write or return shape.
BIDIRECTIONALUniversal mapping is governed in both directions.Requires direction-specific fixtures, validation, provenance, and conflict handling.

What Bidirectional Mapping Means

A bidirectional mapping contains approved rules for importing and exporting data. Define and validate each direction explicitly; AMCDR cannot safely infer an inverse from a one-way rule.

Inbound rule set

Defines how FHIR paths or source model fields become openEHR template fields, context values, coded values, and operational references.

Outbound rule set

Defines how canonical composition fields, context, identifiers, and projections become a FHIR resource, Bundle, or partner payload.

Round-trip checks

Representative fixtures must prove that inbound and outbound transforms preserve the required clinical meaning, even when the wire format differs.

Conflict policy

The mapping must state which side owns updates, how external changes are accepted, and how conflicts are rejected, queued, or reconciled.

Bidirectional Mapping Rules

  1. Define inbound and outbound rules explicitly. Do not rely on automatic inversion for production use.
  2. Use one canonical clinical owner for each data element. In AMCDR clinical persistence, that owner is normally the openEHR composition.
  3. Map patient, EHR, encounter, composition, version, and external resource identifiers so repeated exchanges update or reference the correct records.
  4. Preserve terminology details: system, code, display, version, and translation provenance.
  5. Declare any lossy fields. If FHIR cannot represent an openEHR value fully, the mapping must record the omission or extension strategy.
  6. Validate representative fixtures in both directions before publishing.
  7. Record audit and provenance for every ingest, projection, validation failure, replay, and external delivery.
  8. Do not allow an external FHIR payload to overwrite canonical clinical content unless the route, user, policy, and mapping explicitly permit that update.

Design-Time Workflow

  1. Import or publish the openEHR template that owns the clinical data.
  2. Import the FHIR StructureDefinition or select a supported FHIR resource profile.
  3. Create a mapping artifact in Semantic Studio or through the mapping API.
  4. Select the direction: fhir_to_openehr, openehr_to_fhir, or bidirectional.
  5. Bind each required source path to a target path. Use explicit leaf paths for composite openEHR values such as DV_CODED_TEXT, DV_QUANTITY, and DV_IDENTIFIER.
  6. Configure terminology translation where the FHIR profile and openEHR template use different code systems.
  7. Add fixtures for inbound payloads, outbound composition examples, and expected results.
  8. Validate, preview, publish, and record the mapping version before production use.

Choose the full field path

Bind the full source path to the full target path. A node label alone may appear in several places and is not enough to identify a field. The source side shows FHIR or source-model paths such as Procedure.code.coding[].code. The target side shows openEHR template or AQL value paths where available.

Binding typeUseExample
DIRECTMap a value path to a value path.Procedure.code.coding[].code -> target code value path
LOOPMap a repeatable source group to a repeatable target group.Procedure.code.coding[] -> repeated openEHR coding group

Structural parent paths such as Procedure.code, Procedure.code.coding, or an openEHR cluster should not be bound directly to scalar values. Use the parent only as a loop group when both sides are repeatable containers, then map child values such as system, code, and display inside the loop.

The source pane can be resized to review longer FHIR paths or to give the openEHR target paths more space. This keeps mappings readable for complex resources with repeated arrays, extensions, and nested coding structures.

Repeating Data Rules

Map repeating structures explicitly. Common examples are CodeableConcept.coding[], Patient.name[], FHIR extension[], and repeated openEHR clusters or ELEMENT groups.

  1. Create a loop binding between the repeatable source container and the repeatable target container.
  2. Map child value paths inside the loop using direct bindings.
  3. Do not map an array directly into a single scalar target unless the mapping defines an explicit selection or aggregation rule.
  4. Validate loop mappings with payloads that contain zero, one, and multiple repetitions.

FHIR Extensions And Modifier Extensions

FHIR extensions are selected by canonical url, never by array position. A mapping may select a scalar extension value with valueString, valueCode, or the polymorphic value[x] selector. A repeating complex extension is represented as a loop whose child URL mappings write to fields in the same repeatable openEHR cluster. AMCDR preserves the child values at the same occurrence index so identifier, code, display, quantity, and other sibling values cannot be paired with a different repetition.

{
  "fhir_extension_bindings": [
    {
      "url": "https://example.org/fhir/StructureDefinition/fetus",
      "loop": true,
      "fields": [
        {
          "url": "https://example.org/fhir/StructureDefinition/fetus-identifier",
          "target": "fetus_identifier",
          "value": "valueString"
        },
        {
          "url": "https://example.org/fhir/StructureDefinition/fetal-presentation",
          "target": "fetal_presentation",
          "value": "valueCode"
        }
      ]
    }
  ],
  "modifier_extension_policy": {
    "mode": "reject_unmapped",
    "approved_ignored": []
  }
}

This contract is configured in the template version's FHIR binding editor. Each target must also resolve through field_bindings to a published template node. A loop target must be repeatable in the openEHR template. Inbound execution creates correlated repeated RM structures; outbound execution reconstructs the FHIR extension array and canonical URLs.

Handling modifier extensions. AMCDR rejects an unhandled modifierExtension. A mapped modifier URL is handled by its governed mapping. An intentionally ignored modifier requires an explicit URL and a recorded clinical-governance reason. reject_all may be selected for a contract that does not permit modifier extensions.

The original validated FHIR payload remains available for provenance and audit, but raw-payload retention is not a substitute for canonical mapping. Analytics, AQL, SHR, and outbound clinical projections use the explicitly mapped openEHR content.

Runtime APIs

OperationAPIPurpose
List FHIR mappingsGET /fhir/mappingsReturns FHIR profile mapping definitions.
Create FHIR mappingPOST /fhir/mappingsCreates an inbound/outbound mapping definition using targets and/or projections.
FHIR to openEHR ingestPOST /fhir/ingestValidates and transforms FHIR into canonical openEHR compositions.
openEHR to FHIR projectionPOST /fhir/projectProjects AMCDR/openEHR content into FHIR using a selected mapping.
Universal mapping registryGET /mappings, POST /mappingsManages broader cross-model mapping artifacts used by Semantic Studio and integration governance.
Validate mappingPOST /mappings/{mapping_id}/validateChecks mapping completeness, direction compatibility, fixtures, and target coverage.
Preview mappingPOST /mappings/{mapping_id}/previewRuns a non-committing transform preview against a supplied payload.
Publish mappingPOST /mappings/{mapping_id}/publishMakes the validated mapping available for controlled runtime use.

Inbound FHIR Mapping Example

Inbound mappings use targets. Each target describes the openEHR template to create and the rules that copy or transform values from the incoming FHIR payload.

{
  "key": "observation-vitals-to-openehr",
  "direction": "fhir_to_openehr",
  "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" }
          }
        ]
      }
    ]
  }
}

Outbound FHIR Projection Example

Outbound mappings use projections. Each projection describes the FHIR resource to produce and the rules that copy values from canonical composition detail into FHIR paths.

{
  "key": "vital-signs-openehr-to-observation",
  "direction": "openehr_to_fhir",
  "source_template_keys": ["vital_signs.v1"],
  "target_profile_keys": ["vital-signs-observation"],
  "mapping_definition": {
    "projections": [
      {
        "resourceType": "Observation",
        "defaults": {
          "status": "final",
          "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"
          }
        ]
      }
    ]
  }
}

Bidirectional Artifact Example

A bidirectional artifact includes both targets and projections. The two rule sets may share field keys, but each direction remains explicit.

{
  "key": "vital-signs-bidirectional",
  "direction": "bidirectional",
  "source_profile_keys": ["vital-signs-observation"],
  "target_template_keys": ["vital_signs.v1"],
  "mapping_definition": {
    "targets": [
      {
        "template_key": "vital_signs.v1",
        "rules": [
          {
            "from": { "resourceType": "Observation", "path": "valueQuantity.value" },
            "to": { "kind": "field", "key": "body_temperature|magnitude" }
          }
        ]
      }
    ],
    "projections": [
      {
        "resourceType": "Observation",
        "rules": [
          {
            "from": { "kind": "field", "key": "body_temperature|magnitude" },
            "to": "valueQuantity.value"
          }
        ]
      }
    ],
    "round_trip": {
      "required": true,
      "clinical_meaning_must_match": true,
      "lossy_fields": []
    },
    "conflict_policy": {
      "canonical_owner": "openehr_composition",
      "external_update_mode": "review_before_commit"
    }
  }
}

Composite openEHR Values

openEHR RM datatypes often contain several semantic parts. Semantic Studio exposes mappable leaf paths so these values can be aligned with FHIR elements without losing meaning.

openEHR datatypeCommon leavesFHIR target examples
DV_CODED_TEXT|code_string, |value, |terminology_id, |versionCodeableConcept.coding.code, display, system, version
DV_QUANTITY|magnitude, |unit, |units_system, |unit_versionQuantity.value, unit, system, code
DV_IDENTIFIER|id, |issuer, |assigner, |type, |namespace, |schemeIdentifier.value, system, type, assigner

Production Checklist

  1. The source model, target model, direction, version, and owner are recorded.
  2. The mapping references published openEHR templates and imported FHIR profiles where applicable.
  3. Every required source and target path has an explicit binding or documented default.
  4. Terminology translation rules are configured and tested.
  5. Patient, encounter, EHR, composition, and external identifiers are mapped or resolved before commit.
  6. Validation fixtures cover normal, missing-field, coded-field, quantity, identifier, and error scenarios.
  7. Bidirectional mappings include fixtures for both inbound and outbound execution.
  8. Lossy fields, extensions, unsupported paths, and conflict policies are documented.
  9. The mapping is published only after validation and preview succeed.
  10. Runtime ingest and projection are audited with mapping key, mapping version, actor, source system, patient, EHR, and validation result.

Common Problems

ProblemCauseAction
Bidirectional selected but only one direction works.The artifact has only targets or only projections.Add the missing direction-specific rules and fixtures before publishing.
FHIR output misses code system or display.Only the code value was mapped.Map the full coded-text leaves: code, display, system, and version.
FHIR ingest creates a composition without encounter context.Subject was resolved, but encounter or visit context was not provided or mapped.Pass encounter context or map it through a foundation projection when clinically required.
Quantity values are wrong after projection.Magnitude and unit were not mapped separately.Map |magnitude, |unit, and unit system where available.
External update would overwrite clinical truth.No conflict policy or external update review route exists.Use review-before-commit or reject external updates for that mapping.

Related Guides