Quality Measure Implementation Guide

This page is part of the Quality Measure STU2 for FHIR R4 Implementation Guide (v0.1.0: STU 1 Ballot 1) based on FHIR R3. The current version which supercedes this version is 3.0.0. For a full list of available versions, see the Directory of published versions

Library-library-exm55-FHIR

Formats: XML, JSON, Turtle

Id: Library/library-exm55-FHIR
Type: system: http://hl7.org/fhir/library-type
code: logic-library
Identifier: system: http://example.org/fhir/cqi/ecqm/Library/Identifier
value: EXM55
Version: 5.0.0
Title: Example Continuous Variable Measure Library
Status: active
Description: This library is used as an example in the FHIR Quality Measure Implementation Guide
Related:

type: depends-on

Resource:
reference: Library/library-fhir-helpers

Data Requirements:

type: Encounter

type: Encounter

code filter:
path: type
valueset: https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292

type: Encounter

code filter:
path: type
valueset: https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292

type: Condition

code filter:
path: id

type: Encounter

code filter:
path: type
valueset: https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292

Content: type: text/cql
library EXM55_FHIR version '5.0.0' 

/*
This example is a work in progress and should not be considered a final specification
or recommendation for guidance. This example will help guide and direct the process
of finding conventions and usage patterns that meet the needs of the various stakeholders
in the measure development community.
*/

using FHIR version '3.0.0'

include FHIRHelpers version '3.0.0' called FHIRHelpers

codesystem "Diagnosis Role": 'http://hl7.org/fhir/diagnosis-role'

valueset "Emergency Department Visit": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292'
valueset "Psychiatric/Mental Health Patient": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.299'
valueset "Hospital Settings": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.126'

code "Billing": 'billing' from "Diagnosis Role" display 'Billing'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Initial Population":
  "Inpatient Encounter" Encounter
    with ["Encounter": "Emergency Department Visit"] ED
      such that ED.status = 'finished'
        and ED.period ends 1 hour or less before start of Encounter.period

define "Measure Population":
  "Initial Population"

define "Inpatient Encounter":
  ["Encounter"] Encounter
    where LengthInDays(Encounter.period)<= 120
      and Encounter.period ends during "Measurement Period"

define "Measure Population Exclusion":
  "Inpatient Encounter" Encounter
    with ["Encounter": "Emergency Department Visit"] ED
      such that ED.period ends 1 hour or less before start of Encounter.period
        and ED.status = 'finished'
        and ED.hospitalization.admitSource in "Hospital Settings"

define function "PrincipalDiagnosis"(Encounter Encounter):
  ( singleton from ( Encounter.diagnosis D
      where D.role ~ ToConcept("Billing")
        and D.rank = 1
  ) ) PD
    return singleton from ( [Condition: id in "GetId"(PD.condition.reference)] )

define function "LengthInDays"(Value Interval<DateTime>):
  difference in days between start of Value and 
  end of Value

define function "GetId"(uri String):
  Last(Split(uri, '/'))

define "Stratification 1":
  "Inpatient Encounter" Encounter
    where not ( PrincipalDiagnosis(Encounter).code in "Psychiatric/Mental Health Patient" )

define "Stratification 2":
  "Inpatient Encounter" Encounter
    where PrincipalDiagnosis(Encounter).code in "Psychiatric/Mental Health Patient"

define "Stratification 3":
  "Inpatient Encounter" Encounter
    where PrincipalDiagnosis(Encounter)is null 

//Measure Observation

define function "Related ED Visit"(Encounter "Encounter"):
  Last(["Encounter": "Emergency Department Visit"] ED
      where ED.status = 'finished'
        and ED.period ends 1 hour or less before start of Encounter.period
      sort by start of period
  )

define function "Measure Observation"(Encounter "Encounter"):
  duration in minutes of "Related ED Visit"(Encounter).period