Using CQL with FHIR
1.0.0 - STU1 International flag

Using CQL with FHIR, published by HL7 International / Clinical Decision Support. This guide is not an authorized publication; it is the continuous build for version 1.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/cql-ig/ and changes regularly. See the Directory of published versions

Library: Type Mapping Example (Experimental)

Official URL: http://hl7.org/fhir/uv/cql/Library/TypeMappingExample Version: 1.0.0
Active as of 2024-05-08 Computable Name: TypeMappingExample
Other Identifiers: OID:2.16.840.1.113883.4.642.40.37.28.6

Example CQL library providing a complete set of expressions that cover all possible CQL and FHIR Type Mapping, for both input and output. See the Type Mapping Evaluation Result example for an illustration of the type mapping in a Parameters resource.

Related Artifacts

depends-onFHIR model informationhttp://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
depends-onLibrary FHIRHelpershttp://fhir.org/guides/cqf/common/Library/FHIRHelpers|4.0.1
depends-onCode system ExampleCodeSystemCQL IG Example Code System
depends-onCode system LOINCLogical Observation Identifiers, Names and Codes (LOINC)
depends-onValue set ExampleValueSetExample Specific health concern(s) Codes

Parameters

ExampleVocabularyin01Resource
Patientout01Patient
CQLBooleanExampleout01boolean
CQLCodeExampleout01Coding
CQLCodeSystemExampleout01Resource
CQLConceptExampleout01CodeableConcept
CQLDateExampleout01date
CQLDateTimeExampleout01dateTime
CQLDecimalExampleout01decimal
CQLLongExampleout01Resource
CQLIntegerExampleout01integer
CQLQuantityExampleout01Quantity
CQLRatioExampleout01Ratio
CQLStringExampleout01string
CQLTimeExampleout01time
CQLValueSetExampleout01Resource
CQLVocabularyExampleout01Resource
CQLDateIntervalExampleout01Period
CQLDateTimeIntervalExampleout01Period
CQLTimeIntervalExampleout01Resource
CQLIntegerIntervalExampleout01Range
CQLQuantityIntervalExampleout01Range
CQLListExampleout0*integer
CQLTupleExampleout01Resource
CQLChoiceListExampleout0*Resource
CQLTupleListExampleout0*Resource
CQLComplexTupleExampleout01Resource
CQLComplexTupleListExampleout0*Resource
CQLEmptyListExampleout0*Resource
FHIRObservationsout0*Observation
FHIRBloodGlucoseObservationout01Observation
FHIRBooleanExampleout01boolean
FHIRStringExampleout01string
FHIRQuantityExampleout01Quantity
FHIRPeriodExampleout01Period
FHIRRangeExampleout01Range
FHIRObservationExampleout01Observation
FHIRObservationListExampleout0*Observation
FHIREmptyObservationListExampleout0*Observation

Data Requirements

Type: Patient (Patient)
Type: Observation (Observation)

Contents

text/cql

/*
@description: An example library illustrating the FHIR Type mapping for CQL
*/
library TypeMappingExample

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'

codesystem ExampleCodeSystem: 'http://hl7.org/fhir/uv/cql/CodeSystem/example'
codesystem LOINC: 'http://loinc.org'
valueset ExampleValueSet: 'http://hl7.org/fhir/uv/cql/ValueSet/example'
code ExampleCode: 'example-code' from ExampleCodeSystem
code BloodGlucose: '2339-0' from LOINC display 'Glucose Bld-mCnc'
concept ExampleConcept: { ExampleCode }

parameter ExampleVocabulary Vocabulary

context Patient

// Example values as output

// CQL Values
// Boolean
define CQLBooleanExample: true
// Code
define CQLCodeExample: ExampleCode
// CodeSystem
define CQLCodeSystemExample: ExampleCodeSystem
// Concept
define CQLConceptExample: ExampleConcept
// Date
define CQLDateExample: @2024-01-01
// DateTime
define CQLDateTimeExample: @2024-01-01T10:30:00Z
// Decimal
define CQLDecimalExample: 10.0
// Long
define CQLLongExample: 10L
// Integer
define CQLIntegerExample: 10
// Quantity
define CQLQuantityExample: 10 'mg'
// Ratio
define CQLRatioExample: 5 'mg' : 10 'mg'
// String
define CQLStringExample: 'John'
// Time
define CQLTimeExample: @T10:30:00
// ValueSet
define CQLValueSetExample: ExampleValueSet
// Vocabulary
define CQLVocabularyExample: ExampleVocabulary
// Interval<Date>
define CQLDateIntervalExample: Interval[@2024-01-01, @2024-01-31]
// Interval<DateTime>
define CQLDateTimeIntervalExample: Interval[@2024-01-01T10:30:00Z, @2024-01-31T10:30:00Z]
// Interval<Time>
define CQLTimeIntervalExample: Interval[@T10:30:00, @T11:30:00]
// Interval<Integer>
define CQLIntegerIntervalExample: Interval[5, 10]
// Interval<Quantity>
define CQLQuantityIntervalExample: Interval[5 'mg', 10 'mg']
// List
define CQLListExample: { 1, 2, 3, 4, 5 }
// Tuple
define CQLTupleExample: { X: 1, Y: 1 }
// ChoiceList
define CQLChoiceListExample: List<Choice<Integer, Decimal>> { 1, 1.0 }
// TupleList
define CQLTupleListExample: { { X: 1, Y: 1 }, { X: 1, Y: 2 }, { X: 1, Y: 3 } }
// ComplexTuple
define CQLComplexTupleExample: { id: 1, name: 'Patrick', address: { { street: '123 Spinning Ave', city: 'Dayton', state: 'OH' } } }
// ComplexTupleList
define CQLComplexTupleListExample: { CQLComplexTupleExample }
// EmptyList
define CQLEmptyListExample: CQLComplexTupleListExample E where false

// FHIR Values
define private FHIRObservations: [Observation]
define private FHIRBloodGlucoseObservation: (FHIRObservations O where O.code ~ BloodGlucose).single()

// boolean
define FHIRBooleanExample: Patient.active
// string
define FHIRStringExample: Patient.name.first().family
// Quantity
define FHIRQuantityExample: FHIRBloodGlucoseObservation.value as FHIR.Quantity
// Period
define FHIRPeriodExample: Patient.address.first().period
// Range
define FHIRRangeExample: FHIRBloodGlucoseObservation O return FHIR.Range { low: O.referenceRange.first().low, high: O.referenceRange.first().high }
// Observation
define FHIRObservationExample: FHIRBloodGlucoseObservation
// List<Observation>
define FHIRObservationListExample: FHIRObservations
// EmptyList<Observation>
define FHIREmptyObservationListExample: FHIRObservations O where false

Content not shown - (application/elm+xml, size = 287Kb)

Content not shown - (application/elm+json, size = 218Kb)