When trying to return observations of various types in compositions, the following AQL query was used:
SELECT e/ehr_id/value,
c/archetype_details/template_id/value,
c/uid/value,
obs/data[at0002]/events[at0003]/data[at0001]/items/name/value,
obs/data[at0002]/events[at0003]/data[at0001]/items/value
FROM EHR e CONTAINS COMPOSITION c
CONTAINS OBSERVATION obs [openEHR-EHR-OBSERVATION.pulse.v1]
I got all the results as expected in such a query.
Snippet of the response:
...
[
"80a71040-3d37-42f3-a86a-ce5405138ce0",
"Linkoping_University_Physical_Activity",
"8aad14de-4af5-4559-8979-004877eb6a9c::local.ehrbase.org::1",
"Heart beat presence",
{
"_type": "DV_CODED_TEXT",
"defining_code": {
"_type": "CODE_PHRASE",
"code_string": "at1024",
"terminology_id": {
"_type": "TERMINOLOGY_ID",
"value": "local"
}
},
"value": "Present"
}
],
[
"80a71040-3d37-42f3-a86a-ce5405138ce0",
"Linkoping_University_Physical_Activity",
"8aad14de-4af5-4559-8979-004877eb6a9c::local.ehrbase.org::1",
"Pulse Rate",
{
"_type": "DV_QUANTITY",
"magnitude": 21,
"units": "/min"
}
],
...
My question is:
How to get the specific “results” depending the data type of the observation:
- If _type = “DV_CODED_TEXT” OR “DV_TEXT” …, then SELECT the value such as “Present” for “Heart beat presence”;
- If _type = “DV_QUANTITY”, then SELECT the “magnitude” such as 21 and “units” such as “/min”…
The following AQL query returns the results of _type “DV_CODED_TEXT” OR “DV_TEXT” … as expected but returns the results of _type “DV_QUANTITY” as null
SELECT e/ehr_id/value,
c/archetype_details/template_id/value,
c/uid/value,
obs/data[at0002]/events[at0003]/data[at0001]/items/name/value,
obs/data[at0002]/events[at0003]/data[at0001]/items/value/value
FROM EHR e CONTAINS COMPOSITION c
CONTAINS OBSERVATION obs [openEHR-EHR-OBSERVATION.pulse.v1]
The following AQL query applies to the results of _type “DV_QUANTITY” ONLY:
SELECT e/ehr_id/value,
c/archetype_details/template_id/value,
c/uid/value,
obs/data[at0002]/events[at0003]/data[at0001]/items[at0004]/name/value,
obs/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value/magnitude,
obs/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value/units
FROM EHR e CONTAINS COMPOSITION c
CONTAINS OBSERVATION obs [openEHR-EHR-OBSERVATION.pulse.v1]
So, how to query observations of various types in compositions in a single AQL query?
Thanks in advance.