2022 CDC Clinical Practice Guideline for Prescribing Opioids Implementation Guide
2022.1.0 - CI Build

2022 CDC Clinical Practice Guideline for Prescribing Opioids Implementation Guide, published by Centers for Disease Control and Prevention (CDC). This guide is not an authorized publication; it is the continuous build for version 2022.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/opioid-cds-r4/ and changes regularly. See the Directory of published versions

PlanDefinition: Recommendation #10 - Urine Drug Testing (order-sign) (Experimental)

Official URL: http://fhir.org/guides/cdc/opioid-cds/PlanDefinition/opioidcds-10-order-sign Version: 2022.1.0
Draft as of 2025-04-24 Computable Name: PlanDefinition_Recommendation_10_Order_Sign
Other Identifiers: cdc-opioid-guidance (use: official, )

Usage:Clinical Focus: Medication requested (situation), Clinical Focus: Chronic pain (finding), Clinical Focus: 

Copyright/Legal: © CDC 2016+.

When prescribing opioids for subacute or chronic pain, clinicians should consider the benefits and risks of toxicology testing to assess for prescribed medications as well as other prescribed and nonprescribed controlled substances.

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.

Id: opioidcds-10-order-sign
Url: Recommendation #10 - Urine Drug Testing (order-sign)
Version: 2022.1.0
Identifier:

value: cdc-opioid-guidance

Name: PlanDefinition_Recommendation_10_Order_Sign
Title: Recommendation #10 - Urine Drug Testing (order-sign)
Status: draft
Experimental: true
Type:

system: http://terminology.hl7.org/CodeSystem/plan-definition-type

code: eca-rule

display: ECA Rule

Date: 2025-04-24
Publisher: Centers for Disease Control and Prevention (CDC)
Description: When prescribing opioids for subacute or chronic pain, clinicians should consider the benefits and risks of toxicology testing to assess for prescribed medications as well as other prescribed and nonprescribed controlled substances.
Logic Definitions:
Library NameNamesequence
OpioidCDSREC10OrderSign Subacute or Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions 0
define "Subacute or 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 )


Library NameNamesequence
OpioidCDSREC10OrderSign Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential 1
define "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential":
  exists( "Subacute or Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions" )


Library NameNamesequence
OpioidCDSRoutines Patient Age Less Than 18 2
define "Patient Age Less Than 18":
  if (Config."Age Less than 18 Years Is Enabled") then
    AgeInYearsAt(Today()) < 18
  else false


Library NameNamesequence
OpioidCDSRoutines Condition Positive for Sickle Cell 3
define "Condition Positive for Sickle Cell":
  if (Config."Sickle Cell Check Enabled") then
    exists(
      Common."Positive Sickle Cell Condition"
    ) 
  else false


Library NameNamesequence
OpioidCDSRoutines Is Active Cancer Treatment? 4
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


Library NameNamesequence
OpioidCDSRoutines Conditions Likely Terminal for Opioid Prescribing 5
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


Library NameNamesequence
OpioidCDSRoutines Is Opioid Review Useful? 6
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"


Library NameNamesequence
OpioidCDSREC10Common Inclusion Criteria For UDS Recommendation 7
/*
@description: Determines whether an opioid review is appropriate for the patient and whether they had a UDS performed in the past year
*/
define "Inclusion Criteria For UDS Recommendation":
  Routines."Is Opioid Review Useful?"
    and not exists (
      if Config."Use Alternative UDS Lookback Period"
        then "All Opioid or Non-opioid UDS in Alternative Lookback Period"
      else "All Opioid or Non-opioid UDS in Lookback Period"
    )


Library NameNamesequence
OpioidCDSREC10OrderSign Is Perform Drug Screen Recommendation Applicable? 8
define "Is Perform Drug Screen Recommendation Applicable?":
  "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential"
    and Rec10Common."Inclusion Criteria For UDS Recommendation"


Library NameNamesequence
OpioidCDSREC10Common Amphetamine Simple Identifier 9
define "Amphetamine Simple Identifier": 'Amphetamine'


Library NameNamesequence
OpioidCDSREC10Common UDS Lookback Period 10
// Constants

define "UDS Lookback Period":
  Interval[Today() - 12 months - 1 days, Today()]


Library NameNamesequence
OpioidCDSREC10Common All Opioid or Non-opioid UDS in Lookback Period 11
define "All Opioid or Non-opioid UDS in Lookback Period":
  (
    [Observation: Common."All Drug Urine Screening"] Lab
      where date from Lab.effective in day of "UDS Lookback Period"
        and not (
          Lab.status in { 'unknown', 'entered-in-error', 'cancelled' }
        )
  ) X sort by date from effective desc


Library NameNamesequence
OpioidCDSREC10Common Amphetamine Screenings In Lookback Period 12
// Amphetamines
define "Amphetamine Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Amphetamine Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Amphetamine Screenings In Lookback Period 13
define "Positive Amphetamine Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Amphetamine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Amphetamine Screenings In Lookback Period 14
define "Negative Amphetamine Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Amphetamine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Rx Lookback Period 15
define "Rx Lookback Period":
  Interval[Today() - 12 months - 31 days, Today()]


Library NameNamesequence
OpioidCDSREC10Common Normalize Rx In Lookback Period 16
define "Normalize Rx In Lookback Period":
  Common."Get MedicationRequest Medication as Code"(
    [MedicationRequest: category in Common."Community"] Rx
      where Rx.status in { 'active', 'completed', 'stopped' }
        and Rx.intent = 'order'
        and Common."GetDateFromMedicationRequest"(Rx) in day of "Rx Lookback Period"
  )


Library NameNamesequence
OpioidCDSREC10Common Amphetamine Rx In Lookback Period 17
define "Amphetamine Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
      where Rx.medication in Common."Amphetamine Medications"


Library NameNamesequence
OpioidCDSREC10Common Barbiturate Simple Identifier 18
define "Barbiturate Simple Identifier": 'Barbiturate'


Library NameNamesequence
OpioidCDSREC10Common Barbiturate Screenings In Lookback Period 19
// Barbiturates
define "Barbiturate Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Barbiturate Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Barbiturate Screenings In Lookback Period 20
define "Positive Barbiturate Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Barbiturate Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Barbiturate Screenings In Lookback Period 21
define "Negative Barbiturate Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Barbiturate Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Barbiturate Rx In Lookback Period 22
define "Barbiturate Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
      where Rx.medication in Common."Barbiturate Medications"


Library NameNamesequence
OpioidCDSREC10Common Benzodiazepine Simple Identifier 23
define "Benzodiazepine Simple Identifier": 'Benzodiazepine'


Library NameNamesequence
OpioidCDSREC10Common Benzodiazepine Screenings In Lookback Period 24
// Benzodiazepines
define "Benzodiazepine Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Benzodiazepine Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Benzodiazepine Screenings In Lookback Period 25
define "Positive Benzodiazepine Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Benzodiazepine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Benzodiazepine Screenings In Lookback Period 26
define "Negative Benzodiazepine Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Benzodiazepine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Benzodiazepine Rx In Lookback Period 27
define "Benzodiazepine Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Benzodiazepine medications"


Library NameNamesequence
OpioidCDSREC10Common Buprenorphine Simple Identifier 28
define "Buprenorphine Simple Identifier": 'Buprenorphine'


Library NameNamesequence
OpioidCDSREC10Common Buprenorphine Screenings In Lookback Period 29
// Buprenorphine
define "Buprenorphine Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Buprenorphine Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Buprenorphine Screenings In Lookback Period 30
define "Positive Buprenorphine Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Buprenorphine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Buprenorphine Screenings In Lookback Period 31
define "Negative Buprenorphine Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Buprenorphine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Buprenorphine Rx In Lookback Period 32
define "Buprenorphine Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Buprenorphine Medications"


Library NameNamesequence
OpioidCDSREC10Common Cannabinoid Simple Identifier 33
define "Cannabinoid Simple Identifier": 'Cannabinoid'


Library NameNamesequence
OpioidCDSREC10Common Cannabinoid Screenings In Lookback Period 34
// Cannabinoids
define "Cannabinoid Screenings In Lookback Period":
  if Config."Cannabinoid Urine Screening Check Enabled"
    then (
      "All Opioid or Non-opioid UDS in Lookback Period" Lab
        where Lab.code in Common."Cannabinoid Urine Tests"
    ) else null


Library NameNamesequence
OpioidCDSCommonConfig Cannabinoid Urine Screening Check Enabled 35
define "Cannabinoid Urine Screening Check Enabled":
  false


Library NameNamesequence
OpioidCDSREC10Common Positive Cannabinoid Screenings In Lookback Period 36
define "Positive Cannabinoid Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Cannabinoid Screenings In Lookback Period", Config."Cannabinoid Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Negative Cannabinoid Screenings In Lookback Period 37
define "Negative Cannabinoid Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Cannabinoid Screenings In Lookback Period", Config."Cannabinoid Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Cocaine Simple Identifier 38
define "Cocaine Simple Identifier": 'Cocaine'


Library NameNamesequence
OpioidCDSREC10Common Cocaine Screenings In Lookback Period 39
// Cocaine
define "Cocaine Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Cocaine Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Cocaine Screenings In Lookback Period 40
define "Positive Cocaine Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Cocaine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Cocaine Screenings In Lookback Period 41
define "Negative Cocaine Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Cocaine Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Fentanyl Simple Identifier 42
define "Fentanyl Simple Identifier": 'Fentanyl'


Library NameNamesequence
OpioidCDSREC10Common Fentanyl Screenings In Lookback Period 43
// Fentanyl
define "Fentanyl Screenings In Lookback Period":
  if Config."Opiate Urine Screening Check Enabled"
  then (
    "All Opioid or Non-opioid UDS in Lookback Period" AllLabs
      where AllLabs.code in Common."Fentanyl Urine Tests"
  ) else null


Library NameNamesequence
OpioidCDSCommonConfig Opiate Urine Screening Check Enabled 44
// Recommendation 10
define "Opiate Urine Screening Check Enabled":
  true


Library NameNamesequence
OpioidCDSREC10Common Positive Fentanyl Screenings In Lookback Period 45
define "Positive Fentanyl Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Fentanyl Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Negative Fentanyl Screenings In Lookback Period 46
define "Negative Fentanyl Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Fentanyl Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Fentanyl Rx In Lookback Period 47
define "Fentanyl Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Fentanyl Medications"


Library NameNamesequence
OpioidCDSREC10Common Heroin Simple Identifier 48
define "Heroin Simple Identifier": 'Heroin (6-AM)'


Library NameNamesequence
OpioidCDSREC10Common Heroin Screenings In Lookback Period 49
// Heroin
define "Heroin Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Heroin Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Heroin Screenings In Lookback Period 50
define "Positive Heroin Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Heroin Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Heroin Screenings In Lookback Period 51
define "Negative Heroin Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Heroin Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Methadone Simple Identifier 52
define "Methadone Simple Identifier": 'Methadone'


Library NameNamesequence
OpioidCDSREC10Common Methadone Screenings In Lookback Period 53
// Methadone
define "Methadone Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" Lab
    where Lab.code in Common."Methadone Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive Methadone Screenings In Lookback Period 54
define "Positive Methadone Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Methadone Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative Methadone Screenings In Lookback Period 55
define "Negative Methadone Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Methadone Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Methadone Rx In Lookback Period 56
define "Methadone Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Methadone Medications"


Library NameNamesequence
OpioidCDSREC10Common Opiate Simple Identifier 57
define "Opiate Simple Identifier": 'Opiate'


Library NameNamesequence
OpioidCDSREC10Common Opiate Screenings In Lookback Period 58
// Opiates
define "Opiate Screenings In Lookback Period":
  if Config."Opiate Urine Screening Check Enabled"
    then (
      "All Opioid or Non-opioid UDS in Lookback Period" Lab
        where Lab.code in Common."General Opiate Urine Tests"
    ) else null


Library NameNamesequence
OpioidCDSREC10Common Positive Opiate Screenings In Lookback Period 59
define "Positive Opiate Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Opiate Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Negative Opiate Screenings In Lookback Period 60
define "Negative Opiate Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Opiate Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Opiate Rx In Lookback Period 61
define "Opiate Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Opiate Medications"


Library NameNamesequence
OpioidCDSREC10Common Oxycodone Simple Identifier 62
define "Oxycodone Simple Identifier": 'Oxycodone'


Library NameNamesequence
OpioidCDSREC10Common Oxycodone Screenings In Lookback Period 63
// Oxycodone
define "Oxycodone Screenings In Lookback Period":
  if Config."Opiate Urine Screening Check Enabled"
    then (
      "All Opioid or Non-opioid UDS in Lookback Period" Lab
        where Lab.code in Common."Oxycodone Urine Tests"
    ) else null


Library NameNamesequence
OpioidCDSREC10Common Positive Oxycodone Screenings In Lookback Period 64
define "Positive Oxycodone Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("Oxycodone Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Negative Oxycodone Screenings In Lookback Period 65
define "Negative Oxycodone Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("Oxycodone Screenings In Lookback Period", Config."Opiate Urine Screening Check Enabled")


Library NameNamesequence
OpioidCDSREC10Common Oxycodone Rx In Lookback Period 66
define "Oxycodone Rx In Lookback Period":
  "Normalize Rx In Lookback Period" Rx
    where Rx.medication in Common."Oxycodone Medications"


Library NameNamesequence
OpioidCDSREC10Common PCP Simple Identifier 67
define "PCP Simple Identifier": 'Phencyclidine (PCP)'


Library NameNamesequence
OpioidCDSREC10Common PCP Screenings In Lookback Period 68
// PCP
define "PCP Screenings In Lookback Period":
  "All Opioid or Non-opioid UDS in Lookback Period" AllLabs
    where AllLabs.code in Common."PCP Urine Tests"


Library NameNamesequence
OpioidCDSREC10Common Positive PCP Screenings In Lookback Period 69
define "Positive PCP Screenings In Lookback Period":
  GetPositiveLabsInLookbackPeriod("PCP Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Negative PCP Screenings In Lookback Period 70
define "Negative PCP Screenings In Lookback Period":
  GetNegativeLabsInLookbackPeriod("PCP Screenings In Lookback Period", true)


Library NameNamesequence
OpioidCDSREC10Common Unexpected Details 71
// Details Logic

define "Unexpected Details":
  {
    CreateDetailWithPossibleUnexpectedNegative(
      "Amphetamine Simple Identifier", "Positive Amphetamine Screenings In Lookback Period", 
      "Negative Amphetamine Screenings In Lookback Period", "Amphetamine Rx In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Barbiturate Simple Identifier", "Positive Barbiturate Screenings In Lookback Period", 
      "Negative Barbiturate Screenings In Lookback Period", "Barbiturate Rx In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Benzodiazepine Simple Identifier", "Positive Benzodiazepine Screenings In Lookback Period", 
      "Negative Benzodiazepine Screenings In Lookback Period", "Benzodiazepine Rx In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Buprenorphine Simple Identifier", "Positive Buprenorphine Screenings In Lookback Period", 
      "Negative Buprenorphine Screenings In Lookback Period", "Buprenorphine Rx In Lookback Period"
    ),
    CreateDetailWithoutPossibleUnexpectedNegative(
      "Cannabinoid Simple Identifier", "Positive Cannabinoid Screenings In Lookback Period", 
      "Negative Cannabinoid Screenings In Lookback Period"
    ),
    CreateDetailWithoutPossibleUnexpectedNegative(
      "Cocaine Simple Identifier", "Positive Cocaine Screenings In Lookback Period", 
      "Negative Cocaine Screenings In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Fentanyl Simple Identifier", "Positive Fentanyl Screenings In Lookback Period", 
      "Negative Fentanyl Screenings In Lookback Period", "Fentanyl Rx In Lookback Period"
    ),
    CreateDetailWithoutPossibleUnexpectedNegative(
      "Heroin Simple Identifier", "Positive Heroin Screenings In Lookback Period", 
      "Negative Heroin Screenings In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Methadone Simple Identifier", "Positive Methadone Screenings In Lookback Period", 
      "Negative Methadone Screenings In Lookback Period", "Methadone Rx In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Opiate Simple Identifier", "Positive Opiate Screenings In Lookback Period", 
      "Negative Opiate Screenings In Lookback Period", "Opiate Rx In Lookback Period"
    ),
    CreateDetailWithPossibleUnexpectedNegative(
      "Oxycodone Simple Identifier", "Positive Oxycodone Screenings In Lookback Period", 
      "Negative Oxycodone Screenings In Lookback Period", "Oxycodone Rx In Lookback Period"
    ),
    CreateDetailWithoutPossibleUnexpectedNegative(
      "PCP Simple Identifier", "Positive PCP Screenings In Lookback Period", 
      "Negative PCP Screenings In Lookback Period"
    )
  }


Library NameNamesequence
OpioidCDSREC10Common Remove Substances Without Positive or Negative Results 72
define "Remove Substances Without Positive or Negative Results":
  "Unexpected Details" Details
    where (Details.posDates is not null and Length(Details.posDates) != 0)
      or (Details.negDates is not null and Length(Details.negDates) != 0)


Library NameNamesequence
OpioidCDSREC10Common Inclusion Criteria For Unexpected Results 73
define "Inclusion Criteria For Unexpected Results":
  Routines."Is Opioid Review Useful?"
  and AnyTrue(
    "Remove Substances Without Positive or Negative Results" Details
      return (exists Details.unexpectedPosDetails) or (exists Details.unexpectedNegDetails)
  )


Library NameNamesequence
OpioidCDSREC10OrderSign Applicable Because of Unexpected Results 74
define "Applicable Because of Unexpected Results":
  "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential"
    and Rec10Common."Inclusion Criteria For Unexpected Results"


Library NameNamesequence
OpioidCDSCommon Style Header 75
define "Style Header":
  '<style>\r\n  .alert-body {\r\n    width: 670px;\r\n    font-family: segoe-ui, sans-serif;\r\n    background-color: #FEFFF1;\r\n  }\r\n\r\n  .details-table {\r\n    border-collapse:collapse;\r\n    border-style: ridge;\r\n    background-color: #FEFFF1;\r\n    padding: 2px;\r\n  }\r\n\r\n  .details-caption {\r\n    border-style: ridge;\r\n    border-bottom: none;\r\n    background-color: #FEFFF1;\r\n    padding: 2px;\r\n  }\r\n\r\n  .details-table-header {\r\n    border-style: ridge;\r\n    padding: 5px;\r\n  }\r\n\r\n  .details-table-cell {\r\n    border-style: ridge;\r\n    padding: 5px;\r\n  }\r\n\r\n  .details-table-footer-cell {\r\n    border-style: ridge;\r\n    padding: 5px;\r\n    font-size: small;\r\n  }\r\n\r\n  .details-table-cell-unexpected {\r\n    border-style: ridge;\r\n    padding: 5px;\r\n    color: red;\r\n    font-weight: bold;\r\n  }\r\n\r\n  .more-text {\r\n    position: relative;\r\n    margin-bottom: 2em;\r\n  }\r\n  \r\n  .more {\r\n    display:none;\r\n  }\r\n\r\n  .show-more:checked + .more {\r\n    display:block;\r\n  }\r\n<\/style>'


Library NameNamesequence
OpioidCDSREC10Common Unexpected Div Start 76
define "Unexpected Div Start":
  '<div class=\"alert-body\"><div><p>Patient may have <strong>unexpected urine toxicology test results<\/strong> in the past year.<\/p><\/div>'


Library NameNamesequence
OpioidCDSREC10Common Table Start 77
define "Table Start":
  '<div><table class=\"details-table\"><caption class=\"details-caption\">Urine Toxicology Results<\/caption><tr><th class=\"details-table-header\">Substance<\/th>'


Library NameNamesequence
OpioidCDSREC10Common All Lab Dates in Lookback Period 78
// Helpers  

define "All Lab Dates in Lookback Period":
  (
    "All Opioid or Non-opioid UDS in Lookback Period" Lab
      return date from Lab.effective
  ) X sort desc


Library NameNamesequence
OpioidCDSREC10Common Table Headers 79
define "Table Headers":
  "All Lab Dates in Lookback Period" LabDate
    return '<th class=\"details-table-header\">' & ToString(LabDate) & '<\/th>'


Library NameNamesequence
OpioidCDSREC10Common Generate Table Rows 80
define "Generate Table Rows":
  "Remove Substances Without Positive or Negative Results" BOT
    let row: ToString(IndexOf("Remove Substances Without Positive or Negative Results", BOT) + 1)
    return '<tr>' + GetExpectedColumn(BOT.ingredient) + Combine(
      "All Lab Dates in Lookback Period" LabDate
        let col: ToString(IndexOf("All Lab Dates in Lookback Period", LabDate) + 2)
        return all (
          if BOT.unexpectedPosDetails.date contains LabDate
            then GetUnexpectedColumn('pos', row & ':' & col)
          else if BOT.unexpectedNegDetails.udsDate contains LabDate
            then GetUnexpectedColumn('neg', row & ':' & col)
          else if BOT.posDates contains LabDate
            then GetExpectedColumn('pos*')
          else if BOT.negDates contains LabDate
            then GetExpectedColumn('neg*')
          else GetExpectedColumn('n/a')
        )
    ) + '<\/tr>'


Library NameNamesequence
OpioidCDSREC10Common Generate Footer Rows 81
define "Generate Footer Rows":
  "Remove Substances Without Positive or Negative Results" BOT
      let row: ToString(IndexOf("Remove Substances Without Positive or Negative Results", BOT) + 1),
      colspan: Length("All Lab Dates in Lookback Period") + 1
      return Combine(
          "All Lab Dates in Lookback Period" LabDate
            let col: ToString(IndexOf("All Lab Dates in Lookback Period", LabDate) + 2)
            return all (
              if BOT.unexpectedPosDetails.date contains LabDate
                then Coalesce(
                  BOT.unexpectedPosDetails PosDetail
                    where PosDetail.date same day as LabDate
                      return '<tr>' & GetFooterColumn(colspan, row & ':' & col & ' - Possible unexpected substance found: ' & PosDetail.udsDetail) & '<\/tr>'
                )
              else if BOT.unexpectedNegDetails.udsDate contains LabDate
                then Coalesce(
                  BOT.unexpectedNegDetails NegDetail
                    where NegDetail.udsDate same day as LabDate
                      return '<tr>' & GetFooterColumn(colspan, row + ':' & col & ' - Possible unexpected negative result found: prescribed ' & NegDetail.rxDetail & ' on ' & ToString(NegDetail.rxDate)) & '<\/tr>'
                )
              else ''
            )
      )


Library NameNamesequence
OpioidCDSREC10Common Table End 82
define "Table End":
  '<\/table><\/div>'


Library NameNamesequence
OpioidCDSREC10Common Details Table 83
define "Details Table": 
  "Table Start" & Combine("Table Headers") 
    & '<tbody>' & Combine("Generate Table Rows") & '</tbody>' 
    & '<tfoot>' & Combine("Generate Footer Rows") & '<\/tfoot>' 
  & "Table End"


Library NameNamesequence
OpioidCDSREC10Common Expected Result Footnote 84
define "Expected Result Footnote":
  '<div>* - These are expected results based on an analysis of the patient\'s medication list 30 days prior to the corresponding lab results.<\/div>'


Library NameNamesequence
OpioidCDSREC10Common Details More Info 85
define "Details More Info":
  '<div id=\"box\">\r\n  <p>Note on false positives and unexpected negative results...<\/p>\r\n  <input type=\"checkbox\" class=\"show-more\"> Show more\r\n  <div class=\"more\">\r\n  <p>An unexpectedly negative test may be due to time since last dose, diversion, intermittent use, aberrant drug use behavior, or other factors, including a false negative result. Clinicians should interpret this result in the context of the overall treatment plan.<\/p>\r\n\r\n  <p>Positive results may be a false positives or could represent occasional use or possible substance use disorder.<br\/><br\/>For a review regarding interpreting possible false positive urine toxicology results, see <a target=\"_blank\" href=\"https:\/\/pubmed.ncbi.nlm.nih.gov\/24986836\">http:\/\/pubmed.ncbi.nlm.nih.gov\/24986836<\/a>. It is unknown if the findings reported in this article can be extrapolated to other laboratory analyzers that were not used in the referenced studies.<br\/><br\/>For guidance regarding evaluating and addressing unexpected toxicology tests results, see <a target=\"_blank\" href=\"https:\/\/www.cdc.gov\/mmwr\/volumes\/71\/rr\/rr7103a1.htm#Recommendation10\">Recommendation 10 of the 22 CDC Clinical Practice Guideiline<\/a>.<\/p><\/div>\r\n<\/div>'


Library NameNamesequence
OpioidCDSREC10Common Div End 86
define "Div End": '<\/div>'


Library NameNamesequence
OpioidCDSREC10Common Get HTML Details 87
// HTML Generation

define "Get HTML Details":
  Common."Style Header" & "Unexpected Div Start" & "Details Table" & "Expected Result Footnote" & "Details More Info" & "Div End"


Library NameNamesequence
OpioidCDSREC10OrderSign Detail 88
define "Detail":
  Rec10Common."Get HTML Details"


Library NameNamesequence
OpioidCDSCommon Is Opioid Analgesic with Ambulatory Misuse Potential? 89
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"


Library NameNamesequence
OpioidCDSCommon Get MedicationRequest Medication as Code 90
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
      }


Library NameNamesequence
FHIRHelpers ToConcept 91
define function ToConcept(concept FHIR.CodeableConcept):
    if concept is null then
        null
    else
        System.Concept {
            codes: concept.coding C return ToCode(C),
            display: concept.text.value
        }


Library NameNamesequence
OpioidCDSRoutines Is Subacute or Chronic Pain Prescription? 92
// 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)


Library NameNamesequence
OpioidCDSRoutines Is Subacute or Chronic Pain Using Expected Supply Duration 93
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 
      )
  )


Library NameNamesequence
OpioidCDSCommon GetDurationInDays 94
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


Library NameNamesequence
OpioidCDSRoutines Is Subacute or Chronic Pain Using Validity Period 95
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 
      )
  )


Library NameNamesequence
FHIRHelpers ToDateTime 96
define function ToDateTime(value dateTime): value.value


Library NameNamesequence
OpioidCDSREC10Common CreateDetailWithPossibleUnexpectedNegative 97
define function CreateDetailWithPossibleUnexpectedNegative(TheSubstance String, ThePosLabs List<Observation>, TheNegLabs List<Observation>, TheMeds List<MedicationRequest>):
  {
    ingredient: TheSubstance,
    posDates: (
      ThePosLabs PosLab
        return date from PosLab.effective
    ),
    negDates: (
      TheNegLabs NegLab
        return date from NegLab.effective
    ),
    unexpectedPosDetails: (
      ThePosLabs PosLab
        where not exists (
          TheMeds Rx
            where Common.GetDateFromMedicationRequest(Rx)
              in day of Interval[
                date from PosLab.effective - 31 days,
                date from PosLab.effective - 1 days
              ]
        )
        return {
          date: date from PosLab.effective,
          udsDetail:
            if exists(PosLab.code.coding)
              then PosLab.code.coding[0].display
              else 'Unable to determine a detailed identifier'
        }
    ),
    unexpectedNegDetails: (
      from TheNegLabs NegLab,
        ( if exists(TheMeds) then TheMeds else { null as MedicationRequest } ) Rx
        let medDate: Common.GetDateFromMedicationRequest(Rx)
          where medDate in day of Interval[date from NegLab.effective - 31 days, date from NegLab.effective - 1 days]
          return {
            udsDate: date from NegLab.effective,
            udsDetail: if exists (NegLab.code.coding) then NegLab.code.coding[0].display else 'Unable to determine a detailed identifier',
            rxDate: medDate,
            rxDetail: 
              if Rx.medication.text is not null then Rx.medication.text
              else if exists (Rx.medication.coding) and Rx.medication.coding[0].display is not null then Rx.medication.coding[0].display 
              else 'Unable to determine a detailed identifier'
          }
    )
  }


Library NameNamesequence
OpioidCDSCommon GetDateFromMedicationRequest 98
define function "GetDateFromMedicationRequest"(med FHIR.MedicationRequest):
  if med is null then
    null
  else if med.authoredOn is not null then
    date from med.authoredOn
  else
    Max(
      med.dosageInstruction DI
        return Coalesce(
          // If there are timing events, take the latest.
          Max(DI.timing.event E return date from E),
          // Otherwise, if there's a Period, use its start.
          if DI.timing.repeat is not null
             and DI.timing.repeat.bounds is FHIR.Period
          then
            date from start of FHIRHelpers.ToInterval(DI.timing.repeat.bounds as FHIR.Period)
          else
            null
        )
    )


Library NameNamesequence
OpioidCDSREC10Common GetPositiveLabsInLookbackPeriod 99
define function GetPositiveLabsInLookbackPeriod(Labs List<FHIR.Observation>, Enabled Boolean):
  if Enabled
    then Labs Lab
     where StartsWith(Lower(Lab.value as FHIR.string), 'pos')
  else {}


Library NameNamesequence
FHIRHelpers ToString 100
define function ToString(value ObservationStatus): value.value


Library NameNamesequence
OpioidCDSREC10Common GetNegativeLabsInLookbackPeriod 101
define function GetNegativeLabsInLookbackPeriod(Labs List<FHIR.Observation>, Enabled Boolean):
  if Enabled
    then Labs Lab
     where StartsWith(Lower(Lab.value as FHIR.string), 'neg')
  else {}


Library NameNamesequence
OpioidCDSREC10Common CreateDetailWithoutPossibleUnexpectedNegative 102
define function CreateDetailWithoutPossibleUnexpectedNegative(TheSubstance String, ThePosLabs List<Observation>, TheNegLabs List<Observation>):
  {
    ingredient: TheSubstance,
    posDates: (
      ThePosLabs PosLab
        return date from PosLab.effective
    ),
    negDates: (
      TheNegLabs NegLab
        return date from NegLab.effective
    ),
    unexpectedPosDetails: (
      ThePosLabs PosLab
        return {
          date: date from PosLab.effective,
          udsDetail: if exists (PosLab.code.coding) then PosLab.code.coding[0].display else 'Unable to determine a detailed identifier'
        }
    ),
    unexpectedNegDetails: {
      null as Tuple{ udsDate System.Date, udsDetail System.String, rxDate System.Date, rxDetail System.String }
    }
  }


Library NameNamesequence
OpioidCDSREC10Common GetExpectedColumn 103
define function GetExpectedColumn(Content String):
  '<td class=\"details-table-cell\">' & Content & '<\/td>'


Knowledge Capability: shareable computable executable publishable
Use Context:
codevaluedisplay
focus 182888003 Medication requested (situation)
focus 82423001 Chronic pain (finding)
focus
Purpose:

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.

Usage: Before starting opioids and periodically (at least annually) during opioid therapy, clinicians should consider the benefits and risks of toxicology testing to assess for prescribed opioids and other prescription and nonprescription controlled substances that increase risk for overdose when combined with opioids, including nonprescribed and illicit opioids and benzodiazepines.
Copyright:

© CDC 2016+.

Related Artifacts:

Documentation

Libraries:
Library - Recommendation #10 - Urine Drug Testing
Actions:
Consider the Benefits and Risks of Conducting a Urine Toxicology Screen: Consider the benefits and risks of toxicology testing to assess for prescribed medications as well as other prescribed and nonprescribed controlled substances. For guidance regarding utilizing toxicology tests when prescribing opioids, see [Recommendation 10 of the 2022 CDC Clinical Practice Guideline](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#Recommendation10).
When: Named Event: order-sign
If: Applicability: Patient has not had a urine screening in the past 12 months (Is Perform Drug Screen Recommendation Applicable?)
Then:
:
Then:
:
Then:
:
Then:
:
Then:
Patient May Have Unexpected Toxicology Test Results: Patient may have unexpected urine toxicology test results in the past year
When: Named Event: order-sign
If: Applicability: Patient may have unexpected urine toxicology test results in the past year (Applicable Because of Unexpected Results)
Then:
:
Then:
:
Then:
:
Then: