Common CQL Artifacts for FHIR (US-Based)
1.0.0 - Informative 1 United States of America flag

Common CQL Artifacts for FHIR (US-Based), published by HL7 International / Clinical Decision Support. This guide is not an authorized publication; it is the continuous build for version 1.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/us-cql-ig/ and changes regularly. See the Directory of published versions

Library: Expression Library for the Genetic/Molecular testing preauthorization Example (Experimental)

Official URL: http://hl7.org/fhir/us/cql/Library/GMTPInitialExpressions Version: 1.0.0
Standards status: Informative Maturity Level: 3 Computable Name: GMTPInitialExpressions

Initial expressions for use in populating answers to questions in the Genetic/Molecular testing preauthorization example questionnaire.

Metadata
Title Expression Library for the Genetic/Molecular testing preauthorization Example
Version 1.0.0
Status Draft
Experimental true
Jurisdiction United States of America
Steward (Publisher) HL7 International / Clinical Decision Support
Description

Initial expressions for use in populating answers to questions in the Genetic/Molecular testing preauthorization example questionnaire.

Type Logic Library
Parameter Name: Coverage
Use: In
Min Cardinality: 0
Max Cardinality: 1
Type: Coverage
Parameter Name: ServiceRequest
Use: In
Min Cardinality: 0
Max Cardinality: 1
Type: ServiceRequest
Parameter Name: Patient
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: All Problem List Items
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: Patient history
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Patient history including age at diagnosis
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Retrieve Member Coverage test parameter
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Coverage
Parameter Name: Member Coverage
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Coverage
Parameter Name: Billing Provider
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: Billing Provider Name
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Billing Provider Phone
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: ContactPoint
Parameter Name: Billing Provider Address
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Address
Parameter Name: Retrieve Service Request test parameter
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: ServiceRequest
Parameter Name: Most Recent ServiceRequest
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: ServiceRequest
Parameter Name: Billing Provider NPI
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Billing Provider Fax
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Date of Service
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: dateTime
Parameter Name: Requested Test
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: CodeableConcept
Parameter Name: Test ID
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Test name
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Test ICD Codes
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Test CPT Codes
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: ALL ICD and CPT Test Codes
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Test Related Condition
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: Diagnosis Descriptions
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Billing Provider different from Servicing Provider
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Research Subject
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: ResearchSubject
Parameter Name: Clinical Trial
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: ResearchStudy
Parameter Name: Clinical Trial Organization
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: BillingProvider is Clinical Trial Organization
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: Is Research Subject
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: Part of clinical trial
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Clinical Trial ID
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Parameter Name: Previous genetic testing for condition
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: string
Data Requirement Type: Coverage
Profile(s): Coverage
Data Requirement Type: ServiceRequest
Profile(s): ServiceRequest
Library Content
CQL Content
library GMTPInitialExpressions

using USCore version '7.0.0'
using FHIR version '4.0.1'

include hl7.fhir.uv.cql.FHIRHelpers version '4.0.1' called FHIRHelpers
include hl7.fhir.uv.cql.FHIRCommon version '2.0.0'
include USCoreCommon called UC
include USCoreElements called UCE

codesystem "LOINC": 'http://loinc.org'
codesystem "Identifier Type": 'http://terminology.hl7.org/CodeSystem/v2-0203'
code "Member Number": 'MB' from "Identifier Type"

parameter "Coverage" FHIR.Coverage
parameter "ServiceRequest" FHIR.ServiceRequest

context Patient

define "All Problem List Items":
  UCE."All Problem List Items"

/*
@question: Patient history (including age at diagnosis):
TODO: Determine whether we should be considering encounter diagnoses and/or health concerns
TODO: Determine whether age at onset is actually relevant, or if we would, in an automated context, just return the Condition resource
TODO: Does "age at diagnosis" mean "age at onset" or is it really asking for when the diagnosis was recorded?
TODO: Is there a version of patient history that is reusable here?
*/
define "Patient history":
  "All Problem List Items" C
    let prevalence: C.prevalenceInterval()
    where C.isConfirmed()
    return {
      diagnosis: C.code.coding.first().code,
      ageAtOnset: ToString(Patient.ageInYearsAt(ToDate(start of prevalence))),
      onset: ToString(start of prevalence),
      abatement: ToString(if prevalence.hasEnd() then end of prevalence else null)
    }

/*
@linkId: history|patient-history
*/
define "Patient history including age at diagnosis":
  "Patient history" H
    return H.diagnosis & (', ' + H.ageAtOnset + ' yrs') & (', abated ' + H.abatement)

define "Billing Provider Name":
  "Billing Provider".name

define "Billing Provider Phone":
  "Billing Provider".work()

define "Billing Provider Address":
  First(
    "Billing Provider".address address
      where address.use in { 'billing', 'work' }
        and address.period is not null implies address.period includes Today()
  )

define "Retrieve Member Coverage test parameter":
  // When executing CQL with the VSCode extension retrieve the resource specific for the test case
  //   the list of resource ids match the resources from the test case folders
  singleton from ([FHIR.Coverage] CV where CV.id in {
    'Coverage-example-GMTP', // testcase: GMTP-example-patient-2
    'coverage-GMTP-1'        // testcase: USCorePatient-GMTP-1
  })

define "Member Coverage":
  Coalesce(
    Coverage,
    "Retrieve Member Coverage test parameter"
  )

define "Retrieve Service Request test parameter":
  // When executing CQL with the VSCode extension retrieve the resource specific for the test case
  //   the list of resource ids match the resources from the test case folders
  singleton from ([FHIR.ServiceRequest] SR where SR.id in {
    'ServiceRequest-example-1-GMTP',       // testcase: GMTP-example-patient-2
    'service-request-USCorePatient-GMTP-1' // testcase: USCorePatient-GMTP-1
  })

define "Most Recent ServiceRequest":
  Coalesce(
    ServiceRequest,
    "Retrieve Service Request test parameter"
  )

define "Billing Provider":
  UCE.BillingProvider("Member Coverage")

define "Billing Provider NPI":
  "Billing Provider".identifier I 
  where I.system = 'http://hl7.org/fhir/sid/us-npi'
  return I.value

define "Billing Provider Fax":
  "Billing Provider".telecom T
  where T.system = 'fax'
  return T.value

define "Date of Service":
  "Most Recent ServiceRequest".occurrence.value

define "Requested Test":
  "Most Recent ServiceRequest".code

define "Test ID":
  Combine("Requested Test".coding.code.value, ', ') 

define "Test name":
   Combine("Requested Test".coding.display.value, ', ')

define "ALL ICD and CPT Test Codes":
   "Test ICD Codes" union "Test CPT Codes"

define "Test ICD Codes":
 "Requested Test".coding C
  where C.system.value = 'http://hl7.org/fhir/sid/icd-10-cm'
  return C.code.value
  
define "Test CPT Codes":
  "Requested Test".coding C
  where C.system.value =  'http://www.ama-assn.org/go/cpt'
  return C.code.value

define "Test Related Condition":
  UCE.RelatedCondition("Most Recent ServiceRequest")
  //.reasonReference changed to .reason in FHIR R5

define "Diagnosis Descriptions":
  "Test Related Condition".code.coding.display.value

define "Billing Provider different from Servicing Provider":
  if "Billing Provider".id != First(UCE.ServicingProvider("Most Recent ServiceRequest").id) then
  'Yes'
  else 
  'No'

define "Clinical Trial Organization":
  First(UCE."Clinical Trial Organization" O 
    with "Clinical Trial"  T such that EndsWith(T.sponsor.reference, O.id))  
 //in FHIR R5 T.associatedParty instead of T.sponsor 

define "BillingProvider is Clinical Trial Organization":
  "Billing Provider" = "Clinical Trial Organization"

//TODO does not get populated properly
define "Part of clinical trial":
 if "Is Research Subject" and "BillingProvider is Clinical Trial Organization" then
 'Yes'
 else
 'No'

define "Is Research Subject":
  exists("Research Subject")

define "Research Subject":
  UCE."Research Subject"
     //ResearchSubject.individual is from FHIR version v4.0.1 and has been replaced by R.subject in FHIR R5

define "Clinical Trial":
  UCE."All Clinical Trials" R 
    with "Research Subject" S such that EndsWith(S.study.reference, R.id)
    with  "Test Related Condition" C such that C.code in R.condition

define "Clinical Trial ID":
  "Clinical Trial".identifier C
  where C.system = 'https://clinicaltrials.gov'
  return C.value.value

define "Previous genetic testing for condition":
  from 
    UCE."All ServiceRequests" S,
    ServiceRequest SR
  where S.occurrence before SR.occurrence
    and S.id != SR.id
    and S.reasonReference = SR.reasonReference
  return S.id.value

//define "Family history of genetic testing"
//too general to prefill?
ELM XML Content
Encoded data (153752 characters)
ELM JSON Content
Encoded data (290288 characters)
Generated using version 0.4.9 of the sample-content-ig Liquid templates