Common CQL Artifacts for FHIR (US-Based)
1.0.0 - Informative 1 United States of America flag

Common CQL Artifacts for FHIR (US-Based), 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/us-cql-ig/ and changes regularly. See the Directory of published versions

Library: US Core Common

Official URL: http://hl7.org/fhir/us/cql/Library/USCoreCommon Version: 1.0.0
Standards status: Informative Maturity Level: 3 Computable Name: USCoreCommon

This library defines functions to expose extensions defined in USCore as fluent functions in CQL, as well as common terminology and functions used in writing CQL with FHIR and USCore profiles.

Metadata
Title US Core Common
Version 1.0.0
Jurisdiction United States of America
Topic FHIR
Topic CQL
Steward (Publisher) HL7 International / Clinical Decision Support
Description

This library defines functions to expose extensions defined in USCore as fluent functions in CQL, as well as common terminology and functions used in writing CQL with FHIR and USCore profiles.

Type logic-library from http://terminology.hl7.org/CodeSystem/library-type
Dependency Description: Library FHIRHelpers
Resource: http://hl7.org/fhir/uv/cql/Library/FHIRHelpers|4.0.1
Canonical URL: http://hl7.org/fhir/uv/cql/Library/FHIRHelpers|4.0.1
Dependency Description: Library FHIRCommon
Resource: http://hl7.org/fhir/uv/cql/Library/FHIRCommon|2.0.0
Canonical URL: http://hl7.org/fhir/uv/cql/Library/FHIRCommon|2.0.0
Dependency Description: Code System CVX
Resource: Vaccine Administered Code Set (CVX)
Canonical URL: http://hl7.org/fhir/sid/cvx
Dependency Description: Code System ActCode
Resource: ActCode
Canonical URL: http://terminology.hl7.org/CodeSystem/v3-ActCode
Dependency Description: Code System USCoreConditionCategory
Resource: US Core Condition Category Extension Codes
Canonical URL: http://hl7.org/fhir/us/core/CodeSystem/condition-category
Dependency Description: Code System CDC Race and Ethnicity Codes
Resource: CDC Race and Ethnicity
Canonical URL: urn:oid:2.16.840.1.113883.6.238
Dependency Description: Code System CommunicationCategoryCodeSystem
Resource: CommunicationCategory
Canonical URL: http://terminology.hl7.org/CodeSystem/communication-category
Dependency Description: Code System IdentifierType
Resource: identifierType
Canonical URL: http://terminology.hl7.org/CodeSystem/v2-0203
Dependency Description: Code System ObservationInterpretation
Resource: ObservationInterpretation
Canonical URL: http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation
Parameters
Name Use Card. Type Documentation
Patient Out 0..1 Patient
Library Content
CQL Content
/*
@author: Bryn Rhodes
@description: This library defines functions to expose extensions defined
in USCore as fluent functions in CQL, as well as common terminology and functions
used in writing CQL with FHIR and USCore profiles.
*/
library USCoreCommon

using FHIR version '4.0.1'
using USCore version '7.0.0'

include hl7.fhir.uv.cql.FHIRHelpers version '4.0.1'
include hl7.fhir.uv.cql.FHIRCommon version '2.0.0'

codesystem "CVX": 'http://hl7.org/fhir/sid/cvx'
codesystem "ActCode": 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
codesystem "USCoreConditionCategory": 'http://hl7.org/fhir/us/core/CodeSystem/condition-category'
codesystem "CDC Race and Ethnicity Codes": 'urn:oid:2.16.840.1.113883.6.238'
codesystem "CommunicationCategoryCodeSystem": 'http://terminology.hl7.org/CodeSystem/communication-category'
codesystem "IdentifierType": 'http://terminology.hl7.org/CodeSystem/v2-0203'
codesystem "ObservationInterpretation": 'http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation'

code "MedicalRecordNumber": 'MR' from "IdentifierType" display 'Medical record number'

// Encounter Class Codes
code "ambulatory": 'AMB' from ActCode display 'ambulatory'
code "emergency": 'EMER' from ActCode display 'emergency'
code "field": 'FLD' from ActCode display 'field'
code "home health": 'HH' from ActCode display 'home health'
code "inpatient encounter": 'IMP' from ActCode display 'inpatient encounter'
code "inpatient acute": 'ACUTE' from ActCode display 'inpatient acute'
code "inpatient non-acute": 'NONAC' from ActCode display 'inpatient non-acute'
code "observation encounter": 'OBSENC' from ActCode display 'observation encounter'
code "pre-admission": 'PRENC' from ActCode display 'pre-admission'
code "short stay": 'SS' from ActCode display 'short stay'
code "virtual": 'VR' from ActCode display 'VR'

// Condition Category Codes
code "health-concern": 'health-concern' from "USCoreConditionCategory" display 'Health Concern'

code "Systolic Blood Pressure": '8480-6' from FHIRCommon.LOINC
code "Diastolic Blood Pressure": '8462-4' from FHIRCommon.LOINC
code "BMI": '39156-5' from FHIRCommon.LOINC
code "Positive": 'LA6576-8' from ObservationInterpretation
code "Negative": 'NEG' from ObservationInterpretation

context Patient

define fluent function race(patient Patient):
  (patient.ext('http://hl7.org/fhir/us/core/StructureDefinition/us-core-race')) E
    return {
      ombCategory: (E.exts('ombCategory')) o return o.value as FHIR.Coding,
      detailed: (E.exts('detailed')) d return d.value as FHIR.Coding,
      text: E.ext('text').value as FHIR.string
    }

define fluent function ethnicity(patient Patient):
  (patient.ext('http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity')) E
    return {
      ombCategory: E.ext('ombCategory').value as FHIR.Coding,
      detailed: (E.exts('detailed')) d return d.value as FHIR.Coding,
      text: E.ext('text').value as FHIR.string
    }

define fluent function tribalAffiliation(patient Patient):
  (patient.ext('http://hl7.org/fhir/us/core/StructureDefinition/us-core-tribal-affiliation')) E
    return {
      tribalAffiliation: E.ext('tribalAffiliation').value as CodeableConcept,
      isEnrolled: E.ext('isEnrolled').value as boolean
    }

define fluent function birthSex(patient Patient):
  patient.ext('http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex').value as FHIR.code

define fluent function systolic(bloodPressure Observation):
  singleton from (
    bloodPressure.component C
      where C.code ~ "Systolic Blood Pressure"
  )

define fluent function diastolic(bloodPressure Observation):
  singleton from (
    bloodPressure.component C
      where C.code ~ "Diastolic Blood Pressure"
  )

/*
@description: Returns true if the given condition is a health concern
*/
define fluent function isHealthConcern(condition FHIR.Condition):
  exists (
    condition.category C
      where C ~ "health-concern"
  )

/*
@description: Returns Observations in the given list that have an interpretation of positive
*/
define fluent function positive(observations List<Observation>):
  observations O
    where exists (O.interpretation I where I ~ "Positive")

/*
@description: Returns Observations in the given list that have an interpretation of negative
*/
define fluent function negative(observations List<Observation>):
  observations O
    where exists (O.interpretation I where I ~ "Negative")

/*
@description: Returns Observations in the given list that were issued during the given Encounter
*/
define fluent function during(observations List<Observation>, encounter Encounter):
  observations O
    where O.issued during minute of encounter.period

/*
@description: Returns Observations in the given list that were issued within the given time duration before now
*/
define fluent function within(observations List<Observation>, period Quantity):
  observations O
    where (O.issued + period) on or after minute of Now()

/*
@description: Returns Observations consecutively by when they were issued
*/
define fluent function consecutively(observations List<Observation>):
  observations O
    sort by issued

/*
@description: Returns Observations consecutively by when they were issued, on or after when the given Observation was issued
*/
define fluent function consecutivelyFrom(observations List<Observation>, observation Observation):
  observations O
    where O.issued on or after observation.issued
    sort by issued

ELM XML Content
Encoded data 
ELM JSON Content
Encoded data 
Generated using version 0.5.3-cibuild of the sample-content-ig Liquid templates