usage of templates in AQL

Hello,
I have some question related to the coupling of AQL and templates:
Imagine I want to write an AQL query containing a certain archetype and that archetype is used in multiple templates in the openEHR system.
What do I need to know about the data model structures of the templates potentially containing this archetype ?
When there are multiple templates that contain this archetypes, will they all be found by this query, no matter where the archetype is contained in their structure?
How can I constrain my query so that I only get those of a specific template ?
Do templates have to be specifically mentioned in the queries or are they handled as if they were archetypes as well ?
How could I change my query so that (when I receive results from different template types) that I also get the surrounding information in which template my archetype has been found in ?
Greetings
Georg

Hi Georg,

There is no direct connection between AQL and templates.

What do I need to know about the data model structures of the templates
potentially containing this archetype ?

Nothing - you can use the CONTAINS statement to find your candidate archetype regardless of the enclosing composition/ template

When there are multiple templates that contain this archetypes, will
they all be found by this query, no matter where the archetype is
contained in their structure?

Yes, as above

How can I constrain my query so that I only get those of a specific
template ?

The templateID is carried in the parent composition (optionally though not normally at entry level)

select a_a, a/name/value, a/archetype_details/template_id/value
from EHR e
contains COMPOSITION a
contains EVALUATION a_a[openEHR-EHR-EVALUATION.problem_diagnosis.v1]
where a/archetype_details/template_id/value =‘My lovely template’

Do templates have to be specifically mentioned in the queries or are
they handled as if they were archetypes as well ?

No - you can ignore the templateId - templates are just ‘design-time recipes’ - the name of the recipe ids carried in the '‘archetype_details/template_id/value’ attribute but otherwise this is just pure archetypes.

How could I change my query so that (when I receive results from
different template types) that I also get the surrounding information in
which template my archetype has been found in

select a, a_a, a/name/value, a/archetype_details/template_id/value
from EHR e
contains COMPOSITION a
contains EVALUATION a_a[openEHR-EHR-EVALUATION.problem_diagnosis.v1]
where a/archetype_details/template_id/value =‘My lovely template’

In that example ‘a’ will return the whole containing composition - you probably do not want to do that but you get the idea.

Ian

The short answer is that you don’t have to care at all about the templates that were used. This is one of the fundamental advantages of openEHR - the query will find your blood sugars no matter what application, screen or form was used to capture it.

What you need to know is what kind of Entry and what archetype e.g. Observation (actual glucose measurement), Evaluation.glucose_target (a target) ans so on. You might also want to specify what Composition type, e.g. Only Lab reports containing glucose, and not Device-recorded etc.

Its all about the semantics.

  • thomas

Thanks for the answers.

Is a template apart from being a container which aggregates archetypes, a semi-definition or a derivation of an archetype ? The .oet template definitions always state a derivation from a an existing archetype (archetype_id="openEHR-EHR-COMPOSITION.report.v1"), and the type from which this archetype is inherited from (xsi:type="COMPOSITION").
So when I query with AQL for this archetype I should find those templates, is that correct ?
Greetings
Georg

Hi Georg,

You don’t find the templates as such, you find compositions committed against those templates definitions. Templates are just definitions of how to aggregate archetypes to meet a specific use-case. It is the composition instance that is committed and queried against. The data within that instance is tagged to show which archetype was used to define the data structure, and which overall template was used, but you are not really querying archetypes or templates, you are querying openEHR instance data marked-up to show how those data structures were defined and arranged - that mark-up is what allows you to use the template and archetypes to figure out how to query the data.

Ian

Ah, I understand.
I just made the test to use the json_instance_generator of the CoboLabs openEHR Toolkit by creating an instance of one of my templates. The template name only appears in the archetype_details. The whole rest looks like a standard instance of the archetype the template is based on.

When I have a system in which I have various templates for different kind of reports (e.g. echocardiography, anamnesis, etc.) and I would like to get all echocardiography data. Is it common practice to query using the archetype_details to identify the echocardiography reports, like you exemplified in your former answers ?
Greetings
Georg

We are still working on Imaging but the current presumption is that we would use a generic Imaging Result archetype https://openehr.org/ckm/archetypes/1013.1.1494

which contains Examination result name and modality elements which we would query on to find ‘Echocardiography’ data. The exact use of Examination name and modality is likely to be somewhat dependent on local practice/ terminology use.

Ian

Hi Ian,
Sorry, I did not mean specifically imaging data.
What I meant was that all our templates are based on the archetype openEHR-EHR-COMPOSITION.report.v1.
My question therefore was, if the only possibility to retrieve all data for a specific template type is by querying with something you described:

select a
from EHR e contains COMPOSITION a
where a/archetype_details/template_id/value ='My lovely template'

Greetings
Georg

Yes that works. It is also common to use the name/value attribute of the Composition root to identify a specific composition.
Normally the name/value attribute of a templated Composition defaults to the underlying Composition archetype croot concept name e.g ‘Bericht’ but it can be renamed at template level and then queried

select a
from EHR e contains COMPOSITION a
where a/name/value ='My local composition name'

I have tended to use name/value but am coming round to using the templateId - both are valid.
Ian

There are a bunch of AQL examples at

https://github.com/RippleOSI/Ripple-openEHR/tree/master/docs/bindings/Current%20Ripple%20Headings

Ian