# AQL for multi-occurrence nodes **Category:** [Technical (archive)](https://discourse.openehr.org/c/technical-archive/156) **Created:** 2017-10-27 06:15 UTC **Views:** 3 **Replies:** 8 **URL:** https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365 --- ## Post #1 by @system 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 --- ## Post #2 by @system 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 --- ## Post #3 by @system 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 --- ## Post #4 by @system Hi - agree with Thomas and more here [https://github.com/ethercis/ethercis/issues/69](https://github.com/ethercis/ethercis/issues/69) Ian --- ## Post #5 by @system > 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\. --- ## Post #6 by @system Thanks everybody for the clarification. regards --- ## Post #7 by @system Dear Thomas, Can you point me to details of Java structures regards --- ## Post #8 by @system 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 --- ## Post #9 by @system I would also look at the ITS specification. 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 -------- --- **Canonical:** https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365 **Original content:** https://discourse.openehr.org/t/aql-for-multi-occurrence-nodes/14365