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 Genetic/Molecular testing preauthorization Example (Experimental)

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

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

Title: Expression Library for the Genetic/Molecular testing preauthorization Example
Id: GMTPInitialExpressions
Version: 1.0.0-ballot
Url: Expression Library for the Genetic/Molecular testing preauthorization 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 Genetic/Molecular testing preauthorization example questionnaire.

Jurisdiction: US
Related Artifacts:

Dependencies

Parameters:
NameTypeMinMaxIn/Out
CoverageCoverage01In
ServiceRequestServiceRequest01In
PatientResource01Out
All Problem List ItemsResource0*Out
Patient historyResource0*Out
Retrieve Member Coverage test parameterCoverage01Out
Member CoverageCoverage01Out
Billing ProviderResource01Out
Billing Provider Namestring01Out
Billing Provider Phonestring01Out
Billing Provider Addressstring0*Out
Retrieve Service Request test parameterServiceRequest01Out
Most Recent ServiceRequestServiceRequest01Out
Billing Provider NPIstring0*Out
Billing Provider Faxstring0*Out
Date of ServicedateTime01Out
Requested TestCodeableConcept01Out
Test IDstring01Out
Test namestring01Out
Test ICD Codesstring0*Out
Test CPT Codesstring0*Out
ALL ICD and CPT Test Codesstring0*Out
Test Related ConditionCondition0*Out
Diagnosis Descriptionsstring0*Out
Billing Provider different from Servicing Providerstring01Out
Research SubjectResearchSubject0*Out
Clinical TrialResearchStudy0*Out
Clinical Trial OrganizationResource01Out
BillingProvider is Clinical Trial Organizationboolean01Out
Is Research Subjectboolean01Out
Part of clinical trialstring01Out
Clinical Trial IDstring0*Out
Previous genetic testing for conditionstring0*Out
Data Requirements:
TypeProfileMSCode Filter
Coverage http://hl7.org/fhir/StructureDefinition/Coverage
ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest
Content: text/cql
library GMTPInitialExpressions

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

include FHIRHelpers version '4.0.1' called FHIRHelpers
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":
  UCE."All Problem List Items" C
    let prevalence: C.prevalenceInterval()
    where C.isConfirmed()
    return {
      diagnosis: C.code.display,
      ageAtOnset: ToString(AgeInYearsAt(start of prevalence)),
      onset: ToString(start of prevalence),
      abatement: ToString(if prevalence.hasEnd() then end of prevalence else null)
    }

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

define "Billing Provider Phone":
  UC.Mobile("Billing Provider".telecom).value

define "Billing Provider Address":
  { 'TODO: remove hard-coded address' }

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?
Content: application/elm+xml
Encoded data (136924 characters)
Content: application/elm+json
Encoded data (256472 characters)