cadasto/openehr-assistant-plugin/aql-authoring
Claude Code and agent skill by cadasto/openehr-assistant-plugin
- community
Checking that the SKILL.md file is still in the repository.
This skill should be used when the user asks to "write an AQL query", "optimize an AQL query", "review AQL", or "query openEHR data" — the multi-step authoring/optimization workflow for AQL (Archetype Query Language) over openEHR clinical data. For a one-off explanation of an existing query or a single AQL keyword/operator (no authoring), the `/openehr-explain` command suffices.
Install
npx vskill@latest install cadasto/openehr-assistant-plugin/aql-authoringSKILL.md
The same SKILL.md was published earlier as cadasto/openehr-assistant-plugin/aql-authoring.
AQL Authoring
The inline syntax below is a quick crib. Theaql/syntaxguide loaded in Step 1 is authoritative — if they ever disagree, follow the guide.
Step 1: Load Guides (MANDATORY)
Before writing or reviewing any AQL query, load the authoritative guides:
Consult worked examples (when applicable)
When the user asks for a query to adapt, or when the clinical question matches a common pattern (cohort selection, pagination with total count, time-window filtering, cross-composition joins, terminology value-set matching, "latest per EHR", ISM-state filtering), try examples_search(kind="aql") before drafting. The curated AQL examples are under openehr://examples/aql/{name} and include pattern metadata and related-spec links — reuse and adapt rather than invent. Skip this step if the question is clearly novel or the user already provided the skeleton.
Step 2: Understand the Data Model
AQL queries operate on archetypes. Before writing a query:
- State assumptions about deployed templates/archetypes — verify path endpoints and RM types against the deployed template, not display labels; when a deployed template is named, fetch it (
ckm_template_search→ckm_template_get) rather than guessing paths - Identify which archetypes contain the required data (
ckm_archetype_searchwhen the archetype id is not yet known) - Load the archetype to understand its path structure:
`` ckm_archetype_get("<archetype-id>") ``
- Use
type_specification_getto clarify RM type details when needed
Step 3: AQL Syntax
Basic Structure
Containment
Define the archetype hierarchy using CONTAINS:
Path Syntax
Navigate archetype structure using at-codes:
EHR Predicates
Filter by patient:
Node Predicates (sibling disambiguation)
When one archetype node repeats as multiple named runtime siblings, add the name to the node predicate (spec-defined shortcuts):
Version-Aware Queries (VERSION in FROM)
Always state [LATEST_VERSION] or [ALL_VERSIONS] explicitly — the no-predicate default is not defined by the spec (implementations commonly return latest only). Version predicates are grammar-level constructs; consult the aql/syntax guide for semantics, engine caveats, and the common v/… projections.
Operators
MATCHES with a {…} value list is spec-normative — prefer it for code-set filters; IN is not in the spec (engine extension). LIKE patterns must match the entire value. Details and edge cases in the aql/syntax guide.
Parameterized Queries
Use $parameter syntax for reusable queries:
Step 4: Common Patterns
Latest Composition by Type
Observations in Date Range
Aggregates
Functions — spec vs engine
Spec-normative aggregates: COUNT, MIN, MAX, SUM, AVG (COUNT/MIN/MAX are the safest across engines). For the spec's single-row function list — and what counts as an engine extension — consult the aql/syntax guide before relying on a function; engine coverage varies.
Step 5: Optimization
- Use specific archetype node IDs in containment (avoid unqualified
CONTAINS OBSERVATION o) - Avoid
SELECT *— select only needed paths - Place most selective WHERE conditions first
- Use parameterized queries for repeated execution
- Consider index-friendly patterns (ehr_id, composition time, archetype node IDs)
- Do not assume engine-specific behavior beyond the AQL specification
Step 6: Review
Run through the AQL checklist:
Verify:
- [ ] Correct containment hierarchy matching the archetype structure
- [ ] Valid archetype paths (matching at-codes from the archetype definition)
- [ ] Proper use of aliases for readability
- [ ] Parameters used for variable values
- [ ] Results ordered meaningfully
- [ ]
MATCHES {…}used instead of engine-onlyIN; functions beyond COUNT/MIN/MAX verified against the target engine - [ ] VERSION containments (if any) state
[LATEST_VERSION]/[ALL_VERSIONS]explicitly - [ ] Query is optimized for the CDR
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/aql-authoring/SKILL.md
Popularity
- Repository stars
- 4
- 7-day trend score
- 8
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cadasto/openehr-assistant-plugin/aql-authoring)