# AQL for multi-occurrence nodes

**URL:** https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365
**Category:** Technical (archive)
**Created:** [27 October 2017 06:15 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365 "2017-10-27T06:15:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [27 October 2017 06:15 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/1 "2017-10-27T06:15:21Z")

</div>

Hi,

What is the expected response to AQL on a node with multiple occurrences? Does it return all the occurrences or only the first one?

If it is expected to return all occurrences, what is the structure of the response? will the occurrences be returned as an array?

If only the first one is returned, how do we get all the occurrences? Adding multiple select lines in aql may not be practical as the number of occurrences can vary.

Can nay body give a select statement syntax for this?

regards

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [1 November 2017 20:41 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/2 "2017-11-01T20:41:48Z")

</div>

This is a very interesting topic. I have written out some of the problems in this repo: [https://github.com/DIPSASA/openehr-conformance/tree/master/aql](https://github.com/DIPSASA/openehr-conformance/tree/master/aql)

The general answer is that you need to write you AQL as detailed as possible. Meaning you need to know which level you expect the multiple occurences to appear. Take a look at the examples given above. I would be happy to answer follow ups on this.

Vennlig hilsen  
Bjørn Næss  
Produktansvarlig  
DIPS ASA

Mobil +47 93 43 29 10

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [2 November 2017 14:42 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/3 "2017-11-02T14:42:25Z")

</div>

Hi Dileep

querying is always about returning everything that matches - it’s a declarative concept, not a procedural one. In REST terms, . If you want other structures, e.g. C# / Java / other language etc, please respond here, there are answers for that as well. - thomas

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [2 November 2017 14:52 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/4 "2017-11-02T14:52:35Z")

</div>

Hi - agree with Thomas and more here

[https://github.com/ethercis/ethercis/issues/69](https://github.com/ethercis/ethercis/issues/69)

Ian

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [2 November 2017 17:13 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/5 "2017-11-02T17:13:24Z")

</div>

> Hi,
> 
> What is the expected response to AQL on a node with multiple occurrences?  
> Does it return all the occurrences or only the first one?

If the query matches multiple occurrences of data defined by the same  
archetype node, then all the matched occurrences should be returned. It  
doesn't make sense to return the first occurrence since each occurrence  
contains different clinical data.

> If it is expected to return all occurrences, what is the structure of the  
> response? will the occurrences be returned as an array?

IMO the result will have the structure of the items in the SELECT, if the  
query projection is a COMPOSITION, then the result will be a list of  
compositions, and those might contain multiple occurrences of a node. On  
this context, the match in the WHERE might be that exists a node at certain  
path that contains certain value, that path might have multiple occurrences  
of a node, and the resulting compositions will be returned if any of those  
occurrences have that value.

If the SELECT has a projection for the matched nodes that might have  
multiple occurrences, a list of those nodes will be returned, and those  
might be from many COMPOSITIONs. If the results are just a plain list, it  
will be difficult to know which occurrences have the same context  
(contained on the same composition), I prefer to return the composition uid  
alongside with the data and a timestamp.

> If only the first one is returned, how do we get all the occurrences?  
> Adding multiple select lines in aql may not be practical as the number of  
> occurrences can vary.

I don't think this is an issue of AQL, but an implementations issue on not  
supporting multiple occurrences of nodes on query results. Multiple  
occurrences is a basic part of the openEHR spec IMO and very common in  
clinical records, like having more than one diagnosis on the same document.

As Thomas said, the query should return anything that matches, multiple  
occurrences included.

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [3 November 2017 04:11 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/6 "2017-11-03T04:11:09Z")

</div>

Thanks everybody for the clarification.

regards

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [3 November 2017 04:47 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/7 "2017-11-03T04:47:01Z")

</div>

Dear Thomas,

Can you point me to details of Java structures

regards

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [3 November 2017 17:26 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/8 "2017-11-03T17:26:15Z")

</div>

Dileep,

[see here](https://openehr.atlassian.net/wiki/spaces/spec/pages/4915240/Ocean+Informatics+EHR+Service+Interface#OceanInformaticsEHRServiceInterface-DataStructures). But I suggest you post this question on the [implementers list](http://www.openehr.org/community/mailinglists) to see if someone can point you to classes already available.

- thomas

---

<div class="post-metadata">

### Author: ![system](https://discourse.openehr.org/uploads/default/original/2X/f/f0a1dedb20c42747bddcafd6c7df9db5f34f003c.svg) [@system](https://discourse.openehr.org/u/system)
#### Post date: [3 November 2017 18:19 UTC](https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365/9 "2017-11-03T18:19:51Z")

</div>

I would also look at the ITS specification. [https://github.com/openEHR/specifications-ITS/tree/master/REST\_API](https://github.com/openEHR/specifications-ITS/tree/master/REST_API)

There is a XSD there which defines some structures.

Vennlig hilsen

Bjørn Næss

Produktansvarlig

DIPS ASA

-------- Opprinnelig melding --------
