Agent skill

SQL On Fhir

by aehrc in aehrc/pathling

Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data.

Apache-2.0Auto-check passedResearch & Science

Install SQL On Fhir

skills CLI
$ npx skills add aehrc/pathling --skill sql-on-fhir -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install aehrc/pathling sql-on-fhir --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/aehrc/pathling.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/sql-on-fhir .claude/skills/sql-on-fhir && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
sql-on-fhir
GitHub stars
137
Token cost
~2.3k tokens
SKILL.md length
568 words
Files
5 (incl. references)
Skills in repo
25
Repo updated
First seen
Licence
Apache-2.0

At a glance

Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data.

  • Works in 5 steps: Starts at the resource root → Evaluates each path in the repeat array → For each result, recursively applies the… → …
  • The user asks to create ViewDefinitions
  • SKILL.md covers Core Concepts, ViewDefinition Structure, Column Definitions and Row Iteration with forEach, plus 10 more sections
  • Reaches hl7.org

What it does

SQL On Fhir is an agent skill from aehrc/pathling. Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data. Use this skill when the user asks to create ViewDefinitions, flatten FHIR resources into tables, write FHIRPath expressions for data extraction, implement forEach/forEachOrNull/repeat patterns for unnesting, create where clauses for filtering, use constants in view definitions, combine data with unionAll, execute ViewDefinitions with $run or $export operations, or implement SQL on…

Its SKILL.md is about 2.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 5 other files, including reference files (for example `references/examples.md`, `references/fhirpath-subset.md` and `references/operations.md`).

It sits in Research & Science, covering Clinical and healthcare research and SQL. It works with SQL. The repository describes itself as: Tools that make it easier to use FHIR and clinical terminology within data analytics, built on Apache Spark. The licence is Apache-2.0.

When your agent uses it

  • The user asks to create ViewDefinitions
  • Flatten FHIR resources into tables
  • Write FHIRPath expressions for data extraction
  • Implement forEach/forEachOrNull/repeat patterns for unnesting

Example prompts

  • “ViewDefinition”
  • “SQL on FHIR”
  • “flatten FHIR”
  • “/sql-on-fhir”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Starts at the resource root
  2. Evaluates each path in the repeat array
  3. For each result, recursively applies the same paths
  4. Continues until no more matches exist
  5. Unions all results from all levels

What it can do on your machine

Read from SKILL.md and the folder at commit 56a3b4a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are json).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • hl7.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

SQL On Fhir loads about 2.3k tokens when it runs, and up to ~12k if it reads all its reference files. Until then it costs about 202 tokens; SKILL.md has 568 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~202
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~12k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from aehrc/pathling at commit 56a3b4a, republished under its Apache-2.0 licence (© aehrc). 568 words, ~2,338 tokens.

Download SKILL.mdSave it as .claude/skills/sql-on-fhir/SKILL.md (or your agent's skills folder). This skill also uses 4 other files; get the full folder from GitHub.
name
sql-on-fhir
description
Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data. Use this skill when the user asks to create ViewDefinitions, flatten FHIR resources into tables, write FHIRPath expressions for data extraction, implement forEach/forEachOrNull/repeat patterns for unnesting, create where clauses for filtering, use constants in view definitions, combine data with unionAll, execute ViewDefinitions with $run or $export operations, or implement SQL on FHIR server capabilities. Trigger keywords include "ViewDefinition", "SQL on FHIR", "flatten FHIR", "tabular FHIR", "FHIR to SQL", "FHIR analytics", "FHIRPath columns", "unnest FHIR", "$viewdefinition-run", "$export", "view runner", "repeat", "recursive", "QuestionnaireResponse".

SQL on FHIR

SQL on FHIR v2 defines portable, tabular projections of FHIR resources using FHIRPath expressions. ViewDefinitions transform hierarchical FHIR data into flat tables for analytics.

Core Concepts

A ViewDefinition projects exactly one FHIR resource type into rows and columns. It contains:

  • resource: The FHIR resource type (Patient, Observation, etc.)
  • select: Column definitions and row iteration logic
  • where: Optional filtering criteria
  • constant: Reusable values for expressions

ViewDefinition Structure

Basic structure:

json
{
    "resourceType": "ViewDefinition",
    "resource": "Patient",
    "status": "active",
    "select": [
        {
            "column": [
                { "name": "id", "path": "id" },
                { "name": "gender", "path": "gender" },
                { "name": "birth_date", "path": "birthDate" }
            ]
        }
    ]
}

For complete element reference, see references/view-definition-structure.md.

Column Definitions

Each column has:

  • name: Database-friendly identifier (pattern: ^[A-Za-z][A-Za-z0-9_]*$)
  • path: FHIRPath expression extracting the value
  • type (optional): FHIR primitive type URI
  • collection (optional): Set true if column may contain arrays
  • description (optional): Human-readable explanation
json
{
    "column": [
        {
            "name": "family_name",
            "path": "name.first().family",
            "type": "string",
            "description": "Patient's primary family name"
        }
    ]
}

Row Iteration with forEach

Use forEach to create one row per element in a collection. Without forEach, one row per resource is created.

Example: One row per patient name:

json
{
    "resource": "Patient",
    "select": [
        { "column": [{ "name": "id", "path": "id" }] },
        {
            "forEach": "name",
            "column": [
                { "name": "family", "path": "family" },
                { "name": "given", "path": "given.first()" }
            ]
        }
    ]
}

forEachOrNull: Same as forEach but keeps a row with nulls when the collection is empty.

Nested forEach: Create cross-products by nesting:

json
{
    "forEach": "contact",
    "select": [
        {
            "column": [
                {
                    "name": "contact_phone",
                    "path": "telecom.where(system='phone').value"
                }
            ]
        },
        {
            "forEach": "name.given",
            "column": [{ "name": "given_name", "path": "$this" }]
        }
    ]
}

Recursive Traversal with repeat

Use repeat to recursively traverse nested structures to any depth. This is essential for resources with arbitrary nesting like QuestionnaireResponse items.

Constraint: Only one of forEach, forEachOrNull, or repeat may be specified per select.

json
{
    "resource": "QuestionnaireResponse",
    "select": [
        { "column": [{ "name": "response_id", "path": "id" }] },
        {
            "repeat": ["item", "answer.item"],
            "column": [
                { "name": "link_id", "path": "linkId" },
                {
                    "name": "answer_text",
                    "path": "answer.value.ofType(string).first()"
                }
            ]
        }
    ]
}

The view runner:

  1. Starts at the resource root
  2. Evaluates each path in the repeat array
  3. For each result, recursively applies the same paths
  4. Continues until no more matches exist
  5. Unions all results from all levels

This produces a flat table with all items regardless of nesting depth.

Filtering with where

Filter resources using FHIRPath expressions that must evaluate to true:

json
{
  "resource": "Patient",
  "where": [
    {"path": "active = true"},
    {"path": "name.exists()"}
  ],
  "select": [...]
}

Multiple where clauses are ANDed together.

Constants

Define reusable values referenced via %name syntax:

json
{
    "constant": [{ "name": "use_type", "valueString": "official" }],
    "select": [
        {
            "forEach": "name.where(use = %use_type)",
            "column": [{ "name": "official_name", "path": "family" }]
        }
    ]
}

Supported constant types: valueString, valueInteger, valueBoolean, valueDecimal, valueDate, valueDateTime, valueCode.

Combining Data with unionAll

Combine multiple selection paths with matching column schemas:

json
{
    "select": [
        { "column": [{ "name": "id", "path": "id" }] },
        {
            "unionAll": [
                {
                    "forEach": "telecom",
                    "column": [
                        { "name": "contact", "path": "value" },
                        { "name": "system", "path": "system" }
                    ]
                },
                {
                    "forEach": "contact.telecom",
                    "column": [
                        { "name": "contact", "path": "value" },
                        { "name": "system", "path": "system" }
                    ]
                }
            ]
        }
    ]
}

FHIRPath Subset

ViewDefinitions use a minimal FHIRPath subset. Key functions:

FunctionDescription
first()First element of collection
exists()True if collection has elements
empty()True if collection is empty
where(expr)Filter collection by condition
ofType(type)Filter to specific FHIR type
extension(url)Get extension by URL
join(sep)Join collection into string
getResourceKey()Resource ID (indirect access)
getReferenceKey(type?)Extract ID from reference

Path navigation:

  • Dot notation: name.family
  • Indexing: name[0].family
  • $this: Current context element

For complete FHIRPath reference, see references/fhirpath-subset.md.

Show full SKILL.md (190 more words)Show less

Working with Extensions

Extract extension values using the extension() function:

json
{
    "column": [
        {
            "name": "birth_sex",
            "path": "extension('http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex').value.ofType(code).first()"
        }
    ]
}

Nested extensions:

json
{
    "path": "extension('http://hl7.org/fhir/us/core/StructureDefinition/us-core-race').extension('ombCategory').value.ofType(Coding).code.first()"
}

Profiles

ShareableViewDefinition: For portable definitions. Requires:

  • url: Canonical identifier
  • name: Database-safe identifier
  • fhirVersion: Target FHIR version(s)
  • Column type: Explicit types on all columns

TabularViewDefinition: For scalar/CSV output. Enforces:

  • No collection: true columns
  • Primitive types only (string, boolean, integer, etc.)

Design Constraints

ViewDefinitions intentionally exclude:

  • Cross-resource joins (use SQL after flattening)
  • Sorting, aggregation, limits (apply in analytics layer)
  • Output format specification (runner determines format)

Operations

SQL on FHIR defines two operations for executing ViewDefinitions:

$viewdefinition-run

Synchronous execution returning results immediately.

GET  [base]/ViewDefinition/[id]/$run?_format=csv
POST [base]/ViewDefinition/$run

Key parameters:

  • viewReference or viewResource: The ViewDefinition to execute
  • _format: Output format (json, ndjson, csv, parquet)
  • patient, group: Filter by patient/group
  • _limit: Maximum rows
$export

Asynchronous bulk export for large datasets.

POST [base]/ViewDefinition/$export

Uses async pattern:

  1. POST with Prefer: respond-async → 202 Accepted + status URL
  2. Poll status URL until complete
  3. Download results from output URLs

Key parameters:

  • view: One or more ViewDefinitions to export
  • _format: Output format
  • patient, group, _since: Filtering options

For complete operation details, parameters, and examples, see references/operations.md.

Examples

For comprehensive examples including Patient demographics, Condition flattening, blood pressure extraction, and complex unnesting patterns, see references/examples.md.

© aehrc, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 4 other files (references) in .claude/skills/sql-on-fhir of aehrc/pathling.

  • SKILL.md
  • references/examples.md
  • references/fhirpath-subset.md
  • references/operations.md
  • references/view-definition-structure.md

Open the folder on GitHubat commit 56a3b4a

Compare with similar skills

SQL On Fhir next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

SQL On Fhir compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
SQL On Fhir this skillaehrc/pathling137—~2.3kAutomated safety check: PassApache-2.0
Imaging Data CommonsK-Dense-AI/scientific-agent-skills48k1 repos~7.8kAutomated safety check: PassMIT
SQL PortabilityHL7/sql-on-fhir151—~512Automated safety check: PassCustom licence
Biomarker Database Analysisaws-samples/amazon-bedrock-agents-healthcare-lifesciences274—~1.1kAutomated safety check: PassMIT-0
PaperclipK-Dense-AI/scientific-agent-skills48k1 repos~3.2kAutomated safety check: NotesMIT
Bioconductor MsbackendmassbankbioMate-AI/biomate-bioconductor-kb804—~1kAutomated safety check: PassCustom licence

Similar skills

  • Imaging Data Commons

    K-Dense-AI/scientific-agent-skills

    Queries and downloads public cancer imaging data from NCI Imaging Data Commons.

    48k GitHub starsUsed in 1 repo~7.8k tokens
    DatabasesAuto-check passed
  • SQL Portability

    HL7/sql-on-fhir

    Analyse whether a SQL query is portable across database implementations using sqlglot transpilation.

    151 GitHub stars~512 tokensUpdated 3 days ago
    DatabasesAuto-check passed
  • Biomarker Database Analysis

    aws-samples/amazon-bedrock-agents-healthcare-lifesciences

    Official

    A skill your agent uses when a researcher needs to query biomedical databases for biomarker discovery, build target profiles from UniProt/Open Targets/STRING, rank biomarker candidates by evidence…

    274 GitHub stars~1.1k tokensUpdated 7 days ago
    Research & ScienceAuto-check passed
  • Paperclip

    K-Dense-AI/scientific-agent-skills

    Searches and reads biomedical papers, FDA/PMDA/EMA documents, clinical trials, and protein records with the GXL Paperclip CLI and Python SDK.

    48k GitHub starsUsed in 1 repo~3.2k tokens
    Research & ScienceAuto-check: notes
  • Bioconductor Msbackendmassbank

    bioMate-AI/biomate-bioconductor-kb

    Mass spectrometry (MS) data backend supporting import and export of MS/MS library spectra from MassBank record files.

    804 GitHub stars~1k tokensUpdated 3 mo ago
    DatabasesAuto-check passed
  • Test The Docs

    supabase/supabase

    Official

    Execute runnable docs snippets and examples inside a disposable Docker Compose sandbox (runner container + local Supabase stack via supabase start).

    111k GitHub stars~1.3k tokensUpdated today
    DatabasesAuto-check passed

More from aehrc/pathling

All 25 skills in this repo
  • Databricks CLI

    aehrc/pathling

    Expert guidance for using the Databricks CLI to manage Databricks workspaces, clusters, jobs, pipelines, Unity Catalog, SQL warehouses, serving endpoints, secrets, bundles, and all other Databricks…

    137 GitHub stars~2.1k tokensUpdated yesterday
    Auto-check passed
  • Fhir API

    aehrc/pathling

    Expert guidance for implementing FHIR RESTful API servers and clients following the HL7 FHIR specification.

    137 GitHub stars~1.5k tokensUpdated yesterday
    Auto-check passed
  • Fhir Bulk Data

    aehrc/pathling

    Expert guidance for implementing FHIR Bulk Data Access (Flat FHIR) following the HL7 specification.

    137 GitHub stars~1.8k tokensUpdated yesterday
    Auto-check passed
  • Fhir Search Spec

    aehrc/pathling

    FHIR RESTful search specification expert with access to the official HL7 search specification text and the formal SearchParameter registry.

    137 GitHub stars~649 tokensUpdated yesterday
    Auto-check passed
  • Design and generate comprehensive FHIRPath test suites using input domain partitioning and Pathling's DSL test framework.

    137 GitHub stars~3.6k tokensUpdated yesterday
    Auto-check passed
  • Hapi Fhir Server

    aehrc/pathling

    Expert guidance for implementing FHIR servers using HAPI FHIR Plain Server framework.

    137 GitHub stars~2.6k tokensUpdated yesterday
    Auto-check passed

Works with

Questions about SQL On Fhir

What does SQL On Fhir do?

Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data. SQL On Fhir is an agent skill from aehrc/pathling. Expert guidance for implementing SQL on FHIR v2 ViewDefinitions and operations to create portable, tabular projections of FHIR data.

When should I use SQL On Fhir?

SQL On Fhir fits situations like: the user asks to create ViewDefinitions; flatten FHIR resources into tables; write FHIRPath expressions for data extraction; implement forEach/forEachOrNull/repeat patterns for unnesting.

How do I install SQL On Fhir in Claude Code?

Run `npx skills add aehrc/pathling --skill sql-on-fhir -a claude-code`. Or copy the skill folder (.claude/skills/sql-on-fhir in aehrc/pathling) into .claude/skills/sql-on-fhir in your project. Claude Code loads it when a task matches its description.

How do I install SQL On Fhir in Codex?

Run `npx skills add aehrc/pathling --skill sql-on-fhir -a codex`. Or copy the skill folder (.claude/skills/sql-on-fhir in aehrc/pathling) into .agents/skills/sql-on-fhir in your project. Codex loads it when a task matches its description.

Can I use SQL On Fhir in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add aehrc/pathling --skill sql-on-fhir -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/sql-on-fhir, .gemini/skills/sql-on-fhir, .github/skills/sql-on-fhir and .opencode/skills/sql-on-fhir in your project.

What does SQL On Fhir need to run?

SKILL.md names no scripts, command-line tools or credentials: SQL On Fhir is instructions for the agent only.

Does SQL On Fhir access the network?

SKILL.md names 1 domain. In commands or code: hl7.org; the agent is likely to contact it when it follows the instructions. This is read from the text; nothing was executed.

Is SQL On Fhir safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does SQL On Fhir use?

SQL On Fhir is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does SQL On Fhir use?

About 2.3k tokens (SKILL.md is roughly 9.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 10k tokens, read only when the agent opens those files.

What are the alternatives to SQL On Fhir?

Skills that share tags, products or a category with SQL On Fhir: Imaging Data Commons (K-Dense-AI/scientific-agent-skills, 48k stars), SQL Portability (HL7/sql-on-fhir, 151 stars), Biomarker Database Analysis (aws-samples/amazon-bedrock-agents-healthcare-lifesciences, 274 stars) and Paperclip (K-Dense-AI/scientific-agent-skills, 48k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains SQL On Fhir?

aehrc (a GitHub organization) maintains it in aehrc/pathling, which has 137 GitHub stars. The repository holds 25 skills in this directory. The repository was last updated on October 8, 2026.

Source: aehrc/pathling on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.