Blog

    Running a FHIR Facade Over openEHR in Production: System of Record, Read and Write Paths, Version Mapping and Failure Modes

    By GauravNovember 28, 20269 mins read
    On this page

    Many openEHR platforms end up with a FHIR facade, because apps, partners and regulations speak FHIR while the clinical data lives in an archetype-based repository. A prototype facade that maps a few resources is quick to build. Running one for years, with writes, versions, caching and upgrades on both sides, is a different job.

    This post is for architects and platform teams operating a FHIR API in front of an openEHR clinical data repository. It covers the system of record, the read and write paths, version mapping, caching, search limits and the failure modes that appear only in production.

    What is a FHIR facade over an openEHR repository?

    Choosing an openEHR repository?

    Our selection guide compares openEHR clinical data repositories, including the API and versioning features a FHIR facade depends on.

    A FHIR facade over an openEHR repository is a service that answers FHIR requests by querying and writing openEHR compositions, mapping between the two models on the fly, while the repository stays the only store of clinical data. Agnotic Technologies designs and runs these facades so FHIR clients never need to know openEHR is underneath.

    The facade holds mapping rules, identifier maps and caches, not a second copy of the record. That single principle settles most later design questions.

    Which side is the system of record?

    The openEHR repository should be the system of record, and the facade should be stateless apart from caches and identifier maps. Two stores of clinical truth drift apart, and nobody can say which one is right.

    Avoid designs where the facade keeps its own FHIR server and synchronizes with openEHR behind it. That is a second system with its own versions, and every sync failure becomes a clinical data question.

    The same rule applies to identifiers. Patient ids, practitioner ids and resource ids may live in a small map owned by the facade, but they point at openEHR data; they never hold clinical values of their own.

    How does the read path work?

    The read path turns a FHIR read or search into one or more AQL queries, fetches the matching compositions, and maps each relevant entry into a FHIR resource. Mapping rules are chosen by template and archetype.

    FHIR facade over an openEHR repository: FHIR clients send reads and searches to the facade, which translates them to AQL, maps compositions to FHIR resources and caches by composition version; writes are mapped to compositions and sent with If-Match; the openEHR repository is the system of record, with a lane for mapping rules and identifier maps
    • Translate: FHIR search parameters become AQL conditions on archetype paths.
    • Fetch: compositions returned with their version ids.
    • Map: entries become resources, one composition often producing several, such as one Observation per vital sign.
    • Identify: each resource gets a stable id built from the composition's versioned object id and the entry path.

    Stable ids matter more than they look. If a resource id changes when a composition is amended, every client that stored a reference loses track of it.

    How does the write path work?

    The write path maps an incoming FHIR resource into a composition for a known template, then commits it to the repository with a version check. Start with a small set of writable resource types and make everything else read-only.

    The openEHR REST API updates a COMPOSITION only when the If-Match header carries the existing latest version_uid, the preceding_version_uid, and returns 412 Precondition Failed, with the latest version_uid in the ETag header, when it does not match.

    • Create: map to a new composition, validate against the template, then commit.
    • Update: read the composition, apply the change, send it with the preceding version id.
    • Conflict: on 412, return a FHIR conflict to the client rather than retrying blindly.
    • Partial resources: reject writes that would leave required template fields empty.

    How do openEHR versions map to FHIR versions?

    Map each FHIR resource version to the version of the composition it came from. An openEHR version id ends in a version tree number, which gives the facade a natural source for FHIR version ids.

    In HL7 FHIR R4, Meta.versionId is the version-specific identifier that changes when a resource is created, updated or deleted; there is no fixed order for version ids, and the same versionId can never be used for more than one version of the same resource.

    One consequence surprises teams: amending one entry creates a new composition version, so every FHIR resource from that composition gets a new version id, even unchanged ones. Accept it and document it, or compare content and keep the old version id where nothing changed.

    Caching without stale clinical data

    Cache mapped resources by composition version id, because a committed version never changes. A new version gets a new key, so the cache cannot serve an amended record as current.

    • Safe to cache: mapping results keyed by composition version id.
    • Cache briefly or not at all: search results, which change as new compositions arrive.
    • Never share across users: anything cached after an authorization decision.
    • Purge on delete: remove entries when a composition is deleted, not only when it expires.

    Measure the cache hit rate per resource type. A low rate on a busy type usually means the key includes something that changes too often, such as a request parameter that should not be part of it.

    Search translation and its limits

    Not every FHIR search translates well to AQL. Support the parameters your clients need, measure their cost, and advertise only those in the CapabilityStatement.

    Chained searches, wide includes and free-text parameters are the usual problem cases. Returning an error for an unsupported parameter is better than silently ignoring it and returning too much data.

    Paging needs the same care. AQL offset and limit map naturally to FHIR paging, but results must be ordered the same way on every page, or clients will see duplicates and gaps when new compositions arrive mid-search.

    How should authorization work across both models?

    Authorization should be decided once, in the facade, using rules that respect both the SMART scopes a client holds and the access rules of the openEHR platform. Neither side alone is enough.

    • Scopes: a SMART scope grants a resource type, which the facade maps to the templates that feed it.
    • Restrictions: sensitive templates stay hidden even when the scope would allow the resource type.
    • Patient context: every AQL query is limited to the patient in the launch context or the token.
    • Audit: each request logged with the client, the scope used and the compositions read.

    What fails in production?

    Failures come from change on either side and from load. The facade sits between two models that each evolve on their own schedule.

    • Template drift: a new template version adds or moves fields, and mapping rules silently skip them.
    • Unstable ids: id rules that depend on position change when entries are added.
    • Heavy queries: a broad FHIR search becomes an AQL query that scans far more than expected.
    • Authorization gaps: SMART scopes allow a resource type that openEHR access rules would restrict.
    • Write conflicts: clients retry 412 responses without re-reading, creating loops.

    Treat template changes like API changes. Every template update should run the mapping test suite before it reaches production, and the facade should refuse to map a template version it has no rules for.

    A worked example: a SMART app on an openEHR platform

    A regional health platform stores vital signs, problems and medication orders in openEHR and wants a SMART on FHIR app to show trends to clinicians. The facade exposes Patient, Observation, Condition and MedicationRequest as read-only resources.

    Observations come from the vital signs templates, one per measurement, with ids built from the composition and path. Mapped results are cached by composition version, and search results are not cached.

    A year later, the platform adds Observation writes for home readings. Only one template accepts them, every write carries the preceding version id, and conflicts return to the app as errors the user can resolve.

    Who owns what?

    A facade spans clinical modelling, the repository and the API. Each part needs a named owner.

    • Clinical modellers: templates and the clinical meaning behind each mapping.
    • Facade team: mapping rules, id scheme, caching, search support and the CapabilityStatement.
    • Repository team: AQL performance, versioning and notice of template changes.
    • Security team: aligning SMART scopes with openEHR access rules.

    Template releases need a shared calendar. When the modelling team plans a new template version, the facade team should have the sample compositions and the release date early enough to update rules and tests.

    How do you test and monitor the facade?

    Test the facade with round trips from FHIR to openEHR and back, and monitor latency per search parameter. Mapping correctness and query cost are the two things that drift.

    • Round trips: a written resource read back must match what was sent, field by field.
    • Template suite: every template version mapped against sample compositions.
    • Id stability: amend a composition and confirm resource ids stay the same.
    • Latency by parameter: slow searches identified before clients rely on them.

    In production, alert on mapping errors per template, 412 conflict rates and the slowest searches. Each one points to a different owner, so route the alert to the right team from the start.

    What are openEHR FHIR facade best practices?

    Keep openEHR as the only system of record, build stable resource ids from composition and path, and map FHIR versions from composition versions. Start read-only and add writes per resource type with version checks.

    Cache by composition version, advertise only searches you support well, run the mapping suite on every template change, and align SMART scopes with openEHR access rules.

    How Agnotic can help

    Agnotic builds and operates FHIR facades over openEHR repositories: mapping rules, stable identifiers, version mapping, caching, write paths and the tests that keep them aligned as templates change. We work with your clinical modellers so mappings keep their meaning.

    Put a FHIR API on your openEHR platform

    We design facades that run reliably on top of openEHR repositories.

    Sources

    Frequently Asked Questions

    No. Keep the openEHR repository as the only system of record and let the facade hold mapping rules, identifier maps and caches only.

    Talk to an engineer about your project

    Tell us about your openEHR platform and FHIR clients. We will outline the facade design and its risks.