Common CQL Assets for FHIR (US-Based)
1.0.0-ballot - STU 1 Ballot United States of America flag

This page is part of the Common CQL Assets for FHIR (US-Based) (v1.0.0-ballot: STU 1 Ballot 1) based on FHIR (HL7® FHIR® Standard) R4. No current official version has been published yet. For a full list of available versions, see the Directory of published versions

Library: Expression Library for the Uniform Pharmacy Prior Authorization Request Form Example (Experimental)

Official URL: http://hl7.org/fhir/us/cql/Library/UPPARFInitialExpressions Version: 1.0.0-ballot
Standards status: Informative Computable Name: UPPARFInitialExpressions

Initial expressions for use in populating answers to questions in the Example Uniform Pharmacy Prior Authorization Request Form example questionnaire.

Title: Expression Library for the Uniform Pharmacy Prior Authorization Request Form Example
Id: UPPARFInitialExpressions
Version: 1.0.0-ballot
Url: Expression Library for the Uniform Pharmacy Prior Authorization Request Form Example
Status: draft
Experimental: true
Type:

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

code: logic-library

Date: 2025-04-01 14:00:55+0000
Publisher: HL7 International / Clinical Decision Support
Description:

Initial expressions for use in populating answers to questions in the Example Uniform Pharmacy Prior Authorization Request Form example questionnaire.

Jurisdiction: US
Related Artifacts:

Dependencies

Parameters:
NameTypeMinMaxIn/Out
MedicationRequestResource01In
PatientResource01Out
Most Recent Medication RequestResource01Out
Urgencystring01Out
Most Recent MedicationResource01Out
Most Recent Medication Namestring01Out
Is Opioid TreatmentResource01Out
Prior PrescriptionResource01Out
Is First Prior Authenticationboolean01Out
Initial Request DatedateTime01Out
Is First Request > 12 Monthsboolean01Out
Prescription DatedateTime01Out
RequesterResource01Out
Prescriber Namestring01Out
Prescriber Faxstring01Out
Prescriber Phonestring01Out
Prescriber Pagerstring01Out
Prescriber Addressstring01Out
Prescriber Contactstring01Out
Prescriber NPIstring01Out
Prescriber DEAResource01Out
Prescriber Tax IDstring01Out
RequesterRoleResource01Out
Prescriber Specialtystring01Out
Prescriber Email Addressstring01Out
Request Typestring01Out
ICD 10 Codesstring0*Out
Diagnosis Descriptionsstring0*Out
Dosage Value as Stringstring01Out
Dosage Unitstring01Out
Unit Volume of Named Drugsstring01Out
Dosestring01Out
Routestring01Out
Most Recent Dosage InstructionResource01Out
Frequencystring01Out
Refillsinteger01Out
Todaydate01Out
Start Date and Lengthstring01Out
Content: text/cql
library UPPARFInitialExpressions

using USCore version '3.1.1'
using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'
include USCoreCommon called UC
include USCoreElements called UCE
include CumulativeMedicationDuration called CMD 

codesystem "Identifier Type": 'http://terminology.hl7.org/CodeSystem/v2-0203'
codesystem "Verification Status": 'http://terminology.hl7.org/CodeSystem/condition-ver-status'
codesystem "Condition Clinical": 'http://terminology.hl7.org/CodeSystem/condition-clinical'
codesystem "ICD10": 'http://hl7.org/fhir/sid/icd-10-cm' 

valueset "ICD10 vs": 'http://hl7.org/fhir/ValueSet/icd-10'

code "ICD10 example code": 'example' from "ICD10"
code "Member Number": 'MB' from "Identifier Type"
code "Subscriber Number": 'SN' from "Identifier Type"
code "Confirmed": 'confirmed' from "Verification Status"
code "Active": 'active' from "Condition Clinical"

parameter "MedicationRequest" USCore.MedicationRequestProfile

context Patient

define "Urgency":
"Most Recent Medication Request".priority P
  return (
    if P != 'routine' then 'Urgent'
    else  'Not Urgent'
  )

//TODO: name could also be retrieved by MedicationRequest as a codeable concept if there is no reference
define "Most Recent Medication Name":
  "Most Recent Medication" M
    return M.code.display

define "Is Opioid Treatment":
null //TBD

//TODO: can we assume that with a previous prior authentication there also has been a prior prescription?
define "Is First Prior Authentication":
IsNull("Prior Prescription")

//TODO: does the initial request date mean the exact same medication was requested before?
define "Initial Request Date":
if not "Is First Prior Authentication" then
    singleton from (
    UCE."All Medication Requests" M
      where EndsWith(("Most Recent Medication Request".priorPrescription as USCore.Reference).reference, M.id)
      return M.authoredOn
    )
  else 
    null

define "Is First Request > 12 Months":
if IsNull("Initial Request Date") then null else 
(months between "Initial Request Date" and Now() > 12)

define "Prescription Date":
"Most Recent Medication Request".authoredOn

define "Prescriber Name":
   First(Requester.name).family
   //TODO: should this be First("Requester".name).family with double quotes?
   //TODO: prefix, suffix and given do not work as expected.

define "Prescriber Fax":
  UC.Fax(Requester.telecom).value

define "Prescriber Phone":
  UC.Mobile(Requester.telecom).value

define "Prescriber Pager":
  UC.Pager(Requester.telecom).value

define "Prescriber Address":
'TODO: remove hard coded address'

define "Prescriber Contact":
'TODO: remove hard coded contact'
//TBD: would this be a work phone or more something like an address?

define "Prescriber NPI":
First (
  "Requester".identifier I
  where I.system = 'http://hl7.org.fhir/sid/us-npi'
  ).value

//TODO: what is DEA?
define "Prescriber DEA":
  null

define "Prescriber Tax ID":
First (
  "Requester".identifier I
  where I.system = 'urn:oid:2.16.840.1.113883.4.4'
  ).value

define "Prescriber Specialty":
First(RequesterRole.specialty.codes).display

define "Prescriber Email Address":
  UC.Email(Requester.telecom).value

define "Request Type":
//TODO: is this logic correct?
if "Is First Prior Authentication" then
  'New Request' else 'Reauthorization'

define "ICD 10 Codes":
  UCE."Active Confirmed Problem List Items".code.codes C
  where C.system ~ "ICD10 example code".system //"ICD10".id
  return C.code

define "Diagnosis Descriptions":
  UCE."Active Confirmed Problem List Items".code.display

define "Unit Volume of Named Drugs":
  "Dosage Value as String" + "Dosage Unit"

define "Dose": 
  "Dosage Value as String"

define "Route": 
  First("Most Recent Medication Request".dosageInstruction).route.display

define "Most Recent Dosage Instruction":
  singleton from ("Most Recent Medication Request".dosageInstruction)

define "Frequency": 
  "Most Recent Dosage Instruction" DI
    return ToString(DI.timing.repeat.frequency) + ' times per ' 
      + ToString(DI.timing.repeat.period) 
      + DI.timing.repeat.periodUnit

define "Refills": 
  "Most Recent Medication Request".dispenseRequest.numberOfRepeatsAllowed

define "Today":
  Today()

define "Dosage Value as String":
  ToString(("Most Recent Medication Request".dosageInstruction.doseAndRate[0].dose as System.Quantity).value)

define "Dosage Unit":
  ("Most Recent Medication Request".dosageInstruction.doseAndRate[0].dose as System.Quantity).unit

//helper definitions
//TODO: medications are not necessarily a reference but could also be represented by a codeable concept
define "Most Recent Medication":
singleton from (
  UCE."All Medications" M
    where EndsWith(("Most Recent Medication Request".medication as USCore.Reference).reference, M.id))
 
define "Most Recent Medication Request":
  MedicationRequest
  // UCE."Most Recent Medication Request"

define "Prior Prescription":
  "Most Recent Medication Request".priorPrescription

define "Requester":
  UCE.Requester("Most Recent Medication Request")

define "RequesterRole":
  UCE.RequesterRole("Most Recent Medication Request")

//email, pager, and fax functions moved to USCoreCommon.cql

//IMPORTANT NOTE: Missing the entire (or majority) of the "Prior Authorization Request for Drug Benefit" section of the quesstionnaire. Expect errors on Postman regarding the items in this section.
define "Start Date and Length":
  null as System.String
Content: application/elm+xml
Encoded data (127580 characters)
Content: application/elm+json
Encoded data (237000 characters)