# AQL fetch issue when Two different templates has same archetype in version 23

**URL:** https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461
**Category:** AQL
**Tags:** aql, archetype, template, ehrbase
**Created:** [18 January 2023 12:44 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461 "2023-01-18T12:44:01Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)
#### Post date: [18 January 2023 12:44 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/1 "2023-01-18T12:44:02Z")

</div>

Hi Team,

We have created two templates with same archetype sign/symptom created using same composition encounter v1,

While inserting data we have inserted two data points one is observation, and other is for cluster for template1  
Where as, for the second template we have inserted for only cluster.

SO, when we try to fetch the data inserted for both templates, we are getting only one row for template1 where we had inserted for both data points(observation and cluster), but expected was 2 rows for both templates. This expected result was working in version 20, but the same is not working on 23.

Below is AQL used :

{  
“q” : “SELECT e/ehr\_id/value as ehrId, c/uid/value as composition\_id, c1/items[at0001]/value/value as name, o1/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/value as story,c/archetype\_details/template\_id/value as template FROM ehr e[ehr\_id/value=‘{{ehrId}}’] CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.encounter.v1] contains (observation o1[openEHR-EHR-OBSERVATION.story.v1] or cluster c1[openEHR-EHR-CLUSTER.symptom\_sign.v1]) where (c1/items[at0001]/value/value=‘encounter-test-one’ and c/archetype\_details/template\_id/value =‘encounter-signsymptom-1.en.v0’ and o1/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/value=‘Test’) or (c1/items[at0001]/value/value=‘test-encounter-two’ and c/archetype\_details/template\_id/value =‘encounter-signsyptom-2.en.v0’)”  
}

Can you please help us identify the issue in new version, since it was working in version 20.

Thanks in Advance.

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [18 January 2023 15:01 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/2 "2023-01-18T15:01:52Z")

</div>

Which CDR implementation are you using?

---

<div class="post-metadata">

### Author: ![borut.jures](https://discourse.openehr.org/user_avatar/discourse.openehr.org/borut.jures/32/1391_2.png) [@borut.jures](https://discourse.openehr.org/u/borut.jures)
#### Post date: [18 January 2023 15:26 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/3 "2023-01-18T15:26:16Z")

</div>

It is tagged as EHRBase.  
They also mentioned EHRBase in other posts.  
I guess they are using EHRBase 😊

---

<div class="post-metadata">

### Author: ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)
#### Post date: [19 January 2023 04:51 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/4 "2023-01-19T04:51:59Z")

</div>

We are using ehrbase version 0.23.0

---

<div class="post-metadata">

### Author: ![birger.haarbrandt](https://discourse.openehr.org/user_avatar/discourse.openehr.org/birger.haarbrandt/32/24_2.png) [@birger.haarbrandt](https://discourse.openehr.org/u/birger.haarbrandt)
#### Post date: [19 January 2023 05:45 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/5 "2023-01-19T05:45:38Z")

</div>

Hi @Mancini,

would you be so kind to open an issue at the GitHub? [Issues · ehrbase/ehrbase · GitHub](https://github.com/ehrbase/ehrbase/issues)?

---

<div class="post-metadata">

### Author: ![sebastian.iancu](https://discourse.openehr.org/user_avatar/discourse.openehr.org/sebastian.iancu/32/31_2.png) [@sebastian.iancu](https://discourse.openehr.org/u/sebastian.iancu)
#### Post date: [19 January 2023 09:47 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/6 "2023-01-19T09:47:44Z")

</div>

Hi @Mancini,  
I guess you’re question is related to [Behaviour of logical operators(OR, AND, NOT) in FROM Clause - #32 by pablo](https://discourse.openehr.org/t/behaviour-of-logical-operators-or-and-not-in-from-clause/1596/32).  
Both are product-related questions, and best is to place them (or similar future questions) under [Platform - openEHR](https://discourse.openehr.org/c/implem/platform-implem/7) section.  
This section is a placeholder for question on AQL specifications, and therefore should be more generic or conceptual, not necessarily focused on a specific product.  
Also, it would be nice if you could format next time the SQL and extract it from the JSON - so that it gets more readable.  
However, if you now follow @birger.haarbrandt recommendation and I’m sure you’ll get an answer to your issue.

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [19 January 2023 14:12 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/7 "2023-01-19T14:12:57Z")

</div>

> [@Mancini](#):
>
> While inserting data we have inserted two data points one is observation, and other is for cluster for template1  
> Where as, for the second template we have inserted for only cluster.

This confuses me, where is the CLUSTER located in the COMPOSITION? A COMPO can’t have a CLUSTER directly in it, it should have some entry, the entry would have some structure and the structure the cluster.

Can you provide sample templates and compositions?

---

<div class="post-metadata">

### Author: ![ian.mcnicoll](https://discourse.openehr.org/user_avatar/discourse.openehr.org/ian.mcnicoll/32/4430_2.png) [@ian.mcnicoll](https://discourse.openehr.org/u/ian.mcnicoll)
#### Post date: [20 January 2023 09:07 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/8 "2023-01-20T09:07:07Z")

</div>

It will be in context/other\_details.

Example

 ![image](https://discourse.openehr.org/uploads/default/original/2X/7/7ed2bcc0a50cad32e3331406d20fcc5403e1cd11.png)

---

<div class="post-metadata">

### Author: ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)
#### Post date: [20 January 2023 12:25 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/9 "2023-01-20T12:25:18Z")

</div>

@birger.haarbrandt , raised an issue on GitHub. Thanks

---

<div class="post-metadata">

### Author: ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)
#### Post date: [20 January 2023 12:34 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/10 "2023-01-20T12:34:01Z")

</div>

Template -1  
[encounter-signsymptom-3.en.v0.opt](https://discourse.openehr.org/uploads/short-url/e5b8LMe6a3qm7g93cjse5qxXWhE.opt) (25.0 KB)  
[encounter-signsymptom-3.en.v0-FLAT.json](https://discourse.openehr.org/uploads/short-url/ryFiqHNZ44rLhNbdnQ7E8wUeDm.json) (1.4 KB)  
[encounter-signsymptom-3.en.v0.t.json](https://discourse.openehr.org/uploads/short-url/dwfhMMpiwPvfTiEpXiE3OLMvR6M.json) (10.8 KB)

---

<div class="post-metadata">

### Author: ![Mancini](https://discourse.openehr.org/user_avatar/discourse.openehr.org/mancini/32/2002_2.png) [@Mancini](https://discourse.openehr.org/u/Mancini)
#### Post date: [20 January 2023 12:34 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/11 "2023-01-20T12:34:38Z")

</div>

Template-2  
[aql.json](https://discourse.openehr.org/uploads/short-url/yAPD2AnkzDsdxH1KWvKXE2HxalZ.json) (757 Bytes)  
[encounter-signsymptom-5.en.v0.json](https://discourse.openehr.org/uploads/short-url/kRKd6Kyqk1y7hztPQnRuUWZXHs2.json) (1.5 KB)  
[encounter-signsymptom-5.en.v0.t.json](https://discourse.openehr.org/uploads/short-url/9sUizsn5oPmNr5DIpfbzPm5LA97.json) (14.1 KB)  
[encounter-signsymptom-5.en.v0.opt](https://discourse.openehr.org/uploads/short-url/jydS2bm9wqtBOsKnVwPnvrHJ694.opt) (118.7 KB)

---

<div class="post-metadata">

### Author: ![pablo](https://discourse.openehr.org/user_avatar/discourse.openehr.org/pablo/32/3505_2.png) [@pablo](https://discourse.openehr.org/u/pablo)
#### Post date: [20 January 2023 17:51 UTC](https://discourse.openehr.org/t/aql-fetch-issue-when-two-different-templates-has-same-archetype-in-version-23/3461/12 "2023-01-20T17:51:34Z")

</div>

I see the -5 file to have data in the observation, but the -3 doesn’t have data in the observation, it seems this is the only data point “encounter-signsymptom-5.en.v0/story\_history/any\_event:0/symptom\_sign/symptom\_sign\_name” in the -5 file.

And this “encounter-signsymptom-3.en.v0/story\_history/any\_event:0/story:0” might be only a name, not data in a data structure. So not sure where is the cluster you mention. Maybe I don’t see it (I’m not used to custom formats, personally prefer canonical JSON).

Also there is a strange underscore in the \_end\_time and \_health\_care\_facility, those are normal attributes like the rest, I think the underscore prefix might not be right. If those work, then maybe the CDR isn’t consistent in attribute naming.
