Clinical Quality Framework Common FHIR Assets (US-Based)
0.1.0 - CI Build United States of America (USA)

Clinical Quality Framework Common FHIR Assets (US-Based), published by Clinical Quality Framework. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/cqf-us/ and changes regularly. See the Directory of published versions

Library:

Official URL: http://fhir.org/guides/cqf/us/common/Library/USCoreElements Version: 0.1.0
Draft as of 2024-11-18 Computable Name: USCoreElements
Id: USCoreElements
Version: 0.1.0
Url: USCoreElements
Status: draft
Type:

code: logic-library

Date: 2024-11-18 00:51:22+0000
Publisher: Clinical Quality Framework
Jurisdiction: 840
Related Artifacts:

Dependencies

Parameters:
NameTypeMinMaxIn/Out
PatientResource01Out
Usual NameResource01Out
Official NameResource01Out
First Occurrence of Non-Official, Non-Usual NameResource01Out
NameResource01Out
Last Namestring01Out
Name - First Middle(s) Laststring01Out
Name - Last, First Middle(s)string01Out
All Allergies and IntolerancesResource0*Out
Active Confirmed Allergies and IntolerancesResource0*Out
Common Allergies and IntolerancesResource0*Out
Active Confirmed Common Allergies and IntolerancesResource0*Out
No Known Allergies (Not Asked)Resource0*Out
No Known Allergies (Confirmed)Resource0*Out
All ConditionsResource0*Out
All Problem List ItemsResource0*Out
Active Confirmed Problem List ItemsResource0*Out
All Encounter DiagnosesResource0*Out
All Health ConcernsResource0*Out
All Diagnostic Reports for Laboratory ResultsResource0*Out
All Diagnostic Report NotesResource0*Out
All EncountersResource0*Out
All Performed EncountersResource0*Out
All ImmunizationsResource0*Out
All Completed ImmunizationsResource0*Out
All Implantable DevicesResource0*Out
All Laboratory ResultsResource0*Out
Resulted Laboratory ResultsResource0*Out
All Medication RequestsResource0*Out
Most Recent Medication RequestResource01Out
Active Medication OrdersResource0*Out
All MedicationsResource0*Out
Pediatric BMI for AgeResource0*Out
Pediatric BMI for Age All StatusesResource0*Out
Pediatric Weight for HeightResource0*Out
Pediatric Weight for Height All StatusesResource0*Out
All ProceduresResource0*Out
All Performed ProceduresResource0*Out
Pulse OximetryResource0*Out
Pulse Oximetry All StatusesResource0*Out
Smoking StatusResource0*Out
Smoking Status All StatusesResource0*Out
Most Recent Smoking StatusResource01Out
All Vital Signs PanelsResource0*Out
All Vital Signs Panels All StatusesResource0*Out
All Respiratory Rate MeasurementsResource0*Out
All Respiratory Rate Measurements All StatusesResource0*Out
All Heart Rate MeasurementsResource0*Out
All Heart Rate Measurements All StatusesResource0*Out
All Oxygen Saturation MeasurementsResource0*Out
All Oxygen Saturation Measurements All StatusesResource0*Out
All Body Temperature MeasurementsResource0*Out
All Body Temperature Measurements All StatusesResource0*Out
All Body Height MeasurementsResource0*Out
All Body Height Measurements All StatusesResource0*Out
All Head Circumference MeasurementsResource0*Out
All Head Circumference Measurements All StatusesResource0*Out
All Body Weight MeasurementsResource0*Out
All Body Weight Measurements All StatusesResource0*Out
All Body Mass Index MeasurementsResource0*Out
All Body Mass Index Measurements All StatusesResource0*Out
All Blood Pressure MeasurementsResource0*Out
All Blood Pressure Measurements All StatusesResource0*Out
Systolic Blood PressureResource0*Out
Diastolic Blood PressureResource0*Out
CoverageCoverage01Out
Member IDstring01Out
Medical Record Numberstring01Out
Most Recent BSAQuantity01Out
All ServiceRequestsServiceRequest0*Out
Most Recent ServiceRequestServiceRequest01Out
Requesting Provider PractitionerResource0*Out
Requesting ProviderResource0*Out
Servicing ProviderResource01Out
Test CoverageCoverage0*Out
Billing ProviderResource01Out
Test Related ConditionCondition0*Out
Research SubjectResearchSubject0*Out
All Clinical TrialsResearchStudy0*Out
Clinical Trial OrganizationResource0*Out
Policy NumberIdentifier01Out
RequesterResource01Out
RequesterRoleResource01Out
Data Requirements:
TypeProfileMSCode Filter
Patient http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient
Patient http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient ;;
Patient http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient ;;
Patient http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient ;;
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance ;
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance ;
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance ;
Condition http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
Condition http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
Condition http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
Condition http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
DiagnosticReport http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-lab
DiagnosticReport http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-note
Encounter http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter
Encounter http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter ;;
Immunization http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization
Immunization http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization ;;
Device http://hl7.org/fhir/us/core/StructureDefinition/us-core-implantable-device
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab ;;
MedicationRequest http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest
MedicationRequest http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest ;;;;
Medication http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-bmi-for-age
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-bmi-for-age
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-bmi-for-age
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-weight-for-height
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-weight-for-height
Observation http://hl7.org/fhir/us/core/StructureDefinition/pediatric-weight-for-height
Procedure http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure ;;
Procedure http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure ;;
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-pulse-oximetry
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-smokingstatus ;;
Observation http://hl7.org/fhir/StructureDefinition/vitalspanel
Observation http://hl7.org/fhir/StructureDefinition/vitalspanel
Observation http://hl7.org/fhir/StructureDefinition/vitalspanel
Observation http://hl7.org/fhir/StructureDefinition/resprate
Observation http://hl7.org/fhir/StructureDefinition/resprate
Observation http://hl7.org/fhir/StructureDefinition/resprate
Observation http://hl7.org/fhir/StructureDefinition/heartrate
Observation http://hl7.org/fhir/StructureDefinition/heartrate
Observation http://hl7.org/fhir/StructureDefinition/heartrate
Observation http://hl7.org/fhir/StructureDefinition/oxygensat
Observation http://hl7.org/fhir/StructureDefinition/oxygensat
Observation http://hl7.org/fhir/StructureDefinition/oxygensat
Observation http://hl7.org/fhir/StructureDefinition/bodytemp
Observation http://hl7.org/fhir/StructureDefinition/bodytemp
Observation http://hl7.org/fhir/StructureDefinition/bodytemp
Observation http://hl7.org/fhir/StructureDefinition/bodyheight
Observation http://hl7.org/fhir/StructureDefinition/bodyheight
Observation http://hl7.org/fhir/StructureDefinition/headcircum
Observation http://hl7.org/fhir/StructureDefinition/headcircum
Observation http://hl7.org/fhir/StructureDefinition/headcircum
Observation http://hl7.org/fhir/StructureDefinition/bodyweight
Observation http://hl7.org/fhir/StructureDefinition/bodyweight
Observation http://hl7.org/fhir/StructureDefinition/bodyweight
Observation http://hl7.org/fhir/StructureDefinition/bmi
Observation http://hl7.org/fhir/StructureDefinition/bmi
Observation http://hl7.org/fhir/StructureDefinition/bmi
Observation http://hl7.org/fhir/StructureDefinition/bp
Observation http://hl7.org/fhir/StructureDefinition/bp
Observation http://hl7.org/fhir/StructureDefinition/bp
Observation http://hl7.org/fhir/StructureDefinition/bp ;;
Observation http://hl7.org/fhir/StructureDefinition/bp ;;
Observation http://hl7.org/fhir/StructureDefinition/bp ;;
Observation http://hl7.org/fhir/StructureDefinition/bp ;;
Coverage http://hl7.org/fhir/StructureDefinition/Coverage ;;;;
Coverage http://hl7.org/fhir/StructureDefinition/Coverage ;;;;
Patient http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient ;
Observation http://hl7.org/fhir/StructureDefinition/Observation ; code filter:
path: code

system: http://loinc.org

code: 8277-6

display: Intensive care unit

ServiceRequest http://hl7.org/fhir/StructureDefinition/ServiceRequest
Practitioner http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitioner ;;
Organization http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization ;;
Coverage http://hl7.org/fhir/StructureDefinition/Coverage ;
Organization http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization ;;
Condition http://hl7.org/fhir/StructureDefinition/Condition ;
ResearchSubject http://hl7.org/fhir/StructureDefinition/ResearchSubject ;;
ResearchStudy http://hl7.org/fhir/StructureDefinition/ResearchStudy
Organization http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization
Condition http://hl7.org/fhir/StructureDefinition/Condition ;
Coverage http://hl7.org/fhir/StructureDefinition/Coverage ;;;;
Practitioner http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitioner ;;
PractitionerRole http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitionerrole ;;;
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance ;
Condition http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition
Observation http://hl7.org/fhir/StructureDefinition/bodyheight
Practitioner http://hl7.org/fhir/us/core/StructureDefinition/us-core-practitioner ;;
Content: text/cql
library USCoreElements version '0.1.0'

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

include FHIRHelpers version '4.1.0'
include USCoreCommon version '0.1.0' 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://hl7.org/fhir/us/core/ValueSet/us-core-allergy-substance'

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

context Patient

// Patient Patterns

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

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

define "Usual Name":
  First(
    Patient.name name
      where name.use ~ 'usual'
  )

define "Official Name":
  First(
    Patient.name name
      where name.use ~ 'official'
  )

define "First Occurrence of Non-Official, Non-Usual Name":
  First(
    Patient.name name
      where not(name.use ~ 'official') and not(name.use ~ 'usual')
  )

define "Name":
  Coalesce("Official Name", "Usual Name", "First Occurrence of Non-Official, Non-Usual Name")

// TODO: Correct this once USCore.HumanName.given works as expected
// define "First Name":
//   "Name".given[0]

// TODO: Correct this once USCore.HumanName.given works as expected
// define "Middle Names":
//   Combine(Skip("Name".given, 1), ' ')

define "Last Name":
  "Name".family

// TODO: Correct this once USCore.HumanName.given works as expected
define "Name - First Middle(s) Last":
  //Combine("Name".given, ' ') + ' ' + "Name".family
  "Name".family

// TODO: Correct this once USCore.HumanName.given works as expected
define "Name - Last, First Middle(s)":
  //"Name".family + ', ' + Combine("Name".given, ' ')
  "Name".family



// Allergy/Intolerance

/*
@description: Returns all allergies and intolerances
@comment: This definition returns all allergies and intolerances conforming to the US Core 3.1.1
[AllergyIntolerance](https://hl7.org/fhir/us/core/STU3.1.1/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".allergyActive().allergyConfirmed()

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".allergyActive().allergyConfirmed()

// 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.isAllergyActive()
      and A.isAllergyUnconfirmed()

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

// Condition

/*
@description: Returns all problem list items, encounter diagnoses, and health concerns
@comment: This definition returns all conditions of any category conforming to the US Core 3.1.1
[Condition](https://hl7.org/fhir/us/core/STU3.1.1/StructureDefinition-us-core-condition.html) profile.
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":
  [USCore."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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/StructureDefinition-us-core-medicationrequest.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest
*/
define "Most Recent Medication Request":
  UC.MostRecentMR("All Medication Requests")

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/STU3.1.1/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/STU3.1.1/StructureDefinition-head-occipital-frontal-circumference-percentile.html)
@profile: http://hl7.org/fhir/us/core/StructureDefinition/head-occipital-frontal-circumference-percentile
*/
//define "All Pediatric Head Circumference Percentile Measurements":
  //TODO - profile not in modelinfo
  //UsCorePediatricHeadOccipitalFrontalCircumferencePercentileProfile


// Pediatric Weight for Height

/*
@comment: [Pediatric Weight for Height](https://hl7.org/fhir/us/core/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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/STU3.1.1/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 3.1.1 [Smoking Status](https://hl7.org/fhir/us/core/STU3.1.1/StructureDefinition-us-core-smokingstatus.html)
profile.
*/
define "Most Recent Smoking Status":
  Last(
    "Smoking Status" SS
        where SS.status = 'final'
        sort by issued
  )

// Vital Signs Panel

/*
@comment: [Vital Signs Panel](http://hl7.org/fhir/R4/vitalspanel.html)
@profile: http://hl7.org/fhir/StructureDefinition/vitalspanel
*/
define "All Vital Signs Panels":
  ((["observation-vitalspanel"]).resulted()) O 
    return O as "observation-vitalspanel"

define "All Vital Signs Panels All Statuses":
  ["observation-vitalspanel"]

// Respiratory Rate

/*
@comment: [Respiratory Rate](http://hl7.org/fhir/R4/resprate.html)
@profile: http://hl7.org/fhir/StructureDefinition/resprate
*/
define "All Respiratory Rate Measurements":
  ((["observation-resprate"]).resulted()) O 
    return O as "observation-resprate"

define "All Respiratory Rate Measurements All Statuses":
  ["observation-resprate"]

// Heart Rate

/*
@comment: [Heart Rate](http://hl7.org/fhir/R4/heartrate.html)
@profile:http://hl7.org/fhir/StructureDefinition/heartrate
*/
define "All Heart Rate Measurements":
  ((["observation-heartrate"]).resulted()) O 
    return O as "observation-heartrate"

define "All Heart Rate Measurements All Statuses":
  ["observation-heartrate"]

// Oxygen Saturation

/*
@comment: [Oxygen Saturation](http://hl7.org/fhir/R4/oxygensat.html)
@profile: http://hl7.org/fhir/StructureDefinition/oxygensat
*/
define "All Oxygen Saturation Measurements":
  ((["observation-oxygensat"]).resulted()) O 
    return O as "observation-oxygensat"

define "All Oxygen Saturation Measurements All Statuses":
  ["observation-oxygensat"]

// Body Temperature

/*
@comment: [Body Temperature](http://hl7.org/fhir/R4/bodytemp.html)
@profile: http://hl7.org/fhir/StructureDefinition/bodytemp
*/
define "All Body Temperature Measurements":
  ((["observation-bodytemp"]).resulted()) O 
    return O as "observation-bodytemp"

define "All Body Temperature Measurements All Statuses":
  ["observation-bodytemp"]

// Body Height

/*
@comment: [Body Height](http://hl7.org/fhir/R4/bodyheight.html)
@profile: http://hl7.org/fhir/StructureDefinition/bodyheight
*/
define "All Body Height Measurements":
   (["observation-bodyheight"]).resulted()

/*define "All Body Height Measurements":
   ((["observation-bodyheight"]).resulted()) O 
     return O as "observation-bodyheight" */
// bug req: "observation-bodyheight" does not work in list of choices in USCoreCommons when all others do.

define "All Body Height Measurements All Statuses":
  ["observation-bodyheight"] 

// Head Circumference

/*
@comment: [Head Circumference](http://hl7.org/fhir/R4/headcircum.html)
@profile: http://hl7.org/fhir/StructureDefinition/headcircum
*/
define "All Head Circumference Measurements":
  ((["observation-headcircum"]).resulted()) O 
    return O as "observation-headcircum"

define "All Head Circumference Measurements All Statuses":
  ["observation-headcircum"]

// Body Weight

/*
@comment: [Body Weight](http://hl7.org/fhir/R4/bodyweight.html)
@profile: http://hl7.org/fhir/StructureDefinition/bodyweight
*/
define "All Body Weight Measurements":
  ((["observation-bodyweight"]).resulted()) O 
    return O as "observation-bodyweight"

define "All Body Weight Measurements All Statuses":
  ["observation-bodyweight"]

// Body Mass Index

/*
@comment: [Body Mass Index](http://hl7.org/fhir/R4/bmi.html)
@profile: http://hl7.org/fhir/StructureDefinition/bmi
*/
define "All Body Mass Index Measurements":
  ((["observation-bmi"]).resulted()) O 
    return O as "observation-bmi"

define "All Body Mass Index Measurements All Statuses":
  ["observation-bmi"]

// Blood Pressure

/*
@comment: [Blood Pressure](http://hl7.org/fhir/R4/bp.html)
@profile: http://hl7.org/fhir/StructureDefinition/bp
*/
define "All Blood Pressure Measurements":
  ((["observation-bp"]).resulted()) O 
    return O as "observation-bp"

define "All Blood Pressure Measurements All Statuses":
  ["observation-bp"]

// Systolic Blood Pressure
define "Systolic Blood Pressure":
  "All Blood Pressure Measurements".SystolicBP.value
  
// Diastolic Blood Pressure
define "Diastolic Blood Pressure":
  "All Blood Pressure Measurements".DiastolicBP.value

/* MBODA InitialExpressions */

// TODO: Need to address how to identify which coverage is in use
define "Coverage":
  First(
    [FHIR.Coverage] C
      where EndsWith(C.beneficiary.reference, Patient.id)
        and C.period includes Today()
      sort by Coalesce(period.end, period.start) desc
  )

define "Member ID":
  Coverage.identifier.where(type ~ "Member Number").single().value

define "Medical Record Number":
  Patient.identifier.where(type ~ UC.MedicalRecordNumber).single().value

define "Most Recent BSA":
  convert ([FHIR.Observation: "Body surface area"]).resulted().mostRecent().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 "Most Recent ServiceRequest":
  UC.MostRecentSR("All ServiceRequests")

define "Requesting Provider Practitioner"://assuming the requester is a practitioner
  [PractitionerProfile] P
    where EndsWith("Most Recent ServiceRequest".requester.reference.value, P.id)
/*
define "Requesting Provider Organization":
  [OrganizationProfile] O
    where EndsWith("Most Recent ServiceRequest".requester.reference.value, O.id)
*/

define "Requesting Provider":
  "Requesting Provider Practitioner"

define "Servicing Provider"://assuming the servicing provider is a lab - (molecular/genetic testing)
  singleton from ([OrganizationProfile] O
    where EndsWith(First("Most Recent ServiceRequest".performer.reference.value), O.id))

define "Test Coverage":
  [FHIR.Coverage] C
    with "Most Recent ServiceRequest" SR such that EndsWith(First(SR.insurance.reference), C.id)

define "Billing Provider":
  singleton from([OrganizationProfile] O
    where EndsWith(First("Test Coverage".payor.reference.value), O.id))

define "Test Related Condition":
  [FHIR.Condition] C
    where EndsWith(First("Most Recent ServiceRequest".reasonReference.reference.value), C.id)
  //.reasonReference changed to .reason in FHIR R5

define "Research Subject":
  [FHIR.ResearchSubject] R
    where  EndsWith(R.individual.reference, Patient.id)
    //ResearchSubject.individual is from FHIR version v4.0.1 and has been replaced by R.subject in FHIR R5

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

//bug req (does not work if full statement is in USCoreElements and referenced in GMTPInitialExpressions)
/*define "Clinical Trial":
  [FHIR.ResearchStudy] 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 Organization":
  [OrganizationProfile] O
  
define function "GetServiceRequestReasonCondition"(S ServiceRequest):
  [FHIR.Condition] C
  with  "Most Recent ServiceRequest" SR such that  EndsWith(First(SR.insurance.reference), C.id)
  return C

define "Policy Number":
  singleton from (
    Coverage.identifier I
      where I.type ~ "Subscriber Number"
  )

// May not be appropriate for the Elements library, this is based on identifying a medication request...
define "Requester":
  singleton from (
    [USCore.PractitionerProfile] P
      where EndsWith("Most Recent Medication Request".requester.reference, P.id)
  )

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

Content: application/elm+xml
Encoded data (341592 characters)
Content: application/elm+json
Encoded data (603844 characters)