Common CQL Artifacts for FHIR (US-Based)
1.0.0-ballot - STU 1 Ballot 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-ballot 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 Example Patient And Coverage Questionnaire (Experimental)

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

This library defines initial expressions for use in populating answers to questions in the Example Patient And Coverage questionnaire.

Title: Expression Library for the Example Patient And Coverage Questionnaire
Id: ExamplePatientAndCoverageInitialExpressions
Version: 1.0.0-ballot
Url: Expression Library for the Example Patient And Coverage Questionnaire
Status: draft
Experimental: true
Type:

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

code: logic-library

Date: 2025-09-10 20:00:05+0000
Publisher: HL7 International / Clinical Decision Support
Description:

This library defines initial expressions for use in populating answers to questions in the Example Patient And Coverage questionnaire.

Jurisdiction: US
Content: text/cql
library ExamplePatientAndCoverageInitialExpressions

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

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

codesystem "Identifier Type": 'http://terminology.hl7.org/CodeSystem/v2-0203'

code "Member Number": 'MB' from "Identifier Type"
code "Subscriber Number": 'SN' from "Identifier Type"

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

context Patient

define "Retrieve Service Request test parameter":
  // The VSCode extension doesn't support parameters
  // 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 { 
    'minimal-service-request-example'
  })

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

define "Retrieve Coverage test parameter":
  // The VSCode extension doesn't support parameters
  // 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 { 
    'minimal-coverage-example'
  })

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

define "Patient Name":
  UCE."Name - First Middle(s) Last"

define "Date of Birth":
  Patient.birthDate

define "Birth Sex":
  Patient.birthsex

define "Medical Record Number":
  UCE."Medical Record Number"

define "Phone Number":
  UC.Mobile(Patient.telecom).value

define "Email Address":
  UC.Email(Patient.telecom).value

define "Address":
  (singleton from Patient.address).line

define "City":
  Patient.address.city

define "State":
  Patient.address.state

define "Postal Code":
  Patient.address.postalCode

// Coverage
// define "Coverage":
//   First(clinical C where C is FHIR.Coverage)

// TODO: is there a need to check for coverage period and order? 
//       also, do we need to check that the payor organization is the same as the source of the prior auth form?
define "Member ID":
  UCE.MemberID("Member Coverage").value

// TODO: is there a need to check for coverage period and order?
//       also do we need to check that the payor organization is the same as the source of the prior auth form?
define "Policy Number":
  UCE.PolicyNumber("Member Coverage").value

define "Requesting Provider":
  UCE.RequestingProvider("Service Request")

define "Requesting Provider Name":
  "Requesting Provider".name.family

define "Requesting Provider Phone":
  UC.Work("Requesting Provider".telecom).value

define "Requesting Provider Address":
  (singleton from "Requesting Provider".address).line

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

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

define "Servicing Provider":
  UCE.ServicingProvider("Service Request")

define "Servicing Provider Name":
  "Servicing Provider".name

define "Servicing Provider Phone":
  UC.Work("Servicing Provider".telecom).value

define "Servicing Provider Address":
  (singleton from "Servicing Provider".address).text

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

define "Servicing Provider Fax":
  "Servicing Provider".telecom T
  where T.system = 'fax'
  return T.value
Content: application/elm+xml