Common CQL Artifacts for FHIR (US-Based)
2.0.0-ballot - Informative 2 Ballot

Common CQL Artifacts for FHIR (US-Based) - Downloaded Version null 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: 2.0.0-ballot | Highlight text changes?
Standards status: Informative Draft as of 2026-04-03 | 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 | 2.0.0-ballot
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 from http://terminology.hl7.org/CodeSystem/library-type
Dependency | Description: Library FHIRHelpers Resource: http://hl7.org/fhir/uv/cql/Library/FHIRHelpers|4.0.1 Canonical URL: `http://hl7.org/fhir/uv/cql/Library/FHIRHelpers|4.0.1`
Dependency | Description: Library FHIRCommon Resource: http://hl7.org/fhir/uv/cql/Library/FHIRCommon|2.0.0 Canonical URL: `http://hl7.org/fhir/uv/cql/Library/FHIRCommon|2.0.0`
Dependency | Description: Library UC Resource: US Core Commonversion: null2.0.0-ballot) Canonical URL: `http://hl7.org/fhir/us/cql/Library/USCoreCommon|2.0.0-ballot`
Dependency | Description: Library UCE Resource: US Core Elementsversion: null2.0.0-ballot) Canonical URL: `http://hl7.org/fhir/us/cql/Library/USCoreElements|2.0.0-ballot`
Dependency | Description: Code System LOINC Resource: Logical Observation Identifiers, Names and Codes (LOINC) Canonical URL: `http://loinc.org`
Dependency | Description: Code System Identifier Type Resource: identifierType Canonical URL: `http://terminology.hl7.org/CodeSystem/v2-0203`
Data Requirement | Type: Coverage Profile(s): Coverage
Data Requirement | Type: ServiceRequest Profile(s): ServiceRequest
Parameters
Name | Use | Card. | Type | Documentation
Coverage | In | 0..1 | Coverage |
ServiceRequest | In | 0..1 | ServiceRequest |
Patient | Out | 0..1 | Resource |
All Problem List Items | Out | 0..* | Condition |
Patient history | Out | 0..* | Resource |
Patient history including age at diagnosis | Out | 0..* | string |
Retrieve Member Coverage test parameter | Out | 0..1 | Coverage |
Member Coverage | Out | 0..1 | Coverage |
Billing Provider | Out | 0..1 | Resource |
Billing Provider Name | Out | 0..1 | string |
Billing Provider Phone | Out | 0..1 | ContactPoint |
Billing Provider Address | Out | 0..1 | Address |
Retrieve Service Request test parameter | Out | 0..1 | ServiceRequest |
Most Recent ServiceRequest | Out | 0..1 | ServiceRequest |
Billing Provider NPI | Out | 0..* | string |
Billing Provider Fax | Out | 0..* | string |
Date of Service | Out | 0..1 | dateTime |
Requested Test | Out | 0..1 | CodeableConcept |
Test ID | Out | 0..1 | string |
Test name | Out | 0..1 | string |
Test ICD Codes | Out | 0..* | string |
Test CPT Codes | Out | 0..* | string |
ALL ICD and CPT Test Codes | Out | 0..* | string |
Test Related Condition | Out | 0..* | Condition |
Diagnosis Descriptions | Out | 0..* | string |
Billing Provider different from Servicing Provider | Out | 0..1 | string |
Research Subject | Out | 0..* | ResearchSubject |
Clinical Trial | Out | 0..* | ResearchStudy |
Clinical Trial Organization | Out | 0..1 | Resource |
BillingProvider is Clinical Trial Organization | Out | 0..1 | boolean |
Is Research Subject | Out | 0..1 | boolean |
Part of clinical trial | Out | 0..1 | string |
Clinical Trial ID | Out | 0..* | string |
Previous genetic testing for condition | Out | 0..* | string |
Library Content
CQL Content |
    library GMTPInitialExpressions version '2.0.0-ballot'

    using USCore version '6.1.0-derived'
    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 version '2.0.0-ballot' called UC
    include USCoreElements version '2.0.0-ballot' 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
ELM JSON Content |
    Encoded data
Generated using version 0.5.3-cibuild of the sample-content-ig Liquid templates