AQL - Querying compositions with multiple observations of the same type

Hi all,

Long time reader, first time poster :slight_smile:

Given a composition C that has multiple instances of the same observation archetype O, should I be able to query for all instances of O?

A trivial example: for the given ehr, there is one composition that contains two progress_note observations.
Using EHRBase and the query below, I only get one of the observations returned.

WHERE e/ehr_id/value = $ehr_id

If I add a second composition with multiple notes, I get 2 results; one note form each composition.

Is this expected? If so, how/can my query be adjusted to return all progress notes in this example?


Hi Alex, selecting observation and filtering by archetype id should return all the instances of the observations complying with that archetype, single or multiple inside the same compo.

1 Like

Hi Alex,
EhrBase is quite mature, so I too would expect your query to return two observations, given a composition with two observations.

There used to be a period during which EhrBase team were talking about implementing behaviour that would be more intuitive for users who may be less exposed to query languages such as SQL or XQuery etc.

AQL’s story is kind of complicated when it comes to how it behaves. I advocated for it to have a formal execution semantics for years (literally) but we could not get that effort off the ground (for good reasons). So as things stand, each vendor may or may not give you an explanation of how it functions, but these days most implementations converge in terms of results, except when they don’t :slight_smile:

I still think the outcome should be what you’re expecting. If you’re able to perform a GET from the REST api and share the json form (or XML) of your compositions, we can speculate with a bit more confidence.

Re the history of the semantics discussion, these may make interesting (or boring )reading:
A discussion about Archetype Query Language semantics – Musings of a confused technology addict. (

Archetype Query Language, The Confusing Bits – Musings of a confused technology addict. (

Archetype Query Language, The Confusing Bits, II – Musings of a confused technology addict. (

serefarikan/aql-discussion: examples in xquery and sparql to discuss aql semantics (

1 Like

Hi all,

thank you for your kind words @Seref, but in this case, it is a known bug (AQL Not returning multiple diagnosis from one composition · Issue #1019 · ehrbase/ehrbase · GitHub). The team is currently working on a revision of EHRbase’s AQL engine which will address this behavior amongst others. Once this is done, EHRbase will also finally be released as 1.0.


Thank you @pablo @Seref @birger.haarbrandt

1 Like

Updates on this problem? Is the solution about to be released? if not, do you have an idea of what the expected timelines could be?