An openEHR clinical data repository already holds what most AI projects lack: structured data with a published model behind every field. Teams still stall when they try to train on it, because a CDR is built to answer clinical queries one patient at a time, not to hand a data scientist a clean, dated, de-identified table.
This post is for data engineers and ML teams working on an openEHR repository. It covers AQL extracts that feed feature tables, archetype paths as feature definitions, point-in-time training sets from version history, terminology checks and de-identified export for ML and LLM work.
What does AI-ready openEHR data mean?
Still choosing an openEHR repository?
Our selection guide compares openEHR clinical data repositories on query support, versioning and export, the features that decide how easily AI teams can use the data.
AI-ready openEHR data is repository content turned into versioned feature tables and document sets, where each column traces to an archetype path, each row is dated by what was known at that time, codes are checked, and identifiers are removed before export. Agnotic Technologies builds these extract layers so models train on data the CDR can reproduce.
The repository itself does not change. The work sits in a layer beside it that queries, flattens, dates and cleans the data on a schedule.
Why openEHR data suits model training
openEHR data suits model training because every value already sits inside a shared clinical model. A blood pressure reading is not a free column named bp_sys in one system and SYSTOLIC in another; it is an element inside the published blood pressure archetype, with units and ranges defined.
openEHR describes itself as a technology made of open specifications, clinical models and software that is completely model-driven and separates domain semantics from software, with information models for EHR data, an archetype formalism for domain content, a portable query language (AQL) and an open API specification.
That separation is the reason to build on it. When a hospital adds a new form, the template changes but the archetypes underneath stay the same, so a feature built on an archetype path keeps working after the form is redesigned.
How do AQL extracts become feature tables?
AQL extracts become feature tables through a scheduled job that runs one query per feature group, writes the rows to staging with their composition ids and times, and then pivots them into one row per patient and time window. The repository answers the queries; the pipeline owns the shape.
The openEHR Archetype Query Language (AQL) is a declarative language for searching and retrieving data in archetype-based repositories, and it uses openEHR path syntax in its SELECT and WHERE clauses to locate any node or data value defined within an archetype.
- One query per group: vital signs, lab results, problems and medications each get their own AQL statement, so a slow query does not block the rest.
- Long staging rows: patient id, composition id, archetype path, value, unit, code and both clinical and commit times.
- Pivot step: staging becomes wide feature tables per window, such as the last 24 hours before an index event.
- Run record: each extract stores its query text, repository version and row counts.
Keep the long staging format even after the wide tables exist. Analysts debugging a strange feature value need to see the original rows, and a new feature can be added from staging without querying the repository again.
Archetype paths as feature definitions
Use the archetype path, not a column name, as the definition of each feature. A feature registry entry for systolic pressure records the archetype id, such as openEHR-EHR-OBSERVATION.blood_pressure.v2, the full path to the systolic element, the unit and the aggregation rule.
- Archetype id and version: a major version change can alter meaning, so the registry pins it.
- Path: the exact node, so two teams asking for systolic pressure get the same value.
- Aggregation: last value, mean, minimum or count within the window, stated per feature.
- Template list: which templates in this repository actually populate the path.
The template list matters more than it looks. An archetype can appear in several templates, and one clinic's form may record a value that another clinic's form never asks for, which shows up later as a site bias in the model.
How do you build point-in-time training sets?
Build point-in-time training sets by filtering on when each value became known, not only when it was measured. openEHR keeps every committed version of a composition with its commit time, so a training row can include only the data a clinician could have seen at the prediction moment.
Two timestamps matter. The clinical time says when the observation happened, and the commit time says when it entered the record. A lab result taken at 08:00 but committed at 14:00 must not appear in a feature row dated 10:00.
Corrections follow the same rule. When a composition is amended, the training set as of an earlier date should hold the old version, because that is what the model would have used in production. Keep the version id in staging so this can be proved later.
Which terminology bindings need checking?
Check every coded value for which terminology it uses and whether that terminology is consistent across templates. A coded element can hold a local archetype code, a SNOMED CT concept or a LOINC code, and different templates may bind the same element to different value sets.
- Local codes: map the archetype's internal at-codes to labels, and to external codes where a binding exists.
- External codes: record the terminology id and version used in the composition, not just the code string.
- Free text fallbacks: count how often a coded element holds text instead of a code, per site.
- Value set drift: compare code distributions between sites before treating them as one population.
A model that learns from codes nobody checked often learns which site the patient attended. Running the code distribution report per template catches this before training starts.
How should openEHR data be de-identified before export?
De-identify openEHR data in the pipeline, after staging and before anything leaves for the ML environment. The repository keeps identified data for care; the export carries a study id, shifted or generalized dates and no direct identifiers.
HIPAA allows two ways to de-identify health data: expert determination, or the safe harbor method, which removes 18 categories of identifiers.
openEHR adds two places identifiers hide. Demographic data may sit in a separate service, which helps, but free text elements, comments and attachments inside compositions can still name patients, relatives or staff. Treat every text element as untrusted until a scan clears it.
How should compositions be prepared for LLM use?
Prepare compositions for LLM use by rendering each one as a short structured document that keeps archetype node names as headings and values with units beside them. A language model reads a labelled note far more reliably than a nested JSON tree with node ids.
- One document per composition, labelled with the template name and a shifted date.
- Headings from node names, so a reader sees Blood pressure, Systolic and 132 mm[Hg] together.
- Retrieval metadata: archetype ids, codes and version id kept beside the text for filtering.
- Text scan: the same identifier scan as the tabular export, applied before indexing.
What goes wrong when openEHR data feeds a model?
Most failures come from treating the repository like a flat database. The data looks complete until a model trained on it meets live use.
- Leakage through commit time: features include values that were recorded after the prediction moment.
- Template blindness: a feature exists only for patients seen on one form, so missing values mean site, not health.
- Pinned to nothing: queries written against an archetype without a version, then silently changed by an upgrade.
- Amendments lost: the latest version replaces history, so training sets cannot be rebuilt.
- Text left in: a comment field carries a name into the export.
A worked example: an early warning feature set
A hospital wants a model that flags ward patients at risk of deterioration within the next 12 hours. The team defines features for respiratory rate, oxygen saturation, systolic pressure, pulse, temperature and level of consciousness, each as an archetype path in the registry.
The extract runs AQL per vital sign group into staging, keeps clinical and commit times, and pivots into hourly windows. Rows only include values committed before each window ends, so a late entry from a busy night shift does not leak into the earlier hour.
Before export, the pipeline replaces patient ids with study ids, shifts dates per patient and scans comment elements. The data science team receives extract version one with row counts per ward and the registry version it was built from.
Who owns what?
Ownership splits between the clinical modelling side, the platform side and the data science side. Each one controls a different part of the definition.
- Clinical modellers: archetype and template choices, and approval of each feature's clinical meaning.
- Repository team: AQL access, query performance and notice of template or archetype upgrades.
- Data engineering: extract jobs, staging, the feature registry, versioning and de-identification.
- Data science: feature requests, labels, training and the evaluation set.
- Privacy officer: the export rules and sign-off on each new data element leaving the repository.
How do you check an extract before training?
Check an extract against the repository on a sample, then automatically on every run. Row counts on their own catch missing data but not wrong data.
- Round trip: for a sample of patients, rebuild feature values by hand from the compositions and compare.
- Time check: confirm no value in a window has a commit time after the window ends.
- Coverage report: share of patients with each feature, per template and per site.
- Identifier scan: search the export for names, record numbers and full dates before release.
Store each check result with the extract version. When a model's performance changes, the first question is whether the data changed, and those records answer it.
What are openEHR AI data preparation best practices?
Define every feature as a pinned archetype path in a registry, keep long staging rows with clinical and commit times, and build training sets on commit time. Check terminology per template and per site before pooling data.
De-identify after staging and before export, scan every text element, and version each extract with its queries and counts so any training set can be rebuilt.
How Agnotic can help
Agnotic builds the extract layer beside an openEHR repository: AQL jobs, staging, feature registries, point-in-time training sets, de-identification and LLM-ready document sets. We work with your clinical modellers and repository team so features stay tied to the models they came from.
Plan your openEHR data pipeline with Agnotic
We design extract, feature and export layers for clinical AI teams.
Related reading on Agnotic
openEHR, FHIR data pipelines and de-identification.


