Hi - great question. 
The answer is as always; it depends. The query below (similar to yours) will 
work also. 
What you have to consider when building AQLs is repeatable structures to make 
sure you hit the right instance. For this use-case I guess you would like any 
EHR which has a Calcium result. Thus you don’t care about which result is 
Calcium. But if you wanted to get the excact CLUSTER with Calcium combined with 
i.e. HISTORY.time you have to be a bit careful. 

SELECT
    e    
FROM
    EHR e
        CONTAINS COMPOSITION c
            CONTAINS OBSERVATION o[openEHR-EHR-OBSERVATION.laboratory_test.v1]
                CONTAINS CLUSTER 
c2[openEHR-EHR-CLUSTER.laboratory_test_panel.v1]
WHERE
    c2/items[at0002]/items[at0001]/value/magnitude > 123
ORDER BY
    o/data[at0001]/events[at0002]/time DESC
LIMIT 10


An even simpler AQL if you want any CLUSTER of a specific type is to only query 
for Composition with the CLUSTER. Like this: 

SELECT
    e
FROM
    EHR e
        CONTAINS COMPOSITION c
            CONTAINS CLUSTER c2[openEHR-EHR-CLUSTER.laboratory_test_panel.v1]
LIMIT 10

Vennlig hilsen
Bjørn Næss
Produktansvarlig 
DIPS ASA

Mobil +47 93 43 29 10


-----Original Message-----
From: openEHR-technical <[email protected]> On Behalf 
Of Georg Fette
Sent: torsdag 25. april 2019 14:18
To: For openEHR technical discussions <[email protected]>
Subject: AQL questions

Hello,
I have some problems concerning the formulation of an AQL query.
I would like to check a laboratory analyte within a laboratory test. The 
analyte should have "Calcium" as analyte name and I would like to receive all 
EHRs that contain the analyte as the query result.
The SELECT part seems easy, as I just want the EHRs, so this looks like
this:

SELECT e

A problem I now have is about the nesting of the Archetypes. As the test is an 
OBSERVATION and an EHR contains only COMPOSITIONs, I wonder if I have to 
include a COMPOSITION in order to reach the tests. This would lead to a FROM 
part looking like this:

FROM EHR e
     CONTAINS COMPOSITION
         CONTAINS OBSERVATION
b[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]

The next problem I have is about the definition of the containment of the 
analyte in the FROM part or better in the WHERE part. The FROM part would 
require me to define the actual nesting structure of the test-OBSERVATION up to 
the analyte-CLUSTER. This would look like this:

FROM EHR e
     CONTAINS COMPOSITION
         CONTAINS OBSERVATION
b[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]
             CONTAINS HISTORY
                 CONTAINS EVENT
                     CONTAINS ITEM_TREE
                         CONTAINS CLUSTER 
c[openEHR-EHR-CLUSTER.laboratory_test_analyte.v1]

This looks a bit bloated, so I think this should rather be moved to the WHERE 
part, which would look like this:

FROM EHR e
     CONTAINS COMPOSITION
         CONTAINS OBSERVATION
b[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]
WHERE
b/data[at0001]/events[at0002]/data[at0003]/items[at0097]/items[at0024].value
= 'Calcium'

In this WHERE path I am wondering about the necessity of the path part 
predicates (i.e. the [at...] parts). Are these predicates always necessary for 
every path part ? Or are they only necessary when the path part object would be 
ambiguous without the predicate (e.g. in the items of CLUSTERs or ITEM_LISTs) ?
Furthermore I wonder about the namespace from which the predicates are taken 
from. For the first part of the WHERE until the archetype slot is reached (i.e. 
b/data[at0001]/events[at0002]/data[at0003]/items[at0097])
the predicates are from the laboratory_test_result archetype. For the rest of 
the path (i.e. /items[at0024].value) the predicates are taken from the 
laboratory_test_analyte archetype. This switching of namespaces seems wrong, so 
I think I still have some misunderstanding of AQL concerning the predicates.

How would the correct query/queries look like ? Are there multiple valid 
alternatives to express my query using combinations of the approaches scetched 
above ?
Greetings
Georg

--
---------------------------------------------------------------------
Dipl.-Inf. Georg Fette      Raum: B001
Universität Würzburg        Tel.: +49-(0)931-31-85516
Am Hubland                  Fax.: +49-(0)931-31-86732
97074 Würzburg              mail: [email protected]
---------------------------------------------------------------------


_______________________________________________
openEHR-technical mailing list
[email protected]
http://lists.openehr.org/mailman/listinfo/openehr-technical_lists.openehr.org
_______________________________________________
openEHR-technical mailing list
[email protected]
http://lists.openehr.org/mailman/listinfo/openehr-technical_lists.openehr.org

Reply via email to