SQL on FHIR
3.0.0-ballot - STU 3 Ballot International flag

SQL on FHIR, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 3.0.0-ballot built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/sql-on-fhir/ and changes regularly. See the Directory of published versions

Example ViewDefinition: US Core Blood Pressures

This view acts on the Observation resource to produce a table named "us_core_blood_pressures" where code.coding.exists(system='http://loinc.org' and code=%bp_code).

The table contains the following columns:

NameFhir TypeSQL TypeCollection
idstringString
patient_idstringString
effective_date_timedateTimeDateTime
sbp_quantity_systemstringString
sbp_quantity_codestringString
sbp_quantity_unitstringString
sbp_quantity_valuedecimalDecimal
dbp_quantity_systemstringString
dbp_quantity_codestringString
dbp_quantity_unitstringString
dbp_quantity_valuedecimalDecimal

Constants:

NameValue
systolic_bp8480-6
diastolic_bp8462-4
bp_code85354-9

Selection Rules:

ItemCollTypeDescription
us_core_blood_pressuresObservation
us_core_blood_pressures / Select
us_core_blood_pressures / Select / idgetResourceKey()
us_core_blood_pressures / Select / patient_idsubject.getReferenceKey(Patient)
Can be used to join to patient tables created by other views.
us_core_blood_pressures / Select / effective_date_timeeffective.ofType(dateTime)
us_core_blood_pressures / Selectfor each component.where(code.coding.exists(system='http://loinc.org' and code=%systolic_bp)).first()
us_core_blood_pressures / Select / sbp_quantity_systemvalue.ofType(Quantity).system
us_core_blood_pressures / Select / sbp_quantity_codevalue.ofType(Quantity).code
us_core_blood_pressures / Select / sbp_quantity_unitvalue.ofType(Quantity).unit
us_core_blood_pressures / Select / sbp_quantity_valuevalue.ofType(Quantity).value
us_core_blood_pressures / Selectfor each component.where(code.coding.exists(system='http://loinc.org' and code=%diastolic_bp)).first()
us_core_blood_pressures / Select / dbp_quantity_systemvalue.ofType(Quantity).system
us_core_blood_pressures / Select / dbp_quantity_codevalue.ofType(Quantity).code
us_core_blood_pressures / Select / dbp_quantity_unitvalue.ofType(Quantity).unit
us_core_blood_pressures / Select / dbp_quantity_valuevalue.ofType(Quantity).value

Notes:

This will result in a "us_core_blood_pressures" table that looks like this:

idpatient_ideffective_date_timesbp_quantity_systemsbp_quantity_codesbp_quantity_unitsbp_quantity_valuedbp_quantity_systemdbp_quantity_codedbp_quantity_unitdbp_quantity_value
20282020-01-01T00:00:00Zhttp://unitsofmeasure.orgmm[Hg]mm[Hg]120.0http://unitsofmeasure.orgmm[Hg]mm[Hg]80.0
21282020-01-02T00:00:00Zhttp://unitsofmeasure.orgmm[Hg]mm[Hg]130.0http://unitsofmeasure.orgmm[Hg]mm[Hg]90.0
22292020-01-03T00:00:00Zhttp://unitsofmeasure.orgmm[Hg]mm[Hg]140.0http://unitsofmeasure.orgmm[Hg]mm[Hg]100.0
23302020-01-04T00:00:00Zhttp://unitsofmeasure.orgmm[Hg]mm[Hg]150.0http://unitsofmeasure.orgmm[Hg]mm[Hg]110.0
24302020-01-05T00:00:00Zhttp://unitsofmeasure.orgmm[Hg]mm[Hg]160.0http://unitsofmeasure.orgmm[Hg]mm[Hg]120.0