CDC MME CQL Calculator
3.0.0 - release

This page is part of the CDC Opioid MME Calculator (v3.0.0: Release) based on FHIR R4. This is the current published version in its permanent home (it will always be available at this URL). For a full list of available versions, see the Directory of published versions

Library: Tests of the Opioid Management Terminology Knowledge Logic library

Id: OMTKLogicTests
Url: http://fhir.org/guides/cdc/opioid-mme-r4/Library/OMTKLogicTests
Version: 3.0.0
Name: OMTKLogicTests
Title: Tests of the Opioid Management Terminology Knowledge Logic library
Status: active
Experimental: true
Type:

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

code: logic-library

Date: 2021-11-25T15:13:44+11:00
Publisher: Alphora
Description: This library tests the MME calculator provided by the OMTKLogic library
Knowledge Capability: shareable computable publishable executable
Knowledge Representation Level: structured
Jurisdiction: 840
Copyright: Copyright 2019+ Centers for Disease Control and Prevention (CDC)
Related Artifacts:

Dependencies

  • http://fhir.org/guides/cdc/opioid-mme-r4/Library/OMTKLogic|3.0.0
  • http://fhir.org/guides/cdc/opioid-mme-r4/Library/OMTKData|3.0.0
  • http://fhir.org/guides/cdc/opioid-mme-r4/Library/ConversionFactors|3.0.0
  • http://www.nlm.nih.gov/research/umls/rxnorm
  • http://terminology.hl7.org/CodeSystem/usage-context-type
  • http://fhir.org/guides/cdc/opioid-mme-r4/CodeSystem/CDCMMEUsageContextCodes
Parameters:
NameTypeMinMaxIn/Out
ErrorLevelstring01in
ConversionFactorSupplementNamestring01in
TestToUCUM_MGboolean01out
TestToUCUM_MGPerACTUATboolean01out
TestToUCUM_MGPerMLboolean01out
TestToUCUM_MGPerHRboolean01out
TestToUCUM_Unknownboolean01out
TestToDaily_hboolean01out
TestToDaily_minboolean01out
TestToDaily_sboolean01out
TestToDaily_dboolean01out
TestToDaily_wkboolean01out
TestToDaily_moboolean01out
TestToDaily_aboolean01out
TestToDaily_unknownboolean01out
TestIngredients_FentanylAny0*out
TestIngredients_Fentanyl_SprayAny0*out
TestIngredients_Fentanyl_RopivicaineAny0*out
TestIngredients_MethadoneAny0*out
TestDrug_Fentanyl_TransdermalAny01out
TestDrug_Fentanyl_0375_TransdermalAny01out
TestDrug_Fentanyl_InjectionAny01out
TestDrug_MethadoneAny01out
TestDrug_Fentanyl_SprayAny01out
TestDrug_Fentanyl_FilmAny01out
TestDrug_Fentanyl_Mucosal_SprayAny01out
TestDrug_OxycodoneAny01out
TestDrug_Oxycodone_ERAny01out
TestDrugsAny0*out
TestStripPer_Nullboolean01out
TestStripPer_Emptyboolean01out
TestStripPer_Tabboolean01out
TestStripPer_MGboolean01out
TestStripPer_UGPerHboolean01out
TestStripPer_MGPerTabboolean01out
TestStripPer_Multipleboolean01out
TestGetDailyDoseAny0*out
TestCalculateMMEsAny0*out
TestGetIngredientsAny0*out
Content: text/cql
library OMTKLogicTests version '3.0.0'
using FHIR version '4.0.1'
include OMTKLogic version '3.0.0'

// define function ToUCUM(unit String):
define TestToUCUM_MG: OMTKLogic.ToUCUM('MG') = 'mg'
define TestToUCUM_MGPerACTUAT: OMTKLogic.ToUCUM('MG/ACTUAT') = 'mg/{actuat}'
define TestToUCUM_MGPerML: OMTKLogic.ToUCUM('MG/ML') = 'mg/mL'
define TestToUCUM_MGPerHR: OMTKLogic.ToUCUM('MG/HR') = 'mg/h'
define TestToUCUM_Unknown: OMTKLogic.ToUCUM('Unknown') is null

// define function ToDaily(frequency Integer, period Quantity):
define TestToDaily_h: OMTKLogic.ToDaily(2, 4 'h') = 12
define TestToDaily_min: OMTKLogic.ToDaily(1, 30 'min') = 48
define TestToDaily_s: OMTKLogic.ToDaily(1, 30 's') = 2880
define TestToDaily_d: OMTKLogic.ToDaily(4, 1 'd') = 4
define TestToDaily_wk: OMTKLogic.ToDaily(2, 1 'wk') = 0.28571428
define TestToDaily_mo: OMTKLogic.ToDaily(10, 1 'mo') = 0.33333333
define TestToDaily_a: OMTKLogic.ToDaily(10, 1 'a') = 0.02739726
define TestToDaily_unknown: OMTKLogic.ToDaily(10, 1 'mg') is null

//define function EnsureMicrogramQuantity(strength Quantity):
//define TestEnsureMicrogramQuantityNormal: OMTKLogic.EnsureMicrogramQuantity(10 'mg') = 10 'mg'
//define TestEnsureMicrogramQuantityMicrogram: OMTKLogic.EnsureMicrogramQuantity(0.001 'mg') = 1 'ug'
//define TestEnsureMicrogramQuantityMicrogramPerML: OMTKLogic.EnsureMicrogramQuantity(0.05 'mg/mL') = 50 'ug/mL'

//define function GetIngredients(rxNormCode Code):
//GetIngredients:
//  List<{
//    rxNormCode Code,
//    doseFormCode Code,
//    ingredientCode code,
//    strength Quantity
//  }>
define TestIngredients_Fentanyl: OMTKLogic.GetIngredients(Code '1603495' from OMTKLogic.RXNORM)
define TestIngredients_Fentanyl_Spray: OMTKLogic.GetIngredients(Code '1115577' from OMTKLogic.RXNORM)
define TestIngredients_Fentanyl_Ropivicaine: OMTKLogic.GetIngredients(Code '1233687' from OMTKLogic.RXNORM)
define TestIngredients_Methadone: OMTKLogic.GetIngredients(Code '864706' from OMTKLogic.RXNORM)

// 25 µg/hr fentanyl patch X (10 patches/ 30 days) X 7.2  = 60 MME/day
// See this issue for discussion: https://github.com/cqframework/opioid-cds/issues/60
define TestDrug_Fentanyl_Transdermal: { rxNormCode: Code '245134' from OMTKLogic.RXNORM display '72 HR fentanyl 0.025 MG/HR Transdermal System', doseQuantity: 1 '{patch}', dosesPerDay: 0.3333, mme: 60 '{MME}/d' }

// 37.5 µg/hr fentanyl patch X (10 patches/ 30 days) X 7.2  = 90 MME/day
define TestDrug_Fentanyl_0375_Transdermal: { rxNormCode: Code '1603495' from OMTKLogic.RXNORM display '72 HR fentanyl 0.0375 MG/HR Transdermal System', doseQuantity: 1 '{patch}', dosesPerDay: 0.3333, mme: 90 '{MME}/d' }

// Injection calculation not supported
define TestDrug_Fentanyl_Injection: { rxNormCode: Code '1244687' from OMTKLogic.RXNORM display 'fentanyl 0.004 MG/ML / ropivacaine hydrochloride 2 MG/ML Injectable Solution', doseQuantity: 1 '{injection}', dosesPerDay: 1.0, mme: null as Quantity }

// 10 MG methadone X (180 tablets/ 30 days) X 10 = 600 MME/day
// NOTE: Methodone has variable equivalency based on route, dose, and length of use. Buprenorphine and methadone are excluded from calculation in some systems.
// They are still considered relevant opioids, but no MME calculation is given in those systems.
define TestDrug_Methadone: { rxNormCode: Code '864706' from OMTKLogic.RXNORM display 'methadone hydrochloride 10 MG Oral Tablet', doseQuantity: 2 '{tab}', dosesPerDay: 3.0, mme: 600 '{MME}/d' }

// 0.4 MG fentanyl spray X (90 sprays/ 30 days) X 160 = 192 MME/day
// NOTE: Had to add Metered Dose Nasal Spray as a dose form code to the GetConversionFactor for Fentanyl, same category as other sprays
define TestDrug_Fentanyl_Spray: { rxNormCode: Code '1115577' from OMTKLogic.RXNORM display 'fentaNYL 0.4 MG/ACTUAT', doseQuantity: 1 '{actuat}', dosesPerDay: 3.0, mme: 192 '{MME}/d' }

// 1.2 mg buccal film X (60 films/ 30 days) X 180 = 432 MME/day
// NOTE: This drug is not in our OMTKData, not sure why 858087 is an SDC RXCUI and the code is active, and was introduced in 2009
define TestDrug_Fentanyl_Film: { rxNormCode: Code '858087' from OMTKLogic.RXNORM display 'fentanyl 1.2 MG Buccal Film', doseQuantity: 1 '{film}', dosesPerDay: 2.0, mme: 432 '{MME}/d' }

// 0.1 mg fentanyl spray X (90 sprays/ 30 days) X 160 = 48 MME/day
define TestDrug_Fentanyl_Mucosal_Spray: { rxNormCode: Code '1237050' from OMTKLogic.RXNORM display 'fentanyl 0.1 MG/ACTUAT Mucosal Spray', doseQuantity: 1 '{actuat}', dosesPerDay: 3.0, mme: 48 '{MME}/d' }

// 10 mg oxycodone tablets X (120 tablets/ 30 days) X 1.5 = 60 MME/day
define TestDrug_Oxycodone: { rxNormCode: Code '1049683' from OMTKLogic.RXNORM display 'oxycodone hydrochloride 10 MG Oral Tablet', doseQuantity: 1 '{tab}', dosesPerDay: 4.0, mme: 60 '{MME}/d' }

// 30 mg oxycodone tables X (60 tablets/ 30 days) X 1.5 = 90 MME/day
define TestDrug_Oxycodone_ER: { rxNormCode: Code '1049574' from OMTKLogic.RXNORM display '12 HR oxycodone hydrochloride 30 MG Extended Release Oral Tablet', doseQuantity: 1 '{tab}', dosesPerDay: 2.0, mme: 90 '{MME}/d' }

// TODO: Determine how this will be reflected, I don't see any RxNav data that uses bottles?
// For example, a butorphanol spray is packaged as a 2.5ml bottle.
// This MME file indicates the strength is 10mg/ml and the conversion factor is 7.
// The prescription data lists a quantity of 1 and a days supply of 30.
// If it is determined that the quantity likely reflects the number of bottles,
// the quantity should be changed to 2.5 since each bottle of that butorphanol
// product contains 2.5 ml. Using the formula above, this yields 10mg/ml  x 2.5ml/30 days x 7= 5.8 MME/day.

define TestDrugs: {
  TestDrug_Fentanyl_Transdermal,
  TestDrug_Fentanyl_0375_Transdermal,
  TestDrug_Fentanyl_Injection,
  TestDrug_Methadone,
  TestDrug_Fentanyl_Spray,
  TestDrug_Fentanyl_Film,
  TestDrug_Fentanyl_Mucosal_Spray,
  TestDrug_Oxycodone,
  TestDrug_Oxycodone_ER
}

//define function StripPer(unit String):
define TestStripPer_Null: OMTKLogic.StripPer(null) is null
define TestStripPer_Empty: OMTKLogic.StripPer('') = ''
define TestStripPer_Tab: OMTKLogic.StripPer('{tab}') = '{tab}'
define TestStripPer_MG: OMTKLogic.StripPer('mg') = 'mg'
define TestStripPer_UGPerH: OMTKLogic.StripPer('ug/h') = 'ug'
define TestStripPer_MGPerTab: OMTKLogic.StripPer('mg/{tab}') = 'mg'
define TestStripPer_Multiple: OMTKLogic.StripPer('mg/h/h') = 'mg/h'

//define function GetDailyDose(ingredientCode Code, strength Quantity, doseFormCode Code, doseQuantity Quantity, dosesPerDay Decimal):
define TestGetDailyDose:
  flatten (
    TestDrugs D
      let i: OMTKLogic.GetIngredients(D.rxNormCode)
      return i I
        return OMTKLogic.GetDailyDose(I.ingredientCode, I.strength, I.doseFormCode, D.doseQuantity, D.dosesPerDay)
  )

//define function GetMedicationName(rxNormCode Code):
//define function GetDailyDoseDescription(ingredientCode Code, ingredientName String, strength Quantity, doseFormCode Code, doseFormName String, doseQuantity Quantity, dosesPerDay Decimal, dailyDose Quantity):

//define function CalculateMMEs(medications List<Tuple { rxNormCode Code, doseQuantity Quantity, dosesPerDay Decimal }>):
define TestCalculateMMEs:
  TestDrugs D
    let mmes: OMTKLogic.CalculateMMEs({ D d return { rxNormCode: d.rxNormCode, doseQuantity: d.doseQuantity, dosesPerDay: d.dosesPerDay }})
    return {
      rxNormCode: D.rxNormCode,
      mme: Sum(mmes.mme),
      expectedMme: D.mme,
      description: Combine(mmes.dailyDoseDescription, ', ')
    }


define TestGetIngredients: OMTKLogic.GetIngredients(Code '1049221' from OMTKLogic.RXNORM)
Content: application/elm+xml
Encoded data (114888 characters)
Content: application/elm+json
Encoded data (548680 characters)