@prefix fhir: <http://hl7.org/fhir/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sct: <http://snomed.info/sct/> .

# - resource -------------------------------------------------------------------

[] a fhir:PlanDefinition;
  fhir:Resource.id [ fhir:value "opioidcds-09"], [ fhir:value "effective-data-requirements"];
  fhir:Resource.meta [
     fhir:Meta.profile [
       fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-recommendationdefinition";
       fhir:index 0
     ], [
       fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-publishableplandefinition";
       fhir:index 1
     ]
  ];
  fhir:DomainResource.extension [
     fhir:index 0;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability" ];
     fhir:Extension.value [ fhir:value "shareable" ]
  ], [
     fhir:index 1;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability" ];
     fhir:Extension.value [ fhir:value "computable" ]
  ], [
     fhir:index 2;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability" ];
     fhir:Extension.value [ fhir:value "executable" ]
  ], [
     fhir:index 3;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-knowledgeCapability" ];
     fhir:Extension.value [ fhir:value "publishable" ]
  ], [
     fhir:index 4;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions\":\n  ( Common.\"Is Opioid Analgesic with Ambulatory Misuse Potential?\"( ContextPrescriptions ) ) AmbulatoryOpioidPrescription\n    where Routines.\"Is Subacute or Chronic Pain Prescription?\"( AmbulatoryOpioidPrescription )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "0" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 5;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential\":\n  exists( \"Chronic Pain Opioid Analgesic with Ambulatory Misuse Potential Prescriptions\" )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "1" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 6;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Age Less than 18 Years Is Enabled" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// CDC 2022 General Inclusion Criteria\ndefine \"Age Less than 18 Years Is Enabled\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "2" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 7;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Patient Age Less Than 18" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Patient Age Less Than 18\":\n  if (Config.\"Age Less than 18 Years Is Enabled\") then\n    AgeInYearsAt(Today()) < 18\n  else false" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "3" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 8;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Sickle Cell Check Enabled" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// Sickle Cell\ndefine \"Sickle Cell Check Enabled\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "4" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 9;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Sickle Cell Assumed Active" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Sickle Cell Assumed Active\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "5" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 10;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "US Core-Categorized Conditions" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// 3. Medications indicating end of life\n    /* or exists (\n      \"Medications Indicating End of Life\"\n    ) */\n\ndefine \"US Core-Categorized Conditions\":\n  [Condition: category in \"Encounter Diagnosis Condition Category\"]\n    union [Condition: category in \"Problem List Condition Category\"]\n    union [Condition: category in \"US Core Health Concern Condition Category\"]" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "6" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 11;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Positive Sickle Cell Condition" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Positive Sickle Cell Condition\":\n  if Config.\"Sickle Cell Check Enabled\" and not Config.\"Sickle Cell Assumed Active\"\n    then (\n      \"US Core-Categorized Conditions\" C\n        where C.code in \"Sickle Cell Diseases\"\n          and C.clinicalStatus in \"Active Condition\"\n    ) else if Config.\"Sickle Cell Check Enabled\" and Config.\"Sickle Cell Assumed Active\"\n        then (\n          \"US Core-Categorized Conditions\" C\n            where C.code in \"Sickle Cell Diseases\"\n        )\n      else null" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "7" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 12;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Condition Positive for Sickle Cell" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Condition Positive for Sickle Cell\":\n  if (Config.\"Sickle Cell Check Enabled\") then\n    exists(\n      Common.\"Positive Sickle Cell Condition\"\n    ) \n  else false" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "8" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 13;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Active Cancer Treatment Encounters Condition Is Enabled" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// Active Cancer Treatment\ndefine \"Active Cancer Treatment Encounters Condition Is Enabled\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "9" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 14;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Encounter Period" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// End of Opioid Naive Routine\n\n/*\n**  Routine #3\n**  Active Cancer Treatment Routine\n**\n**  Definition                    | Answer to Proceed   | Details                                    | Data (Terminology) Requirement\n**  ---------------------------------------------------------------------------------------------------------------------------------\n**  Two office visits within the  | No                  | Look for a minimum of two distinct         | Office Visit\n**  past 12 months                |                     | encounters within 12 months of the date    |\n**                                |                     | of the current visit for which each of the |\n**                                |                     | following is true:                         |\n**                                |                     |   - the encounter diagnosis (primary or    |\n**                                |                     |     secondary or co-morbidity diagnosis)   |\n**                                |                     |     is listed in the CDC Malignant Cancer  |\n**                                |                     |     Conditions value set                   |\n**  ---------------------------------------------------------------------------------------------------------------------------------\n**  Office visits with an         | No                  | The encounter is performed by an           | Oncology specialty\n**  oncology specialist           |                     | oncologist as defined in the oncology      | designations (NUCC)\n**  present                       |                     | specialty designations using the           |\n**                                |                     | National Uniform Claim Committee           |\n**                                |                     | (NUCC) classifications                     |\n**  ---------------------------------------------------------------------------------------------------------------------------------\n**  Office visits including CDC   | No                  | The encounter diagnosis (primary or        | CDC malignant cancer\n**  malignant cancer              |                     | secondary or co-morbidity diagnosis)       | conditions\n**  condition                     |                     | is listed in the CDC Malignant Cancer      |\n**                                |                     | Conditions value set                       |\n**  ----------------------------------------------------------------------------------------------------------------------------------\n**\n*/\n\ndefine \"Encounter Period\":\n  Interval[Today() - 12 months, Today())" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "10" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 15;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "USCore Encounter Cancer Diagnoses" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"USCore Encounter Cancer Diagnoses\":\n  [Condition: category in \"Encounter Diagnosis Condition Category\"] CancerDiagnoses\n    where CancerDiagnoses.code in \"CDC malignant cancer conditions\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "11" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 16;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Encounters with Cancer Diagnosis During Encounter Period" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// encounter-diagnosis, problem-list and health-concern Conditions\n// define \"US Core-Categorized Cancer Diagnoses\":\n//   Common.\"US Core-Categorized Conditions\" C\n//     where C.code in Common.\"CDC malignant cancer conditions\"\n\n// define \"Encounters with Cancer Diagnosis During Encounter Period\":\n//   [Encounter] Encounter\n//     with \"US Core-Categorized Cancer Diagnoses\" CancerDiagnosis\n//     such that date from Encounter.period.\"start\".value in day of \"Encounter Period\"\n//       and EndsWith(CancerDiagnosis.encounter.reference, Encounter.id)\n\ndefine \"Encounters with Cancer Diagnosis During Encounter Period\":\n  [Encounter] Encounters\n    where date from Encounters.period.\"start\" in day of \"Encounter Period\"\n      and exists (\n        Common.\"USCore Encounter Cancer Diagnoses\" CancerDiagnoses\n          where EndsWith(CancerDiagnoses.encounter.reference, Encounters.id)\n      )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "12" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 17;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Number of Encounters with Cancer Diagnosis During Encounter Period" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Number of Encounters with Cancer Diagnosis During Encounter Period\":\n  Count (\"Encounters with Cancer Diagnosis During Encounter Period\")" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "13" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 18;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Has Two or More Encounters with Cancer Diagnosis During Encounter Period" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Has Two or More Encounters with Cancer Diagnosis During Encounter Period\":\n  \"Number of Encounters with Cancer Diagnosis During Encounter Period\" >= 2" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "14" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 19;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "USCore Problem List Cancer Diagnoses" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"USCore Problem List Cancer Diagnoses\":\n  [Condition: category in \"Problem List Condition Category\"] CancerDiagnoses\n    where CancerDiagnoses.code in \"CDC malignant cancer conditions\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "15" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 20;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Has Active Cancer Diagnosis on Problem List" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Has Active Cancer Diagnosis on Problem List\":\n  exists (\n    Common.\"USCore Problem List Cancer Diagnoses\" CancerDiagnoses\n      where CancerDiagnoses.category in Common.\"Problem List Condition Category\"\n        and exists(\n          CancerDiagnoses.clinicalStatus.coding ClinicalStatus\n            where ClinicalStatus.code ~ 'active'\n        )\n  )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "16" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 21;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Active Cancer Treatment?" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Is Active Cancer Treatment?\":\n  if (Config.\"Active Cancer Treatment Encounters Condition Is Enabled\") \n    then \"Has Two or More Encounters with Cancer Diagnosis During Encounter Period\"\n      or \"Has Active Cancer Diagnosis on Problem List\"\n  else false" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "17" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 22;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "End-Stage Disease Criteria Enabled" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// CDC 2022 General Inclusion Criteria\ndefine \"End-Stage Disease Criteria Enabled\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "18" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 23;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Conditions Likely Terminal for Opioid Prescribing" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Conditions Likely Terminal for Opioid Prescribing\":\n  if (Config.\"End-Stage Disease Criteria Enabled\") then\n    exists (\n      Common.\"US Core-Categorized Conditions\" EOLC\n        where EOLC.code in Common.\"Conditions likely terminal for opioid prescribing\"\n          // and EOLC.clinicalStatus in Common.\"Active Condition\"\n    )\n  else false" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "19" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 24;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "CDC 2022 Guideline General Inclusion Criteria" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"CDC 2022 Guideline General Inclusion Criteria\":\n  not \"Patient Age Less Than 18\"\n    and not \"Condition Positive for Sickle Cell\"\n    and not \"Is Active Cancer Treatment?\"\n    and not \"Conditions Likely Terminal for Opioid Prescribing\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "20" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 25;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommonConfig" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "PDMP Data Not Reviewed in Past 90 Days Criteria Enabled" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// Recommendation 9\ndefine \"PDMP Data Not Reviewed in Past 90 Days Criteria Enabled\":\n  true" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "21" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 26;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Look Back 90 Days" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Look Back 90 Days\":\n  Interval[Today() - 90 days, Today()]" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "22" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 27;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "PDMP Data Not Reviewed in Past 90 Days" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"PDMP Data Not Reviewed in Past 90 Days\":\n  Config.\"PDMP Data Not Reviewed in Past 90 Days Criteria Enabled\"\n    and not (\n      exists (\n        [Procedure: Common.\"PDMP review procedure\"] P\n          where P.status ~ 'completed'\n            and P.performed during \"Look Back 90 Days\"\n      )\n      or exists (\n        [Observation: Common.\"PDMP data reviewed finding\"] O\n          where O.status in { 'final', 'amended' }\n            and (\n              if O.effective is FHIR.Period\n                then (O.effective as FHIR.Period) during day of \"Look Back 90 Days\"\n                else if O.effective is FHIR.dateTime\n                  then date from O.effective in day of \"Look Back 90 Days\"\n                  else false\n          )\n      )\n    )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "23" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 28;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Inclusion Criteria" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Inclusion Criteria\":\n  \"Patient Is Being Prescribed Opioid Analgesic with Ambulatory Misuse Potential\"\n    and Routines.\"CDC 2022 Guideline General Inclusion Criteria\"\n    and \"PDMP Data Not Reviewed in Past 90 Days\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "24" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 29;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Exclusion Criteria" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Exclusion Criteria\":\n  false" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "25" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 30;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSREC09" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Recommendation Applicable?" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define \"Is Recommendation Applicable?\":\n  \"Inclusion Criteria\"\n    and not \"Exclusion Criteria\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "26" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 31;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Opioid Analgesic with Ambulatory Misuse Potential?" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function \"Is Opioid Analgesic with Ambulatory Misuse Potential?\"(value List<MedicationRequest>):\n  (\"Get MedicationRequest Medication as Code\"(value)) Rx\n    where Rx.medication in \"Opioid analgesics with ambulatory misuse potential\" \n      and Rx.category in \"Community\"" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "27" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 32;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Get MedicationRequest Medication as Code" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function \"Get MedicationRequest Medication as Code\"(value List<MedicationRequest>):\n  value Rx\n    let Med: \n      if Rx.medication is Reference then singleton from (\n        [Medication] M\n          where M.id = (Last(Split((Rx.medication as FHIR.Reference).reference, '/')))\n      ) else null\n    return \n      MedicationRequest {\n        id: Rx.id,\n        status: Rx.status,\n        intent: Rx.intent,\n        category: Rx.category,\n        medication: if Rx.medication is Reference then Med.code else Rx.medication as CodeableConcept,\n        subject: Rx.subject,\n        authoredOn: Rx.authoredOn,\n        recorder: Rx.recorder,\n        dosageInstruction: Rx.dosageInstruction,\n        dispenseRequest: Rx.dispenseRequest\n      }" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "28" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 33;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToString" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToString(value string): value.value" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "29" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 34;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToConcept" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToConcept(concept FHIR.CodeableConcept):\n    if concept is null then\n        null\n    else\n        System.Concept {\n            codes: concept.coding C return ToCode(C),\n            display: concept.text.value\n        }" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "30" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 35;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToCode" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToCode(coding FHIR.Coding):\n    if coding is null then\n        null\n    else\n        System.Code {\n          code: coding.code.value,\n          system: coding.system.value,\n          version: coding.version.value,\n          display: coding.display.value\n        }" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "31" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 36;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Subacute or Chronic Pain Prescription?" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "// End of Active Cancer Treatment Routine\n\n/*\n**  Routine #4\n**  For Subacute or Chronic Pain Routine\n**\n**  Definition                  | Answer to Proceed   | Details                                        | Data (Terminology) Requirement\n**  -----------------------------------------------------------------------------------------------------------------------------------\n**  Order for opioid analgesic  | Yes                 | Order for opioid analgesics with ambulatory    | Opioid analgesics with\n**  with expected supply        |                     | misuse potential with a supply duration of >=  | ambulatory misuse potential\n**  duration >= 28 days         |                     | 28 days                                        |\n**                              |                     |                                                |\n**                              |                     | - Subacute definition = order for opioid       |\n**                              |                     |   analgesics with ambulatory misuse            |\n**                              |                     |   potential with a supply duration of one to   |\n**                              |                     |   two months.                                  |\n**                              |                     | - Chronic pain definition = order for opioid   |\n**                              |                     |   analgesics with ambulatory misuse            |\n**                              |                     |   potential with a supply duration of >= two   |\n**                              |                     |   months.                                      |\n**  -----------------------------------------------------------------------------------------------------------------------------------\n**\n*/\n\ndefine function \"Is Subacute or Chronic Pain Prescription?\"(prescription FHIR.MedicationRequest):\n  \"Is Subacute or Chronic Pain Using Expected Supply Duration\"(prescription)\n    or \"Is Subacute or Chronic Pain Using Validity Period\"(prescription)" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "32" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 37;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Subacute or Chronic Pain Using Expected Supply Duration" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function \"Is Subacute or Chronic Pain Using Expected Supply Duration\"(prescription FHIR.MedicationRequest):\n  (\n    prescription.dispenseRequest is not null\n      and prescription.dispenseRequest.expectedSupplyDuration is not null\n      and (\n        Common.GetDurationInDays(prescription.dispenseRequest.expectedSupplyDuration) >= 28 days \n      )\n  )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "33" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 38;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSCommon" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "GetDurationInDays" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function GetDurationInDays(value FHIR.Duration):\n  if value is null then null\n  else\n    case\n      when value.code.value ~ 'a' then System.Quantity{ value: value.value.value * 365.0, unit: 'days' }\n      when value.code.value ~ 'mo' then System.Quantity{ value: value.value.value * 30.0, unit: 'days' }\n      when value.code.value ~ 'wk' then System.Quantity{ value: value.value.value * 7.0, unit: 'days' }\n      when value.code.value ~ 'd' then System.Quantity{ value: value.value.value, unit: 'days' }\n      when value.code.value ~ 'h' then System.Quantity{ value: value.value.value / 24.0, unit: 'days' }\n      when value.code.value ~ 'min' then System.Quantity{ value: value.value.value / 60.0 / 24.0, unit: 'days' }\n      when value.code.value ~ 's' then System.Quantity{ value: value.value.value / 60.0 / 60.0 / 24.0, unit: 'days' }\n      when value.code.value ~ 'ms' then System.Quantity{ value: value.value.value / 60.0 / 60.0 / 24.0 / 1000.0, unit: 'days' }\n      when value.code.value is null then Message(1000, true, 'Undefined', 'Error', 'Duration unit code is null')\n      else Message(1000, true, 'Undefined', 'Error', 'Unsupported duration unit code: ' + value.code.value)\nend" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "34" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 39;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "OpioidCDSRoutines" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "Is Subacute or Chronic Pain Using Validity Period" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function \"Is Subacute or Chronic Pain Using Validity Period\"(prescription FHIR.MedicationRequest):\n  (\n    prescription.dispenseRequest is not null\n      and prescription.dispenseRequest.validityPeriod is not null\n      and (\n        days between prescription.dispenseRequest.validityPeriod.start and prescription.dispenseRequest.validityPeriod.end >= 28 \n      )\n  )" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "35" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 40;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToDateTime" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToDateTime(value dateTime): value.value" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "36" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 41;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToString" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToString(value ProcedureStatus): value.value" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "37" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 42;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToInterval" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToInterval(period FHIR.Period):\n    if period is null then\n        null\n    else\n        if period.\"start\" is null then\n            Interval(period.\"start\".value, period.\"end\".value]\n        else\n            Interval[period.\"start\".value, period.\"end\".value]" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "38" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 43;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToString" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToString(value ObservationStatus): value.value" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "39" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 44;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "libraryName" ];
       fhir:Extension.value [ fhir:value "FHIRHelpers" ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "name" ];
       fhir:Extension.value [ fhir:value "ToDateTime" ]
     ], [
       fhir:index 2;
       fhir:Extension.url [ fhir:value "statement" ];
       fhir:Extension.value [ fhir:value "define function ToDateTime(value instant): value.value" ]
     ], [
       fhir:index 3;
       fhir:Extension.url [ fhir:value "displaySequence" ];
       fhir:Extension.value [ fhir:value "40" ]
     ];
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-logicDefinition" ]
  ], [
     fhir:index 45;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-softwaresystem" ];
     fhir:Extension.value [
       fhir:Reference.reference [ fhir:value "Device/cqf-tooling" ]
     ]
  ], [
     fhir:index 46;
     fhir:Extension.url [ fhir:value "http://hl7.org/fhir/uv/crmi/StructureDefinition/crmi-effectiveDataRequirements" ];
     fhir:Extension.value [ fhir:value "#effective-data-requirements" ]
  ];
  fhir:PlanDefinition.url [ fhir:value "http://fhir.org/guides/cdc/opioid-cds/PlanDefinition/opioidcds-09"];
  fhir:PlanDefinition.identifier [
     fhir:index 0;
     fhir:Identifier.use [ fhir:value "official" ];
     fhir:Identifier.value [ fhir:value "cdc-opioid-guidance" ]
  ];
  fhir:PlanDefinition.version [ fhir:value "2022.1.0"];
  fhir:PlanDefinition.name [ fhir:value "PlanDefinition_Recommendation_09_Order_Sign"];
  fhir:PlanDefinition.title [ fhir:value "Recommendation #9 - Consider Patient's History of Controlled Substance Prescriptions"];
  fhir:PlanDefinition.type [
     fhir:CodeableConcept.coding [
       fhir:index 0;
       fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/plan-definition-type" ];
       fhir:Coding.code [ fhir:value "eca-rule" ];
       fhir:Coding.display [ fhir:value "ECA Rule" ]
     ]
  ];
  fhir:PlanDefinition.status [ fhir:value "draft"];
  fhir:PlanDefinition.experimental [ fhir:value "true"];
  fhir:PlanDefinition.date [ fhir:value "2025-08-06"];
  fhir:PlanDefinition.publisher [ fhir:value "Centers for Disease Control and Prevention (CDC)"];
  fhir:PlanDefinition.contact [
     fhir:index 0;
     fhir:ContactDetail.telecom [
       fhir:index 0;
       fhir:ContactPoint.system [ fhir:value "url" ];
       fhir:ContactPoint.value [ fhir:value "https://www.cdc.gov" ]
     ]
  ];
  fhir:PlanDefinition.description [ fhir:value "When prescribing initial opioid therapy for acute, subacute, or chronic pain, and periodically during opioid therapy for chronic pain, clinicians should review the patient's history of controlled substance prescriptions using state prescription drug monitoring program (PDMP) data to determine whether the patient is receiving opioid dosages or combinations that put the patient at high risk for overdose."];
  fhir:PlanDefinition.useContext [
     fhir:index 0;
     fhir:UsageContext.code [
       fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/usage-context-type" ];
       fhir:Coding.code [ fhir:value "focus" ];
       fhir:Coding.display [ fhir:value "Clinical Focus" ]
     ];
     fhir:UsageContext.value [
       a sct:182888003;
       fhir:CodeableConcept.coding [
         fhir:index 0;
         a sct:182888003;
         fhir:Coding.system [ fhir:value "http://snomed.info/sct" ];
         fhir:Coding.code [ fhir:value "182888003" ];
         fhir:Coding.display [ fhir:value "Medication requested (situation)" ]
       ]
     ]
  ], [
     fhir:index 1;
     fhir:UsageContext.code [
       fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/usage-context-type" ];
       fhir:Coding.code [ fhir:value "focus" ];
       fhir:Coding.display [ fhir:value "Clinical Focus" ]
     ];
     fhir:UsageContext.value [
       a sct:82423001;
       fhir:CodeableConcept.coding [
         fhir:index 0;
         a sct:82423001;
         fhir:Coding.system [ fhir:value "http://snomed.info/sct" ];
         fhir:Coding.code [ fhir:value "82423001" ];
         fhir:Coding.display [ fhir:value "Chronic pain (finding)" ]
       ]
     ]
  ], [
     fhir:index 2;
     fhir:UsageContext.code [
       fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/usage-context-type" ];
       fhir:Coding.code [ fhir:value "focus" ];
       fhir:Coding.display [ fhir:value "Clinical Focus" ]
     ];
     fhir:UsageContext.value [
       a sct:274663001;
       fhir:CodeableConcept.coding [
         fhir:index 0;
         a sct:274663001;
         fhir:Coding.system [ fhir:value "http://snomed.info/sct" ];
         fhir:Coding.code [ fhir:value "274663001" ];
         fhir:Coding.display [ fhir:value "Acute pain (finding)" ]
       ]
     ]
  ], [
     fhir:index 3;
     fhir:UsageContext.code [
       fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/usage-context-type" ];
       fhir:Coding.code [ fhir:value "focus" ];
       fhir:Coding.display [ fhir:value "Clinical Focus" ]
     ];
     fhir:UsageContext.value [
       fhir:CodeableConcept.text [ fhir:value "Subacute pain" ]
     ]
  ];
  fhir:PlanDefinition.jurisdiction [
     fhir:index 0;
     fhir:CodeableConcept.coding [ fhir:index 0 ]
  ];
  fhir:PlanDefinition.purpose [ fhir:value "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."];
  fhir:PlanDefinition.usage [ fhir:value "At a minimum, during long-term opioid therapy, PDMP data should be reviewed before an initial opioid prescription and then every 3 months or more frequently."];
  fhir:PlanDefinition.copyright [ fhir:value "© CDC 2016+."];
  fhir:PlanDefinition.topic [
     fhir:index 0;
     fhir:CodeableConcept.text [ fhir:value "Opioid Prescribing" ]
  ];
  fhir:PlanDefinition.author [
     fhir:index 0;
     fhir:ContactDetail.name [ fhir:value "Kensaku Kawamoto, MD, PhD, MHS" ]
  ], [
     fhir:index 1;
     fhir:ContactDetail.name [ fhir:value "Bryn Rhodes" ]
  ], [
     fhir:index 2;
     fhir:ContactDetail.name [ fhir:value "Floyd Eisenberg, MD, MPH" ]
  ], [
     fhir:index 3;
     fhir:ContactDetail.name [ fhir:value "Robert McClure, MD, MPH" ]
  ];
  fhir:PlanDefinition.relatedArtifact [
     fhir:index 0;
     fhir:RelatedArtifact.type [ fhir:value "documentation" ];
     fhir:RelatedArtifact.display [ fhir:value "2022 CDC Clinical Practice Guideline for Prescribing Opioids for Pain" ];
     fhir:RelatedArtifact.url [ fhir:value "https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm" ];
     fhir:RelatedArtifact.document [
       fhir:Attachment.url [ fhir:value "https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm" ]
     ]
  ];
  fhir:PlanDefinition.library [
     fhir:value "http://fhir.org/guides/cdc/opioid-cds/Library/OpioidCDSREC09";
     fhir:index 0
  ];
  fhir:PlanDefinition.action [
     fhir:index 0;
     fhir:Element.extension [
       fhir:index 0;
       fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-strengthOfRecommendation" ];
       fhir:Extension.value [
         fhir:CodeableConcept.coding [
           fhir:index 0;
           fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/recommendation-strength" ];
           fhir:Coding.code [ fhir:value "weak" ];
           fhir:Coding.display [ fhir:value "Weak" ]
         ]
       ]
     ], [
       fhir:index 1;
       fhir:Extension.url [ fhir:value "http://hl7.org/fhir/StructureDefinition/cqf-qualityOfEvidence" ];
       fhir:Extension.value [
         fhir:CodeableConcept.coding [
           fhir:index 0;
           fhir:Coding.system [ fhir:value "http://terminology.hl7.org/CodeSystem/evidence-quality" ];
           fhir:Coding.code [ fhir:value "very-low" ];
           fhir:Coding.display [ fhir:value "Very low quality" ]
         ]
       ]
     ];
     fhir:PlanDefinition.title [ fhir:value "Before Ordering Opioids, Review PDMP Data" ];
     fhir:PlanDefinition.description [ fhir:value "Review PDMP data for this patient before completing an opioid order.\r\n\r\nFor guidance about utilizing PDMP information to improve patient safety, see [Recommendation 9 of the 2022 CDC Clinical Practice Guideline](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#:~:text=Clinicians%20should%20take,see%20Recommendation%2010).).\r\n\r\n[CDC advises not to dismiss patients from your practice on the basis of PDMP information](https://www.cdc.gov/mmwr/volumes/71/rr/rr7103a1.htm#:~:text=Clinicians%20should%20not%20dismiss,Recommendations%208%20and%2012%5D).)" ];
     fhir:PlanDefinition.priority [ fhir:value "urgent" ];
     fhir:PlanDefinition.trigger [
       fhir:index 0;
       fhir:TriggerDefinition.type [ fhir:value "named-event" ];
       fhir:TriggerDefinition.name [ fhir:value "order-sign" ]
     ];
     fhir:PlanDefinition.condition [
       fhir:index 0;
       fhir:PlanDefinition.kind [ fhir:value "applicability" ];
       fhir:PlanDefinition.expression [
         fhir:Expression.description [ fhir:value "Check whether the current order is for an opioid with ambulatory misuse potential, if the 2022 CDC guideline general inclusion criteria is met or there exists evidence of a prescription drug monitoring program (PDMP) review procedure or finding occurred in the past 90 days." ];
         fhir:Expression.language [ fhir:value "text/cql.identifier" ];
         fhir:Expression.expression [ fhir:value "Is Recommendation Applicable?" ]
       ]
     ];
     fhir:PlanDefinition.groupingBehavior [ fhir:value "visual-group" ];
     fhir:PlanDefinition.selectionBehavior [ fhir:value "any" ];
     fhir:PlanDefinition.action [
       fhir:index 0;
       fhir:PlanDefinition.description [ fhir:value "Access Data - Launch app to review PDMP data" ]
     ], [
       fhir:index 1;
       fhir:PlanDefinition.description [ fhir:value "Document - PDMP data reviewed, snooze 3 months" ]
     ], [
       fhir:index 2;
       fhir:PlanDefinition.description [ fhir:value "Snooze* - N/A see comment, snooze 3 months" ]
     ]
  ] .

# -------------------------------------------------------------------------------------

