SQL on FHIR
2.1.0-pre - release
SQL on FHIR, published by SQL on FHIR Working Group. This guide is not an authorized publication; it is the continuous build for version 2.1.0-pre built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/FHIR/sql-on-fhir-v2/ and changes regularly. See the Directory of published versions
| Official URL: https://sql-on-fhir.org/ig/Library/SqlOnFhirExample | Version: 2.1.0-pre | |||
| Active as of 2026-02-24 | Computable Name: SqlOnFhirExample | |||
Demonstrates SQL annotations that tooling can use to generate Library metadata.
/*
@name: SqlOnFhirExample
@title: Blood Pressure Trend Report
@description: Return blood pressure observations for a patient in a date range
@version: 1.0.0
@status: active
@author: Clinical Informatics Team
@publisher: Regional Medical Center
*/
-- @relatedDependency: https://example.org/ViewDefinition/patient_view as patient_view
-- @relatedDependency: https://example.org/ViewDefinition/blood_pressure_view as blood_pressure_view
-- @param: patient_id string Patient identifier
-- @param: from_date date Start date (inclusive)
-- @param: to_date date End date (inclusive)
SELECT
patient_view.id AS patient_id,
patient_view.name,
blood_pressure_view.systolic,
blood_pressure_view.diastolic,
blood_pressure_view.effective_date
FROM patient_view
JOIN blood_pressure_view
ON patient_view.id = blood_pressure_view.patient_id
WHERE patient_view.id = :patient_id
AND blood_pressure_view.effective_date >= :from_date
AND blood_pressure_view.effective_date <= :to_date
ORDER BY blood_pressure_view.effective_date
Profile: SQL Query Library
| Author | Clinical Informatics Team |
| Depends On | patient_view | https://example.org/ViewDefinition/patient_view |
| Depends On | blood_pressure_view | https://example.org/ViewDefinition/blood_pressure_view |
| patient_id | in | string | Patient identifier | ||
| from_date | in | date | Start date for observations | ||
| to_date | in | date | End date for observations |
application/sql
/*
@name: SqlOnFhirExample
@title: Blood Pressure Trend Report
@description: Return blood pressure observations for a patient in a date range
@version: 1.0.0
@status: active
@author: Clinical Informatics Team
@publisher: Regional Medical Center
*/
-- @relatedDependency: https://example.org/ViewDefinition/patient_view as patient_view
-- @relatedDependency: https://example.org/ViewDefinition/blood_pressure_view as blood_pressure_view
-- @param: patient_id string Patient identifier
-- @param: from_date date Start date (inclusive)
-- @param: to_date date End date (inclusive)
SELECT
patient_view.id AS patient_id,
patient_view.name,
blood_pressure_view.systolic,
blood_pressure_view.diastolic,
blood_pressure_view.effective_date
FROM patient_view
JOIN blood_pressure_view
ON patient_view.id = blood_pressure_view.patient_id
WHERE patient_view.id = :patient_id
AND blood_pressure_view.effective_date >= :from_date
AND blood_pressure_view.effective_date <= :to_date
ORDER BY blood_pressure_view.effective_date