Knowledge Artifact Metadata
Measure Metadata
Short Name Identifier | CMS506FHIR
Version Independent Identifier | urn:uuid:95d529af-66b4-4cfd-bc1f-f43704dc47ad
Version Specific Identifier | urn:uuid:70f3a341-c1dc-4970-a6b1-d4b7cdbbe308
Publisher (CMS) Identifier | 506FHIR
Identifier | org.hl7.fhir.r5.model.Identifier@5d6506dd
Version Number | Draft based on 0.2.004
Rationale | Unintentional opioid overdose fatalities have become a major public health concern in the United States (Rudd, Aleshire, Zibbel, & Gladden, 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, Dixit, Humphreys, Darnall, & Mackey, 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, Bohnert, Kerns, Clay, Ganoczy, & Ilgen, 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;, and New York City Department Of Health and Mental Hygiene (NYC DPOMH), 2013) whenever possible as the combination of these medications may potentiate opioid-induced respiratory depression.
Guidance | 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 an opioid or benzodiazepine prescription should be included in the initial population. Inpatient hospitalizations with discharge medications of two or more opioids or an 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 506v8.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).
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
Measure Population Criteria (ID: 6781a5c2450fe330a8ef3c14)
Summary | Proportion of inpatient hospitalizations for patients 18 years of age and older prescribed two or more opioids or an opioid and benzodiazepine concurrently at discharge.
Initial Population | ID: 345E1255-3623-402A-9016-2B5C9E096C26 Description: 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 opioid and/or benzodiazepine at discharge Logic Definition: Initial Population
Denominator | ID: 9ED4F80C-B465-4CDB-BFDD-CE376A165DD0 Description: Equals Initial Population Logic Definition: Denominator
Denominator Exclusion | ID: 25C57870-241A-428F-BDA8-63C5B4685EE4 Description: 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 (OUD) with active OUD diagnosis or Opioid Medication Assisted Treatment (MAT), 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 Logic Definition: Denominator Exclusion
Numerator | ID: C36B952C-8CCF-436F-A9E2-423A00C56A1A Description: Inpatient hospitalizations where the patient is prescribed two or more opioids or an opioid and benzodiazepine at discharge Logic Definition: Numerator
Population Basis | Encounter
Scoring | [http://terminology.hl7.org/CodeSystem/measure-scoring#proportion: 'Proportion']
Type | [http://terminology.hl7.org/CodeSystem/measure-type#process: 'Process']
Rate Aggregation | None
Improvement Notation | [http://terminology.hl7.org/CodeSystem/measure-improvement-notation#decrease: 'Decreased score indicates improvement']
Supplemental Data Elements
Supplemental Data Element | ID: sde-ethnicity Usage Code: [http://terminology.hl7.org/CodeSystem/measure-data-usage#supplemental-data] Description: SDE Ethnicity Logic Definition: SDE Ethnicity
Supplemental Data Element | ID: sde-payer Usage Code: [http://terminology.hl7.org/CodeSystem/measure-data-usage#supplemental-data] Description: SDE Payer Logic Definition: SDE Payer
Supplemental Data Element | ID: sde-race Usage Code: [http://terminology.hl7.org/CodeSystem/measure-data-usage#supplemental-data] Description: SDE Race Logic Definition: SDE Race
Supplemental Data Element | ID: sde-sex Usage Code: [http://terminology.hl7.org/CodeSystem/measure-data-usage#supplemental-data] Description: SDE Sex Logic Definition: SDE Sex
Measure Logic
Primary Library | https://madie.cms.gov/Library/CMS506FHIRSafeUseofOpioids
Dependency | Description: Library SDE Resource: https://madie.cms.gov/Library/SupplementalDataElements|4.0.000 Canonical URL: `https://madie.cms.gov/Library/SupplementalDataElements|4.0.000`
Dependency | Description: Library FHIRHelpers Resource: https://madie.cms.gov/Library/FHIRHelpers|4.4.000 Canonical URL: `https://madie.cms.gov/Library/FHIRHelpers|4.4.000`
Dependency | Description: Library CQMCommon Resource: https://madie.cms.gov/Library/CQMCommon|3.0.000 Canonical URL: `https://madie.cms.gov/Library/CQMCommon|3.0.000`
Dependency | Description: Library QICoreCommon Resource: https://madie.cms.gov/Library/QICoreCommon|3.0.000 Canonical URL: `https://madie.cms.gov/Library/QICoreCommon|3.0.000`
Dependency | Description: Code system SNOMEDCT Resource: http://snomed.info/sct Canonical URL: `http://snomed.info/sct`
Dependency | Description: Code system DataAbsentReason Resource: http://terminology.hl7.org/CodeSystem/data-absent-reason Canonical URL: `http://terminology.hl7.org/CodeSystem/data-absent-reason`
Dependency | Description: Code system AdministrativeGender Resource: http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender Canonical URL: `http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender`
Dependency | Description: Code system MedicationRequestCategory Resource: http://terminology.hl7.org/CodeSystem/medicationrequest-category Canonical URL: `http://terminology.hl7.org/CodeSystem/medicationrequest-category`
Dependency | Description: Code system ConditionClinicalStatusCodes Resource: http://terminology.hl7.org/CodeSystem/condition-clinical Canonical URL: `http://terminology.hl7.org/CodeSystem/condition-clinical`
Dependency | Description: Value set Encounter Inpatient Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307`
Dependency | Description: Value set Schedule II, III and IV Opioid Medications Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.241 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.241`
Dependency | Description: Value set Schedule IV Benzodiazepines Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1125.1 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1125.1`
Dependency | Description: Value set Payer Type Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591`
Dependency | Description: Value set Cancer Related Pain Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180`
Dependency | Description: Value set Sickle Cell Disease with and without Crisis Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.175 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.175`
Dependency | Description: Value set Medications for Opioid Use Disorder (MOUD) Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.269 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.269`
Dependency | Description: Value set Opioid Medication Assisted Treatment (MAT) Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.177 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.177`
Dependency | Description: Value set Opioid Use Disorder Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.171 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.171`
Dependency | Description: Value set Palliative or Hospice Care Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1579 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1579`
Dependency | Description: Value set Observation Services Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.143 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.143`
Dependency | Description: Value set Emergency Department Visit Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292`
Dependency | Description: Value set Discharge To Acute Care Facility Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.87 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.87`
Dependency | Description: Value set Hospice Care Referral or Admission Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.365 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.365`
Dependency | Description: Value set Patient Expired Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.309 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.309`
Dependency | Description: Value set Left Against Medical Advice Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.308 Canonical URL: `http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.308`
Direct Reference Code | Display: Patient sex unknown (finding) Code: 184115007 System: `http://snomed.info/sct`
Direct Reference Code | Display: Female (finding) Code: 248152002 System: `http://snomed.info/sct`
Direct Reference Code | Display: Male (finding) Code: 248153007 System: `http://snomed.info/sct`
Direct Reference Code | Code: asked-declined System: `http://terminology.hl7.org/CodeSystem/data-absent-reason`
Direct Reference Code | Display: Male Code: M System: `http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender`
Direct Reference Code | Display: Female Code: F System: `http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender`
Direct Reference Code | Display: Community Code: community System: `http://terminology.hl7.org/CodeSystem/medicationrequest-category`
Direct Reference Code | Display: Discharge Code: discharge System: `http://terminology.hl7.org/CodeSystem/medicationrequest-category`
Direct Reference Code | Display: Active Code: active System: `http://terminology.hl7.org/CodeSystem/condition-clinical`
Direct Reference Code | Display: Recurrence Code: recurrence System: `http://terminology.hl7.org/CodeSystem/condition-clinical`
Direct Reference Code | Display: Relapse Code: relapse System: `http://terminology.hl7.org/CodeSystem/condition-clinical`
Parameter | Name: Measurement Period Use: in Min Cardinality: 0 Max Cardinality: 1 Type: Period
Parameter | Name: Numerator Use: out Min Cardinality: 0 Max Cardinality: * Type: Resource
Parameter | Name: Denominator Use: out Min Cardinality: 0 Max Cardinality: * Type: Resource
Parameter | Name: Initial Population Use: out Min Cardinality: 0 Max Cardinality: * Type: Resource
Parameter | Name: Denominator Exclusion Use: out Min Cardinality: 0 Max Cardinality: * Type: Resource
Parameter | Name: SDE Sex Use: out Min Cardinality: 0 Max Cardinality: 1 Type: Coding
Parameter | Name: SDE Payer Use: out Min Cardinality: 0 Max Cardinality: * Type: Resource
Parameter | Name: SDE Ethnicity Use: out Min Cardinality: 0 Max Cardinality: 1 Type: Resource
Parameter | Name: SDE Race Use: out Min Cardinality: 0 Max Cardinality: 1 Type: Resource
Measure Logic Data Requirements
Data Requirement | Type: Patient Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-patient Must Support Elements: extension, gender, gender.value, url, birthDate, birthDate.value
Data Requirement | Type: Encounter Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter Must Support Elements: type, status, status.value, period, reasonCode, reasonReference, hospitalization, hospitalization.dischargeDisposition Code Filter(s): Path: type ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307
Data Requirement | Type: Encounter Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter Must Support Elements: type, status, status.value, period, reasonCode, reasonReference, hospitalization, hospitalization.dischargeDisposition Code Filter(s): Path: type ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.143
Data Requirement | Type: Encounter Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter Must Support Elements: type, status, status.value, period, reasonCode, reasonReference, hospitalization, hospitalization.dischargeDisposition Code Filter(s): Path: type ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292
Data Requirement | Type: MedicationRequest Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest Must Support Elements: medication, status, status.value, intent, intent.value, authoredOn, authoredOn.value Code Filter(s): Path: medication ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1125.1
Data Requirement | Type: MedicationRequest Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest Must Support Elements: medication, status, status.value, intent, intent.value, authoredOn, authoredOn.value Code Filter(s): Path: medication ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.241
Data Requirement | Type: MedicationRequest Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest Must Support Elements: medication, status, status.value, intent, intent.value, authoredOn, authoredOn.value Code Filter(s): Path: medication ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1046.269
Data Requirement | Type: MedicationRequest Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest Must Support Elements: medication.reference.value, authoredOn, authoredOn.value, status, status.value
Data Requirement | Type: Coverage Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-coverage Must Support Elements: type, period Code Filter(s): Path: type ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591
Data Requirement | Type: Resource Profile(s): http://hl7.org/fhir/StructureDefinition/Resource Must Support Elements: id, id.value
Data Requirement | Type: Medication Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medication Must Support Elements: id.value, code
Data Requirement | Type: Procedure Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure Must Support Elements: code, performed, status, status.value Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.177
Data Requirement | Type: Procedure Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-procedure Must Support Elements: code, status, status.value Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1579
Data Requirement | Type: Condition Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns Must Support Elements: code Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.171
Data Requirement | Type: Condition Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns Must Support Elements: code Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180
Data Requirement | Type: Condition Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns Must Support Elements: code Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.175
Data Requirement | Type: ServiceRequest Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest Must Support Elements: code, status, status.value Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1579
Data Requirement | Type: Condition Profile(s): http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-encounter-diagnosis Must Support Elements: code Code Filter(s): Path: code ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1111.180
Measure Logic Definitions
Logic Definition | Library Name: SupplementalDataElements
    define "SDE Sex":
      case
        when Patient.sex = '184115007' then "Patient sex unknown"
        when Patient.sex = '248152002' then "Female"
        when Patient.sex = '248153007' then "Male"
        when Patient.sex = 'asked-declined' then "Asked But Declined"
        when Patient.gender = 'male' then "M"
        when Patient.gender = 'female' then "F"
        else null
      end
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "SDE Sex":
      SDE."SDE Sex"
Logic Definition | Library Name: CQMCommon
    define "Inpatient Encounter":
      [Encounter: "Encounter Inpatient"] EncounterInpatient
        where EncounterInpatient.status = 'finished'
          and EncounterInpatient.period ends during day of "Measurement Period"
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Inpatient Encounter With Age Greater Than Or Equal To 18":
      CQMCommon."Inpatient Encounter" InpatientHospitalEncounter
        where AgeInYearsAt(date from start of InpatientHospitalEncounter.period) >= 18
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Opioid At Discharge":
      ["MedicationRequest": medication in "Schedule II, III and IV Opioid Medications"] OpioidMedications
        where ( OpioidMedications.isCommunity ( )
            or OpioidMedications.isDischarge ( )
        )
          and OpioidMedications.status in { 'active', 'completed' }
          and OpioidMedications.intent = 'order'
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Benzodiazepine At Discharge":
      ["MedicationRequest": medication in "Schedule IV Benzodiazepines"] BenzoMedications
        where ( BenzoMedications.isCommunity ( )
            or BenzoMedications.isDischarge ( )
        )
          and BenzoMedications.status in { 'active', 'completed' }
          and BenzoMedications.intent = 'order'
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Inpatient Encounters With An Opioid Or Benzodiazepine At Discharge":
    /*Captures encounters of patients with an opioid and/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
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Initial Population":
      "Inpatient Encounters With An Opioid Or Benzodiazepine At Discharge"
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Denominator":
      "Initial Population"
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Numerator":
      /*Encounters of patients prescribed two or more opioids or an opioid and benzodiazepine at discharge.*/

      "Denominator" 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
          )
Logic Definition | Library Name: SupplementalDataElements
    define "SDE Payer":
      [Coverage: type in "Payer Type"] Payer
        return {
          code: Payer.type,
          period: Payer.period
        }
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "SDE Payer":
      SDE."SDE Payer"
Logic Definition | Library Name: SupplementalDataElements
    define "SDE Ethnicity":
      Patient.ethnicity E
        return Tuple {
          codes: { E.ombCategory } union E.detailed,
          display: E.text
        }
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "SDE Ethnicity":
      SDE."SDE Ethnicity"
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Medications For Opioid Use Disorder":
      ( ["MedicationRequest": medication in "Medications for Opioid Use Disorder (MOUD)"] MedicationTreatmentOrder
          where ( MedicationTreatmentOrder.isCommunity ( )
              or MedicationTreatmentOrder.isDischarge ( )
          )
            and MedicationTreatmentOrder.status in { 'active', 'completed' }
            and MedicationTreatmentOrder.intent = 'order'
      )
        union ( ["MedicationRequest": "Medications for Opioid Use Disorder (MOUD)"] MedicationTreatmentActive
            where MedicationTreatmentActive.status = 'active'
        )
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Treatment For Opioid Use Disorders":
      ( "Medications For Opioid Use Disorder" 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"
              and MAT.status = 'completed'
      )
        union ( "Medications For Opioid Use Disorder" MedicationTreatment
            with ["ConditionProblemsHealthConcerns": "Opioid Use Disorder"] OUD
              such that MedicationTreatment.authoredOn during day of OUD.prevalenceInterval ( )
                and OUD.prevalenceInterval ( ) overlaps day of "Measurement Period"
                and OUD.isActive ( )
        )
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Intervention Palliative Or Hospice Care":
      ( ["ServiceRequest": "Palliative or Hospice Care"] PalliativeOrHospiceCareOrder
          where PalliativeOrHospiceCareOrder.status in { 'active', 'completed', 'on-hold' }
      )
        union ( ["Procedure": "Palliative or Hospice Care"] PalliativeOrHospiceCarePerformed
            where PalliativeOrHospiceCarePerformed.status in { 'completed', 'in-progress' }
        )
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "Denominator Exclusion":
      /*Excludes encounters of patients with cancer pain or who are receiving palliative or hospice care at the time of the encounter or who receive treatment for opioid use disorder, have sickle cell disease, or who are discharged to another inpatient care facility or discharged against medical advice, or expire during the inpatient stay*/

      "Denominator" InpatientEncounter
        where exists ( [ConditionProblemsHealthConcerns: "Cancer Related Pain"] CancerPain
            where CancerPain.isActive ( )
              and CancerPain.prevalenceInterval ( ) overlaps day of InpatientEncounter.period
        )
          or exists ( "Denominator" QualifyingEncounter
              where QualifyingEncounter.reasonCode in "Cancer Related Pain"
                or exists ( [ConditionEncounterDiagnosis: "Cancer Related Pain"] CancerPainEncounter
                    where QualifyingEncounter.reasonReference.references ( CancerPainEncounter )
                )
          )
          or exists ( [ConditionProblemsHealthConcerns: "Sickle Cell Disease with and without Crisis"] SickleCellDisease
              where SickleCellDisease.isActive ( )
                and SickleCellDisease.prevalenceInterval ( ) overlaps day 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"
          )
Logic Definition | Library Name: SupplementalDataElements
    define "SDE Race":
      Patient.race R
        return Tuple {
          codes: R.ombCategory union R.detailed,
          display: R.text
        }
Logic Definition | Library Name: CMS506FHIRSafeUseofOpioids
    define "SDE Race":
      SDE."SDE Race"
Logic Definition | Library Name: FHIRHelpers
    define function ToString(value uri): value.value
Logic Definition | Library Name: FHIRHelpers
    /*
    @description: Converts the given [Period](https://hl7.org/fhir/datatypes.html#Period)
    value to a CQL DateTime Interval
    @comment: If the start value of the given period is unspecified, the starting
    boundary of the resulting interval will be open (meaning the start of the interval
    is unknown, as opposed to interpreted as the beginning of time).
    */
    define function ToInterval(period FHIR.Period):
        if period is null then
            null
        else
            if period."start" is null then
                Interval(period."start".value, period."end".value]
            else
                Interval[period."start".value, period."end".value]
Logic Definition | Library Name: QICoreCommon
    /*
    @description: Returns true if the given MedicationRequest has a category of Community
    */
    define fluent function isCommunity(medicationRequest Choice<MedicationRequest, MedicationNotRequested>):
      exists (medicationRequest.category C
        where C ~ Community
      )
Logic Definition | Library Name: FHIRHelpers
    /*
    @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
            }
Logic Definition | Library Name: QICoreCommon
    /*
    @description: Returns true if the given MedicationRequest has a category of Discharge
    */
    define fluent function isDischarge(medicationRequest Choice<MedicationRequest, MedicationNotRequested>):
      exists (medicationRequest.category C
        where C ~ Discharge
      )
Logic Definition | Library Name: FHIRHelpers
    /*
    @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
            }
Logic Definition | Library Name: QICoreCommon
    /* Candidates for FHIRCommon */

    /*
    @description: Returns true if the given condition has a clinical status of active, recurrence, or relapse
    */
    define fluent function isActive(condition Choice<"ConditionEncounterDiagnosis", "ConditionProblemsHealthConcerns">):
      condition.clinicalStatus ~ "active"
        or condition.clinicalStatus ~ "recurrence"
        or condition.clinicalStatus ~ "relapse"
Logic Definition | Library Name: QICoreCommon
    /*
    @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 Choice<"ConditionEncounterDiagnosis", "ConditionProblemsHealthConcerns">):
    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]
Logic Definition | Library Name: QICoreCommon
    /*
    @description: Returns true if any of the given references are to the given resource
    @comment: Returns true if the `id` element of the given resource exactly equals the tail of any of the given references.
    NOTE: This function assumes resources from the same source server.
    */
    define fluent function references(references List<Reference>, resource Resource):
      exists (references R where R.references(resource))
Logic Definition | Library Name: QICoreCommon
    /*
    @description: Normalizes a value that is a choice of timing-valued types to an equivalent interval
    @comment: Normalizes a choice type of DateTime, Quanitty, Interval<DateTime>, or Interval<Quantity> types
    to an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible
    representations for timing-valued elements in QICore, allowing this function to be used across any resource.
    The input can be provided as a DateTime, Quantity, Interval<DateTime> or Interval<Quantity>.
    The intent of this function is to provide a clear and concise mechanism to treat single
    elements that have multiple possible representations as intervals so that logic doesn't have to account
    for the variability. More complex calculations (such as medication request period or dispense period
    calculation) need specific guidance and consideration. That guidance may make use of this function, but
    the focus of this function is on single element calculations where the semantics are unambiguous.
    If the input is a DateTime, the result a DateTime Interval beginning and ending on that DateTime.
    If the input is a Quantity, the quantity is expected to be a calendar-duration interpreted as an Age,
    and the result is a DateTime Interval beginning on the Date the patient turned that age and ending immediately before one year later.
    If the input is a DateTime Interval, the result is the input.
    If the input is a Quantity Interval, the quantities are expected to be calendar-durations interpreted as an Age, and the result
    is a DateTime Interval beginning on the date the patient turned the age given as the start of the quantity interval, and ending
    immediately before one year later than the date the patient turned the age given as the end of the quantity interval.
    If the input is a Timing, an error will be thrown indicating that Timing calculations are not implemented. Any other input will reslt in a null DateTime Interval
    */
    define fluent function toInterval(choice Choice<DateTime, Quantity, Interval<DateTime>, Interval<Quantity>, Timing>):
      case
    	  when choice is DateTime then
        	Interval[choice as DateTime, choice as DateTime]
    		when choice is Interval<DateTime> then
      		choice as Interval<DateTime>
    		when choice is Quantity then
    		  Interval[Patient.birthDate + (choice as Quantity),
    			  Patient.birthDate + (choice as Quantity) + 1 year)
    		when choice is Interval<Quantity> then
    		  Interval[Patient.birthDate + (choice.low as Quantity),
    			  Patient.birthDate + (choice.high as Quantity) + 1 year)
    		when choice is Timing then
          Message(null, true, 'NOT_IMPLEMENTED', 'Error', 'Calculation of an interval from a Timing value is not supported') as Interval<DateTime>
    		else
    			null as Interval<DateTime>
    	end
Logic Definition | Library Name: CQMCommon
    /*
    @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]
Generated using version 0.4.6 of the sample-content-ig Liquid templates