Add function which allows terminology matches agnostic or defining_code or mapping
Description
Activity
Thomas Beale March 22, 2021 at 3:31 PM
In the example above, the path f/data[at0001]/items[at0002]/value
points to a DV_CODED_TEXT. We could define an equality or equivalence operator on that type, to create expressions like:
f/data[at0001]/items[at0002]/value = ‘snomed_ct::34234561342’
or if we want a special operator, something like:
f/data[at0001]/items[at0002]/value ~= ‘snomed_ct::34234561342’
Such operators are always mapped to functions behind the scenes, but I think this approach makes for nicer AQL, since the paths are shorter and no funny function name needs to be read, or its meaning learned.
To make this work, we need to define that function on the type DV_CODED_TEXT, taking a CODE_PHRASE or DV_CODED_TEXT argument (it’s easy to arrange for both variants), so that would be an RM change as well, and I think a nice one.
It is pretty common to find that as organisations gradually transition to SNOMED or other ref terminologies that both a local code and the ref. code need to be carried but the choice of which is in defining_code can be a bit arbitrary. This makes querying a little complex as we have to write quite a few lines of AQL to capture a specific terminology/code_phrase combination both under defining_code and mappings.
Could we consider a new function which would encapsulate this behaviour, as long a s the mapping is marked as equivalent i.e '='.
e.g
.... MATCHES defining_code_equivalent(terminologyId, code)
which resolves to
ELECT f/data[at0001]/items[at0002]/value as LivingWillType
FROM EHR e
CONTAINS COMPOSITION c
CONTAINS (ADMIN_ENTRY f[openEHR-EHR-ADMIN_ENTRY.legal_authority.v0]
WHERE
(f/data[at0001]/items[at0002]/value/defining_code/code_string = '1234567'
AND
f/data[at0001]/items[at0002]/value/defining_code/terminology_id = 'MYLOCALCODESYSTEM')
OR
(f/data[at0001]/items[at0002]/value/defining_code/code_string = '34234561342'
AND
f/data[at0001]/items[at0002]/value/defining_code/terminology_id = 'SNOMED-CT')
OR
( f/data[at0001]/items[at0002]/value/mappings/target/code_string = '34234561342'
AND f/data[at0001]/items[at0002]/value/mappings/target/terminology_id = 'SNOMED-CT'
AND f/data[at0001]/items[at0002]/value/mappings/match = '='
)
OR
( f/data[at0001]/items[at0002]/value/mappings/target/code_string = '1234567'
AND f/data[at0001]/items[at0002]/value/mappings/target/terminology_id = 'MYLOCALCODESYSTEM'
AND f/data[at0001]/items[at0002]/value/mappings/match = '='
)