Opioid Prescribing Support Implementation Guide
2016.4.0 - CI Build

Opioid Prescribing Support 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 2016.4.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

Library: OpioidCDSREC10CommonLibrary

Official URL: http://fhir.org/guides/cdc/opioid-cds/Library/OpioidCDSREC10Common Version: 2016.4.0
Draft as of 2024-08-29 Computable Name: OpioidCDSREC10Common
Id: OpioidCDSREC10Common
Url: OpioidCDSREC10Common
Version: 2016.4.0
Name: OpioidCDSREC10Common
Status: draft
Type:

system: http://terminology.hl7.org/CodeSystem/library-type

code: logic-library

Date: 2024-08-29 04:46:56+0000
Publisher: Centers for Disease Control and Prevention (CDC)
Related Artifacts:

Dependencies

Parameters:
NameTypeMinMaxIn/Out
PatientPatient01Out
Lookback YearPeriod01Out
Laboratory ObservationsObservation0*Out
Cocaine ScreeningsObservation0*Out
Has Positive Screening for Cocaine in Last 12 Monthsboolean01Out
PCP ScreeningsObservation0*Out
Has Positive Screening for PCP in Last 12 Monthsboolean01Out
Opiate ScreeningsObservation0*Out
Has Positive Screening for Opiates in Last 12 Monthsboolean01Out
Applicable Because of Positive Cocaine or PCP or Opiatesboolean01Out
Non-opioid ScreeningsObservation0*Out
Patient had Urine Screening in Last 12 Monthsboolean01Out
Inclusion Criteriaboolean01Out
Exclusion Criteriaboolean01Out
Positive Opiate ScreeningsObservation0*Out
Negative Opiate ScreeningsObservation0*Out
Positive PCP ScreeningsObservation0*Out
Negative PCP ScreeningsObservation0*Out
Positive Cocaine ScreeningsObservation0*Out
Negative Cocaine ScreeningsObservation0*Out
Negative PCP Screenings Count Since Last Positive Screeninginteger01Out
Negative Opiate Screenings Count Since Last Positive Screeninginteger01Out
Negative Cocaine Screenings Count Since Last Positive Screeninginteger01Out
Positive Opiate Dates in Lookback Periodstring0*Out
Positive Cocaine Dates in Lookback Periodstring0*Out
Positive PCP Dates in Lookback Periodstring0*Out
Cocaine Summarystring01Out
Cocaine Detailstring01Out
Opiates Summarystring01Out
Opiates Detailstring01Out
PCP Summarystring01Out
PCP Detailstring01Out
Indicatorstring01Out
Urine Drug Screening ProcedureRequest CategoryCodeableConcept01Out
Cocaine And PCP Summarystring01Out
Data Requirements:
TypeProfileMSCode Filter
Patient http://hl7.org/fhir/StructureDefinition/Patient
Observation http://hl7.org/fhir/StructureDefinition/Observation ; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Condition http://hl7.org/fhir/StructureDefinition/Condition ; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-encounter-diagnosis-category
Condition http://hl7.org/fhir/StructureDefinition/Condition ; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-problem-list-category
Condition http://hl7.org/fhir/StructureDefinition/Condition ; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/condition-us-core-health-concern-category
ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest
ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest ;;;;
Procedure http://hl7.org/fhir/StructureDefinition/Procedure ;;; code filter:
path: code
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/hospice-procedure
ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest ;;;
Encounter http://hl7.org/fhir/StructureDefinition/Encounter ;;;;
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;;;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Observation http://hl7.org/fhir/StructureDefinition/Observation ;; code filter:
path: category
value set: http://fhir.org/guides/cdc/opioid-cds/ValueSet/observation-category-laboratory
Content: text/cql
library OpioidCDSREC10Common version '2016.4.0'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers
include OpioidCDSCommon version '2016.4.0' called Common
include OpioidCDSRoutines version '2016.4.0' called Routines
include OpioidCDSCommonConfig version '2016.4.0' called Config

/*
**  Recommendation #10
**    When prescribing opioids for chronic pain, providers should use urine drug
**    testing before starting opioid therapy and consider urine drug testing at
**    least annually to assess for prescribed medications as well as other controlled
**    prescription drugs and illicit drugs (recommendation category: B, evidence type: 4)
**
**  When
**    Provider is prescribing an opioid analgesic with ambulatory misuse potential in the outpatient setting
**    Prescription is for treating chronic pain.
**    Opioid review is useful for this patient:
**      Patient is 18 or over
**      Patient does not have findings indicating limited life expectancy
**      Patient does not have orders for therapies indicating end of life care
**      Patient is not undergoing active cancer treatment:
**        Patient has had at least 2 encounters within the past year with any diagnosis of cancer
**    Urine drug screening has not been performed in last 12 months
**  Then
**    Recommend urine drug screening
**      Will perform urine screening
**      Not for chronic pain management, snooze 3 months
**      N/A - see comment, snooze 3 months
**
*/

// META: Plan Definition: http://fhir.org/guides/cdc/opioid-cds/PlanDefinition/opioid-cds-10-patient-view

context Patient

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

define "Applicable Because of Positive Cocaine or PCP or Opiates":
  if exists (Common."Opioid Other Than Synthetic Ordered In Last 12 Months") then
    "Has Positive Screening for Cocaine in Last 12 Months"
    or "Has Positive Screening for PCP in Last 12 Months"
  else
    "Has Positive Screening for Cocaine in Last 12 Months"
      or "Has Positive Screening for PCP in Last 12 Months"
      or
        if Config."Opiate Urine Screening Check Enabled" then
          "Has Positive Screening for Opiates in Last 12 Months"
        else false

define "Inclusion Criteria":
  not Common."Patient Age Less Than 18"
    and Routines."Is Opioid Review Useful?"
    and (not "Patient had Urine Screening in Last 12 Months")

define "Exclusion Criteria":
  Common."End of Life Assessment"

define "Patient had Urine Screening in Last 12 Months":
  (
    exists ("Non-opioid Screenings")
    or exists ("Cocaine Screenings")
    or exists ("PCP Screenings")
  )
  and
    if Config."Opiate Urine Screening Check Enabled" then
      exists ("Opiate Screenings")
    else
      true

define "Laboratory Observations":
  [Observation: "category" in Common."Observation Category Laboratory"]

define "Non-opioid Screenings":
  GetRelevantScreenings("Laboratory Observations" LabObservations
    where (LabObservations.code in Common."Non-opioid drug urine screening")
  )

define "Opiate Screenings":
  GetRelevantScreenings("Laboratory Observations" LabObservations
    where (LabObservations.code in Common."Opioid drug urine screening")
  )

define "Cocaine Screenings":
  GetRelevantScreenings("Laboratory Observations" LabObservations
    where (LabObservations.code in Common."Cocaine Urine Tests")
  )

define "PCP Screenings":
  GetRelevantScreenings("Laboratory Observations" LabObservations
    where (LabObservations.code in Common."PCP Urine Tests")
  )

define function "GetRelevantScreenings" (obsList List<Observation>):
  obsList LabObservations
     where date from LabObservations.effective in day of "Lookback Year"
       and not (LabObservations.status.value in { 'unknown', 'entered-in-error', 'cancelled' })

// Returns a text representation of a dateTime using the CQL `ToString` function.
// @param d - a FHIR dateTime to get text for
// @returns {System.String} the text representation of the dateTime
define function "DateTimeText" (d FHIR.dateTime):
  ToString(d.value)

define "Positive Opiate Screenings":
  "Opiate Screenings" Opiate where StartsWith(Lower(Opiate.value as FHIR.string), 'pos')

define "Negative Opiate Screenings":
  "Opiate Screenings" Opiate where StartsWith(Lower(Opiate.value as FHIR.string), 'neg')

define "Positive PCP Screenings":
  "PCP Screenings" PCP where StartsWith(Lower(PCP.value as FHIR.string), 'pos')

define "Negative PCP Screenings":
  "PCP Screenings" PCP where StartsWith(Lower(PCP.value as FHIR.string), 'neg')

define "Positive Cocaine Screenings":
  "Cocaine Screenings" Cocaine where StartsWith(Lower(Cocaine.value as FHIR.string), 'pos')

define "Negative Cocaine Screenings":
  "Cocaine Screenings" Cocaine where StartsWith(Lower(Cocaine.value as FHIR.string), 'neg')

/*
  borrowed from CDS4CPM CDS_Connect_Commons_for_FHIRv400
  Should this go into OpioidCDSCommon?
*/
define function "MostRecent" (ObsList List<Observation>):
  Last(ObsList O sort by Coalesce(
    (effective as FHIR.dateTime).value,
    (effective as FHIR.Period)."end".value,
    (effective as FHIR.Period)."start".value,
    issued.value)
  )

define "Negative PCP Screenings Count Since Last Positive Screening":
  Count(
    "Negative PCP Screenings" N
      where DateTimeText(N.effective) > DateTimeText("MostRecent"("Positive PCP Screenings").effective)
  )

define "Negative Opiate Screenings Count Since Last Positive Screening":
  Count(
    "Negative Opiate Screenings" N
      where DateTimeText(N.effective) > DateTimeText("MostRecent"("Positive Opiate Screenings").effective)
  )

define "Negative Cocaine Screenings Count Since Last Positive Screening":
  Count(
    "Negative Cocaine Screenings" N
      where DateTimeText(N.effective) > DateTimeText("MostRecent"("Positive Cocaine Screenings").effective)
  )

define "Positive Opiate Dates in Lookback Period":
  "Positive Opiate Screenings" Opiate
    return DateTimeText(Opiate.effective)

define "Positive Cocaine Dates in Lookback Period":
  "Positive Cocaine Screenings" CS
    return DateTimeText(CS.effective)

define "Positive PCP Dates in Lookback Period":
  "Positive PCP Screenings" PS
    return DateTimeText(PS.effective)

define "Has Positive Screening for Cocaine in Last 12 Months":
  exists ("Cocaine Screenings" CS where StartsWith(Lower(CS.value as FHIR.string), 'pos'))

define "Has Positive Screening for PCP in Last 12 Months":
  exists ("PCP Screenings" PCP where StartsWith(Lower(PCP.value as FHIR.string), 'pos'))

define "Has Positive Screening for Opiates in Last 12 Months":
  if Config."Opiate Urine Screening Check Enabled" then
    exists ("Opiate Screenings" Opioid where StartsWith(Lower(Opioid.value as FHIR.string), 'pos'))
  else false

define "Cocaine Detail":
  if "Has Positive Screening for Cocaine in Last 12 Months" then
    "Cocaine Summary"
  else null

define "Opiates Detail":
  if "Has Positive Screening for Opiates in Last 12 Months" then
    "Opiates Summary"
  else null

define "PCP Detail":
  if "Has Positive Screening for PCP in Last 12 Months" then
    "PCP Summary"
  else null

define function "Get Detail" (isScreeningRecommended Boolean):
  if isScreeningRecommended then
    'Patients on opioid therapy should have a urine drug test performed every 12 months.'
  else if "Applicable Because of Positive Cocaine or PCP or Opiates" then
    "Cocaine Detail"&
    "Opiates Detail"&
    "PCP Detail"&
    '<br/>Note: result may be false positive result or indicate patient is occasional user or addicted to the illicit drug.'
  else
      null

define "Indicator":
  'warning'

    /*
        Used only in PlanDefinition
     */
define function "Get Summary" (isScreeningRecommended Boolean):
  if isScreeningRecommended then
    'Annual Urine Screening Check'
  else if "Applicable Because of Positive Cocaine or PCP or Opiates" then
    if Config."Opiate Urine Screening Check Enabled" then
      'Positive Cocaine or PCP or Opiates in Urine Screening'
    else 'Positive Cocaine or PCP in Urine Screening'
  else null

define "Urine Drug Screening ProcedureRequest Category":
  FHIR.CodeableConcept {
    coding: {
      FHIR.Coding {
        system: FHIR.uri { value: 'http://terminology.hl7.org/CodeSystem/medicationrequest-category' },
        code: FHIR.code { value: 'outpatient' },
        display: FHIR.string { value: 'Outpatient' }
      }
    }
  }
  /* singleton from (First(
    [Encounter] E
      where E.period starts same day as Today()
      sort by start of period desc
  ).type) */

define "Cocaine And PCP Summary":
  'Positive for Cocaine AND PCP <br/><br/>' +
    "Cocaine Summary" + '<br/>' + "PCP Summary"

define "Opiates Summary":
  if not exists Common."Opioid Other Than Synthetic Ordered In Last 12 Months" then
    if "Negative Opiate Screenings Count Since Last Positive Screening" > 0 then
      '<br/>*Positive for Opiates: ' +
      Combine("Positive Opiate Dates in Lookback Period", ', ') +
      '  (' + ToString("Negative Opiate Screenings Count Since Last Positive Screening") +
      ' negative since)'
    else
      '<br/>*Positive for Opiates: ' +
      Combine("Positive Opiate Dates in Lookback Period", ', ')
  else null

define "PCP Summary":
  if "Negative PCP Screenings Count Since Last Positive Screening" > 0 then
    '<br/>*Positive for PCP: <br/>' +
    Combine("Positive PCP Dates in Lookback Period", ', ') +
    '  (' + ToString("Negative PCP Screenings Count Since Last Positive Screening") +
    ' negative since)'
  else
    '<br/>*Positive for PCP: <br/>' +
    Combine("Positive PCP Dates in Lookback Period", ', ')

define "Cocaine Summary":
  if "Negative Cocaine Screenings Count Since Last Positive Screening" > 0 then
    '<br/>*Positive for Cocaine: <br/>' +
    Combine("Positive Cocaine Dates in Lookback Period", ', ') +
    '  (' + ToString("Negative Cocaine Screenings Count Since Last Positive Screening") +
    ' negative since)'
  else
    '<br/>*Positive for Cocaine: <br/>' +
    Combine("Positive Cocaine Dates in Lookback Period", ', ')
Content: application/elm+xml
Encoded data (186540 characters)
Content: application/elm+json
Encoded data (338100 characters)