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: US Core Elements

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

A library of expressions, functions, and terminology declarations for use with FHIR in the US Realm.

Metadata
Title US Core Elements
Version 1.0.0
Jurisdiction United States of America
Topic FHIR
Topic CQL
Steward (Publisher) HL7 International / Clinical Decision Support
Description

A library of expressions, functions, and terminology declarations for use with FHIR in the US Realm.

Type Logic Library
Parameter Name: Patient
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Patient
Parameter Name: All Allergies and Intolerances
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Active Confirmed Allergies and Intolerances
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: AllergyIntolerance
Parameter Name: Common Allergies and Intolerances
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Active Confirmed Common Allergies and Intolerances
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: AllergyIntolerance
Parameter Name: No Known Allergies (Not Asked)
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: No Known Allergies (Confirmed)
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Conditions
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: All Problem List Items
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: Active Confirmed Problem List Items
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: All Encounter Diagnoses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: All Health Concerns
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Condition
Parameter Name: All Diagnostic Reports for Laboratory Results
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Diagnostic Report Notes
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Encounters
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Performed Encounters
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Immunizations
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Completed Immunizations
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Implantable Devices
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Laboratory Results
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Resulted Laboratory Results
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Medication Requests
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Most Recent Medication Request
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: MedicationRequest
Parameter Name: Active Medication Orders
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Medications
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pediatric BMI for Age
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pediatric BMI for Age All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pediatric Head Circumference Percentile
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pediatric Weight for Height
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pediatric Weight for Height All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Procedures
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Performed Procedures
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pulse Oximetry
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Pulse Oximetry All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Smoking Status
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Smoking Status All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Most Recent Smoking Status
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: All Vital Signs
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Vital Signs All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Respiratory Rate Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Respiratory Rate Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Heart Rate Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Heart Rate Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Temperature Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Temperature Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Height Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Height Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Head Circumference Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Head Circumference Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Weight Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Weight Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Mass Index Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Body Mass Index Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Blood Pressure Measurements
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: All Blood Pressure Measurements All Statuses
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: Systolic Blood Pressure
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: Diastolic Blood Pressure
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Resource
Parameter Name: Most Recent BSA
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Quantity
Parameter Name: All ServiceRequests
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: ServiceRequest
Parameter Name: Research Subject
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: ResearchSubject
Parameter Name: All Clinical Trials
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: ResearchStudy
Parameter Name: Clinical Trial Organization
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Data Requirement Type: AllergyIntolerance
Profile(s): US Core AllergyIntolerance Profile
Data Requirement Type: DiagnosticReport
Profile(s): US Core DiagnosticReport Profile for Laboratory Results Reporting
Data Requirement Type: DiagnosticReport
Profile(s): US Core DiagnosticReport Profile for Report and Note Exchange
Data Requirement Type: Encounter
Profile(s): US Core Encounter Profile
Data Requirement Type: Immunization
Profile(s): US Core Immunization Profile
Data Requirement Type: Device
Profile(s): US Core Implantable Device Profile
Data Requirement Type: Observation
Profile(s): US Core Laboratory Result Observation Profile
Data Requirement Type: MedicationRequest
Profile(s): US Core MedicationRequest Profile
Data Requirement Type: Medication
Profile(s): US Core Medication Profile
Data Requirement Type: Observation
Profile(s): US Core Pediatric BMI for Age Observation Profile
Data Requirement Type: Observation
Profile(s): US Core Pediatric Head Occipital Frontal Circumference Percentile Profile
Data Requirement Type: Observation
Profile(s): US Core Pediatric Weight for Height Observation Profile
Data Requirement Type: Procedure
Profile(s): US Core Procedure Profile
Data Requirement Type: Observation
Profile(s): US Core Pulse Oximetry Profile
Data Requirement Type: Observation
Profile(s): US Core Smoking Status Observation Profile
Data Requirement Type: Observation
Profile(s): US Core Vital Signs Profile
Data Requirement Type: Observation
Profile(s): US Core Respiratory Rate Profile
Data Requirement Type: Observation
Profile(s): US Core Heart Rate Profile
Data Requirement Type: Observation
Profile(s): US Core Body Temperature Profile
Data Requirement Type: Observation
Profile(s): US Core Body Height Profile
Data Requirement Type: Observation
Profile(s): US Core Head Circumference Profile
Data Requirement Type: Observation
Profile(s): US Core Body Weight Profile
Data Requirement Type: Observation
Profile(s): US Core BMI Profile
Data Requirement Type: Observation
Profile(s): US Core Blood Pressure Profile
Data Requirement Type: Observation
Profile(s): Observation
Code Filter(s):
Path: code
Code(s): LOINC 8277-6: Body surface area
Data Requirement Type: ServiceRequest
Profile(s): ServiceRequest
Data Requirement Type: ResearchSubject
Profile(s): ResearchSubject
Data Requirement Type: ResearchStudy
Profile(s): ResearchStudy
Data Requirement Type: Organization
Profile(s): US Core Organization Profile
Data Requirement Type: Condition
Profile(s): Condition
Data Requirement Type: Practitioner
Profile(s): US Core Practitioner Profile
Data Requirement Type: PractitionerRole
Profile(s): US Core PractitionerRole Profile
Library Content
CQL Content
library USCoreElements

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

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

codesystem "LOINC": 'http://loinc.org'
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'

valueset "Common allergy substances": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1186.8'

code "No known allergy (situation)": '716186003' from FHIRCommon.SNOMEDCT
code "Member Number": 'MB' from "Identifier Type"
code "Subscriber Number": 'SN' from "Identifier Type"
code "Body surface area": '8277-6' from "LOINC" display 'Body surface area'
code "Confirmed": 'confirmed' from "Verification Status"
code "Active": 'active' from "Condition Clinical"

context Patient

// Patient Patterns

define fluent function ageInDaysAt(patient Patient, asOf DateTime):
  CalculateAgeInDaysAt(Patient.birthDate, date from asOf)

define fluent function ageInDays(patient Patient):
  CalculateAgeInDaysAt(Patient.birthDate, Today())

define fluent function ageInMonthsAt(patient Patient, asOf DateTime):
  CalculateAgeInMonthsAt(Patient.birthDate, date from asOf)

define fluent function ageInMonths(patient Patient):
  CalculateAgeInMonthsAt(Patient.birthDate, Today())

define fluent function ageInYearsAt(patient Patient, asOf DateTime):
  CalculateAgeInYearsAt(Patient.birthDate, date from asOf)

define fluent function ageInYears(patient Patient):
  CalculateAgeInYearsAt(Patient.birthDate, Today())

define fluent function name(patient Patient):
  Coalesce(patient.officialName().first(), patient.usualName().first(), patient.firstNonOfficialNonUsualName())

define fluent function usualName(patient Patient):
  patient.name name
    where name.use ~ 'usual'
      and name.period is not null implies name.period includes Today()
    sort by start of period desc

define fluent function officialName(patient Patient):
  patient.name name
    where name.use ~ 'official'
      and name.period is not null implies name.period includes Today()
    sort by start of period desc

define fluent function firstNonOfficialNonUsualName(patient Patient):
  First(
    patient.name name
      where not(name.use ~ 'official') and not(name.use ~ 'usual')
        and name.period is not null implies name.period includes Today()
      sort by start of period desc
  )

define fluent function memberID(coverage FHIR.Coverage):
  coverage.identifier.where(type ~ "Member Number").single().value

define fluent function policyNumber(coverage FHIR.Coverage):
  singleton from (
    coverage.identifier I
      where I.type ~ "Subscriber Number"
  ).value

define fluent function medicalRecordNumber(patient Patient):
  patient.identifier.where(type ~ UC.MedicalRecordNumber).single().value

define fluent function name(practitioner Practitioner):
  Coalesce(practitioner.officialName().first(), practitioner.usualName().first(), practitioner.firstNonOfficialNonUsualName())

define fluent function usualName(practitioner Practitioner):
  practitioner.name name
    where name.use ~ 'usual'
      and name.period is not null implies name.period includes Today()
    sort by start of period desc

define fluent function officialName(practitioner Practitioner):
  practitioner.name name
    where name.use ~ 'official'
      and name.period is not null implies name.period includes Today()
    sort by start of period desc

define fluent function firstNonOfficialNonUsualName(practitioner Practitioner):
  First(
    practitioner.name name
      where not(name.use ~ 'official') and not(name.use ~ 'usual')
        and name.period is not null implies name.period includes Today()
      sort by start of period desc
  )

define fluent function mobile(patient Patient):
  First(
    patient.telecom telecom
      where telecom.use = 'mobile'
        and telecom.period is not null implies telecom.period includes Today()
      sort by start of period desc
  )

define fluent function mobile(practitioner Practitioner):
  First(
    practitioner.telecom telecom
      where telecom.use = 'mobile'
        and telecom.period is not null implies telecom.period includes Today()
      sort by start of period desc
  )

define fluent function work(organization Organization):
  First(
    organization.telecom telecom
      where telecom.use = 'work'
        and telecom.period is not null implies telecom.period includes Today()
      sort by start of period desc
  )

define fluent function name(practitioner Practitioner):
  Coalesce(practitioner.officialName().first(), practitioner.usualName().first(), practitioner.firstNonOfficialNonUsualName())

define fluent function firstName(name HumanName):
  name.given.first()

define fluent function middleNames(name HumanName):
  Combine(Skip(name.given, 1), ' ')

define fluent function lastName(name HumanName):
  name.family

define fluent function firstMiddleLast(name HumanName):
  Combine(name.given, ' ') + ' ' + name.family

define fluent function lastFirstMiddle(name HumanName):
  name.family + ', ' + Combine(name.given, ' ')

// Allergy/Intolerance

/*
@description: Returns all allergies and intolerances
@comment: This definition returns all allergies and intolerances conforming to the US Core 7.0.0
[AllergyIntolerance](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-allergyintolerance.html) profile.
Allergies and intolerances returned by this definition include records with any clinical status (including none)
and any verification status (including none).
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance
*/
define "All Allergies and Intolerances":
  [USCore."AllergyIntolerance"]

define "Active Confirmed Allergies and Intolerances":
  "All Allergies and Intolerances".active().confirmed()

define "Common Allergies and Intolerances":
  "All Allergies and Intolerances" A
    where A.code in "Common allergy substances"

define "Active Confirmed Common Allergies and Intolerances":
  "Common Allergies and Intolerances".active().confirmed()

// No Known Allergies (Not Asked)
define "No Known Allergies (Not Asked)":
  "All Allergies and Intolerances" A
    where A.code ~ "No known allergy (situation)"
      and A.isActive()
      and A.isUnconfirmed()

// No Known Allergies (Confirmed)
define "No Known Allergies (Confirmed)":
  "All Allergies and Intolerances" A
    where A.code ~ "No known allergy (situation)"
      and A.isActive()
      and A.isConfirmed()

// Condition

/*
@description: Returns all problem list items, encounter diagnoses, and health concerns
@comment: This definition returns all conditions of any category.
[Condition Encounter Diagnosis](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-condition-encounter-diagnosis.html)
[Condition Problems and Health Concerns](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-condition-problems-health-concerns.html)
Conditions returned by this definition include records with any clinical status (including none) and
any verification status (including none).
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
*/
define "All Conditions":
  [FHIR."Condition"]

define "All Problem List Items":
  "All Conditions" C
    where C.isProblemListItem()

define "Active Confirmed Problem List Items":
  "All Problem List Items".active().confirmed()

define "All Encounter Diagnoses":
  "All Conditions" C
    where C.isEncounterDiagnosis()

define "All Health Concerns":
  "All Conditions" C
    where C.isHealthConcern()

// Laboratory Diagnostic Report

/*
@comment: [Diagnostic Report for Laboratory Results](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-diagnosticreport-lab.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-lab
*/
define "All Diagnostic Reports for Laboratory Results":
  ["DiagnosticReportProfileLaboratoryReporting"]

// Diagnostic Report

/*
@comment: [Diagnostic Report Note](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-diagnosticreport-note.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-note
*/
define "All Diagnostic Report Notes":
  ["DiagnosticReportProfileNoteExchange"]

// Encounter

/*
@comment: [Encounter](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-encounter.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter 
*/
define "All Encounters":
  ["EncounterProfile"]

define "All Performed Encounters":
  "All Encounters" E
    where E.status = 'finished'  

// Immunization

/*
@comment: [Immunization](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-immunization.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization
*/
define "All Immunizations":
  ["ImmunizationProfile"] 

define "All Completed Immunizations":
  "All Immunizations" I
    where I.status = 'completed'

// Implantable Device

/*
@comment: [Implantable Device](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-implantable-device.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-implantable-device
*/
define "All Implantable Devices":
  ["ImplantableDeviceProfile"]

// Laboratory Result

/*
@description: Returns all laboratory results
@comment: [Laboratory Result](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-observation-lab.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab
*/
define "All Laboratory Results":
  ["LaboratoryResultObservationProfile"]

define "Resulted Laboratory Results":
  "All Laboratory Results" L
    where L.status in { 'preliminary', 'final', 'amended', 'corrected' }

// Medication Request

/*
@description: Returns all medication requests
@comment: [Medication Request](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-medicationrequest.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest
*/
define "Most Recent Medication Request":
  "All Medication Requests".mostRecent()

define "All Medication Requests":
  ["MedicationRequestProfile"]

define "Active Medication Orders":
  "All Medication Requests" M
    where M.status = 'active'
      and M.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }

define "All Medications":
  ["MedicationProfile"]

// Pediatric BMI for Age

/*
@comment: [Pediatric BMI for Age](https://hl7.org/fhir/us/core/STU7/StructureDefinition-pediatric-bmi-for-age.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/pediatric-bmi-for-age
*/
define "Pediatric BMI for Age":
  ((["PediatricBMIforAgeObservationProfile"]).resulted()) O 
    return O as "PediatricBMIforAgeObservationProfile"

define "Pediatric BMI for Age All Statuses":
  ["PediatricBMIforAgeObservationProfile"]

// Pediatric Head Circumference Percentile

/*
@comment: [Pediatric Head Circumference Percentile](https://hl7.org/fhir/us/core/STU7/StructureDefinition-head-occipital-frontal-circumference-percentile.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/head-occipital-frontal-circumference-percentile
*/
define "Pediatric Head Circumference Percentile":
  ((["PediatricHeadOccipitalFrontalCircumferencePercentileProfile"]).resulted()) O
    return O as "PediatricHeadOccipitalFrontalCircumferencePercentileProfile"

// Pediatric Weight for Height

/*
@comment: [Pediatric Weight for Height](https://hl7.org/fhir/us/core/STU7/StructureDefinition-pediatric-weight-for-height.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/pediatric-weight-for-height
*/
define "Pediatric Weight for Height":
  ((["PediatricWeightForHeightObservationProfile"]).resulted()) O 
    return O as "PediatricWeightForHeightObservationProfile"

define "Pediatric Weight for Height All Statuses":
  ["PediatricWeightForHeightObservationProfile"]

// Procedure

/*
@comment: [Procedure](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-procedure.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure
*/
define "All Procedures":
  ["ProcedureProfile"] P
    where P.status in { 'preparation', 'in-progress', 'on-hold', 'completed' }

define "All Performed Procedures":
  "All Procedures" P
    where P.status = 'completed'

// Pulse Oximetry

/*
@comment: [Pulse Oximetry](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-pulse-oximetry.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry
*/
define "Pulse Oximetry":
  ((["PulseOximetryProfile"]).resulted()) O 
    return O as "PulseOximetryProfile"

define "Pulse Oximetry All Statuses":
  ["PulseOximetryProfile"]

// Smoking Status

/*
@description: Returns all smoking status observations
@comment: This definition returns all smoking status observations conforming to the US Core 3.1.1
[Smoking Status](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-smokingstatus.html)
profile.
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus
*/
define "Smoking Status":
  ((["SmokingStatusProfile"]).resulted()) O 
    return O as "SmokingStatusProfile"

define "Smoking Status All Statuses":
  ["SmokingStatusProfile"]

/*
@description: Returns the most recent smoking status
@comment: This definition returns the most recent (by issued time) smoking status observation conforming to the
US Core [Smoking Status](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-smokingstatus.html)
profile.
*/
define "Most Recent Smoking Status":
  Last(
    "Smoking Status" SS
        where SS.status = 'final'
        sort by issued
  )

// Vital Signs

/*
@comment: [Vital Signs Panel](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-vital-signs.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-vital-signs
*/
define "All Vital Signs":
  ((["Vital Signs Profile"]).resulted()) O 
    return O as "Vital Signs Profile"

define "All Vital Signs All Statuses":
  ["Vital Signs Profile"]

// Respiratory Rate

/*
@comment: [Respiratory Rate](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-respiratory-rate.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-respiratory-rate
*/
define "All Respiratory Rate Measurements":
  ((["Respiratory Rate Profile"]).resulted()) O 
    return O as "Respiratory Rate Profile"

define "All Respiratory Rate Measurements All Statuses":
  ["Respiratory Rate Profile"]

// Heart Rate

/*
@comment: [Heart Rate](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-heart-rate.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-heart-rate
*/
define "All Heart Rate Measurements":
  ((["Heart Rate Profile"]).resulted()) O 
    return O as "Heart Rate Profile"

define "All Heart Rate Measurements All Statuses":
  ["Heart Rate Profile"]

// Body Temperature

/*
@comment: [Body Temperature](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-body-temperature.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-body-temperature
*/
define "All Body Temperature Measurements":
  ((["Body Temperature Profile"]).resulted()) O 
    return O as "Body Temperature Profile"

define "All Body Temperature Measurements All Statuses":
  ["Body Temperature Profile"]

// Body Height

/*
@comment: [Body Height](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-body-height.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-body-height
*/
define "All Body Height Measurements":
   ((["Body Height Profile"]).resulted()) O
     return O as "Body Height Profile"

define "All Body Height Measurements All Statuses":
  ["Body Height Profile"] 

// Head Circumference

/*
@comment: [Head Circumference](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-head-circumference.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-head-circumference
*/
define "All Head Circumference Measurements":
  ((["Head Circumference Profile"]).resulted()) O 
    return O as "Head Circumference Profile"

define "All Head Circumference Measurements All Statuses":
  ["Head Circumference Profile"]

// Body Weight

/*
@comment: [Body Weight](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-body-weight.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-body-weight
*/
define "All Body Weight Measurements":
  ((["Body Weight Profile"]).resulted()) O 
    return O as "Body Weight Profile"

define "All Body Weight Measurements All Statuses":
  ["Body Weight Profile"]

// Body Mass Index

/*
@comment: [Body Mass Index](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-bmi.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-bmi
*/
define "All Body Mass Index Measurements":
  ((["BMI Profile"]).resulted()) O 
    return O as "BMI Profile"

define "All Body Mass Index Measurements All Statuses":
  ["BMI Profile"]

// Blood Pressure

/*
@comment: [Blood Pressure](https://hl7.org/fhir/us/core/STU7/StructureDefinition-us-core-blood-pressure.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-blood-pressure
*/
define "All Blood Pressure Measurements":
  ((["Blood Pressure Profile"]).resulted()) O 
    return O as "Blood Pressure Profile"

define "All Blood Pressure Measurements All Statuses":
  ["Blood Pressure Profile"]

// Systolic Blood Pressure
define "Systolic Blood Pressure":
  "All Blood Pressure Measurements".mostRecent().systolic().value
  
// Diastolic Blood Pressure
define "Diastolic Blood Pressure":
  "All Blood Pressure Measurements".mostRecent().diastolic().value

define "Most Recent BSA":
  convert (([FHIR.Observation: "Body surface area"]).resulted().mostRecent() as FHIR.Observation).value to 'm2'

define function CalculateBSA(alg System.String, height System.Quantity, weight System.Quantity):
  System.Quantity { value: 
    // Mosteller formula using lbs and inches
    if (alg = 'Mosteller') then
      ((((convert(height) to '[in_i]') * (convert(weight) to '[lb_av]'))/3131).value)^0.5
    
    // DuBois and DuBois formula using cm and kg
    // NOTE: never to be used for newborn calculation
    else if (alg = 'DuBois and DuBois') then
      0.007184 * ((convert(height) to 'cm').value^0.725) * ((convert(weight) to 'kg').value^0.425)
    
    // No matching algorithm found
    else null,
    unit: 'm2'
  }

define "All ServiceRequests":
  [FHIR.ServiceRequest]

define function MostRecentSR(serviceRequests List<"FHIR.ServiceRequest">):
  Last(
    serviceRequests SR
      // sort by authoredOn
  )

define fluent function mostRecentSR(serviceRequests List<"FHIR.ServiceRequest">):
  Last(
    serviceRequests SR
      // sort by authoredOn
  )

define function RequestingProvider(serviceRequest FHIR.ServiceRequest):
  [PractitionerProfile] P
    where EndsWith(serviceRequest.requester.reference.value, P.id)

define function ServicingProvider(serviceRequest FHIR.ServiceRequest):
  [PractitionerProfile] P
    where EndsWith(First(serviceRequest.performer.reference.value), P.id)

define function BillingProvider(coverage FHIR.Coverage):
  singleton from([OrganizationProfile] O
    where EndsWith(First(coverage.payor.reference.value), O.id))

define function RelatedCondition(serviceRequest FHIR.ServiceRequest):
  [FHIR.Condition] C
    where EndsWith(First(serviceRequest.reasonReference.reference.value), C.id)

define "Research Subject":
  [FHIR.ResearchSubject] R
    where  EndsWith(R.individual.reference, Patient.id)

define "All Clinical Trials":
  [FHIR.ResearchStudy] 

define "Clinical Trial Organization":
  [OrganizationProfile] O
  
define function "GetServiceRequestReasonCondition"(serviceRequest ServiceRequest):
  [FHIR.Condition] C
    where EndsWith(First(serviceRequest.insurance.reference), C.id)
  return C

define function Requester(medicationRequest MedicationRequestProfile):
  singleton from (
    [USCore.PractitionerProfile] P
      where EndsWith(medicationRequest.requester.reference, P.id)
  )

define function RequesterRole(medicationRequest MedicationRequestProfile):
  singleton from (
    [USCore.PractitionerRoleProfile] R
      where EndsWith(R.practitioner.reference, Requester(medicationRequest).id)
  )

ELM XML Content
Encoded data (462996 characters)
ELM JSON Content
Encoded data (866440 characters)
Generated using version 0.4.9 of the sample-content-ig Liquid templates