This page is part of the FHIR Specification (v4.3.0: R4B - STU). The current version which supercedes this version is 5.0.0. For a full list of available versions, see the Directory of published versions . Page versions: R5 R4B R4
Library-opioidcds-recommendation-10
This is the narrative for the resource. See also the XML, JSON or Turtle format. This example conforms to the profile Library.
Participants
Author | Kensaku Kawamoto, MD, PhD, MHS |
Author | Bryn Rhodes |
Author | Floyd Eisenberg, MD, MPH |
Author | Robert McClure, MD, MPH |
Related Artifacts
Data Requirements
Contents
application/elm+xml
<?xml version="1.0" encoding="UTF-8"?>
<library xmlns="urn:hl7-org:elm:r1" xmlns:t="urn:hl7-org:elm-types:r1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fhir="http://hl7.org/fhir" xmlns:qdm43="urn:healthit-gov:qdm:v4_3" xmlns:qdm53="urn:healthit-gov:qdm:v5_3" xmlns:a="urn:hl7-org:cql-annotations:r1">
<annotation startLine="62" startChar="12" endLine="62" endChar="60" message="Could not resolve code path medicationCodeableConcept for the type of the retrieve FHIR.MedicationRequest." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="62" startChar="12" endLine="62" endChar="60" message="Could not resolve membership operator for terminology target of the retrieve." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="66" startChar="3" endLine="66" endChar="66" message="Could not resolve code path medicationCodeableConcept for the type of the retrieve FHIR.MedicationRequest." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="66" startChar="3" endLine="66" endChar="66" message="Could not resolve membership operator for terminology target of the retrieve." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="74" startChar="3" endLine="74" endChar="64" message="Could not resolve code path combo-code for the type of the retrieve FHIR.Observation." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="74" startChar="3" endLine="74" endChar="64" message="Could not resolve membership operator for terminology target of the retrieve." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="79" startChar="3" endLine="79" endChar="63" message="Could not resolve code path combo-code for the type of the retrieve FHIR.Observation." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="79" startChar="3" endLine="79" endChar="63" message="Could not resolve membership operator for terminology target of the retrieve." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="134" startChar="20" endLine="134" endChar="76" message="List-valued expression was demoted to a singleton." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="143" startChar="16" endLine="143" endChar="17" message="List-valued expression was demoted to a singleton." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="157" startChar="52" endLine="157" endChar="73" message="List-valued expression was demoted to a singleton." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<annotation startLine="171" startChar="62" endLine="171" endChar="78" message="List-valued expression was demoted to a singleton." errorType="semantic" errorSeverity="warning" xsi:type="a:CqlToElmError"/>
<identifier id="OpioidCDS_STU4_REC_10" version="0.1.0"/>
<schemaIdentifier id="urn:hl7-org:elm" version="r1"/>
<usings>
<def localIdentifier="System" uri="urn:hl7-org:elm-types:r1"/>
<def localIdentifier="FHIR" uri="http://hl7.org/fhir" version="3.2.0"/>
</usings>
<includes>
<def localIdentifier="Common" path="OpioidCDS_STU4_Common" version="0.1.0"/>
</includes>
<parameters>
<def name="ContextPrescriptions" accessLevel="Public">
<parameterTypeSpecifier xsi:type="ListTypeSpecifier">
<elementType name="fhir:MedicationRequest" xsi:type="NamedTypeSpecifier"/>
</parameterTypeSpecifier>
</def>
</parameters>
<statements>
<def name="Patient" context="Patient">
<expression xsi:type="SingletonFrom">
<operand dataType="fhir:Patient" xsi:type="Retrieve"/>
</expression>
</def>
<def name="Lookback Year" context="Patient" accessLevel="Public">
<expression lowClosed="true" highClosed="true" xsi:type="Interval">
<low xsi:type="Subtract">
<operand xsi:type="Subtract">
<operand xsi:type="Today"/>
<operand value="12" unit="months" xsi:type="Quantity"/>
</operand>
<operand value="1" unit="days" xsi:type="Quantity"/>
</low>
<high xsi:type="Subtract">
<operand xsi:type="Today"/>
<operand value="1" unit="day" xsi:type="Quantity"/>
</high>
</expression>
</def>
<def name="Validate Trigger Event" context="Patient" accessLevel="Public">
<expression xsi:type="Exists">
<operand xsi:type="Query">
<source alias="triggerScript">
<expression name="ContextPrescriptions" xsi:type="ParameterRef"/>
</source>
<where name="IsOpioidWithAmbulatoryAbusePotential" libraryName="Common" xsi:type="FunctionRef">
<operand name="ToCode" libraryName="Common" xsi:type="FunctionRef">
<operand xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="medication" scope="triggerScript" xsi:type="Property"/>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</operand>
</operand>
</where>
</operand>
</expression>
</def>
<def name="Exclusion Criteria" context="Patient" accessLevel="Public">
<expression xsi:type="Or">
<operand xsi:type="Exists">
<operand dataType="fhir:MedicationRequest" codeProperty="medicationCodeableConcept" xsi:type="Retrieve">
<codes name="End Of Life Opioids" libraryName="Common" xsi:type="ValueSetRef"/>
</operand>
</operand>
<operand name="HasMetastaticCancer" libraryName="Common" xsi:type="ExpressionRef"/>
</expression>
</def>
<def name="Get Active Ambulatory Opioid Rx" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="Rx">
<expression dataType="fhir:MedicationRequest" codeProperty="medicationCodeableConcept" xsi:type="Retrieve">
<codes name="Ambulatory Abuse Potential Opioids" libraryName="Common" xsi:type="ValueSetRef"/>
</expression>
</source>
<where xsi:type="And">
<operand xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="status" scope="Rx" xsi:type="Property"/>
</operand>
<operand valueType="t:String" value="active" xsi:type="Literal"/>
</operand>
<operand xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand xsi:type="Flatten">
<operand xsi:type="Query">
<source alias="$this">
<expression path="category" scope="Rx" xsi:type="Property"/>
</source>
<where xsi:type="Not">
<operand xsi:type="IsNull">
<operand path="coding" xsi:type="Property">
<source name="$this" xsi:type="AliasRef"/>
</operand>
</operand>
</where>
<return>
<expression path="coding" xsi:type="Property">
<source name="$this" xsi:type="AliasRef"/>
</expression>
</return>
</operand>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:String" value="outpatient" xsi:type="Literal"/>
</operand>
</where>
</expression>
</def>
<def name="Get Illicit Drug Urine Screenings in Last 12 Months" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="observation">
<expression dataType="fhir:Observation" codeProperty="combo-code" xsi:type="Retrieve">
<codes name="Illicit Drug Screening" libraryName="Common" xsi:type="ValueSetRef"/>
</expression>
</source>
<where xsi:type="In">
<operand path="value" xsi:type="Property">
<source path="effective" scope="observation" xsi:type="Property"/>
</operand>
<operand name="Lookback Year" xsi:type="ExpressionRef"/>
</where>
<sort>
<by direction="asc" xsi:type="ByExpression">
<expression path="value" xsi:type="Property">
<source name="effective" xsi:type="IdentifierRef"/>
</expression>
</by>
</sort>
</expression>
</def>
<def name="Most Recent Illicit Drug Urine Screenings in Last 12 Months" context="Patient" accessLevel="Public">
<expression xsi:type="Last">
<source name="Get Illicit Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</expression>
</def>
<def name="Get Opioid Drug Urine Screenings in Last 12 Months" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="observation">
<expression dataType="fhir:Observation" codeProperty="combo-code" xsi:type="Retrieve">
<codes name="Opioid Drug Screening" libraryName="Common" xsi:type="ValueSetRef"/>
</expression>
</source>
<where xsi:type="In">
<operand path="value" xsi:type="Property">
<source path="effective" scope="observation" xsi:type="Property"/>
</operand>
<operand name="Lookback Year" xsi:type="ExpressionRef"/>
</where>
<sort>
<by direction="asc" xsi:type="ByExpression">
<expression path="value" xsi:type="Property">
<source name="effective" xsi:type="IdentifierRef"/>
</expression>
</by>
</sort>
</expression>
</def>
<def name="Most Recent Opioid Drug Urine Screenings in Last 12 Months" context="Patient" accessLevel="Public">
<expression xsi:type="Last">
<source name="Get Opioid Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</expression>
</def>
<def name="No Urine Screening In Last 12 Months" context="Patient" accessLevel="Public">
<expression xsi:type="And">
<operand xsi:type="IsNull">
<operand name="Most Recent Illicit Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</operand>
<operand xsi:type="IsNull">
<operand name="Most Recent Opioid Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="Positive Opioid Drug Screening" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="mostRecentScreening">
<expression name="Most Recent Opioid Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</source>
<where xsi:type="Or">
<operand xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="interpretation" scope="mostRecentScreening" xsi:type="Property"/>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:String" value="POS" xsi:type="Literal"/>
</operand>
<operand xsi:type="If">
<condition asType="t:Boolean" xsi:type="As">
<operand xsi:type="Not">
<operand xsi:type="IsNull">
<operand xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</operand>
</operand>
</operand>
</condition>
<then xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="interpretation" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:String" value="POS" xsi:type="Literal"/>
</then>
<else valueType="t:Boolean" value="false" xsi:type="Literal"/>
</operand>
</where>
</expression>
</def>
<def name="Orders Before Most Recent Opioid Screening" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="orders">
<expression name="Get Active Ambulatory Opioid Rx" xsi:type="ExpressionRef"/>
</source>
<relationship alias="mostRecentScreening" xsi:type="With">
<expression name="Positive Opioid Drug Screening" xsi:type="ExpressionRef"/>
<suchThat xsi:type="Less">
<operand path="value" xsi:type="Property">
<source path="authoredOn" scope="orders" xsi:type="Property"/>
</operand>
<operand path="value" xsi:type="Property">
<source path="effective" scope="mostRecentScreening" xsi:type="Property"/>
</operand>
</suchThat>
</relationship>
<return>
<expression name="orders" xsi:type="AliasRef"/>
</return>
</expression>
</def>
<def name="Prescribed Opioids" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="orders">
<expression name="Orders Before Most Recent Opioid Screening" xsi:type="ExpressionRef"/>
</source>
<return>
<expression xsi:type="Lower">
<operand xsi:type="SingletonFrom">
<operand name="GetIngredient" libraryName="Common" xsi:type="FunctionRef">
<operand name="ToCode" libraryName="Common" xsi:type="FunctionRef">
<operand xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="medication" scope="orders" xsi:type="Property"/>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</operand>
</operand>
</operand>
</operand>
</expression>
</return>
</expression>
</def>
<def name="GetOpioid" context="Patient" accessLevel="Public" xsi:type="FunctionDef">
<expression xsi:type="Case">
<comparand name="value" xsi:type="OperandRef"/>
<caseItem>
<when valueType="t:String" value="3299-5" xsi:type="Literal"/>
<then valueType="t:String" value="Acetaminophen" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="14184-6" xsi:type="Literal"/>
<then valueType="t:String" value="Atropine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="16485-5" xsi:type="Literal"/>
<then valueType="t:String" value="Bromodiphenhydramine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3408-2" xsi:type="Literal"/>
<then valueType="t:String" value="Brompheniramine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3414-0" xsi:type="Literal"/>
<then valueType="t:String" value="Buprenorphine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3421-5" xsi:type="Literal"/>
<then valueType="t:String" value="Butalbital" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="12333-1" xsi:type="Literal"/>
<then valueType="t:String" value="Butorphanol" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3423-1" xsi:type="Literal"/>
<then valueType="t:String" value="Caffeine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="21142-5" xsi:type="Literal"/>
<then valueType="t:String" value="Carisoprodol" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="16605-8" xsi:type="Literal"/>
<then valueType="t:String" value="Chlorcyclizine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3467-8" xsi:type="Literal"/>
<then valueType="t:String" value="Chlorpheniramine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3507-1" xsi:type="Literal"/>
<then valueType="t:String" value="Codeine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="14066-5" xsi:type="Literal"/>
<then valueType="t:String" value="Dihydrocodeine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3571-7" xsi:type="Literal"/>
<then valueType="t:String" value="Diphenhydramine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="11235-9" xsi:type="Literal"/>
<then valueType="t:String" value="Fentanyl" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="12308-3" xsi:type="Literal"/>
<then valueType="t:String" value="Hydrocodone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="9834-3" xsi:type="Literal"/>
<then valueType="t:String" value="Hydromorphone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="14071" xsi:type="Literal"/>
<then valueType="t:String" value="Ibuprofen" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3711-9" xsi:type="Literal"/>
<then valueType="t:String" value="Levorphanol" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3746-5" xsi:type="Literal"/>
<then valueType="t:String" value="Meperidine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3773-9" xsi:type="Literal"/>
<then valueType="t:String" value="Methadone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3830-7" xsi:type="Literal"/>
<then valueType="t:String" value="Morphine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="42618-9" xsi:type="Literal"/>
<then valueType="t:String" value="Naloxone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="12309-1" xsi:type="Literal"/>
<then valueType="t:String" value="Naltrexone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="10998-3" xsi:type="Literal"/>
<then valueType="t:String" value="Oxycodone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="11247-4" xsi:type="Literal"/>
<then valueType="t:String" value="Oxymorphone" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3917-2" xsi:type="Literal"/>
<then valueType="t:String" value="Pentazocine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3962-8" xsi:type="Literal"/>
<then valueType="t:String" value="Phenylephrine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3965-1" xsi:type="Literal"/>
<then valueType="t:String" value="Phenylpropanolamine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="11000-7" xsi:type="Literal"/>
<then valueType="t:String" value="Promethazine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="4003-0" xsi:type="Literal"/>
<then valueType="t:String" value="Pseudoephedrine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="4009-7" xsi:type="Literal"/>
<then valueType="t:String" value="Pyrilamine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="65807-0" xsi:type="Literal"/>
<then valueType="t:String" value="Tapentadol" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="43219-5" xsi:type="Literal"/>
<then valueType="t:String" value="Tramadol" xsi:type="Literal"/>
</caseItem>
<else xsi:type="Concatenate">
<operand valueType="t:String" value="Unknown code: " xsi:type="Literal"/>
<operand name="value" xsi:type="OperandRef"/>
</else>
</expression>
<operand name="value">
<operandTypeSpecifier name="t:String" xsi:type="NamedTypeSpecifier"/>
</operand>
</def>
<def name="Missing Opioids" context="Patient" accessLevel="Public">
<expression xsi:type="If">
<condition asType="t:Boolean" xsi:type="As">
<operand xsi:type="Not">
<operand xsi:type="IsNull">
<operand name="Positive Opioid Drug Screening" xsi:type="ExpressionRef"/>
</operand>
</operand>
</condition>
<then xsi:type="Except">
<operand xsi:type="Query">
<source alias="Prescriptions">
<expression name="Prescribed Opioids" xsi:type="ExpressionRef"/>
</source>
</operand>
<operand xsi:type="ToList">
<operand xsi:type="Lower">
<operand name="GetOpioid" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="code" xsi:type="Property">
<source name="Positive Opioid Drug Screening" xsi:type="ExpressionRef"/>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</operand>
</operand>
</operand>
</then>
<else xsi:type="As">
<operand xsi:type="Null"/>
<asTypeSpecifier xsi:type="ListTypeSpecifier">
<elementType name="t:String" xsi:type="NamedTypeSpecifier"/>
</asTypeSpecifier>
</else>
</expression>
</def>
<def name="Has Missing Opioids?" context="Patient" accessLevel="Public">
<expression xsi:type="Exists">
<operand name="Missing Opioids" xsi:type="ExpressionRef"/>
</expression>
</def>
<def name="Get Opioids From Most Recent Screening" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="mostRecentScreening">
<expression name="Positive Opioid Drug Screening" xsi:type="ExpressionRef"/>
</source>
<return>
<expression xsi:type="Union">
<operand xsi:type="ToList">
<operand xsi:type="Lower">
<operand name="GetOpioid" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="code" scope="mostRecentScreening" xsi:type="Property"/>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</operand>
</operand>
</operand>
<operand xsi:type="ToList">
<operand xsi:type="If">
<condition asType="t:Boolean" xsi:type="As">
<operand xsi:type="Not">
<operand xsi:type="IsNull">
<operand xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</operand>
</operand>
</operand>
</condition>
<then xsi:type="Lower">
<operand name="GetOpioid" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</operand>
</then>
<else asType="t:String" xsi:type="As">
<operand xsi:type="SingletonFrom">
<operand xsi:type="List"/>
</operand>
</else>
</operand>
</operand>
</expression>
</return>
</expression>
</def>
<def name="Unprescribed Opioids" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="mostRecentScreeningOpioids">
<expression name="Get Opioids From Most Recent Screening" xsi:type="ExpressionRef"/>
</source>
<relationship alias="ingredients" xsi:type="With">
<expression name="Prescribed Opioids" xsi:type="ExpressionRef"/>
<suchThat xsi:type="Not">
<operand xsi:type="In">
<operand name="mostRecentScreeningOpioids" xsi:type="AliasRef"/>
<operand xsi:type="ToList">
<operand name="ingredients" xsi:type="AliasRef"/>
</operand>
</operand>
</suchThat>
</relationship>
<return>
<expression name="mostRecentScreeningOpioids" xsi:type="AliasRef"/>
</return>
</expression>
</def>
<def name="Has Unprescribed Opioids?" context="Patient" accessLevel="Public">
<expression xsi:type="Exists">
<operand name="Unprescribed Opioids" xsi:type="ExpressionRef"/>
</expression>
</def>
<def name="Positive Illicit Drug Screening" context="Patient" accessLevel="Public">
<expression xsi:type="Query">
<source alias="mostRecentScreening">
<expression name="Most Recent Illicit Drug Urine Screenings in Last 12 Months" xsi:type="ExpressionRef"/>
</source>
<where xsi:type="Or">
<operand xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="interpretation" scope="mostRecentScreening" xsi:type="Property"/>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:String" value="POS" xsi:type="Literal"/>
</operand>
<operand xsi:type="If">
<condition asType="t:Boolean" xsi:type="As">
<operand xsi:type="Not">
<operand xsi:type="IsNull">
<operand xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</operand>
</operand>
</operand>
</condition>
<then xsi:type="Equal">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="interpretation" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="component" scope="mostRecentScreening" xsi:type="Property"/>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
<operand valueType="t:String" value="POS" xsi:type="Literal"/>
</then>
<else valueType="t:Boolean" value="false" xsi:type="Literal"/>
</operand>
</where>
</expression>
</def>
<def name="Has Illicit Drugs in Screening?" context="Patient" accessLevel="Public">
<expression xsi:type="Exists">
<operand xsi:type="ToList">
<operand name="Positive Illicit Drug Screening" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="Inclusion Criteria" context="Patient" accessLevel="Public">
<expression xsi:type="And">
<operand xsi:type="And">
<operand xsi:type="And">
<operand name="Validate Trigger Event" xsi:type="ExpressionRef"/>
<operand xsi:type="Not">
<operand name="Exclusion Criteria" xsi:type="ExpressionRef"/>
</operand>
</operand>
<operand xsi:type="AnyTrue">
<source name="ProbableDaysInRange" libraryName="Common" xsi:type="FunctionRef">
<operand name="Get Active Ambulatory Opioid Rx" xsi:type="ExpressionRef"/>
<operand valueType="t:Integer" value="90" xsi:type="Literal"/>
<operand valueType="t:Integer" value="80" xsi:type="Literal"/>
</source>
</operand>
</operand>
<operand xsi:type="Or">
<operand xsi:type="Or">
<operand xsi:type="Or">
<operand name="No Urine Screening In Last 12 Months" xsi:type="ExpressionRef"/>
<operand name="Has Missing Opioids?" xsi:type="ExpressionRef"/>
</operand>
<operand name="Has Unprescribed Opioids?" xsi:type="ExpressionRef"/>
</operand>
<operand name="Has Illicit Drugs in Screening?" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="GetIllicitDrug" context="Patient" accessLevel="Public" xsi:type="FunctionDef">
<expression xsi:type="Case">
<comparand name="value" xsi:type="OperandRef"/>
<caseItem>
<when valueType="t:String" value="3397-7" xsi:type="Literal"/>
<then valueType="t:String" value="Cocaine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="14267-9" xsi:type="Literal"/>
<then valueType="t:String" value="Methylenedioxymethamphetamine (MDMA)" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="29868-7" xsi:type="Literal"/>
<then valueType="t:String" value="Gamma Hydroxybutyric Acid (GHB)" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="12327-3" xsi:type="Literal"/>
<then valueType="t:String" value="Ketamine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3732-5" xsi:type="Literal"/>
<then valueType="t:String" value="Lysergic Acid Diethylamide (LSD)" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3779-6" xsi:type="Literal"/>
<then valueType="t:String" value="Methamphetamine" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="17504-2" xsi:type="Literal"/>
<then valueType="t:String" value="Psilocybin" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="41020-9" xsi:type="Literal"/>
<then valueType="t:String" value="Flunitrazepam (Rohypnol)" xsi:type="Literal"/>
</caseItem>
<caseItem>
<when valueType="t:String" value="3426-4" xsi:type="Literal"/>
<then valueType="t:String" value="Tetrahydrocannabinol (THC)" xsi:type="Literal"/>
</caseItem>
<else xsi:type="Concatenate">
<operand valueType="t:String" value="Unknown code: " xsi:type="Literal"/>
<operand name="value" xsi:type="OperandRef"/>
</else>
</expression>
<operand name="value">
<operandTypeSpecifier name="t:String" xsi:type="NamedTypeSpecifier"/>
</operand>
</def>
<def name="Inconsistent Illicit Drugs" context="Patient" accessLevel="Public">
<expression xsi:type="Concatenate">
<operand valueType="t:String" value="Found the following illicit drug(s) in urine drug screen: " xsi:type="Literal"/>
<operand xsi:type="If">
<condition asType="t:Boolean" xsi:type="As">
<operand xsi:type="IsNull">
<operand name="GetIllicitDrug" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="code" xsi:type="Property">
<source name="Positive Illicit Drug Screening" xsi:type="ExpressionRef"/>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</operand>
</operand>
</condition>
<then name="GetIllicitDrug" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="interpretation" xsi:type="Property">
<source name="Positive Illicit Drug Screening" xsi:type="ExpressionRef"/>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</then>
<else name="GetIllicitDrug" xsi:type="FunctionRef">
<operand path="value" xsi:type="Property">
<source path="code" xsi:type="Property">
<source xsi:type="Indexer">
<operand path="coding" xsi:type="Property">
<source path="code" xsi:type="Property">
<source name="Positive Illicit Drug Screening" xsi:type="ExpressionRef"/>
</source>
</operand>
<operand valueType="t:Integer" value="0" xsi:type="Literal"/>
</source>
</source>
</operand>
</else>
</operand>
</expression>
</def>
<def name="Has Opioids in Screening?" context="Patient" accessLevel="Public">
<expression xsi:type="Exists">
<operand xsi:type="ToList">
<operand name="Positive Opioid Drug Screening" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="Inconsistent Unprescribed Opioids" context="Patient" accessLevel="Public">
<expression xsi:type="Concatenate">
<operand valueType="t:String" value="Found the following unprescribed opioid(s): " xsi:type="Literal"/>
<operand xsi:type="SingletonFrom">
<operand name="Unprescribed Opioids" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="Inconsistent Missing Opioids" context="Patient" accessLevel="Public">
<expression xsi:type="Concatenate">
<operand valueType="t:String" value="The following opioids are missing from the screening: " xsi:type="Literal"/>
<operand xsi:type="SingletonFrom">
<operand name="Missing Opioids" xsi:type="ExpressionRef"/>
</operand>
</expression>
</def>
<def name="Get Indicator" context="Patient" accessLevel="Public">
<expression valueType="t:String" value="warning" xsi:type="Literal"/>
</def>
</statements>
</library>
Usage note: every effort has been made to ensure that the
examples are correct and useful, but they are not a normative part
of the specification.