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/MBODAInitialExpressions Version: 0.1.0
Draft as of 2024-11-18 Computable Name: MBODAInitialExpressions
Id: MBODAInitialExpressions
Version: 0.1.0
Url: MBODAInitialExpressions
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
ErrorLevelstring01In
PatientResource01Out
Last Namestring01Out
Allergiesstring0*Out
HeightQuantity01Out
Height in [in_i]decimal01Out
WeightQuantity01Out
Weight in [lb_av]decimal01Out
BMIQuantity0*Out
Most Recent BSAQuantity01Out
Calculated BSA - MostellerQuantity01Out
BSAQuantity01Out
BSA in m2decimal01Out
Height in cmQuantity01Out
Weight in kgQuantity01Out
Calculated BSA - DuBois and DuBoisQuantity01Out
Diagnosis CodesCodeableConcept0*Out
Diagnosis Descriptionsstring0*Out
Most Recent Medication RequestResource01Out
Medication RequestedResource0*Out
Medication Namestring0*Out
Code of Requested DrugCodeableConcept0*Out
Medication Request Referencesstring01Out
Most Recent Medication Request dosageInstructionResource01Out
Most Recent Medication Request dosageInstruction.doseAndRateResource01Out
Medication DoseResource01Out
Medication RouteCodeableConcept01Out
Medication Frequency valueinteger01Out
Medication Frequency PeriodQuantity01Out
Medication Frequencystring01Out
Quantity or Number of requested VisitsQuantity01Out
Prior PrescriptionResource01Out
New therapyboolean01Out
New therapy codeCoding01Out
Initial date of therapydateTime0*Out
Medication Request PeriodPeriod01Out
Expected Therapy LengthQuantity01Out
Anticipated/actual date of servicedate01Out
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 ;;
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 ;;;
Observation http://hl7.org/fhir/StructureDefinition/bodyheight
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/Observation ; code filter:
path: code

system: http://loinc.org

code: 8277-6

display: Intensive care unit

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 ;;
MedicationRequest http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest
Medication http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication
Medication http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication ;;;;
Medication http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication ;;;;
Medication http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication ;;;;
AllergyIntolerance http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance
Observation http://hl7.org/fhir/StructureDefinition/bodyheight
Content: text/cql
library MBODAInitialExpressions 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
include USCoreElements version '0.1.0' called UCE

//CumulativeMedicationDuration was created as part of the US ECQM and CDC Opioid Guideline development 
//http://fhir.org/guides/cdc/opioid-mme-r4
include CumulativeMedicationDuration version '3.1.000' called CMD

codesystem "LOINC": 'http://loinc.org'
codesystem "Identifier Type": 'http://terminology.hl7.org/CodeSystem/v2-0203'
code "Body surface area": '8277-6' from "LOINC" display 'Intensive care unit'
code "Member Number": 'MB' from "Identifier Type"

context Patient

define "Last Name":
  UCE."Last Name"

// TODO: Error: Could not resolve data provider for package 'java.util'.
// define "First Name":
//   Patient.name.given.first()

define "Allergies":
  UCE."Active Confirmed Allergies and Intolerances".code.codes.display 

define "Height":
  convert(
    (
      (
        UCE."All Body Height Measurements"
      ).mostRecent()
    ).value
  ) to '[in_i]'

define "Height in [in_i]":
  "Height".value

define "Weight":
  convert(
    (
      (
        UCE."All Body Weight Measurements"
      ).mostRecent()
    ).value
  ) to '[lb_av]'

define "Weight in [lb_av]":
  "Weight".value

define "BMI":
  (UCE."All Body Mass Index Measurements").value

define "Most Recent BSA":
  UCE."Most Recent BSA"

define "BSA":
  Coalesce("Most Recent BSA", "Calculated BSA - Mosteller")

define "BSA in m2":
  "BSA".value

// Mosteller formula using lbs and inches
define "Calculated BSA - Mosteller":
  UCE.CalculateBSA('Mosteller', "Height", "Weight")
  //((("Weight"*"Height")/3131).value)^0.5

define "Height in cm":
  convert("Height") to 'cm'

define "Weight in kg":
  convert("Weight") to 'kg'

define "Calculated BSA - DuBois and DuBois":
  UCE.CalculateBSA('DuBois and DuBois', "Height", "Weight")

define "Diagnosis Codes":
  UCE."All Conditions" C
    return C.code

define "Diagnosis Descriptions":
  "Diagnosis Codes" ConceptItem
    return Combine(((ConceptItem.codes) C return C.display), '|')

define "Medication Requested":
  UCE."All Medications" M
    where EndsWith(("Most Recent Medication Request".medication as USCore.Reference).reference, M.id)

define "Medication Name":
  "Medication Requested" M
    return M.code.display

define "Code of Requested Drug":
  "Medication Requested" M
    return M.code

define "Most Recent Medication Request":
  UCE."Most Recent Medication Request"

define "Medication Request References":
  ("Most Recent Medication Request".medication as USCore.Reference).reference

define "Most Recent Medication Request dosageInstruction":
  // TODO: should this really be a singleton?
  singleton from "Most Recent Medication Request".dosageInstruction

define "Most Recent Medication Request dosageInstruction.doseAndRate":
  // TODO: should this really be a singleton?
  singleton from "Most Recent Medication Request dosageInstruction".doseAndRate

define "Medication Dose":
  "Most Recent Medication Request dosageInstruction.doseAndRate".dose

define "Medication Route":
  "Most Recent Medication Request dosageInstruction".route

define "Medication Frequency value":
  "Most Recent Medication Request dosageInstruction".timing.repeat.frequency

define "Medication Frequency Period":
  if (IsNull("Most Recent Medication Request dosageInstruction".timing.repeat.period)) then 
    null
  else
    System.Quantity {
      value: "Most Recent Medication Request dosageInstruction".timing.repeat.period,
      unit: "Most Recent Medication Request dosageInstruction".timing.repeat.periodUnit
    }

define "Medication Frequency": // '1x per 1d', '3x per 2wk', '1x per 1mo'
  ToString("Medication Frequency value") + 'x' +
  ' per ' + ToString("Medication Frequency Period".value) + 
  ' ' + "Medication Frequency Period".unit

define "Quantity or Number of requested Visits":
  "Most Recent Medication Request".dispenseRequest.quantity

define "Prior Prescription":
  "Most Recent Medication Request".priorPrescription

define "New therapy":
  IsNull("Prior Prescription")

define "New therapy code":
  if ("New therapy") then
    System.Code { code: 'NewMedication', display: 'New Medication' }
  else
    System.Code { code: 'ContinuedTherapy', display: 'Continuation of therapy' }

// MISSING: needs test data to validate
//Initial date of therapy does not return correct result if there have been more than 1 prior Prescriptions - logic needs to be adapted to that case
define "Initial date of therapy":
  if not "New therapy" then
    UCE."All Medication Requests" M
      where EndsWith(("Most Recent Medication Request".priorPrescription as USCore.Reference).reference, M.id)
      return M.authoredOn
  else 
    null

define "Medication Request Period":
  CMD."MedicationRequestPeriod"("Most Recent Medication Request")

define "Expected Therapy Length":
  convert(
    CMD.Quantity(days between start of "Medication Request Period" and end of "Medication Request Period", 'd')
  ) to 'd'

define "Anticipated/actual date of service":
  start of "Medication Request Period"

/*
//related Procedures - Procedure is not linked to medication request - not possible to find the related procedures
*/
Content: application/elm+xml
Encoded data (103792 characters)
Content: application/elm+json
Encoded data (182588 characters)