I found a similar structure in COVID-19 Pneumonia Diagnosis and Treatment (7th edition).opt and thanks to @pablo instance generator, I have a composition instance to use.
It uses medication_order.v2 instead of v3 but it probably doesn’t mater for this exercise.
I couldn’t wait for the data instances for your example @siljelb so I adapted the 1st example to the COVID-19 OPT.
What do you think?
I’m not saying AQL is wrong. I’m just experimenting with more widely available SQL and all the tooling already available. By using SQL, I was able to write a working CDR which can be queried with SQL. I’m not sure how much time it took to build other CDRs for this feature set, but I’m sure it was more than 3 weeks
SELECT $uid,
$medication_order.activities.description.items,
$health_risk.data.items.value.value
FROM `openEHR-EHR-COMPOSITION.encounter.v1`
LET $adhoc = rel(`openEHR-EHR-SECTION.adhoc.v1`),
$medication_order = $adhoc.rel(`openEHR-EHR-INSTRUCTION.medication_order.v2`),
$health_risk = $adhoc.rel(`openEHR-EHR-EVALUATION.health_risk.v1`)
WHERE archetype_details.template_id.value LIKE 'COVID%'
AND $medication_order CONTAINS ( activities CONTAINS (
archetype_node_id = 'at0001' AND
description.archetype_node_id = 'at0002' AND
description.items CONTAINS (
archetype_node_id = 'at0070' AND
name.value= 'Medication item' AND
value.defining_code.code_string = '45754009'
)
))
AND $health_risk CONTAINS ( data.items CONTAINS (
value.value = 'Fit for discharge'
))