opioidcds-04-05
type: PlanDefinition
node role: treeRoot
id:
  v: opioidcds-04-05
meta:
  profile:
    v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-recommendationdefinition
    link: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-recommendationdefinition
  profile:
    v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-publishableplandefinition
    link: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-publishableplandefinition
text:
  status:
    v: extensions
  div: Id: opioidcds-04-05 Url: Recommendations #4 and #5 - Lowest Effective Dose Version: 2022.1.0 Identifier: value: cdc-opioid-guidance Name: PlanDefinition_Recommendation_04_05_Order_Sign Title: Recommendations #4 and #5 - Lowest Effective Dose Status: draft Experimental: true Type: system: http://terminology.hl7.org/CodeSystem/plan-definition-type code: eca-rule display: ECA Rule Date: 2025-07-01 Publisher: Centers for Disease Control and Prevention (CDC) Description: Recommendation 4: When opioids are initiated for opioid-naïve patients with acute, subacute, or chronic pain, clinicians should prescribe the lowest effective dosage. If opioids are continued for subacute or chronic pain, clinicians should use caution when prescribing opioids at any dosage, should carefully evaluate individual benefits and risks when considering increasing dosage, and should avoid increasing dosage above levels likely to yield diminishing returns in benefits relative to risks to patients. Recommendation 5: For patients already receiving opioid therapy, clinicians should carefully weigh benefits and risks and exercise care when changing opioid dosage. If benefits outweigh risks of continued opioid therapy, clinicians should work closely with patients to optimize nonopioid therapies while continuing opioid therapy. If benefits do not outweigh risks of continued opioid therapy, clinicians should optimize other therapies and work closely with patients to gradually taper to lower dosages or, if warranted based on the individual circumstances of the patient, appropriately taper and discontinue opioids. Unless there are indications of a life-threatening issue such as warning signs of impending overdose (e.g., confusion, sedation, or slurred speech), opioid therapy should not be discontinued abruptly, and clinicians should not rapidly reduce opioid dosages from higher dosages. Logic Definitions: Library Name Name sequence OpioidCDSREC04And05 Chronic Pain Opioid Analgesic with Ambulatory Misuse P…
contained: Library
  id:
    v: effective-data-requirements
  name:
    v: EffectiveDataRequirements
  status:
    v: active
  type:
    coding:
      system:
        v: http://terminology.hl7.org/CodeSystem/library-type
      code:
        v: module-definition
  related artifact:
    type:
      v: depends-on
    display:
      v: Library Common
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/OpioidCDSCommon|2022.1.0
      link: 2022.1
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library FHIRHelpers
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/FHIRHelpers|4.0.1
      link: 4.0
      link: .1
  related artifact:
    type:
      v: depends-on
    display:
      v: Library Routines
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/OpioidCDSRoutines|2022.1.0
      link: 2022.1
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library MMECalculator
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/MMECalculator|3.0.0
      link: 3.0
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library OMTKLogic
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/OMTKLogic|3.0.0
      link: 3.0
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library OMTKData
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/OMTKData|3.0.0
      link: 3.0
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library ConversionFactors
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/ConversionFactors|3.0.0
      link: 3.0
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Library CDCMMEClinicalConversionFactors
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/Library/CDCMMEClinicalConversionFactors|3.0.0
      link: 3.0
      link: .0
  related artifact:
    type:
      v: depends-on
    display:
      v: Code system Usage Context Type
    resource:
      v: http://terminology.hl7.org/CodeSystem/usage-context-type
      link: http://terminology.hl7.org/CodeSystem/usage-context-type
  related artifact:
    type:
      v: depends-on
    display:
      v: Code system CDC MME Usage Context Codes
    resource:
      v: http://fhir.org/guides/cdc/opioid-mme-r4/CodeSystem/CDCMMEUsageContextCodes
      link: http://fhir.org/guides/cdc/opioid-mme-r4/CodeSystem/CDCMMEUsageContextCodes
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Opioid analgesics with ambulatory misuse potential
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/opioid-analgesics-with-ambulatory-misuse-potential
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/opioid-analgesics-with-ambulatory-misuse-potential
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Community
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/medicationrequest-category-community
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/medicationrequest-category-community
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Encounter Diagnosis Condition Category
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-encounter-diagnosis-category
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-encounter-diagnosis-category
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Problem List Condition Category
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-problem-list-category
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-problem-list-category
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set US Core Health Concern Condition Category
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-us-core-health-concern-category
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-us-core-health-concern-category
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Conditions likely terminal for opioid prescribing
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/conditions-likely-terminal-for-opioid-prescribing
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/conditions-likely-terminal-for-opioid-prescribing
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Active Condition
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-clinical-status-active
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-clinical-status-active
  related artifact:
    type:
      v: depends-on
    display:
      v: Value set Limited life expectancy conditions
    resource:
      v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/limited-life-expectancy-conditions
      link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/limited-life-expectancy-conditions
  parameter:
    name:
      v: ContextPrescriptions
    use:
      v: in
    min:
      v: 0
    max:
      v: *
    type:
      v: MedicationRequest
  parameter:
    name:
      v: ErrorLevel
    use:
      v: in
    min:
      v: 0
    max:
      v: 1
    type:
      v: string

name:
  v: ConversionFactorSupplementName
use:
  v: in
min:
  v: 0
max:
  v: 1
type:
  v: string

name:
  v: Is Recommendation Applicable?
use:
  v: out
min:
  v: 0
max:
  v: 1
type:
  v: boolean

type:
  v: Condition
profile:
  v: http://hl7.org/fhir/StructureDefinition/Condition
  link: http://hl7.org/fhir/StructureDefinition/Condition
must support:
  v: category
must support:
  v: code
must support:
  v: clinicalStatus
code filter:
  path:
    v: category
  value set:
    v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-encounter-diagnosis-category
    link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-encounter-diagnosis-category

type:
  v: Condition
profile:
  v: http://hl7.org/fhir/StructureDefinition/Condition
  link: http://hl7.org/fhir/StructureDefinition/Condition
must support:
  v: category
must support:
  v: code
must support:
  v: clinicalStatus
code filter:
  path:
    v: category
  value set:
    v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-problem-list-category
    link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-problem-list-category

type:
  v: Condition
profile:
  v: http://hl7.org/fhir/StructureDefinition/Condition
  link: http://hl7.org/fhir/StructureDefinition/Condition
must support:
  v: category
must support:
  v: code
must support:
  v: clinicalStatus
code filter:
  path:
    v: category
  value set:
    v: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-us-core-health-concern-category
    link: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-us-core-health-concern-category

type:
  v: Encounter
profile:
  v: http://hl7.org/fhir/StructureDefinition/Encounter
  link: http://hl7.org/fhir/StructureDefinition/Encounter
must support:
  v: period
must support:
  v: period.start
must support:
  v: status
must support:
  v: status.value

url:
  v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability
value: code
  v: shareable

url:
  v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability
value: code
  v: computable

url:
  v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability
value: code
  v: executable

url:
  v: http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability
value: code
  v: publishable

url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-directReferenceCode
value: Coding
  system:
    v: http://terminology.hl7.org/CodeSystem/usage-context-type
  code:
    v: task

url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-directReferenceCode
value: Coding
  system:
    v: http://fhir.org/guides/cdc/opioid-mme-r4/CodeSystem/CDCMMEUsageContextCodes
  code:
    v: mme-calculation

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions
extension:
  url:
    v: statement
  value: string
    v: define "Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions": ( Common."Is Opioid Analgesic with Ambulatory Misuse Potential?"( ContextPrescriptions ) ) AmbulatoryOpioidPrescription where Routines."Is Subacute or Chronic Pain Prescription?"( AmbulatoryOpioidPrescription )
extension:
  url:
    v: displaySequence
  value: integer
    v: 0
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential
extension:
  url:
    v: statement
  value: string
    v: define "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential": exists( "Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions" )
extension:
  url:
    v: displaySequence
  value: integer
    v: 1
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Patient Age Less Than 18
extension:
  url:
    v: statement
  value: string
    v: define "Patient Age Less Than 18": if (Config."Age Less than 18 Years Is Enabled") then AgeInYearsAt(Today()) < 18 else false
extension:
  url:
    v: displaySequence
  value: integer
    v: 2
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Condition Positive for Sickle Cell
extension:
  url:
    v: statement
  value: string
    v: define "Condition Positive for Sickle Cell": if (Config."Sickle Cell Check Enabled") then exists( Common."Positive Sickle Cell Condition" ) else false
extension:
  url:
    v: displaySequence
  value: integer
    v: 3
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Is Active Cancer Treatment?
extension:
  url:
    v: statement
  value: string
    v: define "Is Active Cancer Treatment?": if (Config."Active Cancer Treatment Encounters Condition Is Enabled") then "Has Two or More Encounters with Cancer Diagnosis During Encounter Period" or "Has Active Cancer Diagnosis on Problem List" else false
extension:
  url:
    v: displaySequence
  value: integer
    v: 4
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Conditions Likely Terminal for Opioid Prescribing
extension:
  url:
    v: statement
  value: string
    v: define "Conditions Likely Terminal for Opioid Prescribing": if (Config."End-Stage Disease Criteria Enabled") then exists ( Common."US Core-Categorized Conditions" EOLC where EOLC.code in Common."Conditions likely terminal for opioid prescribing" // and EOLC.clinicalStatus in Common."Active Condition" ) else false
extension:
  url:
    v: displaySequence
  value: integer
    v: 5
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Is Opioid Review Useful?
extension:
  url:
    v: statement
  value: string
    v: define "Is Opioid Review Useful?": not "Patient Age Less Than 18" and not "Condition Positive for Sickle Cell" and not "Is Active Cancer Treatment?" and not "Conditions Likely Terminal for Opioid Prescribing"
extension:
  url:
    v: displaySequence
  value: integer
    v: 6
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKData
extension:
  url:
    v: name
  value: string
    v: DrugIngredients
extension:
  url:
    v: statement
  value: string
    v: /* This library contains drug ingredient data for opioid ingredients of combinations drugs as determined using the [RxNav](https://rxnav.nlm.nih.gov/) API. The content was produced using the process described [here](http://build.fhir.org/ig/cqframework/opioid-cds-r4/service-documentation.html#solution-component-1-medication-and-terminology-knowledge-base). This version of the content was generated on 2020-10-20 This product uses publicly available data courtesy of the U.S. National Library of Medicine (NLM), National Institutes of Health, Department of Health and Human Services; NLM is not responsible for the product and does not endorse or recommend this or any other product. Nelson SJ, Zeng K, Kilbourne J, Powell T, Moore R. Normalized names for clinical drugs: RxNorm at 6 years. J Am Med Inform Assoc. 2011 Jul-Aug;18(4)441-8. doi: 10.1136/amiajnl-2011-000116. Epub 2011 Apr 21. PubMed PMID: 21515544; PubMed Central PMCID: PMC3128404. [Full text](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3128404/) */ /* DrugIngredients: List<{ drugCode Integer, drugName String, doseFormCode Integer, doseFormName String, ingredientCode Integer, ingredientName String, strength String, strengthValue Decimal, strengthUnit String }> */ // Generated from LocalDataStore_RxNav_OpioidCds-2020-10-20.sqlite define DrugIngredients: { { drugCode: 197696, drugName: '72 HR fentanyl 0.075 MG/HR Transdermal System', doseFormCode: 316987, doseFormName: 'Transdermal System', ingredientCode: 4337, ingredientName: 'Fentanyl', strength: '0.075 MG/HR', strengthValue: 0.075, strengthUnit: 'MG/HR' }, { drugCode: 197873, drugName: 'levorphanol tartrate 2 MG Oral Tablet', doseFormCode: 317541, doseFormName: 'Oral Tablet', ingredientCode: 6378, ingredientName: 'Levorphanol', strength: '2 MG', strengthValue: 2.0, strengthUnit: 'MG' }, { drugCode: 205533, drugName: '1 ML buprenorphine 0.3 MG/ML Injection [Buprenex]', doseFormCode: 1649574, doseFormName: 'Injection', ingredientCode: 1819, ingredientName: 'Bup…
extension:
  url:
    v: displaySequence
  value: integer
    v: 7
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: CDCMMEClinicalConversionFactors
extension:
  url:
    v: name
  value: string
    v: CDCMMEClinicalConversionFactorsCodeSystem
extension:
  url:
    v: statement
  value: string
    v: define CDCMMEClinicalConversionFactorsCodeSystem: CodeSystem { name: string { value: 'CDCMMEClinicalConversionFactors' }, supplements: canonical { value: 'http://www.nlm.nih.gov/research/umls/rxnorm' }, concept: List<FHIR.CodeSystem.Concept> { FHIR.CodeSystem.Concept { code: code { value: '2670' }, display: string { value: 'Codeine' }, property: List<FHIR.CodeSystem."Concept"."Property"> { FHIR.CodeSystem."Concept"."Property" { code: code { value: 'conversion-factor' }, value: decimal { value: 0.15 } } } }, FHIR.CodeSystem.Concept { code: code { value: '4337' }, display: string { value: 'Fentanyl' }, property: List<FHIR.CodeSystem."Concept"."Property"> { FHIR.CodeSystem."Concept"."Property" { code: code { value: 'dose-form-conversion-factor' }, value: string { value: '316987:7200@0.33333333' } } } }, FHIR.CodeSystem.Concept { code: code { value: '3423' }, display: string { value: 'Hydromorphone' }, property: List<FHIR.CodeSystem."Concept"."Property"> { FHIR.CodeSystem."Concept"."Property" { code: code { value: 'conversion-factor' }, value: decimal { value: 4 } } } }, FHIR.CodeSystem.Concept { code: code { value: '5489' }, display: string { value: 'Hydrocodone' }, property: List<FHIR.CodeSystem."Concept"."Property"> { FHIR.CodeSystem."Concept"."Property" { code: code { value: 'conversion-factor' }, value: decimal { value: 1 } } } }, FHIR.CodeSystem.Concept { code: code { value: '6813' }, display: string { value: 'Methadone' }, property: List<FHIR.CodeSystem."Concept"."Property"> { FHIR.CodeSystem."Concept"."Property" { code: code { value: 'dose-range-conversion-factor' }, value: string { value: '1-20:4' } }, FHIR.CodeSystem."Concept"."Property" { code: code { value: 'dose-range-conversion-factor' }, value: string { value: '21-40:8' } }, FHIR.CodeSystem."Concept"."Property" { code: code { value: 'dose-range-conversion-factor' }, value: string { value: '41-60:10' } }, FHIR.CodeSystem."Concept"."Property" { code: code { value: 'dose-range-conversion-factor' }, value: st…
extension:
  url:
    v: displaySequence
  value: integer
    v: 8
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ConversionFactorSupplement
extension:
  url:
    v: statement
  value: string
    v: /* The use of the CDCMMEClinicalConversionFactors is a workaround for the fact that we can't retrieve the formally defined CodeSystem resource (https://fhir.org/guides/cdc/opioid-mme-r4/CodeSystem-CDCMMEClinicalConversionFactors.html) from the FHIR server */ define ConversionFactorSupplement: CDCMMEClinicalConversionFactors."CDCMMEClinicalConversionFactorsCodeSystem" C where C.supplements.value = 'http://www.nlm.nih.gov/research/umls/rxnorm' and ( C.name.value = ConversionFactorSupplementName or exists ( C.useContext UC where UC.code ~ "Task Usage Context" and UC.value ~ "MME Calculation" ) )
extension:
  url:
    v: displaySequence
  value: integer
    v: 9
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: Active Ambulatory Opioid Rx
extension:
  url:
    v: statement
  value: string
    v: define "Active Ambulatory Opioid Rx": if Config."Can the implementing EHR support queries for past medications by date range?" then ( "Get MedicationRequest Medication as Code"("Get Active Ambulatory Medication Requests"([MedicationRequest])) ) Rx where date from Rx.authoredOn 2 years or less on or before Today() and Rx.medication in "Opioid analgesics with ambulatory misuse potential" else List<FHIR.MedicationRequest>{}
extension:
  url:
    v: displaySequence
  value: integer
    v: 10
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Total MME
extension:
  url:
    v: statement
  value: string
    v: define "Total MME": MMECalculator.TotalMME( ( "Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions" union Common."Active Ambulatory Opioid Rx" ) AmbulatoryOpioidPrescription where Routines."Is Subacute or Chronic Pain Prescription?"( AmbulatoryOpioidPrescription ) )
extension:
  url:
    v: displaySequence
  value: integer
    v: 11
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Inclusion Criteria
extension:
  url:
    v: statement
  value: string
    v: define "Inclusion Criteria": "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential" and Routines."Is Opioid Review Useful?" and "Total MME" >= 50 '{MME}/d'
extension:
  url:
    v: displaySequence
  value: integer
    v: 12
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: US Core-Categorized Conditions
extension:
  url:
    v: statement
  value: string
    v: // 3. Medications indicating end of life /* or exists ( "Medications Indicating End of Life" ) */ define "US Core-Categorized Conditions": [Condition: category in "Encounter Diagnosis Condition Category"] union [Condition: category in "Problem List Condition Category"] union [Condition: category in "US Core Health Concern Condition Category"]
extension:
  url:
    v: displaySequence
  value: integer
    v: 13
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: Conditions Indicating End of Life or With Limited Life Expectancy
extension:
  url:
    v: statement
  value: string
    v: define "Conditions Indicating End of Life or With Limited Life Expectancy": ( "US Core-Categorized Conditions" C where C.code in "Conditions likely terminal for opioid prescribing" and C.clinicalStatus in "Active Condition" ) union ( "US Core-Categorized Conditions" C where C.code in "Limited life expectancy conditions" and C.clinicalStatus in "Active Condition" )
extension:
  url:
    v: displaySequence
  value: integer
    v: 14
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: Admitted/Referred/Discharged to Hospice Care
extension:
  url:
    v: statement
  value: string
    v: define "Admitted/Referred/Discharged to Hospice Care": ( if (Config."Hospice Findings Exclusion Enabled") then [Observation: code in "Hospice Finding Codes"] O where not (O.status.value in { 'unknown', 'entered-in-error', 'cancelled' }) else {} ) union ( [Encounter] E where date from E.period.start 1 year or less on or before Today() and ( if E.hospitalization.dischargeDisposition.coding is null or not exists (E.hospitalization.dischargeDisposition.coding) then false else E.hospitalization.dischargeDisposition in "Hospice Disposition" ) and E.status.value in { 'planned', 'arrived', 'in-progress', 'finished', 'onleave' } )
extension:
  url:
    v: displaySequence
  value: integer
    v: 15
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: End of Life Assessment
extension:
  url:
    v: statement
  value: string
    v: define "End of Life Assessment": // 1. Conditions indicating end of life or with limited life expectancy exists ( "Conditions Indicating End of Life or With Limited Life Expectancy" ) // 2. Admitted/referred/discharged to hospice care or exists ( "Admitted/Referred/Discharged to Hospice Care" )
extension:
  url:
    v: displaySequence
  value: integer
    v: 16
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Exclusion Criteria
extension:
  url:
    v: statement
  value: string
    v: define "Exclusion Criteria": Common."End of Life Assessment"
extension:
  url:
    v: displaySequence
  value: integer
    v: 17
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSREC04And05
extension:
  url:
    v: name
  value: string
    v: Is Recommendation Applicable?
extension:
  url:
    v: statement
  value: string
    v: define "Is Recommendation Applicable?": "Inclusion Criteria" and not "Exclusion Criteria"
extension:
  url:
    v: displaySequence
  value: integer
    v: 18
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: Is Opioid Analgesic with Ambulatory Misuse Potential?
extension:
  url:
    v: statement
  value: string
    v: define function "Is Opioid Analgesic with Ambulatory Misuse Potential?"(value List<MedicationRequest>): ("Get MedicationRequest Medication as Code"(value)) Rx where Rx.medication in "Opioid analgesics with ambulatory misuse potential" and Rx.category in "Community"
extension:
  url:
    v: displaySequence
  value: integer
    v: 19
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: Get MedicationRequest Medication as Code
extension:
  url:
    v: statement
  value: string
    v: define function "Get MedicationRequest Medication as Code"(value List<MedicationRequest>): value Rx let Med: if Rx.medication is Reference then singleton from ( [Medication] M where M.id = (Last(Split((Rx.medication as FHIR.Reference).reference, '/'))) ) else null return MedicationRequest { id: Rx.id, status: Rx.status, intent: Rx.intent, category: Rx.category, medication: if Rx.medication is Reference then Med.code else Rx.medication as CodeableConcept, subject: Rx.subject, authoredOn: Rx.authoredOn, recorder: Rx.recorder, dosageInstruction: Rx.dosageInstruction, dispenseRequest: Rx.dispenseRequest }
extension:
  url:
    v: displaySequence
  value: integer
    v: 20
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: FHIRHelpers
extension:
  url:
    v: name
  value: string
    v: ToConcept
extension:
  url:
    v: statement
  value: string
    v: 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 }
extension:
  url:
    v: displaySequence
  value: integer
    v: 21
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Is Subacute or Chronic Pain Prescription?
extension:
  url:
    v: statement
  value: string
    v: // End of Active Cancer Treatment Routine /* ** Routine #4 ** For Subacute or Chronic Pain Routine ** ** Definition | Answer to Proceed | Details | Data (Terminology) Requirement ** ----------------------------------------------------------------------------------------------------------------------------------- ** Order for opioid analgesic | Yes | Order for opioid analgesics with ambulatory | Opioid analgesics with ** with expected supply | | misuse potential with a supply duration of >= | ambulatory misuse potential ** duration >= 28 days | | 28 days | ** | | | ** | | - Subacute definition = order for opioid | ** | | analgesics with ambulatory misuse | ** | | potential with a supply duration of one to | ** | | two months. | ** | | - Chronic pain definition = order for opioid | ** | | analgesics with ambulatory misuse | ** | | potential with a supply duration of >= two | ** | | months. | ** ----------------------------------------------------------------------------------------------------------------------------------- ** */ define function "Is Subacute or Chronic Pain Prescription?"(prescription FHIR.MedicationRequest): "Is Subacute or Chronic Pain Using Expected Supply Duration"(prescription) or "Is Subacute or Chronic Pain Using Validity Period"(prescription)
extension:
  url:
    v: displaySequence
  value: integer
    v: 22
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Is Subacute or Chronic Pain Using Expected Supply Duration
extension:
  url:
    v: statement
  value: string
    v: define function "Is Subacute or Chronic Pain Using Expected Supply Duration"(prescription FHIR.MedicationRequest): ( prescription.dispenseRequest is not null and prescription.dispenseRequest.expectedSupplyDuration is not null and ( Common.GetDurationInDays(prescription.dispenseRequest.expectedSupplyDuration) >= 28 days ) )
extension:
  url:
    v: displaySequence
  value: integer
    v: 23
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSCommon
extension:
  url:
    v: name
  value: string
    v: GetDurationInDays
extension:
  url:
    v: statement
  value: string
    v: define function GetDurationInDays(value FHIR.Duration): if value is null then null else case when value.code.value ~ 'a' then System.Quantity{ value: value.value.value * 365.0, unit: 'days' } when value.code.value ~ 'mo' then System.Quantity{ value: value.value.value * 30.0, unit: 'days' } when value.code.value ~ 'wk' then System.Quantity{ value: value.value.value * 7.0, unit: 'days' } when value.code.value ~ 'd' then System.Quantity{ value: value.value.value, unit: 'days' } when value.code.value ~ 'h' then System.Quantity{ value: value.value.value / 24.0, unit: 'days' } when value.code.value ~ 'min' then System.Quantity{ value: value.value.value / 60.0 / 24.0, unit: 'days' } when value.code.value ~ 's' then System.Quantity{ value: value.value.value / 60.0 / 60.0 / 24.0, unit: 'days' } when value.code.value ~ 'ms' then System.Quantity{ value: value.value.value / 60.0 / 60.0 / 24.0 / 1000.0, unit: 'days' } when value.code.value is null then Message(1000, true, 'Undefined', 'Error', 'Duration unit code is null') else Message(1000, true, 'Undefined', 'Error', 'Unsupported duration unit code: ' + value.code.value) end
extension:
  url:
    v: displaySequence
  value: integer
    v: 24
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OpioidCDSRoutines
extension:
  url:
    v: name
  value: string
    v: Is Subacute or Chronic Pain Using Validity Period
extension:
  url:
    v: statement
  value: string
    v: define function "Is Subacute or Chronic Pain Using Validity Period"(prescription FHIR.MedicationRequest): ( prescription.dispenseRequest is not null and prescription.dispenseRequest.validityPeriod is not null and ( days between prescription.dispenseRequest.validityPeriod.start and prescription.dispenseRequest.validityPeriod.end >= 28 ) )
extension:
  url:
    v: displaySequence
  value: integer
    v: 25
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: FHIRHelpers
extension:
  url:
    v: name
  value: string
    v: ToDateTime
extension:
  url:
    v: statement
  value: string
    v: define function ToDateTime(value dateTime): value.value
extension:
  url:
    v: displaySequence
  value: integer
    v: 26
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: TotalMME
extension:
  url:
    v: statement
  value: string
    v: /* Calculates total Morphine Milligram Equivalent (MME) for the given list of medications. The calculation assumes the most aggressive dosing, and is performed for all medications in the given list (i.e. no additional filtering for status is performed). */ define function TotalMME(prescriptions List<MedicationRequest>): OMTKLogic.Quantity( Sum((MME(prescriptions)) M return M.mme.value), '{MME}/d' )
extension:
  url:
    v: displaySequence
  value: integer
    v: 27
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: Quantity
extension:
  url:
    v: statement
  value: string
    v: define function Quantity(value Decimal, unit String): if value is not null then Quantity { value: value, unit: unit } else null
extension:
  url:
    v: displaySequence
  value: integer
    v: 28
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: MME
extension:
  url:
    v: statement
  value: string
    v: /* Calculates Morphine Milligram Equivalent (MME) for each medication in the given list. The calculation assumes the most aggresive dosing, and is performed for all medications in the given list (i.e. no additional filtering for status is performed). */ define function MME(prescriptions List<MedicationRequest>): (Prescriptions(prescriptions)) P let mmePerIngredient: OMTKLogic.CalculateMMEs({ { rxNormCode: P.rxNormCode, doseQuantity: P.dose, dosesPerDay: P.dosesPerDay } }) return { rxNormCode: P.rxNormCode, isDraft: P.isDraft, isPRN: P.isPRN, prescription: P.prescription, dailyDose: Combine(mmePerIngredient X return X.dailyDoseDescription, '\r\n'), mme: Sum(mmePerIngredient X return X.mme) }
extension:
  url:
    v: displaySequence
  value: integer
    v: 29
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: Prescriptions
extension:
  url:
    v: statement
  value: string
    v: /* Extracts the relevant information for prescription calculation from a list of FHIR MedicationRequest resources. This assumes a MedicationRequest that conforms to the MMEMedicationRequest profile, specifically: * 1 and only 1 dosageInstruction * 1 and only 1 doseAndRate * 1 timing with 1 repeat * frequency, frequencyMax, defaulting to 1 * period, periodUnit, defaulting to 1 'd' * doseQuantity or doseRange * timeOfDay Note that if timeOfDay is specified in addition to frequency and period, it is ignored (i.e. assumed to be consistent with the specified frequency and period). TimeOfDay is only used to determine timesPerDay if frequency and period are not specified. */ define function Prescriptions(Orders List<MedicationRequest>): Orders O let rxNormCode: OMTKLogic.GetMedicationCode(O.medication), medicationName: OMTKLogic.GetMedicationName(rxNormCode), // NOTE: Assuming a single dosage instruction element dosageInstruction: singleton from O.dosageInstruction, // NOTE: Some systems return multiple doseAndRate entries, with system-specific codes for the types. In those cases, // this logic should select the most appropriate dose and rate, but standardization on doseAndRate type codes is // needed to make this logic shareable doseAndRate: singleton from (dosageInstruction.doseAndRate DR where DR.type is null or DR.type.text = 'ordered'), repeat: dosageInstruction.timing.repeat, frequency: Coalesce(repeat.frequencyMax.value, repeat.frequency.value), period: OMTKLogic.Quantity(repeat.period.value, repeat.periodUnit.value), doseRange: ToFHIRRange(doseAndRate.dose), doseQuantity: ToFHIRQuantity(doseAndRate.dose), doseHigh: ToQuantity(doseRange.high as FHIR.SimpleQuantity), timesPerDay: Count(repeat.timeOfDay), doseDescription: Coalesce( ToString(ToQuantity(doseQuantity)), ToString(doseRange.low.value.value) + '-' + ToString(doseRange.high.value.value) + ' ' + doseRange.high.unit.value ), frequencyDescription: ToString(dosageInstruction.timing.repeat.frequency.value) + Coal…
extension:
  url:
    v: displaySequence
  value: integer
    v: 30
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetMedicationCode
extension:
  url:
    v: statement
  value: string
    v: /* Returns the first RxNorm code in the given concept that matches a drug code specified in OMTKData. */ define function GetMedicationCode(concept Concept): First( ((concept.codes) C where C.system = 'http://www.nlm.nih.gov/research/umls/rxnorm' return singleton from ( OMTKData.DrugIngredients DI where DI.drugCode = ToInteger(C.code) return Code { code: ToString(DI.drugCode), system: 'http://www.nlm.nih.gov/research/umls/rxnorm', display: DI.drugName } ) ) X where X is not null )
extension:
  url:
    v: displaySequence
  value: integer
    v: 31
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetMedicationName
extension:
  url:
    v: statement
  value: string
    v: /* Returns the display of the given code, if present, otherwise looks it up from the OMTK data */ define function GetMedicationName(rxNormCode Code): if rxNormCode.display is null then singleton from ( OMTKData.DrugIngredients DI where DI.drugCode = ToInteger(rxNormCode.code) return DI.drugName ) else rxNormCode.display
extension:
  url:
    v: displaySequence
  value: integer
    v: 32
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: FHIRHelpers
extension:
  url:
    v: name
  value: string
    v: ToString
extension:
  url:
    v: statement
  value: string
    v: define function ToString(value string): value.value
extension:
  url:
    v: displaySequence
  value: integer
    v: 33
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: ToFHIRRange
extension:
  url:
    v: statement
  value: string
    v: /* Helper function to force the choice of the FHIR.Range value. This avoids the need for the _is_ and _as_ operators on choices, which is not implemented in the JavaScript CQL engine. */ define function ToFHIRRange(range FHIR.Range): range
extension:
  url:
    v: displaySequence
  value: integer
    v: 34
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: ToFHIRQuantity
extension:
  url:
    v: statement
  value: string
    v: /* Helper function to force the choice of the FHIR.SimpleQuantity value. This avoids the need for the _is_ and _as_ operators on choices, which is not implemented in the JavaScript CQL engine. */ define function ToFHIRQuantity(quantity FHIR.SimpleQuantity): quantity
extension:
  url:
    v: displaySequence
  value: integer
    v: 35
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: MMECalculator
extension:
  url:
    v: name
  value: string
    v: ToQuantity
extension:
  url:
    v: statement
  value: string
    v: /* FHIRHelpers ToQuantity logic incorrectly uses the unit element of the FHIR Quantity, when it should be using the code element as the actual coded unit. https://github.com/cqframework/clinical_quality_language/issues/557 Until the above issue is addressed, this function provides ToQuantity functionality for this library */ define function ToQuantity(quantity FHIR.SimpleQuantity): case when quantity is null then null when quantity.value is null then null when quantity.system is null or quantity.system = 'http://unitsofmeasure.org' then System.Quantity { value: quantity.value.value, unit: quantity.code.value } when quantity.system.value = 'http://terminology.hl7.org/CodeSystem/v3-orderableDrugForm' then System.Quantity { value: quantity.value.value, unit: Coalesce(quantity.code.value, quantity.unit.value)} else Message(null, true, 'MMECalculator.ToQuantity.InvalidFHIRQuantity', ErrorLevel, 'Invalid FHIR Quantity code: ' & quantity.code.value) end
extension:
  url:
    v: displaySequence
  value: integer
    v: 36
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: ToDaily
extension:
  url:
    v: statement
  value: string
    v: /* Calculates daily frequency given frequency within a period */ define function ToDaily(frequency Integer, period Quantity): case period.unit when 'h' then frequency * (24.0 / period.value) when 'min' then frequency * (24.0 / period.value) * 60 when 's' then frequency * (24.0 / period.value) * 60 * 60 when 'd' then frequency * (24.0 / period.value) / 24 when 'wk' then frequency * (24.0 / period.value) / (24 * 7) when 'mo' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'a' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ when 'hour' then frequency * (24.0 / period.value) when 'minute' then frequency * (24.0 / period.value) * 60 when 'second' then frequency * (24.0 / period.value) * 60 * 60 when 'day' then frequency * (24.0 / period.value) / 24 when 'week' then frequency * (24.0 / period.value) / (24 * 7) when 'month' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'year' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ when 'hours' then frequency * (24.0 / period.value) when 'minutes' then frequency * (24.0 / period.value) * 60 when 'seconds' then frequency * (24.0 / period.value) * 60 * 60 when 'days' then frequency * (24.0 / period.value) / 24 when 'weeks' then frequency * (24.0 / period.value) / (24 * 7) when 'months' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */ when 'years' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */ else Message(null, true, 'OMTKLogic.ToDaily.UnknownUnit', ErrorLevel, 'Unknown unit ' & period.unit) end
extension:
  url:
    v: displaySequence
  value: integer
    v: 37
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: CalculateMMEs
extension:
  url:
    v: statement
  value: string
    v: /* Calculates MMEs for the given input prescription information and returns it as a list of tuples: List<Tuple { rxNormCode Code, doseFormCode Code, doseQuantity Quantity, dosesPerDay Decimal, ingredientCode Code, strength Quantity, dailyDose Quantity, dailyDoseDescription String, conversionFactor Decimal, mme Quantity }> */ define function CalculateMMEs(medications List<Tuple { rxNormCode Code, doseQuantity Quantity, dosesPerDay Decimal }>): Flatten( medications M let Ingredients: GetIngredients(M.rxNormCode) return Ingredients I let adjustedDoseQuantity: M.doseQuantity, dailyDose: GetDailyDose(I.ingredientCode, I.strength, I.doseFormCode, adjustedDoseQuantity, M.dosesPerDay), factor: ConversionFactors.GetConversionFactor(I.ingredientCode, dailyDose.result, I.doseFormCode, M.dosesPerDay) return { rxNormCode: M.rxNormCode, doseFormCode: I.doseFormCode, doseQuantity: adjustedDoseQuantity, dosesPerDay: M.dosesPerDay, ingredientCode: I.ingredientCode, strength: I.strength, dailyDose: dailyDose.result, dailyDoseDescription: dailyDose.description & (' * factor: ' + Coalesce(ToString(factor), 'No conversion factor available')), conversionFactor: factor, mme: Quantity( Round(dailyDose.result.value * factor, 1), '{MME}/d' ) } )
extension:
  url:
    v: displaySequence
  value: integer
    v: 38
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetIngredients
extension:
  url:
    v: statement
  value: string
    v: /* Returns the opioid ingredients and their strengths that make up the drug identified by the given rxNormCode as a list of tuples: List<Tuple { rxNormCode Code, doseFormCode Code, doseFormName String, ingredientCode Code, ingredientName String, strength Quantity }> */ /* GetIngredients: List<{ rxNormCode Code, doseFormCode Code, ingredientCode code, strength Quantity }> */ define function GetIngredients(rxNormCode Code): OMTKData.DrugIngredients DI where DI.drugCode = ToInteger(rxNormCode.code) return { rxNormCode: Code { code: ToString(DI.drugCode), system: 'http://www.nlm.nih.gov/research/umls/rxnorm', display: DI.drugName }, doseFormCode: Code { code: ToString(DI.doseFormCode), system: 'http://www.nlm.nih.gov/research/umls/rxnorm', display: DI.doseFormName }, ingredientCode: Code { code: ToString(DI.ingredientCode), system: 'http://www.nlm.nih.gov/research/umls/rxnorm', display: DI.ingredientName }, strength: Quantity { value: DI.strengthValue, unit: ToUCUM(DI.strengthUnit) } }
extension:
  url:
    v: displaySequence
  value: integer
    v: 39
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: ToUCUM
extension:
  url:
    v: statement
  value: string
    v: /* Normalizes the input units to UCUM units The values listed here are the only ones currently present in the OMTK data Based on the HL7 UCUM subset here: http://download.hl7.de/documents/ucum/ucumdata.html */ define function ToUCUM(unit String): case unit when 'MG' then 'mg' when 'MG/ACTUAT' then 'mg/{actuat}' when 'MG/HR' then 'mg/h' when 'MG/ML' then 'mg/mL' else Message(null, true, 'OMTKLogic.ToUCUM.UnknownUnit', ErrorLevel, 'Unknown unit ' & unit) end
extension:
  url:
    v: displaySequence
  value: integer
    v: 40
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetDailyDose
extension:
  url:
    v: statement
  value: string
    v: /* define function StripPer(unit String): if LastPositionOf('/', unit) >= 0 then Substring(unit, 0, LastPositionOf('/', unit)) else unit */ /* Calculates daily dose for a specific ingredient based on the ingredient strength, dose form, dose quantity, and daily frequency. In addition, returns a textual description of the daily dose. Tuple { result: Quantity, description: String } */ define function GetDailyDose(ingredientCode Code, strength Quantity, doseFormCode Code, doseQuantity Quantity, dosesPerDay Decimal): case when dosesPerDay is null or doseQuantity is null or strength is null or strength.value is null or strength.unit is null then { result: null as Quantity, description: 'Missing doses per day, dose quantity, and/or strength' } /* if patch --> daily dose = dose value (e.g, number patches with doseQuantity unit = "patch") * per-hour strength */ when ToInteger(doseFormCode.code) = 316987 then /* buprenorphine or fentanyl patch */ if ToInteger(ingredientCode.code) in { 1819, 4337 } then (Quantity { value: dosesPerDay * doseQuantity.value * strength.value, unit: strength.unit }) dailyDose return { result: dailyDose, description: GetIngredientName(ingredientCode) & ' patch: ' & ToString(doseQuantity.value) & ' * ' & ToString(dosesPerDay) & '/d * ' & ToString(strength) & ' = ' + ToString(dailyDose) } else { result: null as Quantity, description: 'Unknown patch ingredient: ' & ingredientCode.code & ':' & ingredientCode.display } /* if dose unit in actual mass units (mg or ug -- when it's a single med) --> daily dose = numTimesPerDay * dose */ when doseQuantity.unit in { 'mg', 'ug' } then (Quantity { value: dosesPerDay * doseQuantity.value, unit: doseQuantity.unit }) dailyDose return { result: dailyDose, description: GetIngredientName(ingredientCode) + ' ' + GetDoseFormName(doseFormCode) + ': ' + ToString(dosesPerDay) + '/d * ' + ToString(doseQuantity) + ' = ' + ToString(dailyDose) } /* if doseQuantity is in actual volume units (mL) --> daily dose = numTimesPerDay …
extension:
  url:
    v: displaySequence
  value: integer
    v: 41
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetIngredientName
extension:
  url:
    v: statement
  value: string
    v: /* Returns the display of the given ingredient, if present, otherwise looks it up from the OMTK data */ define function GetIngredientName(ingredientCode Code): if ingredientCode.display is null then singleton from ( OMTKData.DrugIngredients DI where DI.ingredientCode = ToInteger(ingredientCode.code) return DI.ingredientName ) else ingredientCode.display
extension:
  url:
    v: displaySequence
  value: integer
    v: 42
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: GetDoseFormName
extension:
  url:
    v: statement
  value: string
    v: /* Returns the display of the given dose form, if present, otherwise looks it up from the OMTK data */ define function GetDoseFormName(doseFormCode Code): if doseFormCode.display is null then singleton from ( OMTKData.DrugIngredients DI where DI.doseFormCode = ToInteger(doseFormCode.code) return DI.doseFormName ) else doseFormCode.display
extension:
  url:
    v: displaySequence
  value: integer
    v: 43
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: OMTKLogic
extension:
  url:
    v: name
  value: string
    v: StripPer
extension:
  url:
    v: statement
  value: string
    v: /* Removes the last per argument from a unit NOTE: Rewrote to not use LastPositionOf, since that function is not implemented in the JS engine https://github.com/cqframework/cql-execution/issues/147 */ define function StripPer(unit String): unit X let split: Split(unit, '/'), splitCount: Count(split) return if splitCount > 1 then Substring(unit, 0, Length(unit) - Length(split[splitCount - 1]) - 1) else unit
extension:
  url:
    v: displaySequence
  value: integer
    v: 44
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: GetConversionFactor
extension:
  url:
    v: statement
  value: string
    v: /* Returns the conversion factor for the given ingredient CDC Guidance: https://www.cdc.gov/drugoverdose/pdf/calculating_total_daily_dose-a.pdf |Opioid (strength in mg except where noted) |MME Conversion Factor*| |-----------------------------------------------|----------------------| |Codeine | 0.15 | |Fentanyl, transdermal patch (MCG/HR) | 2.4 | |Hydrocodone | 1 | |Hydromorphone | 4 | |Methadone | | | 1-20 mg/d | 4 | | 21-40 mg/d | 8 | | 41-60 mg/d | 10 | | 61-80+ mg/d | 12 | | Morphine | 1 | | Oxycodone | 1.5 | | Oxymorphone | 3 | */ define function GetConversionFactor(ingredientCode System.Code, dailyDose System.Quantity, doseFormCode System.Code, dosesPerDay System.Decimal): Coalesce( LookupConversionFactor(ingredientCode, dailyDose, doseFormCode, dosesPerDay), case ToInteger(ingredientCode.code) when 2670 then 0.15 /* Codeine */ when 4337 then ( /* Fentanyl */ case when ToInteger(doseFormCode.code) = 316987 then (0.33333333 / dosesPerDay) * 7200 /* Transdermal system */ else Message(null, true, 'OMTKLogic.GetConversionFactor.UnknownDoseForm', ErrorLevel, 'Unknown dose form code ' & doseFormCode.code) end ) when 5489 then 1 /* Hydrocodone */ when 3423 then 4 /* Hydromorphone */ when 6813 then ( /* Methadone */ case when dailyDose.value between 1 and 20 then 4 when dailyDose.value between 21 and 40 then 8 when dailyDose.value between 41 and 60 then 10 when dailyDose.value >= 61 then 12 when dailyDose is null or dailyDose.value is null then Message(null, true, 'OMTKLogic.GetConversionFactor.DailyDoseNull', ErrorLevel, 'Daily dose is required to determine methadone conversion factor') else Message(null, dailyDose.value < 1, 'OMTKLogic.GetConversionFactor.DailyDoseLessThanOne', ErrorLevel, 'Daily dose less than 1') end ) when 7052 then 1 /* Morphine */ when 7804 then 1.5 /* Oxycodone */ when 7814 then 3 /* Oxymorphone */ else Message(null, true, 'OMTKLogic.GetConversionFactor.UnknownIngredientCode', ErrorLevel, 'Unknown ingredient code: ' & ingredientCode.code) end…
extension:
  url:
    v: displaySequence
  value: integer
    v: 45
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: LookupConversionFactor
extension:
  url:
    v: statement
  value: string
    v: /* Looks up the conversion factor for the given ingredient, daily dose, and dose form from the configured conversion factor supplement, if available. If no conversion factor supplement is configured, returns null */ define function LookupConversionFactor(ingredientCode System.Code, dailyDose System.Quantity, doseFormCode System.Code, dosesPerDay System.Decimal): ConversionFactorSupplement CFS let ingredientConcept: singleton from (CFS."concept" C where C.code.value = ingredientCode.code), conversionFactor: singleton from (ingredientConcept.property P where P.code.value = 'conversion-factor'), doseFormConversionFactors: (ingredientConcept.property P where P.code.value = 'dose-form-conversion-factor'), doseRangeConversionFactors: (ingredientConcept.property P where P.code.value = 'dose-range-conversion-factor') return Coalesce ( case when exists (doseRangeConversionFactors) then singleton from ( doseRangeConversionFactors DRCF where dailyDose.value in ToDoseRange(DRCF.value) return ToDoseRangeConversionFactor(DRCF.value) ) when exists (doseFormConversionFactors) then singleton from ( doseFormConversionFactors DFCF where doseFormCode.code = ToDoseForm(DFCF.value) return ToDoseFormConversionFactor(DFCF.value, dosesPerDay) ) else null end, ToConversionFactor(conversionFactor.value) )
extension:
  url:
    v: displaySequence
  value: integer
    v: 46
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: FHIRHelpers
extension:
  url:
    v: name
  value: string
    v: ToCode
extension:
  url:
    v: statement
  value: string
    v: 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 }
extension:
  url:
    v: displaySequence
  value: integer
    v: 47
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToDoseRange
extension:
  url:
    v: statement
  value: string
    v: /* Converts the property value of a dose-range-conversion-factor property to the dose range <low-value>-<high-value>:<conversion-factor> Note that low-value and/or high-value may be wildcards '*' */ define function ToDoseRange(propertyValue FHIR.string): ({ : }) X let rangeValues: Split(Split(propertyValue.value, ':')[0], '-') return Interval[ToRangeValue(rangeValues[0]), ToRangeValue(rangeValues[1])]
extension:
  url:
    v: displaySequence
  value: integer
    v: 48
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToRangeValue
extension:
  url:
    v: statement
  value: string
    v: /* Converts a range value boundary to a Decimal (or null for a wildcard) */ define function ToRangeValue(value System.String): if value = '*' then null else ToDecimal(value)
extension:
  url:
    v: displaySequence
  value: integer
    v: 49
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToDoseRangeConversionFactor
extension:
  url:
    v: statement
  value: string
    v: /* Converts the property value of a dose-range-conversion-factor property to the conversion factor <low-value>-<high-value>:<conversion-factor> */ define function ToDoseRangeConversionFactor(propertyValue FHIR.string): ToDecimal(Split(propertyValue.value, ':')[1])
extension:
  url:
    v: displaySequence
  value: integer
    v: 50
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToDoseForm
extension:
  url:
    v: statement
  value: string
    v: /* Converts the property value of a dose-form-conversion-factor property to the dose form <dose-form-code>:<conversion-factor> */ define function ToDoseForm(propertyValue FHIR.string): Split(propertyValue.value, ':')[0]
extension:
  url:
    v: displaySequence
  value: integer
    v: 51
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToDoseFormConversionFactor
extension:
  url:
    v: statement
  value: string
    v: /* Converts the property value of a dose-form-conversion-factor property to the conversion factor <dose-form-code>:<conversion-factor>[@doses-per-day] */ define function ToDoseFormConversionFactor(propertyValue FHIR.string, dosesPerDay System.Decimal): if PositionOf('@', propertyValue.value) > 0 then ToDoseFormDosesPerDayConversionFactor(propertyValue, dosesPerDay) else ToDecimal(Split(propertyValue.value, ':')[1])
extension:
  url:
    v: displaySequence
  value: integer
    v: 52
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

extension:
  url:
    v: libraryName
  value: string
    v: ConversionFactors
extension:
  url:
    v: name
  value: string
    v: ToConversionFactor
extension:
  url:
    v: statement
  value: string
    v: /* Returns the conversion factor for a conversion-factor property NOTE: These functions are used to avoid use of _is_ and _as_ */ define function ToConversionFactor(propertyValue FHIR.decimal): propertyValue.value
extension:
  url:
    v: displaySequence
  value: integer
    v: 53
url:
  v: http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition

id:
  v: effective-data-requirements
url:
  v: http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-effectiveDataRequirements
value: canonical
  v: #effective-data-requirements

use:
  v: official
value:
  v: cdc-opioid-guidance

v: 2022.1.0

v: PlanDefinition_Recommendation_04_05_Order_Sign

v: Recommendations #4 and #5 - Lowest Effective Dose

coding:
  system:
    v: http://terminology.hl7.org/CodeSystem/plan-definition-type
  code:
    v: eca-rule
  display:
    v: ECA Rule

v: draft

v: true

v: 2025-07-01

v: Centers for Disease Control and Prevention (CDC)

telecom:
  system:
    v: url
  value:
    v: https://www.cdc.gov

v: Recommendation 4: When opioids are initiated for opioid-naïve patients with acute, subacute, or chronic pain, clinicians should prescribe the lowest effective dosage. If opioids are continued for subacute or chronic pain, clinicians should use caution when prescribing opioids at any dosage, should carefully evaluate individual benefits and risks when considering increasing dosage, and should avoid increasing dosage above levels likely to yield diminishing returns in benefits relative to risks to patients. Recommendation 5: For patients already receiving opioid therapy, clinicians should carefully weigh benefits and risks and exercise care when changing opioid dosage. If benefits outweigh risks of continued opioid therapy, clinicians should work closely with patients to optimize nonopioid therapies while continuing opioid therapy. If benefits do not outweigh risks of continued opioid therapy, clinicians should optimize other therapies and work closely with patients to gradually taper to lower dosages or, if warranted based on the individual circumstances of the patient, appropriately taper and discontinue opioids. Unless there are indications of a life-threatening issue such as warning signs of impending overdose (e.g., confusion, sedation, or slurred speech), opioid therapy should not be discontinued abruptly, and clinicians should not rapidly reduce opioid dosages from higher dosages.

code:
  system:
    v: http://terminology.hl7.org/CodeSystem/usage-context-type
  code:
    v: focus
  display:
    v: Clinical Focus
value: CodeableConcept
  coding: http://snomed.info/id/182888003
    system:
      v: http://snomed.info/sct
    code:
      v: 182888003
    display:
      v: Medication requested (situation)

code:
  system:
    v: http://terminology.hl7.org/CodeSystem/usage-context-type
  code:
    v: focus
  display:
    v: Clinical Focus
value: CodeableConcept
  coding: http://snomed.info/id/82423001
    system:
      v: http://snomed.info/sct
    code:
      v: 82423001
    display:
      v: Chronic pain (finding)

code:
  system:
    v: http://terminology.hl7.org/CodeSystem/usage-context-type
  code:
    v: focus
  display:
    v: Clinical Focus
value: CodeableConcept
  coding: http://snomed.info/id/274663001
    system:
      v: http://snomed.info/sct
    code:
      v: 274663001
    display:
      v: Acute pain (finding)

code:
  system:
    v: http://terminology.hl7.org/CodeSystem/usage-context-type
  code:
    v: focus
  display:
    v: Clinical Focus
value: CodeableConcept
  text:
    v: Subacute pain

v: The 2022 CDC Clinical Practice Guideline for Prescribing Opioids for Pain is intended to improve communication between clinicians and patients about the benefits and risks of pain treatments, including opioid therapy; improve the effectiveness and safety of pain treatment; mitigate pain; improve function and quality of life for patients with pain; and reduce risks associated with opioid pain therapy, including opioid use disorder, overdose, and death. The recommendations do not apply to pain related to sickle cell disease or cancer or to patients receiving palliative or end-of-life care.

v: The recommendations related to opioid dosages are not intended to be used as an inflexible, rigid standard of care; rather, they are intended to be guideposts to help inform clinician-patient decision-making. Risks of opioid use, including risk for overdose and overdose death, increase continuously with dosage, and there is no single dosage threshold below which risks are eliminated. Therefore, the recommendation language emphasizes that clinicians should avoid increasing dosage above levels likely to yield diminishing returns in benefits relative to risks to patients rather than emphasizing a single specific numeric threshold. Further, these recommendations apply specifically to starting opioids or to increasing opioid dosages, and a different set of benefits and risks applies to reducing opioid dosages.

v: © CDC 2016+.

text:
  v: Opioid Prescribing

name:
  v: Kensaku Kawamoto, MD, PhD, MHS

name:
  v: Bryn Rhodes

name:
  v: Floyd Eisenberg, MD, MPH

name:
  v: Robert McClure, MD, MPH

type:
  v: documentation
display:
  v: 2022 CDC Clinical Practice Guideline for Prescribing Opioids for Pain
url:
  v: https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm
document:
  url:
    v: https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm

extension:
  url:
    v: http://hl7.org/fhir/StructureDefinition/cqf-strengthOfRecommendation
  value: CodeableConcept
    coding:
      id:
        v: recommendation-4-strength-of-recommendation
      system:
        v: http://terminology.hl7.org/CodeSystem/recommendation-strength
      code:
        v: strong
      display:
        v: Strong
    coding:
      id:
        v: recommendation-5-strength-of-recommendation
      system:
        v: http://terminology.hl7.org/CodeSystem/recommendation-strength
      code:
        v: weak
      display:
        v: Weak
extension:
  url:
    v: http://hl7.org/fhir/StructureDefinition/cqf-qualityOfEvidence
  value: CodeableConcept
    coding:
      id:
        v: recommendation-4-evidence-quality
      system:
        v: http://terminology.hl7.org/CodeSystem/evidence-quality
      code:
        v: low
      display:
        v: Low quality
    coding:
      id:
        v: recommendation-5-evidence-quality
      system:
        v: http://terminology.hl7.org/CodeSystem/evidence-quality
      code:
        v: very-low
      display:
        v: Very low quality
title:
  v: Calibrate to Lowest Opioid Dose Needed for Expected Results and Exercise Care When Changing Opioid Dosages
description:
  v: When opioid therapy is considered appropriate, calibrate opioid dosages to lowest dose needed to achieve expected effects. For patients already receiving opioid therapy, clinicians should carefully weigh benefits and risks and exercise care when changing opioid dosage. [For guidance in determining the lowest effective opioid dosage, see Recommendation 4 of the 2022 CDC Clinical Practice Guideline](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#Recommendation4) [For patients who have received opioid therapy for longer durations of time, if tapering, consider working closely with the patient to gradually taper dosages (no more than 10% per month)](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#:~:text=When%20patients%20have%20been%20taking%20opioids%20for%20longer%20durations%20(e.g.%2C%20for%20%E2%89%A51%20year)%2C%20tapers%20of%2010%25%20per%20month%20or%20slower%20are%20likely%20to%20be%20better%20tolerated%20than%20more%20rapid%20tapers.) For a tapering calculator, go to [https://agencymeddirectors.wa.gov/Calculator/TaperDoseCalculator.html](https://www.agencymeddirectors.wa.gov/Calculator/TaperDoseCalculator.html) [For more guidance regarding tapering, please see Recommendation 5 of the 2022 CDC Clinical Practice Guideline for Prescribing Opioids for Pain](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#Recommendation5).) **MME Calculator Cautions** 1) All doses are in mg/day except for fentanyl, which is mcg/hr. 2) Equianalgesic dose conversions are only estimates and cannot account for individual variability in genetics and pharmacokinetics. 3) Do not use the calculated dose in MMEs to determine the doses to use when converting one opioid to another; when converting opioids, the new opioid is typically dosed at a substantially lower dose than the calculated MME dose to avoid overdose because of incomplete cross-tolerance and individual variability in opioid pharmacokinetics. Consult the FDA approved product labeling for specific guidance on medica…
priority:
  v: urgent
trigger:
  type:
    v: named-event
  name:
    v: order-sign
condition:
  kind:
    v: applicability
  expression:
    description:
      v: Check whether the current order is for an opioid with ambulatory misuse potential, the calculated MME result for the order and other active opioid medications for the patient is greater than or equal to 50 and if an opioid review is appropriate for the patient
    language:
      v: text/cql.identifier
    expression:
      v: Is Recommendation Applicable?
grouping behavior:
  v: visual-group
selection behavior:
  v: any
action:
  description:
    v: Document - Will prescribe a lower dose
action:
  description:
    v: Document - Will calibrate a gradual change in dosage
action:
  description:
    v: Snooze* - Benefits outweigh risks, snooze 3 months
action:
  description:
    v: Snooze* - Short term benefits outweigh risks, snooze 1 month
action:
  description:
    v: Snooze* - N/A add comment, snooze 3 months