eCQM QICore Content Implementation Guide
2024.0.0 - CI Build

eCQM QICore Content Implementation Guide, published by cqframework. This guide is not an authorized publication; it is the continuous build for version 2024.0.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/cqframework/ecqm-content-qicore-2024/ and changes regularly. See the Directory of published versions

Measure: Anticoagulation Therapy for Atrial Fibrillation/FlutterFHIR

Official URL: https://madie.cms.gov/Measure/CMS71FHIRSTKAnticoagAFFlutter Version: 0.3.001
Active as of 2024-12-18 Responsible: The Joint Commission Computable Name: CMS71FHIRSTKAnticoagAFFlutter
Other Identifiers: Short Name: CMS71FHIR (use: usual, ), UUID:bc80e4cf-d267-47bf-ad0d-4d37f8ae2328 (use: official, ), UUID:5c16a2fb-1882-49aa-802b-a0b73ed17c05 (use: official, ), Publisher: 71FHIR (use: official, )

Copyright/Legal: Measure specifications are in the Public Domain.

LOINC(R) copyright 2004-2024 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2024 International Health Terminology Standards Development Organisation. ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

Ischemic stroke patients with atrial fibrillation/flutter who are prescribed or continuing to take anticoagulation therapy at hospital discharge

UNKNOWN

Title: Anticoagulation Therapy for Atrial Fibrillation/FlutterFHIR
Id: CMS71FHIRSTKAnticoagAFFlutter
Version: 0.3.001
Url: Anticoagulation Therapy for Atrial Fibrillation/FlutterFHIR
Short Name Identifier:

CMS71FHIR

Version Independent Identifier:

urn:uuid:bc80e4cf-d267-47bf-ad0d-4d37f8ae2328

Version Specific Identifier:

urn:uuid:5c16a2fb-1882-49aa-802b-a0b73ed17c05

Publisher (CMS) Identifier:

71FHIR

Effective Period: 2026-01-01..2026-12-31
Publisher: The Joint Commission
Author: The Joint Commission
Description:

Ischemic stroke patients with atrial fibrillation/flutter who are prescribed or continuing to take anticoagulation therapy at hospital discharge

Purpose:

UNKNOWN

Copyright:

Measure specifications are in the Public Domain.

LOINC(R) copyright 2004-2024 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2024 International Health Terminology Standards Development Organisation. ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

Disclaimer:

These performance measures are not clinical guidelines, do not establish a standard of medical care, and have not been tested for all potential applications. The measures and specifications are provided without warranty.

Rationale:

Nonvalvular atrial fibrillation (NVAF) is a common arrhythmia and an important risk factor for stroke. It is one of several conditions and lifestyle factors that have been identified as risk factors for stroke. It has been estimated that over 2 million adults in the United States have NVAF (Kornej, 2020). While the median age of patients with atrial fibrillation is 75 years, the incidence increases with advancing age. For example, The Framingham Heart Study noted a dramatic increase in stroke risk associated with atrial fibrillation with advancing age, from 1.5% for those 50 to 59 years of age to 23.5% for those 80 to 89 years of age. Furthermore, a prior stroke or transient ischemic attack (TIA) are among a limited number of predictors of high stroke risk within the population of patients with atrial fibrillation. Therefore, much emphasis has been placed on identifying methods for preventing recurrent ischemic stroke as well as preventing first stroke. Prevention strategies focus on the modifiable risk factors such as hypertension, smoking, and atrial fibrillation. Analysis of five placebo-controlled clinical trials investigating the efficacy of warfarin in the primary prevention of thromboembolic stroke, found the relative risk of thromboembolic stroke was reduced by 68% for atrial fibrillation patients treated with warfarin. The administration of anticoagulation therapy, unless there are contraindications, is an established effective strategy in preventing recurrent stroke in high stroke risk-atrial fibrillation patients with TIA or prior stroke.

Clinical recommendation statement:

The administration of anticoagulation therapy, unless there are contraindications, is an established effective strategy in preventing recurrent stroke in high stroke risk atrial fibrillation patients with TIA or prior stroke

Guidance (Usage): The "Nonelective Inpatient Encounter" value set intends to capture all non-scheduled hospitalizations. This value set is a subset of the "Inpatient Encounter" value set, excluding concepts that specifically refer to elective hospital admissions. Non-elective Inpatient Encounters include emergency, urgent, and unplanned admissions. The "Medication, Discharge" datatype refers to the discharge medication list and is intended to express medications ordered for post-discharge use. The denominator population includes patients with inpatient hospitalizations and patients from Acute Hospital Care at Home programs, who are treated and billed as inpatients but receive care in their home. This eCQM is an episode-based measure. An episode is defined as each inpatient hospitalization or encounter that ends during the measurement period. This FHIR-based measure has been derived from the QDM-based measure: CMS71v15. Please refer to the HL7 QI-Core Implementation Guide (https://hl7.org/fhir/us/qicore/STU4.1.1/) for more information on QI-Core and mapping recommendations from QDM to QI-Core 4.1.1 (https://hl7.org/fhir/us/qicore/STU4.1.1/qdm-to-qicore.html).
Population Criteria:
64f0d91d56d636294b157d97
Initial Population: Inpatient hospitalizations (non-elective admissions) for patients age 18 and older, discharged from inpatient care with a principal diagnosis of ischemic stroke, that ends during the measurement period
Denominator: Inpatient hospitalizations for patients with a principal diagnosis of ischemic stroke, and a history of atrial ablation, or current or history of atrial fibrillation/flutter
Denominator Exclusion: - Inpatient hospitalizations for patients admitted for elective carotid intervention. This exclusion is implicitly modeled by only including non-elective hospitalizations. - Inpatient hospitalizations for patients discharged to another hospital - Inpatient hospitalizations for patients who left against medical advice - Inpatient hospitalizations for patients who expired - Inpatient hospitalizations for patients discharged to home for hospice care - Inpatient hospitalizations for patients discharged to a health care facility for hospice care - Inpatient hospitalizations for patients with comfort measures documented
Numerator: Inpatient hospitalizations for patients prescribed or continuing to take anticoagulation therapy at hospital discharge
Denominator Exception: Inpatient hospitalizations for patients with a documented reason for not prescribing anticoagulation therapy at discharge
Supplemental Data Elements:

SDE Ethnicity

SDE Payer

SDE Race

SDE Sex

Supplemental Data Guidance : For every patient evaluated by this measure also identify payer, race, ethnicity and sex; SDE Ethnicity-Patient's Ethnicity: Hispanic or Latino Not Hispanic or Latino SDE Payer-Patient's Payer: Categories of types of health care payer entities as defined by the US Public Health Data Consortium SOP code system SDE Race-Patient's Race: Native Hawaiian or Other Pacific Islander Asian American Indian or Alaska Native Other Race White Black or African American SDE Sex-Patient's Sex: Gender identity restricted to only Male and Female used in administrative situations requiring a restriction to these two categories.
Libraries:
CMS71FHIRSTKAnticoagAFFlutter
Terminology and Other Dependencies:
  • Library/SupplementalDataElements|3.5.000
  • Library/TJCOverall|8.15.000
  • Library/FHIRHelpers|4.4.000
  • Library/CQMCommon|2.2.000
  • Library/QICoreCommon|2.1.000
  • AdministrativeGender
  • Diagnosis Role
  • ConditionVerificationStatus
  • MedicationRequest Category Codes
  • Non-Elective Inpatient Encounter
  • Ischemic Stroke
  • Atrial Ablation
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.76
  • Atrial Fibrillation/Flutter
  • Anticoagulant Therapy
  • Payer
  • Discharge To Acute Care Facility
  • Left Against Medical Advice
  • Patient Expired
  • Discharged to Home for Hospice Care
  • Discharged to Health Care Facility for Hospice Care
  • Comfort Measures
  • Observation Services
  • Emergency Department Visit
  • Medical Reason
  • Patient Refusal
  • Parameters:
    name use min max type
    Measurement Period In 0 1 Period
    SDE Sex Out 0 1 Coding
    Numerator Out 0 * Resource
    Denominator Out 0 * Resource
    SDE Payer Out 0 * Resource
    Initial Population Out 0 * Resource
    SDE Ethnicity Out 0 1 Resource
    Denominator Exclusions Out 0 * Resource
    SDE Race Out 0 1 Resource
    Denominator Exceptions Out 0 * Resource
    DataRequirements:
    Resource Type Resource Elements Valueset Name Valueset
    Patient(QICorePatient) ethnicity race
    Encounter(QICoreEncounter) type period rank rank.value use condition condition.reference condition.reference.value status status.value hospitalization hospitalization.dischargeDisposition Nonelective Inpatient Encounter Non-Elective Inpatient Encounter
    Encounter(QICoreEncounter) type period rank rank.value use condition condition.reference condition.reference.value status status.value hospitalization hospitalization.dischargeDisposition Nonelective Inpatient Encounter Non-Elective Inpatient Encounter
    Encounter(QICoreEncounter) type status status.value period rank rank.value use condition condition.reference condition.reference.value hospitalization hospitalization.dischargeDisposition Observation Services Observation Services
    Encounter(QICoreEncounter) type status status.value period rank rank.value use condition condition.reference condition.reference.value hospitalization hospitalization.dischargeDisposition Emergency Department Visit Emergency Department Visit
    Encounter(QICoreEncounter) type period rank rank.value use condition condition.reference condition.reference.value status status.value hospitalization hospitalization.dischargeDisposition Nonelective Inpatient Encounter Non-Elective Inpatient Encounter
    Condition(QICoreCondition) code verificationStatus onset History of Atrial Ablation http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.76
    Condition(QICoreCondition) id id.value code
    Condition(QICoreCondition) code verificationStatus onset Atrial Fibrillation or Flutter Atrial Fibrillation/Flutter
    Procedure(QICoreProcedure) code status status.value performed Atrial Ablation Atrial Ablation
    Procedure(QICoreProcedure) code status status.value Comfort Measures Comfort Measures
    Observation(QICoreObservation) code status status.value effective History of Atrial Ablation http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1110.76
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value authoredOn authoredOn.value Anticoagulant Therapy Anticoagulant Therapy
    Coverage(QICoreCoverage) type period Payer Type Payer
    ServiceRequest(QICoreServiceRequest) code status status.value intent intent.value doNotPerform doNotPerform.value Comfort Measures Comfort Measures
    MedicationRequest(QICoreMedicationNotRequested) medication reasonCode intent intent.value authoredOn authoredOn.value Anticoagulant Therapy Anticoagulant Therapy
    Direct Reference Codes:
    display code system
    Male M http://hl7.org/fhir/administrative-gender
    Female F http://hl7.org/fhir/administrative-gender
    Billing billing http://terminology.hl7.org/CodeSystem/diagnosis-role
    Confirmed confirmed http://terminology.hl7.org/CodeSystem/condition-ver-status
    Community community http://terminology.hl7.org/CodeSystem/medicationrequest-category
    Discharge discharge http://terminology.hl7.org/CodeSystem/medicationrequest-category
    Logic Definitions:
    Group Scoring Population Criteria Expression
    64f0d91d56d636294b157d97 Group scoring: proportion
    Type:

    Process

    Rate Aggregation: None
    Improvement Notation:

    Increased score indicates improvement

    Initial Population
    define "Initial Population":
      TJC."Ischemic Stroke Encounter"
    Denominator
    define "Denominator":
      "Encounter With A History Of Atrial Ablation"
        union "Encounter With Prior Or Present Diagnosis Of Atrial Fibrillation Or Flutter"
    Denominator Exclusion
    define "Denominator Exclusions":
      ( "Denominator" Encounter
          where Encounter.status = 'finished'
            and ( Encounter.hospitalization.dischargeDisposition in "Discharge To Acute Care Facility"
                or Encounter.hospitalization.dischargeDisposition in "Left Against Medical Advice"
                or Encounter.hospitalization.dischargeDisposition in "Patient Expired"
                or Encounter.hospitalization.dischargeDisposition in "Discharged to Home for Hospice Care"
                or Encounter.hospitalization.dischargeDisposition in "Discharged to Health Care Facility for Hospice Care"
            )
      )
        union "Encounter With Comfort Measures During Hospitalization For Patients With Documented Atrial Fibrillation Or Flutter"
    Numerator
    define "Numerator":
      "Denominator" Encounter
        with ["MedicationRequest": medication in "Anticoagulant Therapy"] DischargeAnticoagulant
          such that ( DischargeAnticoagulant.isCommunity ( )
              or DischargeAnticoagulant.isDischarge ( )
          )
            and DischargeAnticoagulant.status in { 'active', 'completed' }
            and DischargeAnticoagulant.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
            and DischargeAnticoagulant.authoredOn during Encounter.period
    Denominator Exception
    //BONNIEMAT-1617-Since there is an anticipated resolution for STU 5 for Medication.Discharge which leaves one blockers on coverage, will leave the assertion logic as is and update the test cases for coverage.
    
    
    define "Denominator Exceptions":
      "Denominator" Encounter
        with "Documented Reason For Not Giving Anticoagulant At Discharge" NoDischargeAnticoagulant
          such that NoDischargeAnticoagulant.authoredOn during Encounter.period
    Library Name Name
    SupplementalDataElements SDE Sex
    define "SDE Sex":
      case
        when Patient.gender = 'male' then "M"
        when Patient.gender = 'female' then "F"
        else null
      end
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter SDE Sex
    define "SDE Sex":
      SDE."SDE Sex"
    Library Name Name
    TJCOverall Non Elective Inpatient Encounter With Age
    define "Non Elective Inpatient Encounter With Age":
      ["Encounter": "Nonelective Inpatient Encounter"] NonElectiveEncounter
            where AgeInYearsAt(date from start of NonElectiveEncounter.period ) >= 18
             and NonElectiveEncounter.period ends during day of "Measurement Period"
    Library Name Name
    TJCOverall Ischemic Stroke Encounter
    define "Ischemic Stroke Encounter":
      "Non Elective Inpatient Encounter With Age" NonElectiveEncounterWithAge
        where NonElectiveEncounterWithAge.principalDiagnosis().code in "Ischemic Stroke"
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Encounter With A History Of Atrial Ablation
    define "Encounter With A History Of Atrial Ablation":
      ( TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
          where exists ( ["Procedure": "Atrial Ablation"] AtrialAblationProcedure
              where AtrialAblationProcedure.status = 'completed'
                and AtrialAblationProcedure.performed.toInterval ( ) starts before start of IschemicStrokeEncounter.period
          )
      )
        union ( TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
            with ["Condition": "History of Atrial Ablation"] AtrialAblationDiagnosis
              such that AtrialAblationDiagnosis.verificationStatus is not null
                and AtrialAblationDiagnosis.verificationStatus ~ QICoreCommon."confirmed"
                and AtrialAblationDiagnosis.onset.toInterval ( ) starts before start of IschemicStrokeEncounter.period
        )
        union ( TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
            with ["Observation": "History of Atrial Ablation"] AtrialAblationObservation
              such that AtrialAblationObservation.status in { 'final', 'amended', 'corrected' }
                and AtrialAblationObservation.effective.earliest ( ) on or before end of IschemicStrokeEncounter.period
        )
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Encounter With Prior Or Present Diagnosis Of Atrial Fibrillation Or Flutter
    define "Encounter With Prior Or Present Diagnosis Of Atrial Fibrillation Or Flutter":
      ( TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
          with ["Condition": "Atrial Fibrillation or Flutter"] AtrialFibrillationFlutter
            such that AtrialFibrillationFlutter.verificationStatus is not null
              and AtrialFibrillationFlutter.verificationStatus ~ QICoreCommon."confirmed"
              and AtrialFibrillationFlutter.onset.toInterval ( ) starts on or before end of IschemicStrokeEncounter.period
      )
        union TJC."Ischemic Stroke Encounter" IschemicStrokeEncounter
          where exists ( ( IschemicStrokeEncounter.encounterDiagnosis ( ) ) EncounterDiagnosis
              where EncounterDiagnosis.code in "Atrial Fibrillation or Flutter"
          )
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Denominator
    define "Denominator":
      "Encounter With A History Of Atrial Ablation"
        union "Encounter With Prior Or Present Diagnosis Of Atrial Fibrillation Or Flutter"
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Numerator
    define "Numerator":
      "Denominator" Encounter
        with ["MedicationRequest": medication in "Anticoagulant Therapy"] DischargeAnticoagulant
          such that ( DischargeAnticoagulant.isCommunity ( )
              or DischargeAnticoagulant.isDischarge ( )
          )
            and DischargeAnticoagulant.status in { 'active', 'completed' }
            and DischargeAnticoagulant.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
            and DischargeAnticoagulant.authoredOn during Encounter.period
    Library Name Name
    SupplementalDataElements SDE Payer
    define "SDE Payer":
      [Coverage: type in "Payer Type"] Payer
        return {
          code: Payer.type,
          period: Payer.period
        }
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter SDE Payer
    define "SDE Payer":
      SDE."SDE Payer"
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Initial Population
    define "Initial Population":
      TJC."Ischemic Stroke Encounter"
    Library Name Name
    SupplementalDataElements SDE Ethnicity
    define "SDE Ethnicity":
      Patient.ethnicity E
        return Tuple {
          codes: { E.ombCategory } union E.detailed,
          display: E.text
        }
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter SDE Ethnicity
    define "SDE Ethnicity":
      SDE."SDE Ethnicity"
    Library Name Name
    TJCOverall Intervention Comfort Measures
    define "Intervention Comfort Measures":
      ( ["ServiceRequest": code in "Comfort Measures"] SR
        where SR.status in { 'active', 'completed', 'on-hold' }
          and SR.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
          and SR.doNotPerform is not true
      )  
      union ( ["Procedure": "Comfort Measures"] InterventionPerformed
            where InterventionPerformed.status in { 'completed', 'in-progress' }
      )
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Encounter With Comfort Measures During Hospitalization For Patients With Documented Atrial Fibrillation Or Flutter
    define "Encounter With Comfort Measures During Hospitalization For Patients With Documented Atrial Fibrillation Or Flutter":
      "Denominator" Encounter
        with TJC."Intervention Comfort Measures" ComfortMeasure
          such that Coalesce(start of ComfortMeasure.performed.toInterval(), ComfortMeasure.authoredOn) during Encounter.hospitalizationWithObservation ( )
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Denominator Exclusions
    define "Denominator Exclusions":
      ( "Denominator" Encounter
          where Encounter.status = 'finished'
            and ( Encounter.hospitalization.dischargeDisposition in "Discharge To Acute Care Facility"
                or Encounter.hospitalization.dischargeDisposition in "Left Against Medical Advice"
                or Encounter.hospitalization.dischargeDisposition in "Patient Expired"
                or Encounter.hospitalization.dischargeDisposition in "Discharged to Home for Hospice Care"
                or Encounter.hospitalization.dischargeDisposition in "Discharged to Health Care Facility for Hospice Care"
            )
      )
        union "Encounter With Comfort Measures During Hospitalization For Patients With Documented Atrial Fibrillation Or Flutter"
    Library Name Name
    SupplementalDataElements SDE Race
    define "SDE Race":
      Patient.race R
        return Tuple {
          codes: R.ombCategory union R.detailed,
          display: R.text
        }
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter SDE Race
    define "SDE Race":
      SDE."SDE Race"
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Documented Reason For Not Giving Anticoagulant At Discharge
    define "Documented Reason For Not Giving Anticoagulant At Discharge":
      ["MedicationNotRequested": medication in "Anticoagulant Therapy"] NoAnticoagulant
        where ( NoAnticoagulant.reasonCode in "Medical Reason For Not Providing Treatment"
            or NoAnticoagulant.reasonCode in "Patient Refusal"
        )
          and ( NoAnticoagulant.isCommunity ( )
              or NoAnticoagulant.isDischarge ( )
          )
          and NoAnticoagulant.intent in { 'order', 'original-order', 'reflex-order', 'filler-order', 'instance-order' }
    Library Name Name
    CMS71FHIRSTKAnticoagAFFlutter Denominator Exceptions
    //BONNIEMAT-1617-Since there is an anticipated resolution for STU 5 for Medication.Discharge which leaves one blockers on coverage, will leave the assertion logic as is and update the test cases for coverage.
    
    
    define "Denominator Exceptions":
      "Denominator" Encounter
        with "Documented Reason For Not Giving Anticoagulant At Discharge" NoDischargeAnticoagulant
          such that NoDischargeAnticoagulant.authoredOn during Encounter.period
    Library Name Name
    CQMCommon principalDiagnosis
    /*
    @description: Returns the condition that is specified as the principal diagnosis for the encounter
    */
    define fluent function principalDiagnosis(Encounter Encounter ):
    	singleton from ((Encounter.diagnosis D where D.rank = 1 and D.use ~ "Billing") PD
          return singleton from ([Condition] C where C.id = PD.condition.reference.getId())
    	)
    Library Name Name
    QICoreCommon getId
    /*
    @description: Returns the tail of the given uri (i.e. everything after the last slash in the URI).
    @comment: This function can be used to determine the logical id of a given resource. It can be used in
    a single-server environment to trace references. However, this function does not attempt to resolve
    or distinguish the base of the given url, and so cannot be used safely in multi-server environments.
    */
    define fluent function getId(uri String):
      Last(Split(uri, '/'))
    Library Name Name
    QICoreCommon earliest
    /*
    @description: Given an interval, return the starting point if the interval has a starting boundary specified,
    otherwise, return the ending point
    */
    define fluent function earliest(choice Choice<DateTime, Quantity, Interval<DateTime>, Interval<Quantity>> ):
      (choice.toInterval()) period
        return
          if (period."hasStart"()) then start of period
          else end of period
    Library Name Name
    CQMCommon encounterDiagnosis
    /*
    @description: Returns the Condition resources referenced by the diagnosis element of the Encounter
    */
    define fluent function encounterDiagnosis(Encounter Encounter ):
      Encounter.diagnosis D
        return singleton from ([Condition] C where C.id = D.condition.reference.getId())
    Library Name Name
    QICoreCommon isCommunity
    /*
    @description: Returns true if the given MedicationRequest has a category of Community
    */
    define fluent function isCommunity(medicationRequest MedicationRequest):
      exists (medicationRequest.category C
        where C ~ Community
      )
    Library Name Name
    FHIRHelpers ToConcept
    /*
    @description: Converts the given FHIR [CodeableConcept](https://hl7.org/fhir/datatypes.html#CodeableConcept) value to a CQL Concept.
    */
    define function ToConcept(concept FHIR.CodeableConcept):
        if concept is null then
            null
        else
            System.Concept {
                codes: concept.coding C return ToCode(C),
                display: concept.text.value
            }
    Library Name Name
    QICoreCommon isDischarge
    /*
    @description: Returns true if the given MedicationRequest has a category of Discharge
    */
    define fluent function isDischarge(medicationRequest MedicationRequest):
      exists (medicationRequest.category C
        where C ~ Discharge
      )
    Library Name Name
    FHIRHelpers ToString
    define function ToString(value uri): value.value
    Library Name Name
    FHIRHelpers ToCode
    /*
    @description: Converts the given FHIR [Coding](https://hl7.org/fhir/datatypes.html#Coding) value to a CQL Code.
    */
    define function ToCode(coding FHIR.Coding):
        if coding is null then
            null
        else
            System.Code {
              code: coding.code.value,
              system: coding.system.value,
              version: coding.version.value,
              display: coding.display.value
            }
    Library Name Name
    CQMCommon hospitalizationWithObservation
    /*
    @description: Hospitalization with Observation returns the total interval from the start of any immediately prior emergency department visit through the observation visit to the discharge of the given encounter
    */
    define fluent function hospitalizationWithObservation(TheEncounter Encounter ):
      TheEncounter Visit
      		let ObsVisit: Last([Encounter: "Observation Services"] LastObs
      				where LastObs.status = 'finished'
                and LastObs.period ends 1 hour or less on or before start of Visit.period
      				sort by end of period
      			),
      			VisitStart: Coalesce(start of ObsVisit.period, start of Visit.period),
      			EDVisit: Last([Encounter: "Emergency Department Visit"] LastED
      				where LastED.status = 'finished'
                and LastED.period ends 1 hour or less on or before VisitStart
      				sort by end of period
      			)
      		return Interval[Coalesce(start of EDVisit.period, VisitStart), end of Visit.period]