Data from more template

Hello,
assume i have more templates for diagnosis archetype - it can be templates for various medical specializations, or situations, sometime diagnose can be nested deeper in template, not just in root.

I want create report for health insurance company and i need get all diagnose code. Do i have to known every template that is including diagnosis archetype?
Let assume i have query to get all diagnosis code, but then we add new type of template using diagnosis archetype, do we need update this aql query or we can get all diagnosis archetype without specifying from which template we want it?

Thank you

1 Like

Great question and this is the really cool thing about openEHR querying - you can do completely composition or template-neutral querying, and search at any depth using the CONTAINS statement

This will do what you want - find me any patient with a diagnosis record, regardless fo which composition it lives in, which template was used to create it, or whether it is nested inside some SECTIONs.

SELECT c/uid/value as compositionId, c/name/value as compositionName,
c/archetype_details/template_id/value as templateId,  e/ehr_id/value as ehrId, k/data[at0001]/items[at0002]/value as diagnosis
FROM EHR e
CONTAINS COMPOSITION c
CONTAINS EVALUATION k[openEHR-EHR-EVALUATION.problem_diagnosis.v1] 

With a resultset like

 {
        "compositionId": "0dac29ed-9091-4846-a201-fe6ea2942830::dhi-scotland.ehrscape.com::1",
        "compositionName": "Medical diagnosis",
        "templateId": "Medical Diagnosis",
        "ehrId": "0f0b7938-1b97-4a01-8af4-76de96e27483",
        "diagnosis": {
            "@class": "DV_CODED_TEXT",
            "value": "Conductive hearing loss, bilateral",
            "defining_code": {
                "@class": "CODE_PHRASE",
                "terminology_id": {
                    "@class": "TERMINOLOGY_ID",
                    "value": "ICD-10"
                },
                "code_string": "H90.0"
            }
        }
    },
    {
        "compositionId": "0a1f58e1-66de-4ab5-a504-3fd450b075c8::dhi-scotland.ehrscape.com::1",
        "compositionName": "Medical diagnosis",
        "templateId": "Medical Diagnosis",
        "ehrId": "0f0b7938-1b97-4a01-8af4-76de96e27483",
        "diagnosis": {
            "@class": "DV_CODED_TEXT",
            "value": "Superficial frostbite of neck",
            "defining_code": {
                "@class": "CODE_PHRASE",
                "terminology_id": {
                    "@class": "TERMINOLOGY_ID",
                    "value": "ICD-10"
                },
                "code_string": "T33.1"
            }
        }
    },
...
3 Likes

Thank you very much