AQL: Support to join two composition on ehrid

We have two compositions
(COMPOSITION c1 CONTAINS OBSERVATION o1) OR
(COMPOSITION c2 CONTAINS EVALUATOIN e1)
We want to join these two composition .
First template has sign and symptom screening which has symptom values like ‘Depression’
and second is a Person details which has Gender ‘Female/Male’.
We want to be able to get count of all Female(from c2) who have Depression(from c1)

Following AQL does not work:

SELECT c1 FROM EHR e
CONTAINS
(COMPOSITION c1 CONTAINS OBSERVATION o1) OR
(COMPOSITION c2 CONTAINS EVALUATOIN e1)
WHERE e1/path/to/attribute=‘Female’ and (o1/path/to/attribute=‘Depression’ and o1/path/to/attribute=‘Yes’)

AND

SELECT o1, e1 FROM EHR e
CONTAINS
(COMPOSITION c1 CONTAINS OBSERVATION o1) OR
(COMPOSITION c2 CONTAINS EVALUATOIN e1)

The Following two AQLs work:
SELECT o1 FROM EHR e1
CONTAINS
(COMPOSITION c1 CONTAINS OBSERVATION o1) OR
(COMPOSITION c2 CONTAINS EVALUATOIN e1)
WHERE o1/path/to/attribute=‘value’

AND

SELECT e1 FROM EHR e
CONTAINS
(COMPOSITION c1 CONTAINS OBSERVATION o1) OR
(COMPOSITION c2 CONTAINS EVALUATOIN e1)
WHERE e1/path/to/attribute=‘value’

But when we combine the two compositions either in select or where clause, it does not work.
How do we specify JOIN queries in AQL. Here we want to join on ehrId’s

Just as a curiosity, why not doing a single query that contains either of the compositions (with an OR, not an AND)?
I’m assuming you want to get all the different compositions that may have a given EHR_ID for the stated compositions

1 Like

Sorry we tied with an OR. will update.
The issue is we are not able to provide an element from the first composition and another element from the second composition in either select or where clause in the single AQL query

Attaching the two templayes with composition and the aqls for referral
Template1: patient-data.en.v0
Template2: sample_questionnaire.en.v0

patient_data.en.v0.opt (37.4 KB)
patient_data.en.v0.t.json (61.3 KB)
sample_questionnaire.en.v0.opt (42.4 KB)
sample_questionnaire.en.v0.t.json (114.7 KB)
patient_data-composition.json (4.4 KB)
sample_questionnaire-composition-1.json (7.0 KB)
aql-join-issues.json (3.5 KB)