AQL Syntax Description
Overview
AQL has five clauses: SELECT, FROM, WHERE, and ORDER BY. The SELECT clause specifies the data elements to be returned. The FROM clause specifies the result source and the corresponding containment criteria. The WHERE clause specifies data value criteria within the result source. The ORDER BY clause indicates the data items used to order the returned result set.
In AQL, openEHR path syntax is used to locate any node or data values defined within archetypes. In the SELECT clause, the openEHR path syntax can be used to indicate expected objects or data values to be returned (similarly to how SQL 'projections' work). The FROM clause uses containment mechanisms indicating the scope of the query data source. WHERE clause uses archetype path to set query criteria on archetypes or any node within the archetypes. The following sections introduce the AQL syntax in detail.
If no ORDER BY clause is specified, then the query result doesn’t have any default ordering criteria defined by this specification. Ordering could be defined by each implementation or be random. In terms of compliance to this specification, default ordering in results is undefined.
|
Reserved words and characters
Keywords in AQL are not case sensitive, so SELECT, Select, select, SeLeCt, etc. are processed in the same way. AQL has the following reserved keywords and characters:
-
SELECT,FROM,WHERE,ORDER BY -
TOP,AND,OR,NOT,CONTAINS -
max,now,current-date,current-date-time -
matches,in,exists,not in -
"and': double and single quote characters are used to delimit string values; -
|: bar characters are used to delimit intervals; -
[]: brackets are used to delimit coded terms, archetype id values or openEHR reference model class attribute values. -
{}: brackets are used withmatchesdelimiting matches criteria -
<,>,=,%,!,$
openEHR path syntax
The openEHR path syntax has been described in detail (see the Architecture Overview specification). AQL utilises the basic openEHR path syntax to reference both coarse-grainedand fine-grained archetype nodes (objects and data values, respectively), and openEHR class instances and attributes, when referencing something that is not defined in an archetype but is part of the openEHR Reference Model. A set of openEHR path examples are provided on this section.
openEHR path examples - archetype path
An archetype path is the path referring to any node within an archetype. The following is an ADL workbench screen shot of apgar observation node map. The table below shows some examples.
| Archetype RM type | Archetype node name | Archetype ID | Path syntax | Referenced RM Type |
|---|---|---|---|---|
|
Apgar score |
openEHR-EHR-OBSERVATION.apgar.v1 |
|
|
|
Heart rate |
openEHR-EHR-OBSERVATION.pulse.v1 |
|
|
|
Systolic |
openEHR-EHR-OBSERVATION.blood_pressure.v2 |
|
|
openEHR path examples - path to RM class attributes
Another type of openEHR path is the path pointing to an attribute of openEHR Reference Model classes. The examples shown below uses the attributes from the COMPOSITION class.
| openEHR RM attribute name | Path syntax |
|---|---|
|
|
|
|
|
|
AQL variables
AQL variables are used to refer a specific openEHR class defined within an AQL FROM clause. Consider the following example:
SELECT
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/magnitude,
o/data[at0001]/events[at0006]/data[at0003]/items[at0005]/value/magnitude
FROM
EHR [ehr_id/value='1234']
CONTAINS COMPOSITION [openEHR-EHR-COMPOSITION.encounter.v1]
CONTAINS OBSERVATION o [openEHR-EHR-OBSERVATION.blood_pressure.v1]
WHERE
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/magnitude >= 140 OR
o/data[at0001]/events[at0006]/data[at0003]/items[at0005]/value/magnitude >= 90
This example defines only one AQL variable: o, which represents OBSERVATIONs that conform to (i.e. created using) the openEHR-EHR-OBSERVATION.blood_pressure.v1 archetype.
AQL variables have the following features:
-
AQL variable names are defined in the AQL
FROMclause. -
A variable name must be unique within an AQL statement.
-
Not all classes defined within the
FROMclause need a variable name. It is required only when other AQL clauses need to refer to the class identified in theFROMclause. The example above doesn’t define a variable name for theEHRorCOMPOSITIONclasses, only for theOBSERVATIONclass (variableo), to allow the latter to be referred to in theWHEREandSELECTclauses, as the root object of specific paths.
The combination of a variable reference and a subordinate path forms one kind of identified path (see AQL Identified Paths), used to specify a fine-grained data element within a larger object matched by the FROM clause. In the above example, o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/magnitude specifies the systolic value of the Observation archetype openEHR-EHR-OBSERVATION.blood_pressure.v1.
A variable name is formed of an initial letter followed by any number of alphanumerics and underscores, as long as it does not clash with a reserved word. Variable names are not case-sensitive. Digits are not recommended at the beginning of a variable name although there is no formal restriction.
Parameters
AQL syntax supports parameterisation. AQL parameters are used to indicate criteria, which will be substituted with values at run time. Supporting parameterisation is one of the mechanisms used to realise sharing AQL statements within a system or across system boundaries.
The parameters can be EHR specific (such as the parameter of EHR identifier or EHR creation date/time), archetype specific (such as an archetype identifier, or archetype constraints), or template specific (such as a template identifier or template constraints).
Parameter syntax
A parameter always starts with a dollar sign $ followed by the parameter name, e.g. $ehrUid. The parameter name can consist of letters, digits and underscores. It cannot have spaces and it cannot be an AQL reserved word.
A parameter can be used for any criteria values within an AQL statement, e.g.:
-
within a predicate:
[$archetypeId],[at0003, $nameValue],[ehr_id/value=$ehrId] -
withing a WHERE criteria:
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/value > $systolicCriteria
In the WHERE criteria, when the value of the parameter is not a number or boolean value, it should be substituted with the corresponding quotes added to the value, for instance o/../.. = $textVariable, when substituted should look like this o/../.. = "value" (single or double quotes could be used). So substituted values follow the same rules as each type when the value is specified as a constant in the AQL expression: strings, dates, times and datetimes should be quoted, numbers and booleans are not quoted.
|
When parameters are needed
Parameters are needed when the same AQL query statement is used with different criteria values. This AQL example is to return all abnormal blood pressure values for a single specific EHR. This query has a parameter $ehrUid. This parameter will be substituted by a specific EHR.ehr_id value at run time. Consequently, this query can be reused for all EHRs either within an EHR system or by other EHR systems (assuming these EHR systems support AQL).
Where and how parameters are resolved
AQL query parameters can be resolved at application level, or EHR system level. It depends on what the query parameters are used for and the design/implementation of the system or components. Query parameters would be normally resolved outside of a query engine.
If a query needs to be reusable across different EHR systems, any query parameters normally need to be registered in these EHR systems so that they can be resolved with real values from each environment. A typical example of this type of query parameter is $ehrUid. If the query is only used within an application, then the query parameters would be resolved by the application, such as the parameter of healthcare facility identifier or template identifier.
There are no specific guidelines on how to resolve query parameters. Generally speaking, a parameter name is used as a key (or a key is associated with a parameter name) and the key needs to be unique within the boundary where the parameters are resolved. The EHR system or application needs to have the API functions to get the real value with a given parameter name or key.
Predicates
AQL has three types of predicates: the standard predicate, the archetype predicate, and the node predicate.
Standard predicate
Standard predicates always have a left operand, operator and right operand, e.g. [ehr_id/value='123456'].
-
The left operand is normally an openEHR path, such as
ehr_id/value,name/value. -
The right operand is normally a criterion value or a parameter, such as
'123456',$ehrUid. It can also be an openEHR path (based on the BNF). -
The operator can be one of the following:
>, >=, =, <, <=, !=
Archetype predicate
An archetype predicate is a shortcut of a standard predicate, i.e. the predicate does not have the left operand and operator. It only has an archetype id, e.g. [openEHR-EHR-COMPOSITION.encounter.v1]. The archetype predicate is a specific type of query criterion indicating which archetype instances are relevant to this query. It is used to scope the data source from which the query result data is to be retrieved. Therefore, an archetype predicate is only used within an AQL FROM clause, for example,
FROM EHR [ehr_id/value='1234']
CONTAINS COMPOSITION c [openEHR-EHR-COMPOSITION.encounter.v1]
CONTAINS OBSERVATION o [openEHR-EHR-OBSERVATION.blood_pressure.v1]
This predicates could also be written as Standard predicates:
FROM EHR e
CONTAINS COMPOSITION c
CONTAINS OBSERVATION o
WHERE
e/ehr_id/value = '1234' AND
c/archetype_node_id = 'openEHR-EHR-COMPOSITION.encounter.v1' AND
o/archetype_node_id = 'openEHR-EHR-OBSERVATION.blood_pressure.v1'
This equivalence could be used by implementers of AQL to transform predicates into their standard form, as a canonical representation of the query, which can simplified its processing, validation, evaluation and transformation into specific database query languages.
Node predicate
A node predicate is also a shortcut of a standard predicate. It has the following forms:
-
Containing an
archetype_node_id(i.e. an at-code) only, e.g.:[at0002]The corresponding standard predicate would be:
[archetype_node_id=at0002] -
Containing an
archetype_node_idand aname value/criterion, e.g.:[at0002 and name/value=$nameValue] [at0002 and name/value='real name value']The corresponding standard predicates would be:
[archetype_node_id=at0002 and name/value=$nameValue] [archetype_node_id=at0002 and name/value='real name value'] -
Containing an
archetype_node_idand a shortcut of aname/valuecriterion, e.g.:[at0002, $nameValue] [at0002, 'real name value']The corresponding standard predicates would be:
[archetype_node_id=at0002 and name/value=$nameValue] [archetype_node_id=at0002 and name/value='real name value'] -
The above three forms are the most common node predicates. A more advanced form is to include a general criterion instead of the
name/valuecriterion within the predicate. The general criterion consists of left operand, operator, and right operand, e.g.:[at0002 and value/defining_code/terminology_id/value=$terminologyId]
A node predicate defines criteria on fine-grained data.
Operators
Comparison operators
The table below shows the supported AQL comparison operators, meaning and example.
| Operator | Meaning | Example |
|---|---|---|
= |
Equal |
|
> |
Greater than |
|
>= |
Greater than or equal to |
|
< |
Smaller than |
|
<= |
Smaller than or equal to |
|
!= |
not equals to |
|
matches |
advanced matcher |
|
matches operator definition
The matches binary operator is used in the WHERE clause. The left operand is an AQL identified path. The right operand is enclosed within braces ('{}'), and may take the following forms:
-
cADL list constraint: a comma-separated value list, which is one of the cADL constraint forms used in the Archetype Definition Language (ADL). Below is an example using a string value list:
SELECT o/data[at0002]/events[at0003]/data/items[at0015]/items[at0018]/name FROM EHR [uid=$ehrUid] CONTAINS Composition c CONTAINS Observation o[openEHR-EHR-OBSERVATION.microbiology.v1] WHERE o/data[at0002]/events[at0003]/data/items[at0015]/items[at0018]/items[at0019]/items[at0021]/name/defining_code/code_string matches {'18919-1', '18961-3', '19000-9'}Value list items may be of type string, date/time, integer, or real. Quotes are required for strings and date/times.
A value list is only used in AQL
WHEREclause when the criteria is to match one item of the list. The relationships among these value list items are "OR".Some examples of value list:
matches {'string item 1', 'string item 2', 'string item3'} // A string list, equivalent to // matches 'string item1' or .. // matches 'string item 2' or .. // matches 'string item 3' matches {'2006-01-01', '2007-01-01', '2008-01-01'} // a date value list matches {1, 2, 3} // an integer list matches {1.1, 2.5, 3.8} // a real value list -
URI: can be a terminology URI, openEHR EHR URI, or other URI. An example with a terminology URI is shown below:
SELECT e/ehr_status/subject/external_ref/id/value, diagnosis/data/items[at0002.1]/value FROM EHR e CONTAINS Composition c[openEHR-EHR-COMPOSITION.problem_list.v1] CONTAINS Evaluation diagnosis[openEHR-EHR-EVALUATION.problem-diagnosis.v1] WHERE c/name/value='Current Problems' AND diagnosis/data/items[at0002.1]/value/defining_code matches { terminology://snomed-ct/hierarchy?rootConceptId=50043002 }URI data is enclosed within curly braces after
matchesoperator. A URI is expressed in IETF RFC 3986 format. URIs are not case sensitive.A terminology URI consists of the following components:
-
terminology: the URI schemes value;
-
terminology service: the URI authority value, such as SNOMED-CT;
-
terminology function name: the URI path, e.g. "hierarchy" is the function name in the example shown below;
-
argument values required by the terminology functions - URI queries;
This is an example of a terminology URI:
terminology://snomed-CT/hierarchy?rootConceptId=50043002 \_________/ \_______/ \_______/ \___________/ \______/ | | | |__________| scheme authority path | queries | | | | | | terminology terminology function argument argument uri service name value
-
Logical operators
AND
AND is a binary boolean operator used to link two boolean expressions. It evaluates to true when both operands evaluate to true, and it evaluates to false otherwise.
OR
OR is a binary boolean operator used to link two boolean expressions. It evaluates to true when any of the operands evaluate to true, and it evaluates to false otherwise.
NOT
NOT is a unary Boolean operator which is always followed by either a Boolean identified expression (see Identified expression) or other Boolean-valued operand, such as an expression using the EXISTS operator. It returns a Boolean result: true means the operand is false. A NOT expression is a kind of identified expression (see below).
The example below uses NOT operator followed by a Boolean identified expression:
SELECT
e/ehr_id/value
FROM
EHR e
CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.administrative_encounter.v1]
CONTAINS ADMIN_ENTRY admission[openEHR-EHR-ADMIN_ENTRY.admission.v1]
WHERE
NOT (EXISTS c/content[openEHR-EHR-ADMIN_ENTRY.discharge.v1] AND
e/ehr_status/subject/external_ref/namespace = 'CEC')
The above example is equivalent to the two expressions shown in the following WHERE clause:
SELECT
e/ehr_id/value
FROM
EHR e
CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.administrative_encounter.v1]
CONTAINS ADMIN_ENTRY admission[openEHR-EHR-ADMIN_ENTRY.admission.v1]
WHERE
NOT EXISTS c/content[openEHR-EHR-ADMIN_ENTRY.discharge.v1] OR
e/ehr_status/subject/external_ref/namespace != 'CEC'
These advanced operators are not yet supported by the grammar. The operator syntax is borrowed from ADL specifications. These are proposed to improve the richness and flexibility of AQL so that AQL syntax supports more complicated query scenarios.
EXISTS
EXISTS is a unary operator, whose operand is an identified path (described in AQL Identified Paths). It returns a Boolean result: true means the data associated with the specified path exists, false otherwise. An EXISTS expression is a kind of identified expression (see below).
In the AQL example below, EXISTS is used in negated form to filter out COMPOSITIONs (and therefore EHRs) that do not contain a discharge ADMIN_ENTRY instance:
SELECT
e/ehr_id/value
FROM
EHR e
CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.administrative_encounter.v1]
CONTAINS ADMIN_ENTRY admission[openEHR-EHR-ADMIN_ENTRY.admission.v1]
WHERE
NOT EXISTS c/content[openEHR-EHR-ADMIN_ENTRY.discharge.v1]
AQL Identified Paths
Usage
In AQL, an identified path is the association of a variable reference (the identifier; see above) and an archetype path and/or predicate. Except for the FROM clause, an identified path may appear in any clause of an AQL statement. For example, it can be used to indicate the data to be returned in a SELECT clause, or the data item on which query criteria are applied in a WHERE clause.
Syntax
An AQL identified path can take any of the following forms:
-
a variable name defined in the
FROMclause followed by an archetype path, which specifies a data item at that path within the object, as follows:o/data[at0001]/.../data[at0003]/items[at0004]/value/value -
a variable name followed by a predicate, which specifies an object that satisfies the predicate, as follows:
o[name/value=$nameValue] -
a variable name followed by a predicate and an archetype path, which specifies a data item at a path within an object satisfying the predicate, as follows:
o[name/value=$nameValue]/data[at0001]/.../data[at0003]/items[at0004]/value/value
Built-in Types
Integer data
Integers are represented as numeric literals, such as 1, 2, 365. Commas or periods for breaking long numbers are not allowed. Hexadecimal representation is not supported.
Real data
Real numbers are the decimal literals that include a decimal point, such as 3.1415926. Commas or periods for breaking long numbers are not allowed.
Boolean data
Boolean values are indicated using the case-insensitive literals true or false.
String Data
All strings are enclosed in double or single quotes. Line breaks are not supported.
Dates and Times
These types are treated as strings and should comply with the rules for string quoting. The format of the date, time and datetime types should comply with the ISO 8601 Date and Time format specification, which allow the basic or extended formats to be used. In the openEHR specification it is recommended to use the extended format for dates, times and datetimes. Complete or partial values are allowed.
| The underlying types of date/time strings are inferred by the AQL processor from the context (metadata associated with the path to which the date/time value is compared with, or by interpretation of the ISO 8601 format), enabling them to be processed as date/time quantities rather than literal strings by AQL engines. |
Examples are as below:
WHERE composition/context/start_time <= '1986-01-01' // complete date in ISO 8601 extended format. AQL grammar identifies this value as a date value.
WHERE composition/context/start_time > '19860101' // a complete date in ISO 8601 basic format. AQL grammar identifies it as a string value.
WHERE composition/context/start_time < "12:00:00+0930" // ISO 8601 time extended format. AQL grammar identifies it as a string value.
Query structure
Overview
AQL structure was briefly introduced in [_aql_example]. This section describes the syntax in more formal detail. An AQL query may include the following clauses which must occur in the order shown.
-
SELECT(mandatory) -
FROM(mandatory) -
WHERE(optional) -
ORDER BY(optional)
An AQL statement must at least contain the SELECT and FROM clauses.
FROM
The FROM clause is used to specify the subset of all the data available in a repository,
that will be available for the rest of the clauses to filter and return specific data (WHERE, SELECT, etc).
The data available should be defined by an information model, known here as the Reference Model (RM), that supports the use of archetype- and template-based constraint models, as described in the openEHR Architecture Overview and the Archetype Technology Overview.
All the classes referenced by the FROM clause should be defined by the RM. For instance,
if the Reference Model is the openEHR Reference Model, the FROM clause should only include classes like
EHR, COMPOSITION, OBSERVATION, EVALUATION, and so on.
| The AQL specification is not bound to a specific Reference Model, but to use a given RM, it should comply with some requirements: it should be an Object Oriented Model and should follow the dual-model approach. |
Then, the expressions in the WHERE clause will filter data, but only from the subset
defined by the FROM clause. And in the SELECT clause, a final projection is applied,
selecting only the matched data that should be retrieved in the query result. In addition
to the filtering done in the WHERE clause, the class expressions could hold predicates
that also allow filtering data.
In summary:
-
FROM: Defines the subset of data over which the query will be executed; -
WHERE: Filters data from the defined subset, leaving only the data that we need; -
predicates in class expressions: further filters for data in the subset;
-
SELECT: picks the exact data that we need to return from the query, taken from the matched data in the previous two points.
FROM Syntax
A simple FROM clause consists of three parts: keyword FROM, class expression and/or containment constraints, e.g.
FROM
EHR e [ehr_id/value=$ehrId]
CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.report.v1]
Class expressions
Two examples of a class expression are shown below:
-- EHR class, class identifier/variable, and a standard predicate
EHR e [ehr_id/value=$ehrId]
-- COMPOSITION class, class identifier/variable, and an archetype predicate
COMPOSITION c[openEHR-EHR-COMPOSITION.report.v1]
Class expressions are used for two purposes:
-
indicating the constraints on RM classes so as to scope the data source for the query. For instance,
EHR e[ehr_id/value='123456']indicates that the required data must be from a specific EHR withehr_idvalue'123456'; whileCOMPOSITION c[openEHR-EHR-COMPOSITION.report.v1]indicates the required data must be from or must be associated with a Composition instance with archetype id -openEHR-EHR-COMPOSITION.report.v1. -
defining an RM class variable that may be used by other clauses to indicate the required data or data items on which query criteria are applied. The example below uses the class expression to define a variable e which is used by the
SELECTclause indicating all relevantehr_idvalues are retrieved, and a variablecused by theWHEREclause indicating that the query criteria is set on the Compositiontemplate_idvalue.SELECT e/ehr_id/value FROM EHR e CONTAINS COMPOSITION c[openEHR-EHR-COMPOSITION.referral.v1] WHERE c/archetype_details/template_id/value = $templateId
Class expressions syntax include three parts. A class expression must have part one and at least one of part two or part three.
-
part one (mandatory): openEHR RM class name, such as
EHR,COMPOSITION,OBSERVATIONetc. -
part two (optional): AQL variable name
-
part three (optional): a standard predicate or an archetype predicate.
Containment
Since archetypes are in hierarchical structure, AQL has a containment constraint which specifies the hierarchical relationships between parent and child data items. The FROM clause utilises this hierarchical constraint along with class expression to determine the data source to which the AQL query is applied.
The syntax of containment constraint is very simple: using keyword CONTAINS between two class expressions. Left class expression is the the parent object of the right class expression, e.g.
EHR e CONTAINS COMPOSITION c [openEHR-EHR-COMPOSITION.referral.v1]
Boolean operators (AND, OR, NOT) and parentheses are used when multiple containment constrains are required, e.g.
EHR e
CONTAINS COMPOSITION c [openEHR-EHR-COMPOSITION.referral.v1] AND COMPOSITION c1 [openEHR-EHR-COMPOSITION.report.v1]
EHR e
CONTAINS COMPOSITION c [openEHR-EHR-COMPOSITION.referral.v1]
CONTAINS (OBSERVATION o [openEHR-EHR-OBSERVATION-laboratory-hba1c.v1] AND OBSERVATION o1 [openEHR-EHR-OBSERVATION-laboratory-glucose.v1])
WHERE
An AQL WHERE clause is used to represent further criteria applied to the data items within the objects declared in the FROM clause. A WHERE clause expresses the query criteria that cannot be represented in other AQL clauses, such as criteria on archetype id, composition committal date/time, and the criteria on in which order the returned results should be listed.
Syntax
The WHERE clause syntax has the following parts (in order): keyword WHERE and identified expression(s). Boolean operators (AND, OR, NOT) and parenthesis can be used to represent multiple identified expressions. Examples:
WHERE
c/name/value=$nameValue AND c/archetype_details/template_id/value=$templateId
WHERE
(c/name/value = $nameValue OR c/archetype_details/template_id/value = $templateId) AND
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/value >= 140
Identified expression
An identified expression specifies matching criteria in the WHERE clause and comes in two forms. The first form is an expression formed by a unary operator, such as NOT or EXISTS, described earlier. The second is a binary operator expression, formed as follows:
-
left operand: an identified path;
-
operator: a comparison operator;
-
right operand: one of:
-
a value criterion, normally of a primitive type, such as
String,Integer,Boolean,Double, orFloat; if aStringvalue, single or double quotation marks are required; OR -
a replaceable parameter (identified with the
'$'symbol); OR -
an identified path.
-
The following examples illustrate the binary form.
-
Left operand is an identified path; right operand is a primitive value:
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/value >= 140 c/archetype_details/template_id/value = 'health_encounter' -
Left operand is an identified path and right operand is a parameter:
c/archetype_details/template_id/value = $templateParameter -
Both left operand and right operand are identified paths:
o/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/value > o1/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value/value
SELECT
A SELECT clause specifies what data is to be retrieved by the AQL query. The data can be any types from openEHR RM and any primitive data types. In addition, the SELECT clause uses TOP to indicate the number of result sets that should be returned and name alias to rename the retrieved data.
The SELECT syntax always starts with the keyword SELECT, followed by TOP (optional), and identified path(s) or plain variable name(s) defined in the FROM clause. Each variable name or identified path may have a name alias renaming the associated data.
Where a variable name is specified, the full object of the type associated with the variable is retrieved, such as a COMPOSITION, OBSERVATION etc. Where an identified path is specified, the data item(s) having that archetype path are returned. Multiple identifiers or identified paths are separated using a comma.
Some examples are shown below.
Example 1: retrieve all Compositions' name value, context start time and composer name from a specific EHR.
SELECT
c/name/value AS Name, c/context/start_time AS date_time, c/composer/name AS Composer
FROM
EHR e[ehr_id/value=$ehrUid]
CONTAINS COMPOSITION c
Example 2: Retrieve all Composition objects of a specific EHR.
SELECT c
FROM EHR e[ehr_id/value=$ehrUid]
CONTAINS COMPOSITION c
TOP
The TOP syntax was borrowed from SQL language for representing the number of result sets that should be returned by the AQL query. It uses BACKWARD and FORWARD to indicate the direction where to start to get the number of results to be returned.
It starts with keyword TOP, followed by an integer number and/or the direction (i.e. BACKWARD, FORWARD), e.g.
SELECT
TOP 10 c/name/value AS Name, c/context/start_time AS date_time, c/composer/name AS Composer
FROM
EHR e[ehr_id/value=$ehrUid]
CONTAINS COMPOSITION c
Name alias
As in SQL, AQL supports the use of a name alias for the retrieved data. This is done with the keyword AS, followed by the name which conforms to the syntax rule of AQL variable.
ORDER BY
The ORDER BY clause is used to sort the returned results. The keyword ORDER BY is followed by an identified path and the keyword DESC, DESCENDING, ASCE, or ASCENDING, e.g.
ORDER BY c/name/value