Using CQL With FHIR
3.0.0-ballot - STU 3 Ballot International flag

Using CQL With FHIR - Downloaded Version null See the Directory of published versions

Library: Example (Experimental)

Official URL: http://hl7.org/fhir/uv/cql/Library/Example Version: 3.0.0-ballot
Standards status: Informative Computable Name: Example
Other Identifiers: OID:2.16.840.1.113883.4.642.40.37.28.4

Example CQL Library used to demonstrate common patterns used in CQL with FHIR-based models

Metadata
Title Example
Version 3.0.0-ballot
Identifier urn:oid:2.16.840.1.113883.4.642.40.37.28.4
Experimental true
Jurisdiction World
Steward (Publisher) HL7 International / Clinical Decision Support
Description

Example CQL Library used to demonstrate common patterns used in CQL with FHIR-based models

Type logic-library from http://terminology.hl7.org/CodeSystem/library-type
Dependency Description: Library FHIRHelpers
Resource: FHIR Helpers version: 4.0.2-ballot
Canonical URL: http://hl7.org/fhir/uv/cql/Library/FHIRHelpers|4.0.2-ballot
Dependency Description: Code System LOINC
Resource: LOINC
Canonical URL: http://loinc.org
Dependency Description: Code System SNOMED CT
Resource: SNOMED CT (all versions)
Canonical URL: http://snomed.info/sct
Dependency Description: Code System SNOMED CT:2017-09
Resource: http://snomed.info/sct|http://snomed.info/sct/731000124108/version/20250301
Canonical URL: http://snomed.info/sct|http://snomed.info/sct/731000124108/version/20250301
Dependency Description: Code System Country Codes
Resource: Country Codes
Canonical URL: urn:iso:std:iso:3166
Dependency Description: Code System Antenatal Care Concepts
Resource: http://example.org/fhir/CodeSystem/anc-codes-example
Canonical URL: http://example.org/fhir/CodeSystem/anc-codes-example
Dependency Description: Code System ICD-11
Resource: CIE-11 para Estadísticas de Mortalidad y Morbilidad (MMS) - Español
Canonical URL: http://id.who.int/icd/release/11/mms
Dependency Description: Value Set Antithrombotic Therapy
Resource: http://example.org/fhir/ValueSet/antithrombotic-therapy-example
Canonical URL: http://example.org/fhir/ValueSet/antithrombotic-therapy-example
Dependency Description: Value Set Medical Reason
Resource: http://example.org/fhir/ValueSet/medical-reason-example
Canonical URL: http://example.org/fhir/ValueSet/medical-reason-example
Dependency Description: Value Set Absent or Unknown Allergies - IPS
Resource: http://example.org/fhir/uv/ips/ValueSet/absent-or-unknown-allergies-uv-ips
Canonical URL: http://example.org/fhir/uv/ips/ValueSet/absent-or-unknown-allergies-uv-ips
Dependency Description: Value Set Encounter Inpatient SNOMEDCT Value Set
Resource: http://example.org/fhir/ValueSet/encounter-inpatient|20160929
Canonical URL: http://example.org/fhir/ValueSet/encounter-inpatient|20160929
Dependency Description: Value Set Flexible Sigmoidoscopy
Resource: http://example.org/fhir/ValueSet/flexible-sigmoidoscopy
Canonical URL: http://example.org/fhir/ValueSet/flexible-sigmoidoscopy
Data Requirement Type: Observation
Profile(s): Observation
Code Filter(s):
Path: code
Code(s): LOINC: 85354-9 (Blood pressure panel with all children optional)
Data Requirement Type: Medication
Profile(s): Medication
Data Requirement Type: MedicationAdministration
Profile(s): MedicationAdministration
Data Requirement Type: Procedure
Profile(s): Procedure
Code Filter(s):
Path: code
ValueSet: http://example.org/fhir/ValueSet/flexible-sigmoidoscopy
Parameters
Name Use Card. Type Documentation
Measurement Period In 0..1 Period
Patient Out 0..1 Patient
X Out 0..1 boolean
Blood Pressure Observations Within 30 Days Out 0..* Observation
Blood Pressure Observations Within 30 Days (refined) Out 0..* Observation
Blood Pressure With Slices Out 0..* Observation
Blood Pressure With Slices (refined) Out 0..* Observation
Patient Interpreter Required Out 0..1 Patient
Patient Interpreter Required (refined) Out 0..1 Patient
Patient With Citizenship In Switzerland Out 0..1 Patient
Patient With Citizenship In Switzerland (refined) Out 0..1 boolean
Antithrombotic Not Administered Out 0..* MedicationAdministration
Antithrombotic Class Not Administered Out 0..* MedicationAdministration
Antithrombotics Not Administered Out 0..* MedicationAdministration
Flexible Sigmoidoscopy Performed Out 0..* Procedure
Library Content
CQL Content
library Example

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.2-ballot'

codesystem LOINC: 'http://loinc.org'
codesystem "SNOMED CT": 'http://snomed.info/sct'
codesystem "SNOMED CT:2017-09": 'http://snomed.info/sct' version 'http://snomed.info/sct/731000124108/version/20250301'
codesystem "Country Codes": 'urn:iso:std:iso:3166'

valueset "Antithrombotic Therapy": 'http://example.org/fhir/ValueSet/antithrombotic-therapy-example'
valueset "Medical Reason": 'http://example.org/fhir/ValueSet/medical-reason-example'
valueset "Absent or Unknown Allergies - IPS": 'http://example.org/fhir/uv/ips/ValueSet/absent-or-unknown-allergies-uv-ips'
valueset "Encounter Inpatient SNOMEDCT Value Set": 'http://example.org/fhir/ValueSet/encounter-inpatient' version '20160929'
valueset "Flexible Sigmoidoscopy": 'http://example.org/fhir/ValueSet/flexible-sigmoidoscopy'

code "Blood Pressure": '85354-9' from LOINC
code "Diastolic blood pressure": '8462-4' from "LOINC" display 'Diastolic blood pressure'
code "Systolic blood pressure": '8480-6' from "LOINC" display 'Systolic blood pressure'
code "Switzerland (CH)": 'CH' from "Country Codes" display 'Switzerland'

codesystem "Antenatal Care Concepts": 'http://example.org/fhir/CodeSystem/anc-codes-example'
codesystem "ICD-11": 'http://id.who.int/icd/release/11/mms'

code "Tiredness Code": 'ANC.B5.DE40' from "Antenatal Care Concepts" display 'Tiredness'
code "MB22.7": 'MB22.7' from "ICD-11" display 'Tiredness'
code "Venous foot pump, device (physical object)": '442023007' from "SNOMED CT"

concept "Tiredness": { "Tiredness Code", "MB22.7" } display 'Tiredness'

parameter "Measurement Period" Interval<DateTime>

context Patient

define X:
  @2014-01-01 30 days or less before Today()

define "Blood Pressure Observations Within 30 Days":
  [Observation: "Blood Pressure"] O
    where O.status = 'final'
      and (
        (O.effective as dateTime).value 30 days or less before Today()
          or (O.effective as Period) starts 30 days or less before Today()
      )

define fluent function toInterval(choice Choice<FHIR.dateTime, FHIR.Period>):
  case
    when choice is FHIR.dateTime then
      Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]
    when choice is FHIR.Period then
      FHIRHelpers.ToInterval(choice as FHIR.Period)
    else null as Interval<DateTime>
  end

define "Blood Pressure Observations Within 30 Days (refined)":
  [Observation: "Blood Pressure"] O
    where O.status = 'final'
      and O.effective.toInterval() starts 30 days or less before Today()

define "Blood Pressure With Slices":
  [Observation: "Blood Pressure"] BP
    where (singleton from (BP.component C where C.code ~ "Systolic blood pressure")).value < 140 'mm[Hg]'
      and (singleton from (BP.component C where C.code ~ "Diastolic blood pressure")).value < 90 'mm[Hg]'

define fluent function systolic(observation Observation):
  singleton from (observation.component C where C.code ~ "Systolic blood pressure")

define fluent function diastolic(observation Observation):
  singleton from (observation.component C where C.code ~ "Diastolic blood pressure")

define "Blood Pressure With Slices (refined)":
  [Observation: "Blood Pressure"] BP
    where BP.systolic().value < 140 'mm[Hg]'
      and BP.diastolic().value < 90 'mm[Hg]'

define "Patient Interpreter Required":
  Patient P
    let interpreterRequired: singleton from (
        P.extension E where E.url.value = 'http://hl7.org/fhir/StructureDefinition/patient-interpreterRequired'
    ).value as FHIR.boolean
    where interpreterRequired is true

define fluent function interpreterRequired(patient Patient):
  (singleton from (
    patient.extension E where E.url = 'http://hl7.org/fhir/StructureDefinition/patient-interpreterRequired'
  )).value as FHIR.boolean

define "Patient Interpreter Required (refined)":
  Patient P
    where P.interpreterRequired() is true

define "Patient With Citizenship In Switzerland":
  Patient P
    let 
      citizenship: singleton from (
        P.extension E where E.url.value = 'http://hl7.org/fhir/StructureDefinition/patient-citizenship'
      ),
      "code": singleton from (citizenship.extension E where E.url = 'code' return E.value as CodeableConcept),
      period: singleton from (citizenship.extension E where E.url = 'period' return E.value as Period)
    where "code" ~ "Switzerland (CH)"
      and period includes Today()


define fluent function citizenship(patient Patient):
  (patient.extension E where E.url = 'http://hl7.org/fhir/StructureDefinition/patient-citizenship') C
    return {
      "code": singleton from (C.extension E where E.url = 'code' return E.value as CodeableConcept),
      period: singleton from (C.extension E where E.url = 'period' return E.value as Period)
    }

define "Patient With Citizenship In Switzerland (refined)":
  Patient P
    return P.citizenship().single()."code" ~ "Switzerland (CH)"
      and P.citizenship().single().period includes Today()

define "Antithrombotic Not Administered":
  [MedicationAdministration: "Antithrombotic Therapy"] NotAdministered
    where NotAdministered.status = 'not-done'
      and NotAdministered.statusReason in "Medical Reason"

define "Antithrombotic Class Not Administered":
  [MedicationAdministration] NotAdministered
    where NotAdministered.medication.codeOptions() = "Antithrombotic Therapy".id
      and NotAdministered.status = 'not-done'
      and NotAdministered.statusReason in "Medical Reason"

define fluent function codeOptions(element Element):
  (singleton from (element.extension E where E.url = 'http://hl7.org/fhir/StructureDefinition/codeOptions')).value as canonical

define fluent function codeOptions(element Choice<CodeableConcept, Reference>):
  case
    when element is CodeableConcept then (element as CodeableConcept).codeOptions()
    when element is Reference then (element as Reference).codeOptions()
    else null
  end

define "Antithrombotics Not Administered":
  "Antithrombotic Not Administered"
    union "Antithrombotic Class Not Administered"

define fluent function includesOrStartsDuring(condition Condition, encounter Encounter):
  Interval[condition.onset, condition.abatement] includes encounter.period
    or condition.onset during encounter.period

define "Flexible Sigmoidoscopy Performed":
  [Procedure: "Flexible Sigmoidoscopy"] FlexibleSigmoidoscopy
    where FlexibleSigmoidoscopy.status = 'completed'
      and FlexibleSigmoidoscopy.performed.toInterval() ends 5 years or less on or before end of "Measurement Period"
ELM JSON Content
Encoded data 
Generated using version 0.5.6-cibuild of the sample-content-ig Liquid templates