# AQL querying by internal code

**URL:** https://discourse.openehr.org/t/aql-querying-by-internal-code/15831
**Category:** Technical (archive)
**Created:** [2 October 2008 14:13 UTC](https://discourse.openehr.org/t/aql-querying-by-internal-code/15831 "2008-10-02T14:13:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Greg\_Caulton](https://discourse.openehr.org/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@Greg\_Caulton](https://discourse.openehr.org/u/Greg_Caulton)
#### Post date: [2 October 2008 14:13 UTC](https://discourse.openehr.org/t/aql-querying-by-internal-code/15831/1 "2008-10-02T14:13:04Z")

</div>

Will the AQL queries qualifying on Archetype internal codes do so  
using the value of the code and if so will it use the full path to  
that value.

For example if we wanted to find all patients with pupils observed to  
be sluggish/slow would the query be:

Select pupils

> From EHR e CONTAINS Composition anyComposition CONTAINS Observation

pupils[openEHR-EHR-OBSERVATION.pupils.v1]  
Where  
pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value =  
pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value/defining\_code/[at0016]

where [at0016] is the internal code for that archetype.

I couldn't find an example on the wiki.

thanks!

Greg

---

<div class="post-metadata">

### Author: ![Heath\_Frankel3](https://discourse.openehr.org/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@Heath\_Frankel3](https://discourse.openehr.org/u/Heath_Frankel3)
#### Post date: [3 October 2008 02:34 UTC](https://discourse.openehr.org/t/aql-querying-by-internal-code/15831/2 "2008-10-03T02:34:46Z")

</div>

Hi Greg,  
If I understand your requirement correctly the following is the correct AQL  
(take note of the RM class capitalisation):

Select pupils

> From EHR e CONTAINS COMPOSITION anyComposition CONTAINS OBSERVATION

pupils[openEHR-EHR-OBSERVATION.pupils.v1]  
Where  
pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value/defining\_co  
de/code\_string = 'at0016'

A possible variation of the WHERE expression is as follows:

Where  
pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value/defining\_co  
de = 'local::at0016'

Regards

Heath

> From: openehr-technical-bounces@openehr.org [mailto:openehr-technical-  
> bounces@openehr.org] On Behalf Of Greg Caulton  
> Sent: Thursday, 2 October 2008 11:43 PM  
> To: For openEHR technical discussions  
> Subject: AQL querying by internal code
> 
> Will the AQL queries qualifying on Archetype internal codes do so  
> using the value of the code and if so will it use the full path to  
> that value.
> 
> For example if we wanted to find all patients with pupils observed to  
> be sluggish/slow would the query be:
> 
> Select pupils  
> \>From EHR e CONTAINS Composition anyComposition CONTAINS Observation  
> pupils[openEHR-EHR-OBSERVATION.pupils.v1]  
> Where  
> pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value =

pupils/data/events[at0002]/data/rows[at0013]/items[at0015]/value/defining\_co  
de
