eCQM QICore Content Implementation Guide
2024.0.0 - CI Build

eCQM QICore Content Implementation Guide, published by cqframework. This guide is not an authorized publication; it is the continuous build for version 2024.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/ecqm-content-qicore-2024/ and changes regularly. See the Directory of published versions

Measure: Safe Use of Opioids Concurrent PrescribingFHIR

Official URL: https://madie.cms.gov/Measure/SafeUseofOpioidsConcurrentPrescribingFHIR Version: 0.2.000
Draft as of 2024-07-09 Responsible: Centers for Medicare & Medicaid Services (CMS) Computable Name: SafeUseofOpioidsConcurrentPrescribingFHIR
Other Identifiers: Short Name (use: usual, ), UUID:95d529af-66b4-4cfd-bc1f-f43704dc47ad (use: official, ), UUID:18e2d10e-da9c-412b-8d74-07d01207754a (use: official, ), Endorser (use: official, ), Publisher (use: official, )

Copyright/Legal: Limited proprietary coding is contained in the Measure specifications for user convenience. Users of proprietary code sets should obtain all necessary licenses from the owners of the code sets. Mathematica disclaims all liability for use or accuracy of any third party codes contained in the specifications. CPT(R) contained in the measure specifications is copyright 2004-2023 American Medical Association. LOINC(R) copyright 2004-2023 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2023 International Health Terminology Standards Development Organisation. ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

Proportion of inpatient hospitalizations for patients 18 years of age and older prescribed, or continued on, two or more opioids or an opioid and benzodiazepine concurrently at discharge

UNKNOWN

Title: Safe Use of Opioids Concurrent PrescribingFHIR
Id: SafeUseofOpioidsConcurrentPrescribingFHIR
Version: 0.2.000
Url: Safe Use of Opioids Concurrent PrescribingFHIR
short-name identifier:

CMS506FHIR

version-independent identifier:

urn:uuid:95d529af-66b4-4cfd-bc1f-f43704dc47ad

version-specific identifier:

urn:uuid:18e2d10e-da9c-412b-8d74-07d01207754a

endorser (CMS Consensus Based Entity) identifier:

3316e

publisher (CMS) identifier:

506FHIR

Effective Period: 2025-01-01..2025-12-31
Status: draft
Publisher: Centers for Medicare & Medicaid Services (CMS)
Author: Mathematica
Description:

Proportion of inpatient hospitalizations for patients 18 years of age and older prescribed, or continued on, two or more opioids or an opioid and benzodiazepine concurrently at discharge

Purpose:

UNKNOWN

Copyright:

Limited proprietary coding is contained in the Measure specifications for user convenience. Users of proprietary code sets should obtain all necessary licenses from the owners of the code sets. Mathematica disclaims all liability for use or accuracy of any third party codes contained in the specifications. CPT(R) contained in the measure specifications is copyright 2004-2023 American Medical Association. LOINC(R) copyright 2004-2023 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2023 International Health Terminology Standards Development Organisation. ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

Disclaimer:

These performance measures are not clinical guidelines, do not establish a standard of medical care, and have not been tested for all potential applications. THE MEASURES AND SPECIFICATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND. Due to technical limitations, registered trademarks are indicated by (R) or [R] and unregistered trademarks are indicated by (TM) or [TM].

Rationale:

Unintentional opioid overdose fatalities have become a major public health concern in the United States (Rudd et al., 2016). Reducing the number of unintentional overdoses has become a priority for numerous federal organizations including, but not limited to, the Centers for Disease Control and Prevention (CDC), the Federal Interagency Workgroup for Opioid Adverse Drug Events, and the Substance Abuse and Mental Health Services Administration. Concurrent prescriptions of opioids or opioids and benzodiazepines places patients at a greater risk of unintentional overdose due to the increased risk of respiratory depression (Dowell, Haegerich, & Chou, 2016; Dowell, Ragan, Jones, Baldwin, & Chou, 2022). An analysis of national prescribing patterns shows that more than half of patients who received an opioid prescription in 2009 had filled another opioid prescription within the previous 30 days (National Institute on Drug Abuse, 2011). Studies of multiple claims and prescription databases have shown that between 5%-15% of patients receive concurrent opioid prescriptions and 5%-20% of patients receive concurrent opioid and benzodiazepine prescriptions across various settings (Liu et al., 2013; Mack et al., 2015, Park et al., 2015). Patients who have multiple opioid prescriptions have an increased risk for overdose (Jena et al., 2014). Rates of fatal overdose are ten times higher in patients who are co-dispensed opioid analgesics and benzodiazepines than opioids alone (Dasgupta et al., 2015). The number of opioid overdose deaths involving benzodiazepines increased 14% on average each year from 2006 to 2011, while the number of opioid analgesic overdose deaths not involving benzodiazepines did not change significantly (Jones & McAninch, 2015). Furthermore, concurrent use of benzodiazepines with opioids was prevalent in 31%-51% of fatal overdoses (Dowell, Haegerich, & Chou, 2016). One study found that eliminating concurrent use of opioids and benzodiazepines could reduce the risk of opioid overdose-related emergency department (ED) and inpatient visits by 15% and potentially could have prevented an estimated 2,630 deaths related to opioid painkiller overdoses in 2015 (Sun et al., 2017). A study on The Opioid Safety Initiative in the Veterans Health Administration (VHA), which includes an opioid and benzodiazepine concurrent prescribing measure that this measure is based on, was associated with a decrease of 20.67% overall and 0.86% patients per month (781 patients per month) receiving concurrent benzodiazepine with an opioid among all adult VHA patients who filled outpatient opioid prescriptions from October 2012 to September 2014 (Lin et al., 2017). Adopting a measure that calculates the proportion of patients with two or more opioids or opioids and benzodiazepines concurrently has the potential to reduce preventable mortality and reduce the costs associated with adverse events related to opioid use by (1) encouraging providers to identify patients with concurrent prescriptions of opioids or opioids and benzodiazepines and (2) discouraging providers from prescribing two or more opioids or opioids and benzodiazepines concurrently.

Clinical recommendation statement:

The CDC Clinical Practice Guideline for Prescribing Opioids for Pain — United States, 2022 recommends that clinicians should: - “[Use strategies minimizing] opioid use…for both opioid-naïve and opioid-tolerant patients with acute pain when possible. If patients receiving long-term opioid therapy require additional medication for acute pain, nonopioid medications should be used when possible.” - ”Use particular caution when prescribing opioid pain medication and benzodiazepines concurrently." - “Review increased risks for respiratory depression when opioids are taken with benzodiazepines, other sedatives, alcohol, nonprescribed or illicit drugs (e.g., heroin), or other opioids (see Recommendations 8 and 11)” - “Closely monitor patients who are unable to taper and who continue on high-dose or otherwise high-risk opioid regimens (e.g., opioids prescribed concurrently with benzodiazepines) and should work with patients to mitigate overdose risk (e.g., by providing overdose education and naloxone) (see Recommendation 8).” - "Discuss information from the PDMP with the patient and confirm that the patient is aware of any additional prescriptions.” - “Discuss safety concerns, including increased risk for respiratory depression and overdose, with patients found to be receiving overlapping prescription opioids from multiple clinicians who are not coordinating the patient’s care or patients who are receiving medications that increase risk when combined with opioids (e.g., benzodiazepines) (see Recommendation 11), and offer naloxone (see Recommendation 8)." - "Discuss safety concerns with other clinicians who are prescribing controlled substances for the patient. Ideally, clinicians should first discuss concerns with the patient and inform them that they plan to coordinate care with their other clinicians to improve the patient’s safety.” In addition to the 2022 CDC Clinical Practice Guideline for Prescribing Opioids for Pain, opioid prescribing guidelines issued by various state agencies and professional societies for various settings agree with the recommendation to avoid concurrently prescribing opioids (American Academy of Emergency Medicine (AAEM), 2013; and Washington Agency Medical Directors’ Group (WAMDG), 2015), and opioids and benzodiazepines (WAMDG, 2015; American Society of Interventional Pain Physicians (ASIPP), 2012.

Guidance (Usage): Clinician judgement, clinical appropriateness, or both may indicate concurrent prescribing of two unique opioids or an opioid and benzodiazepine is medically necessary, thus the measure is not expected to have a zero rate. Inpatient hospitalizations with discharge medications of a new or continuing opioid or a new or continuing benzodiazepine prescription should be included in the initial population. Inpatient hospitalizations with discharge medications of two or more new or continuing opioids or new or continuing opioid and benzodiazepine resulting in concurrent therapy at discharge should be included in the numerator. Each benzodiazepine and opioid included on the medication discharge list is considered a unique prescription. The denominator population includes patients with inpatient hospitalizations and patients from Acute Hospital Care at Home programs, who are treated and billed as inpatients but receive care in their home. This eCQM is an episode-based measure. An episode is defined as each inpatient hospitalization or encounter that ends during the measurement period. This FHIR-based measure has been derived from the QDM-based measure: CMS 506v7.0. Please refer to the HL7 QI-Core Implementation Guide (https://hl7.org/fhir/us/qicore/STU4.1.1/) for more information on QI-Core and mapping recommendations from QDM to QI-Core 4.1.1 (https://hl7.org/fhir/us/qicore/STU4.1.1/qdm-to-qicore.html). Definition For the purpose of this measure, the following are defined as: - Opioid: Schedule II, III and IV Opioid Medications that do not include naloxone. - Benzodiazepine: Schedule IV benzodiazepine medications. - Medications for Opioid Use Disorder: Methadone, buprenorphine and buprenorphine in combination with naloxone. - Prescribed: The intent of the measure is to capture opioid and/or benzodiazepine medications continued or ordered at discharge - Numerator criteria: Two or more unique orders for opioids, or an opioid and benzodiazepine at discharge
Population Criteria:
64ef764056d636294b157b3e
Initial Population: Inpatient hospitalizations that end during the measurement period, where the patient is 18 years of age and older at the start of the encounter and prescribed one or more new or continuing opioid or benzodiazepine at discharge
Denominator: Equals Initial Population
Denominator Exclusion: Inpatient hospitalizations where patients have cancer pain that begins prior to or during the encounter or are ordered or are receiving palliative or hospice care (including comfort measures, terminal care, and dying care) during the hospitalization or in an emergency department encounter or observation stay immediately prior to hospitalization, patients receiving medication for opioid use disorder, patients with sickle cell disease, patients discharged to another inpatient care facility or left against medical advice, and patients who expire during the inpatient stay
Numerator: Inpatient hospitalizations where the patient is prescribed or continuing to take two or more opioids or an opioid and benzodiazepine at discharge
Supplemental Data Elements:

SDE Ethnicity

SDE Payer

SDE Race

SDE Sex

Supplemental Data Guidance : For every patient evaluated by this measure also identify payer, race, ethnicity and sex; SDE Ethnicity SDE Payer SDE Race SDE Sex
Libraries:
SafeUseofOpioidsConcurrentPrescribingFHIR
Terminology and Other Dependencies:
  • Library/SupplementalDataElements|3.5.000
  • Library/CQMCommon|2.2.000
  • Library/FHIRHelpers|4.4.000
  • Library/QICoreCommon|2.1.000
  • AdministrativeGender
  • MedicationRequest Category Codes
  • Condition Category Codes
  • US Core Condition Category Extension Codes
  • Encounter Inpatient
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.241
  • Schedule IV Benzodiazepines
  • Payer
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.175
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.171
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.269
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.177
  • Palliative or Hospice Care
  • Observation Services
  • Emergency Department Visit
  • Discharge To Acute Care Facility
  • Hospice Care Referral or Admission
  • Patient Expired
  • Left Against Medical Advice
  • Parameters:
    name use min max type
    Measurement Period In 0 1 Period
    SDE Sex Out 0 1 Coding
    Numerator Out 0 * Resource
    Denominator Out 0 * Resource
    SDE Payer Out 0 * Resource
    Initial Population Out 0 * Resource
    SDE Ethnicity Out 0 1 Resource
    Denominator Exclusion Out 0 * Resource
    SDE Race Out 0 1 Resource
    DataRequirements:
    Resource Type Resource Elements Valueset Name Valueset
    Patient(QICorePatient) ethnicity race
    Encounter(QICoreEncounter) type status status.value period condition condition.reference condition.reference.value hospitalization hospitalization.dischargeDisposition Encounter Inpatient Encounter Inpatient
    Encounter(QICoreEncounter) type status status.value period condition condition.reference condition.reference.value hospitalization hospitalization.dischargeDisposition Observation Services Observation Services
    Encounter(QICoreEncounter) type status status.value period condition condition.reference condition.reference.value hospitalization hospitalization.dischargeDisposition Emergency Department Visit Emergency Department Visit
    Medication(QICoreMedication) id
    Medication(QICoreMedication) id
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value authoredOn authoredOn.value Schedule II, III and IV Opioid Medications http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.241
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value authoredOn authoredOn.value Schedule IV Benzodiazepines Schedule IV Benzodiazepines
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value authoredOn authoredOn.value Schedule IV Benzodiazepines Schedule IV Benzodiazepines
    MedicationRequest(QICoreMedicationRequest) medication.reference status status.value intent intent.value authoredOn authoredOn.value medication
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value authoredOn authoredOn.value Medications for Opioid Use Disorder (MOUD) http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.269
    Coverage(QICoreCoverage) type period Payer Type Payer
    Condition(QICoreCondition) id id.value code
    Condition(QICoreCondition) code Cancer Related Pain http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180
    Condition(QICoreCondition) code Sickle Cell Disease with and without Crisis http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.175
    Condition(QICoreCondition) code Opioid Use Disorder http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.171
    Procedure(QICoreProcedure) code performed Opioid Medication Assisted Treatment (MAT) http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.177
    Procedure(QICoreProcedure) code Palliative or Hospice Care Palliative or Hospice Care
    ServiceRequest(QICoreServiceRequest) code Palliative or Hospice Care Palliative or Hospice Care
    Direct Reference Codes:
    display code system
    Male M http://hl7.org/fhir/administrative-gender
    Female F http://hl7.org/fhir/administrative-gender
    Community community http://terminology.hl7.org/CodeSystem/medicationrequest-category
    Discharge discharge http://terminology.hl7.org/CodeSystem/medicationrequest-category
    Problem List Item problem-list-item http://terminology.hl7.org/CodeSystem/condition-category
    Health Concern health-concern http://hl7.org/fhir/us/core/CodeSystem/condition-category
    Logic Definitions:
    Group Scoring Population Criteria Expression
    64ef764056d636294b157b3e Group scoring: proportion
    Type:

    Process

    Rate Aggregation: None
    Improvement Notation:

    increase

    Initial Population
    define "Initial Population":
      "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge"
    Denominator
    define "Denominator":
      "Initial Population"
    Denominator Exclusion
    define "Denominator Exclusion":
      /*Excludes encounters of patients with cancer or who are receiving palliative or hospice care at the time of the encounter or who are discharged to another inpatient care facility or expire during the inpatient stay*/
      
      ( "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge" InpatientEncounter
          where exists ( [Condition: "Cancer Related Pain"] CancerPain
              where ( CancerPain.isProblemListItem ( )
                  or CancerPain.isHealthConcern ( )
              )
                and CancerPain.prevalenceInterval ( ) overlaps day of InpatientEncounter.period
          )
            or exists ( ( InpatientEncounter.encounterDiagnosis ( ) ) InpatientEncounterDiagnosis
                where InpatientEncounterDiagnosis.code in "Cancer Related Pain"
            )
            or exists ( [Condition: "Sickle Cell Disease with and without Crisis"] SickleCellDisease
                where SickleCellDisease.prevalenceInterval ( ) overlaps day of InpatientEncounter.period
            )
            or exists ( [Condition: "Opioid Use Disorder"] OUD
                where start of OUD.prevalenceInterval ( ) before day of end of InpatientEncounter.period
            )
            or exists ( "Treatment for Opioid Use Disorders" OUDTreatment
                where OUDTreatment.authoredOn during day of InpatientEncounter.period
            )
            or exists ( "Intervention Palliative or Hospice Care" PalliativeOrHospiceCare
                where Coalesce(start of PalliativeOrHospiceCare.performed.toInterval(), PalliativeOrHospiceCare.authoredOn) during day of InpatientEncounter."hospitalizationWithObservation" ( )
            )
            or ( InpatientEncounter.hospitalization.dischargeDisposition in "Discharge To Acute Care Facility"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Hospice Care Referral or Admission"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Patient Expired"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Left Against Medical Advice"
            )
      )
    Numerator
    define "Numerator":
      /*Encounters of patients prescribed two or more opioids or an opioid and benzodiazepine at discharge.*/
      
      ( ( "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge" InpatientEncounter
            where ( Count("Opioid at Discharge" OpioidMedications
                  where OpioidMedications.authoredOn during day of InpatientEncounter.period
                  return distinct OpioidMedications.medication
              ) >= 2
            )
              or exists ( "Opioid at Discharge" OpioidDischargeMedications
                  where OpioidDischargeMedications.authoredOn during day of InpatientEncounter.period
                    and exists "Benzodiazepine at Discharge" BenzodiazepineDischargeMedication
                      where BenzodiazepineDischargeMedication.authoredOn during day of InpatientEncounter.period
              )
        )
      )
    Library Name Name
    SupplementalDataElements SDE Sex
    define "SDE Sex":
      case
        when Patient.gender = 'male' then "M"
        when Patient.gender = 'female' then "F"
        else null
      end
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR SDE Sex
    define "SDE Sex":
      SDE."SDE Sex"
    Library Name Name
    CQMCommon Inpatient Encounter
    define "Inpatient Encounter":
      [Encounter: "Encounter Inpatient"] EncounterInpatient
    		where EncounterInpatient.status = 'finished'
    		and EncounterInpatient.period ends during day of "Measurement Period"
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Inpatient Encounter with Age Greater than or Equal to 18
    define "Inpatient Encounter with Age Greater than or Equal to 18":
      CQMCommon."Inpatient Encounter" InpatientHospitalEncounter
        where AgeInYearsAt(date from start of InpatientHospitalEncounter.period) >= 18
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Opioid at Discharge
    define "Opioid at Discharge":
      ( [MedicationRequest: "Schedule II, III and IV Opioid Medications"] OpioidMedications
        where ( OpioidMedications.isCommunity ( )
            or OpioidMedications.isDischarge ( )
        ) ) OpioidDischargeMedication
        where OpioidDischargeMedication.status in { 'active', 'completed' }
          and OpioidDischargeMedication.intent = 'order'
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Benzodiazepine at Discharge
    define "Benzodiazepine at Discharge":
      ( [MedicationRequest: medication in "Schedule IV Benzodiazepines"] BenzoMedications
        where ( BenzoMedications.isCommunity ( )
            or BenzoMedications.isDischarge ( )
        ) ) BenzodiazepineDischargeMedication
        where BenzodiazepineDischargeMedication.status in { 'active', 'completed' }
          and BenzodiazepineDischargeMedication.intent = 'order'
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Inpatient Encounters with an Opioid or Benzodiazepine at Discharge
    define "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge":
      "Inpatient Encounter with Age Greater than or Equal to 18" InpatientEncounter
        with ( "Opioid at Discharge"
          union "Benzodiazepine at Discharge" ) OpioidOrBenzodiazepineAtDischarge
          such that OpioidOrBenzodiazepineAtDischarge.authoredOn during day of InpatientEncounter.period
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Numerator
    define "Numerator":
      /*Encounters of patients prescribed two or more opioids or an opioid and benzodiazepine at discharge.*/
      
      ( ( "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge" InpatientEncounter
            where ( Count("Opioid at Discharge" OpioidMedications
                  where OpioidMedications.authoredOn during day of InpatientEncounter.period
                  return distinct OpioidMedications.medication
              ) >= 2
            )
              or exists ( "Opioid at Discharge" OpioidDischargeMedications
                  where OpioidDischargeMedications.authoredOn during day of InpatientEncounter.period
                    and exists "Benzodiazepine at Discharge" BenzodiazepineDischargeMedication
                      where BenzodiazepineDischargeMedication.authoredOn during day of InpatientEncounter.period
              )
        )
      )
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Initial Population
    define "Initial Population":
      "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge"
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Denominator
    define "Denominator":
      "Initial Population"
    Library Name Name
    SupplementalDataElements SDE Payer
    define "SDE Payer":
      [Coverage: type in "Payer Type"] Payer
        return {
          code: Payer.type,
          period: Payer.period
        }
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR SDE Payer
    define "SDE Payer":
      SDE."SDE Payer"
    Library Name Name
    SupplementalDataElements SDE Ethnicity
    define "SDE Ethnicity":
      Patient.ethnicity E
        return Tuple {
          codes: { E.ombCategory } union E.detailed,
          display: E.text
        }
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR SDE Ethnicity
    define "SDE Ethnicity":
      SDE."SDE Ethnicity"
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Treatment for Opioid Use Disorders
    define "Treatment for Opioid Use Disorders":
      [MedicationRequest: "Medications for Opioid Use Disorder (MOUD)"] MedicationTreatment
        with [Procedure: "Opioid Medication Assisted Treatment (MAT)"] MAT
          such that MedicationTreatment.authoredOn during day of MAT.performed.toInterval ( )
            and MedicationTreatment.authoredOn during day of "Measurement Period"
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Intervention Palliative or Hospice Care
    define "Intervention Palliative or Hospice Care":
      [ServiceRequest: "Palliative or Hospice Care"]
        union [Procedure: "Palliative or Hospice Care"]
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR Denominator Exclusion
    define "Denominator Exclusion":
      /*Excludes encounters of patients with cancer or who are receiving palliative or hospice care at the time of the encounter or who are discharged to another inpatient care facility or expire during the inpatient stay*/
      
      ( "Inpatient Encounters with an Opioid or Benzodiazepine at Discharge" InpatientEncounter
          where exists ( [Condition: "Cancer Related Pain"] CancerPain
              where ( CancerPain.isProblemListItem ( )
                  or CancerPain.isHealthConcern ( )
              )
                and CancerPain.prevalenceInterval ( ) overlaps day of InpatientEncounter.period
          )
            or exists ( ( InpatientEncounter.encounterDiagnosis ( ) ) InpatientEncounterDiagnosis
                where InpatientEncounterDiagnosis.code in "Cancer Related Pain"
            )
            or exists ( [Condition: "Sickle Cell Disease with and without Crisis"] SickleCellDisease
                where SickleCellDisease.prevalenceInterval ( ) overlaps day of InpatientEncounter.period
            )
            or exists ( [Condition: "Opioid Use Disorder"] OUD
                where start of OUD.prevalenceInterval ( ) before day of end of InpatientEncounter.period
            )
            or exists ( "Treatment for Opioid Use Disorders" OUDTreatment
                where OUDTreatment.authoredOn during day of InpatientEncounter.period
            )
            or exists ( "Intervention Palliative or Hospice Care" PalliativeOrHospiceCare
                where Coalesce(start of PalliativeOrHospiceCare.performed.toInterval(), PalliativeOrHospiceCare.authoredOn) during day of InpatientEncounter."hospitalizationWithObservation" ( )
            )
            or ( InpatientEncounter.hospitalization.dischargeDisposition in "Discharge To Acute Care Facility"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Hospice Care Referral or Admission"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Patient Expired"
                or InpatientEncounter.hospitalization.dischargeDisposition in "Left Against Medical Advice"
            )
      )
    Library Name Name
    SupplementalDataElements SDE Race
    define "SDE Race":
      Patient.race R
        return Tuple {
          codes: R.ombCategory union R.detailed,
          display: R.text
        }
    Library Name Name
    SafeUseofOpioidsConcurrentPrescribingFHIR SDE Race
    define "SDE Race":
      SDE."SDE Race"
    Library Name Name
    QICoreCommon isCommunity
    /*
    @description: Returns true if the given MedicationRequest has a category of Community
    */
    define fluent function isCommunity(medicationRequest MedicationRequest):
      exists (medicationRequest.category C
        where C ~ Community
      )
    Library Name Name
    FHIRHelpers ToConcept
    /*
    @description: Converts the given FHIR [CodeableConcept](https://hl7.org/fhir/datatypes.html#CodeableConcept) value to a CQL Concept.
    */
    define function ToConcept(concept FHIR.CodeableConcept):
        if concept is null then
            null
        else
            System.Concept {
                codes: concept.coding C return ToCode(C),
                display: concept.text.value
            }
    Library Name Name
    QICoreCommon isDischarge
    /*
    @description: Returns true if the given MedicationRequest has a category of Discharge
    */
    define fluent function isDischarge(medicationRequest MedicationRequest):
      exists (medicationRequest.category C
        where C ~ Discharge
      )
    Library Name Name
    FHIRHelpers ToString
    define function ToString(value uri): value.value
    Library Name Name
    FHIRHelpers ToCode
    /*
    @description: Converts the given FHIR [Coding](https://hl7.org/fhir/datatypes.html#Coding) value to a CQL Code.
    */
    define function ToCode(coding FHIR.Coding):
        if coding is null then
            null
        else
            System.Code {
              code: coding.code.value,
              system: coding.system.value,
              version: coding.version.value,
              display: coding.display.value
            }
    Library Name Name
    QICoreCommon isProblemListItem
    /*
    @description: Returns true if the given condition is a problem list item.
    */
    define fluent function isProblemListItem(condition Condition):
      exists (condition.category C
        where C ~ "problem-list-item"
      )
    Library Name Name
    QICoreCommon isHealthConcern
    /*
    @description: Returns true if the given condition is a health concern
    */
    define fluent function isHealthConcern(condition Condition):
      exists (condition.category C
        where C ~ "health-concern"
      )
    Library Name Name
    QICoreCommon prevalenceInterval
    /*
    @description: Returns an interval representing the normalized prevalence period of a given Condition.
    @comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from
    onset to abatement as specified in the given Condition. If the condition is active, or has an abatement date the resulting 
    interval will have a closed ending boundary. Otherwise, the resulting interval will have an open ending boundary.
    */
    define fluent function prevalenceInterval(condition Condition):
    if condition.clinicalStatus ~ "active"
      or condition.clinicalStatus ~ "recurrence"
      or condition.clinicalStatus ~ "relapse" then
      Interval[start of condition.onset.toInterval(), end of condition.abatementInterval()]
    else
        (end of condition.abatementInterval()) abatementDate
        return if abatementDate is null then
          Interval[start of condition.onset.toInterval(), abatementDate)
        else
          Interval[start of condition.onset.toInterval(), abatementDate]
    Library Name Name
    CQMCommon encounterDiagnosis
    /*
    @description: Returns the Condition resources referenced by the diagnosis element of the Encounter
    */
    define fluent function encounterDiagnosis(Encounter Encounter ):
      Encounter.diagnosis D
        return singleton from ([Condition] C where C.id = D.condition.reference.getId())
    Library Name Name
    QICoreCommon getId
    /*
    @description: Returns the tail of the given uri (i.e. everything after the last slash in the URI).
    @comment: This function can be used to determine the logical id of a given resource. It can be used in
    a single-server environment to trace references. However, this function does not attempt to resolve
    or distinguish the base of the given url, and so cannot be used safely in multi-server environments.
    */
    define fluent function getId(uri String):
      Last(Split(uri, '/'))
    Library Name Name
    CQMCommon hospitalizationWithObservation
    /*
    @description: Hospitalization with Observation returns the total interval from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter
    */
    define fluent function hospitalizationWithObservation(TheEncounter Encounter ):
      TheEncounter Visit
      		let ObsVisit: Last([Encounter: "Observation Services"] LastObs
      				where LastObs.status = 'finished'
                and LastObs.period ends 1 hour or less on or before start of Visit.period
      				sort by end of period
      			),
      			VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),
      			EDVisit: Last([Encounter: "Emergency Department Visit"] LastED
      				where LastED.status = 'finished'
                and LastED.period ends 1 hour or less on or before VisitStart
      				sort by end of period
      			)
      		return Interval[Coalesce(start of EDVisit.period, VisitStart), end of Visit.period]