Better AQL : Selecting Data from "any event"

I have a template with any event as parent event with cardinality 0…*. I want to select few columns from any_event:0 as well as few from any_event:1 in a single query. Is there any way to do this.

I am new to OpenEHR and AQL so any help would be appreciated.


It depends on a few factors:

  1. Do you want results from any number of "Any event"s, in cases where the composition contains more than the two? If not, how do you identify the two you want?
  2. Are the elements you want returned from each of them the same?

If the answers to both questions are “yes”, something like this should work:

     CONTAINS OBSERVATION o[full ID of the OBSERVATION archetype containing the events]
          CONTAINS EVENT e

This would return the contents of the two elements identified by their paths in the SELECT clause, from any event contained within the OBSERVATION archetype identified by its ID, contained within any COMPOSITION. You can further constrain this if you want to, for example by specifying that the COMPOSITION must be based on a specific template, values of specific elements, the order of the returned rows, or the number of rows in the returned set.

I have element like:

I am not sure how could i get path to this exact element where i just want to show conclusion of any_event:1.

Thanls for your response. Greatly appreciate the help.

In theory, according to the specifications you could add the following to the AQL if you want to get the two first events (chronologically, being e the path to the event):

    e/time ASC

But I don’t know if this is supported by the implementations.

It is supported AFAIK but also depending on the implementation, the multiple events may be labelled with names like event[at0003,‘AnyEvent#1’]

Pull back a full composition as Raw/canonical json had have a look.

it depends on the relationship between each event - if you just need the ‘last’ event by time then the ORDER BY idea will work well

I couldn’t see any label to the multiple events in raw json for the composition.
For order by yes it helps in taking last event data though if i want to select few columns from first event and few from second event and so on.

I was hoping if there was a way to select from any particular event.

Though thanks for the suggestions order by helped when i was able to merge data from different aql in JS view.

Correction: I was able to select from multiple event using Any event #1. Missed it earlier.

1 Like

The only problem with that is that there is a possibility of the order being indeterminate, or at least guaranteed. Probably safe enough with a single CDR vendor/ serialisation but …

What is ‘special’ about the second event? Is it just the last in the series? If not then you could specifically clone and rename it to be clear of the prurpose and make querying accurate.

I don’t see way of doing the differential ‘column query’ between events tough perhaps the UNION clause that Better AQL supports might let you do something? I’ve never used that in anger.