The challenge of querying different levels of data at the same time

Because the template is assembled using slots in multiple Archetypes, the data that should be conceptually/logically at the same level is actually/structurally at different levels, which makes it challenging to query the data at the same time (OR in a single ADL query/subquery), especially for those users who do not know the tree structure of the target template beforehand.

Related Topic:

Hi,
It is not very clear from your post what is challenging/difficult. Perhaps try to explain more on what did with examples, or what you intended to query or find out, how was therefore the AQL query looking, what was your (initial) expectation on writing the query (especially what was challenging), etc.

Hi @sebastian.iancu. Excuse me for my vague (even for myself) expression. Rethinking it carefully, what I wanted to express might be “that would be nice if the two groups of data points could be queried in a single ADL query using the same path”. Actually, maybe it’s not possible to write such an ADL query without specifying their full paths, just like the double slash (//) in an XPath expression “bookstore//book” which omits the middle/intermediate paths.

I don’t know if I made it clear this time?
Thanks again.

You can get similar results by retrieving all the ELEMENTs in AQL, independently of their path.

(I don’t know the exact archetype identifier in the example below)

SELECT elem
FROM EHR e
CONTAINS COMPOSITION c
   CONTAINS OBSERVATION o[openehr-EHR-OBSERVATION.Physical_activity.v1]
      CONTAINS ELEMENT elem
1 Like

Indeed, the ... CONTAINS bookstore CONTAINS book is a search that in xPath would be equivalent to booskstore//book (so a ‘descendant’ relationship), and assuming all what you were looking is a booktype, regardless the relationship level (child, grandchild, etc), then you will get what you are looking for.

1 Like

Ah, it’s just what I want. And I can hardly wait to try this query… Thanks a lot, @damoca.

This query works! Agian, thanks, @damoca.

@sebastian.iancu Thank you for your clear and unambiguous description.