Healthcare Fhir Cql
Generates or debugs spec-correct CQL (Clinical Quality Language / FHIR R4) per the HL7 Clinical Reasoning architecture — FHIRHelpers-based, validated through a compile-to-ELM loop and cross-checked against the Alphora reference engine, optionally packaged as a FHIR Library resource. User-invoked only — say "use cql-helper" or type /cql-helper.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install cql-helperManual setup by platform
Claude Code
~/.claude/skills/cql-helper/SKILL.md
Signing
SignedSLSA L2- Signed by
- skills-hub.ai distributor
- Method
- Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
- Key
- skills-hub-ed25519-2026-11
- Signed
Examples
Prompt
Create a CQL library to identify patients aged 50-65 with hypertension using SNOMED codes, and test with a patient who has a confirmed diagnosis.Output
library HypertensionAssessment version '1.0.0'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
codesystem "SNOMED": 'http://snomed.info/sct'
valueset "Hypertension": 'http://example.org/ValueSet/hypertension'
context Patient
define "AgeInRange":
Interval[System.DateTime]{ start: Today() - 65 years, end: Today() - 50 years }
define "PatientAge":
AgeInYears(Patient.birthDate)
define "HasHypertension":
exists (Condition C where C.code in "Hypertension" and C.subject.reference = 'Patient/' + Patient.id)
// Test Patient Bundle with hypertension diagnosis
// Expect "HasHypertension" to be true for this patient.Prompt
Generate CQL to find patients with elevated LDL cholesterol (LOINC code 2093-3) over 130 mg/dL, and validate with a sample patient resource.Output
library ElevatedLDL version '1.0.0'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
codesystem "LOINC": 'http://loinc.org'
valueset "LDL Cholesterol": 'http://example.org/ValueSet/ldl-cholesterol'
context Patient
define "LDLObservation":
[Observation: code in "LDL Cholesterol"] O where O.valueQuantity > 130 'mg/dL'
define "PatientHasElevatedLDL":
exists "LDLObservation"
// Test Patient Bundle with LDL > 130 mg/dL
// Expect "PatientHasElevatedLDL" to be true for this patient.Instructions
Use scaffold for new queries, trace for broken ones, package to wrap a finished query into a deployable FHIR Library. Syntax patterns, type mappings, terminology bindings, and the Library resource shape live in CQL_REFERENCE.md.
This skill writes standard, spec-correct CQL for any conformant FHIR R4 engine. Validation and execution have a single channel: the Alphora $cql sandbox, called over HTTPS with Node's native fetch. Its response carries both translation errors and per-define results, so one call serves as compiler and execution engine. If the sandbox is unreachable, stop and tell the user — there is no fallback.
Scaffold — generating a CQL query
Step 1: Clarify clinical intent — and confirm CQL is the right tool.
Ask until you know: the target patient population, the clinical data to retrieve or compute, and the relevant time window. If the criterion is simple demographics (gender, an age range), say so — that belongs in a Group.characteristic on the cohort definition, not in CQL. Reserve CQL for temporal or logical complexity (e.g., "three adverse events within a six-month rolling window").
Done when: you can state the intent in one sentence the user confirms, and CQL is confirmed as the right representation.
Step 2: Map to FHIR R4 resources and terminology.
List every FHIR R4 resource the query will touch. Bind every clinical concept to a standard terminology — SNOMED CT for conditions/findings, LOINC for labs and observations, RxNorm for medications, ICD-10 for diagnoses — via codesystem and valueset declarations, never arbitrary strings. Flag missing codes or value set URLs as blockers before writing.
Done when: every clinical concept in the intent maps to a named resource and a terminology-bound value set or code.
Step 3: Scaffold the library.
Write the header in this order: library declaration with version, using FHIR version '4.0.1', include FHIRHelpers version '4.0.1' called FHIRHelpers (it provides the implicit conversions between FHIR types and CQL system types that the retrieval patterns rely on), codesystem and valueset declarations, context Patient. The canonical template is in CQL_REFERENCE.md.
Done when: the header has no undefined references and includes FHIRHelpers.
Step 4: Write define statements.
Build bottom-up — value set retrieves first, population filters next, the output define last. Name each define for what it represents. Align every comparison with the CQL↔FHIR type mapping table in CQL_REFERENCE.md (e.g., Interval<System.DateTime> for a FHIR.Period). Every concept from Step 1 must have a corresponding define, and the output define must return the intended type (Boolean, List<Resource>, Integer, Decimal).
Done when: all Step 1 concepts are covered and each define's return type matches its intended use.
Step 5: Build test patient bundles.
Write fixture Bundles (type collection) in the scratchpad — at minimum one patient that should satisfy the intent and, when the output define is Boolean, one control patient that should fail it, so the run proves the logic discriminates rather than returning true for everyone. Resources, codes, and units in the fixtures must match the Step 2 mappings exactly; give datetime fields full precision (e.g., 2025-12-30T20:00:00Z), since date-only values can compare as null against DateTime intervals.
Done when: each fixture has an expected value for every define, stated before running.
Step 6: Validate and execute against the Alphora reference engine.
POST the raw CQL and each test bundle to the Alphora $cql sandbox (request shape, Node-fetch transport, and the shell/caching pitfalls are in CQL_REFERENCE.md). Translation errors come back in the response: treat each as a corrective prompt — read the message, fix the define, bump the library version string, and re-POST until clean. Watch specifically for hallucinated function names — they surface as Could not resolve call to operator <name> with signature (...); see the common-errors table. Once clean, compare every define's returned value against the expected values from Step 5 for both fixtures.
Done when: the response reports zero errors and every define's value matches its expected value for every fixture.
Step 7: Present and explain.
Output the complete library. Follow with a plain-English breakdown of each non-trivial define — one line per define, written for a clinician who does not know CQL, citing its verified value from Step 6 where useful. The clinician reviews and approves before the artifact goes anywhere.
Done when: user confirms the query matches their intent.
Package — wrapping into a FHIR Library resource
Only when the user needs a deployable artifact (for a PlanDefinition, cohort definition, or FHIR server). Build a Library resource of type logic-library carrying both payloads base64-encoded in content: the raw CQL as text/cql and the compiled ELM as application/elm+json — human-readable for clinical review, instantly executable by the engine. If the logic drives a workflow, point PlanDefinition.action.condition at a named Boolean define in this Library. Exact resource shape in CQL_REFERENCE.md.
Done when: the Library validates as FHIR R4 and both content entries decode back to the reviewed CQL and its ELM.
Trace — debugging a broken CQL query
Step 1: Classify the error.
Determine whether the failure is:
- Syntax — translation rejected the query (unexpected token, missing keyword)
- Semantic — accepted but types mismatch, a symbol is undefined, or a function signature is wrong
- Logic — compiles and runs but returns wrong results
Ask for the error output or unexpected result if not provided.
Done when: the error class is known.
Step 2: Trace to the failing define.
For syntax/semantic: locate the specific define and line from the error entry in the Alphora response. For logic: identify which define returns the wrong value and what it actually returns — run intermediate defines through the sandbox if needed.
Done when: the broken define is named.
Step 3: Fix and re-validate.
Correct the define, then re-run the Alphora $cql call (Scaffold Step 6) on the revised library with the test bundle — bumping the library version string on every re-POST, or the sandbox silently serves the cached previous copy. Iterate until the response is error-free and the results match intent. State in one sentence what was wrong and why the fix is correct. If the fix changes semantics (not just syntax), confirm with the user before presenting the revised query. Consult the common-errors table in CQL_REFERENCE.md if the pattern is familiar.
Done when: the response reports zero errors and the executed result matches the stated clinical intent.
Security
Reviews (0)
More Healthcare skills
Browse category →Frequently asked questions about healthcare-fhir-cql
What does the healthcare-fhir-cql skill do?
Generates or debugs spec-correct CQL (Clinical Quality Language / FHIR R4) per the HL7 Clinical Reasoning architecture — FHIRHelpers-based, validated through a compile-to-ELM loop and cross-checked against the Alphora reference engine, optionally packaged as a FHIR Library resource. User-invoked only — say "use cql-helper" or type /cql-helper. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the healthcare-fhir-cql skill?
Run `npx @skills-hub-ai/cli install cql-helper` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/cql-helper/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does healthcare-fhir-cql work with?
healthcare-fhir-cql runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the healthcare-fhir-cql skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use healthcare-fhir-cql after installing it?
In Claude Code, type `/cql-helper` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the healthcare-fhir-cql skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.