{
"openapi": "3.1.1",
"info": {
"title": "Query API",
"version": "latest",
"x-status": "STABLE",
"x-spec": "query",
"contact": {
"name": "Specifications Editorial Committee openEHR",
"url": "https://specifications.openehr.org/",
"email": "info@openehr.org"
},
"license": {
"name": "Creative Commons Attribution-NoDerivs 3.0 Unported",
"url": "https://creativecommons.org/licenses/by-nd/3.0/"
}
},
"security": [],
"servers": [
{
"url": "https://{baseUrl}/v1",
"description": "An example openEHR server URL.",
"variables": {
"baseUrl": {
"default": "openEHRSys.example.com",
"description": "The (example) server base URL prefix providing openEHR services. This may contain server name, port and base path prefix."
}
}
}
],
"paths": {
"/query/aql": {
"get": {
"operationId": "query_execute_adhoc_query",
"summary": "Execute ad-hoc AQL",
"description": "Execute a given ad-hoc AQL query, supplied by `q` parameter, fetching `fetch` numbers of rows from `offset` and passing `query_parameters` to the underlying query engine.\n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n",
"tags": [
"Query"
],
"parameters": [
{
"$ref": "#/components/parameters/q"
},
{
"$ref": "#/components/parameters/ehr_id_Query"
},
{
"$ref": "#/components/parameters/offset"
},
{
"$ref": "#/components/parameters/fetch"
},
{
"$ref": "#/components/parameters/query_parameters"
}
],
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
},
"post": {
"operationId": "query_execute_adhoc_query_body",
"summary": "Execute ad-hoc AQL (POST)",
"description": "Execute a given ad-hoc AQL query, supplied by `q` attribute, fetching `fetch` numbers of rows from `offset` and passing `query_parameters` to the underlying query engine.\n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n",
"tags": [
"Query"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AdhocQueryExecute"
}
}
},
"required": true
},
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
}
},
"/query/{qualified_query_name}": {
"get": {
"operationId": "query_execute_stored_query",
"summary": "Execute stored AQL",
"description": "Execute a stored query, identified by the supplied `qualified_query_name` (at latest version), fetching `fetch` numbers of rows from `offset` and passing `query_parameters` to the underlying query engine.\n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n\nQueries can be stored or, once stored, their definition can be retrieved using the [definition endpoint](definition.html#tag/Query).\n",
"tags": [
"Query"
],
"parameters": [
{
"$ref": "#/components/parameters/qualified_query_name"
},
{
"$ref": "#/components/parameters/ehr_id_Query"
},
{
"$ref": "#/components/parameters/offset"
},
{
"$ref": "#/components/parameters/fetch"
},
{
"$ref": "#/components/parameters/query_parameters"
}
],
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"404": {
"$ref": "#/components/responses/404_Query"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
},
"post": {
"operationId": "query_execute_stored_query_body",
"summary": "Execute stored AQL (POST)",
"description": "Execute a stored query, identified by the supplied `qualified_query_name` (at latest version). \n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n \nQueries can be stored or, once stored, their definition can be retrieved using the [definition endpoint](definition.html#tag/Query).\n",
"tags": [
"Query"
],
"parameters": [
{
"$ref": "#/components/parameters/qualified_query_name"
}
],
"requestBody": {
"description": "Specifications for a stored AQL query execution.\n",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Query"
}
}
},
"required": true
},
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"404": {
"$ref": "#/components/responses/404_Query"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
}
},
"/query/{qualified_query_name}/{version}": {
"get": {
"operationId": "query_execute_stored_query_version",
"summary": "Execute stored AQL version",
"description": "Execute a stored query, identified by the supplied `qualified_query_name` (at specified `version`), fetching `fetch` numbers of rows from `offset` and passing `query_parameters` to the underlying query engine.\n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n\nQueries can be stored or, once stored, their definition can be retrieved using the [definition endpoint](definition.html#tag/Query).\n",
"tags": [
"Query"
],
"parameters": [
{
"$ref": "#/components/parameters/qualified_query_name"
},
{
"$ref": "#/components/parameters/version"
},
{
"$ref": "#/components/parameters/ehr_id_Query"
},
{
"$ref": "#/components/parameters/offset"
},
{
"$ref": "#/components/parameters/fetch"
},
{
"$ref": "#/components/parameters/query_parameters"
}
],
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"404": {
"$ref": "#/components/responses/404_Query_version"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
},
"post": {
"operationId": "query_execute_stored_query_version_body",
"summary": "Execute stored AQL version (POST)",
"description": "Execute a stored query, identified by the supplied `qualified_query_name` (at specified `version`). \n\nSee also details on usage of [query parameters](query.html#tag/Request/Common-Headers-and-Query-Parameters).\n \nQueries can be stored or, once stored, their definition can be retrieved using the [definition endpoint](definition.html#tag/Query).\n",
"tags": [
"Query"
],
"parameters": [
{
"$ref": "#/components/parameters/qualified_query_name"
},
{
"$ref": "#/components/parameters/version"
}
],
"requestBody": {
"description": "Specifications for a stored AQL query execution.\n",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Query"
}
}
},
"required": true
},
"responses": {
"200": {
"$ref": "#/components/responses/200_Query"
},
"400": {
"$ref": "#/components/responses/400_Query"
},
"404": {
"$ref": "#/components/responses/404_Query_version"
},
"408": {
"$ref": "#/components/responses/408_Query"
}
}
}
}
},
"tags": [
{
"name": "Query_types",
"x-displayName": "Query types",
"description": "[comment]: # (title: Query types)\n\n## Single EHR queries\n\nA common use-case is to execute queries within a specific EHR. \n\nThis is achieved by supplying a `ehr_id` query parameter or setting a `openEHR-EHR-id` request header.\n\n\n## Population queries\n\nPopulation queries are queries which are executed on several EHRs in the same request.\nThese queries are not referring or using any `ehr_id` parameter to constrain the scope on a specific EHR. \n\nExamples of use-cases can be:\n- Ward lists,\n- Explore correlations between patients in a pandemic situation,\n- Research, e.g. epidemiology, population health.\n\n\n## Stored queries\n\nStored queries are queries which have their definition stored (registered) on the server. \nThese are identified by their [qualified name and version](#tag/Qualified_query_name).\n\nUsing stored queries has several of advantages:\n- separation of responsibilities (some users/developers write queries, others just call/execute them and consume the responses),\n- no need to pass long query string over the network.\n\nQueries can be stored or, once stored, their definition can be retrieved using the [definition endpoint](definition.html#tag/Query).\n\n\n## Ad-hoc queries\n\nAs opposed to stored queries, ad-hoc type queries does not have their definitions stored on the server, neither any associated identifier.\nThese queries will be executed as-is, as part request body or query parameter, by the [Execute ad-hoc AQL](#tag/Query/operation/query_execute_adhoc_query) operation endpoint. \n"
},
{
"name": "Qualified_query_name",
"x-displayName": "Qualified query name",
"description": "[comment]: # (title: Qualified query name)\n\nStored queries are identified by their name, used as `qualified_query_name`, and an optional `version` number.\n\nUsually a `qualified_query_name` has a format of `[{namespace}::]{query-name}`.\n\nThe `namespace` is optional, and when used it should be in a form of a reverse domain name, which allows for separation of use of stored queries by teams, companies, etc.\nThe `query-name` may include any combination of characters, matched by the pattern `[a-zA-Z0-9_.-]`. \n\nExamples of valid `qualified_query_name`:\n- `org.openehr::my_compositions`\n- `my_compositions`\n- `ehr::all_influenza_vacc_candidates`\n\nThe `version` identifier is in the format specified by [SEMVER](https://semver.org/) style (i.e. `major.minor.patch`).\nWhen only a partial `version` pattern is supplied, or when `version` is not supplied at all, the system must use the latest `version` with the supplied prefix - i.e. if only `major` or `major.minor` is used, then the latest query version matching supplied prefix will be used.\n\n"
},
{
"name": "Request",
"x-displayName": "Request details",
"description": "[comment]: # (title: Request details)\n\nBelow is a mostly self-documented AQL query in a request body.\n\n```json\n{\n \"q\": \"SELECT o/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value/magnitude AS temperature, o/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value/units AS unit FROM EHR[ehr_id/value='554f896d-faca-4513-bddf-664541146308d'] CONTAINS Observation o[openEHR-EHR-OBSERVATION.body_temperature-zn.v1] WHERE o/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value/magnitude > $temperature AND o/data[at0002]/events[at0003]/data[at0001]/items[at0.63 and name/value='Symptoms']/value/defining_code/code_string=$chills ORDER BY temperature DESC FETCH 3\",\n \"query_parameters\": {\n \"temperature\": 38.5,\n \"chills\": \"at0.64\"\n }\n}\n```\n\n## GET vs POST\n\nRequests based on the `GET` method have URI length restriction, or some characters might not be allowed and have to be encoded.\nLong queries in the `q` parameter and having a long list of `query_parameters` may add up to reach that limit, thus we recommend clients using the `POST` method instead of `GET`.\n\n# Common Headers and Query Parameters \n\nAll query execution requests SHOULD support at least the following parameters:\n- `ehr_id` - used to execute the query within a single EHR context: an EHR identifier taken from EHR.ehr_id.value\n- `offset` - used for paging: the row number in result to start result-set from (`0`-based); default `0`\n- `fetch` - used for paging: the number of rows to fetch (i.e. limit); default depends on the implementation, but cannot be combined with [AQL-top](https://specifications.openehr.org/releases/QUERY/latest/AQL.html#_top)\n- other parameter(s) to replace placeholder(s) within the query, here generically named `query_parameters` (see [below](#tag/Request/Common-Headers-and-Query-Parameters/Query-parameters)).\n\nRelated request headers:\n- `openEHR-EHR-id` - used to execute the query within a single EHR context: an EHR identifier taken from EHR.ehr_id.value\n\nRelated response headers:\n- `ETag` - A unique identifier of the resultSet\n\n\n## About the ehr_id parameter\n\nThe `ehr_id` parameter SHOULD be supplied by clients when executing single EHR queries and MAY be used by the underlying backend to perform routing, optimizations or similar. It MUST NOT be supplied for 'population queries' and similar multi-patient queries.\n\nDepending on the needs, clients MAY supply it as a query parameter `ehr_id` or alternatively as a request header named `openEHR-EHR-id`.\n\n\n## Query parameters\n\nDepending on each query definition, various query parameters SHOULD be supported, generically named `query_parameters`\nin this specification, but in the real request they will have specific names (e.g. `uid`, `systolic_bp`, etc.)\naccording to their names in the query definition.\n\nProvided query parameters SHOULD NOT be prefixed with `$` sign. Instead, the server will (whenever necessary)\nadd the prefix or format queries as valid AQL queries.\n\nAs an example, for the following AQL query\n```\nSELECT c/name/value FROM COMPOSITION c WHERE c/uid/value = $uid\n```\nnamed as `'myQuery'`, the client can supply the `uid` as a query parameter:\n```\nGET https://openEHRSys.example.com/v1/query/myQuery?uid=90910cf0-66a0-4382-b1f8-c0f27e81b42d::openEHRSys.example.com::1\n```\n\nAs another example, the request\n```\nGET https://openEHRSys.example.com/v1/query/com.vendor::compositions?temperature_from=36&temperature_unit=Cel\n```\nwill pass query parameters `temperature_from` and `temperature_unit` to the underlying AQL query named `com.vendor::compositions`.\n\nSee [AQL-parameters](https://specifications.openehr.org/releases/QUERY/latest/AQL.html#_parameters) specification for more details.\n\n"
},
{
"name": "Response",
"x-displayName": "Response details",
"description": "[comment]: # (title: Response details)\n\n## RESULT_SET response\n\nBelow is a synthesized RESULT_SET response with all attributes.\n\n