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

Library: OpioidCDSREC10CommonLibrary

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

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

code: logic-library

Date: 2024-08-29 04:48:05+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
Content: text/cql
library OpioidCDSREC10Common version '2022.1.0'

using FHIR version '4.0.1'

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

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":
  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")
  )
  or
    if Config."Opiate Urine Screening Check Enabled" then
      exists ("Opiate Screenings")
    else
      false

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. Consult [2022 CDC Clinical Practice Guideline Recommendation 10](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#:~:text=evidence%20type%3A%204).-,Implementation%20Considerations,-Toxicology%20testing%20should) for more guidance regarding toxicology testing.'
  else if "Applicable Because of Positive Cocaine or PCP or Opiates" then
    'Patient may have unexpected urine toxicology test results in the past year, including:<br/>'
    & "Cocaine Detail"
    & "Opiates Detail"
    & "PCP Detail"
    & '<br/>Note: Positive results may be false positives or could indicate the patient is an occasional user or addicted to the substance. For a review regarding interpreting possible false positive urine toxicology results, see https://pubmed.ncbi.nlm.nih.gov/24986836/. 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. Consult [2022 CDC Clinical Practice Guideline Recommendation 10](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#:~:text=evidence%20type%3A%204).-,Implementation%20Considerations,-Toxicology%20testing%20should) for more guidance regarding toxicology testing.'
  else
      null

define "Indicator":
  'warning'

    /*
        Used only in PlanDefinition
     */
define function "Get Summary" (isScreeningRecommended Boolean):
  if isScreeningRecommended then
    'Patient May Have Unexpected Toxicology Test Results'
  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 (194456 characters)
Content: application/elm+json
Encoded data (352416 characters)