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: Hospital Harm - Acute Kidney InjuryFHIR

Official URL: https://madie.cms.gov/Measure/CMS832HHAKIFHIR Version: 0.0.003
Active as of 2024-12-18 Responsible: Centers for Medicare & Medicaid Services (CMS) Computable Name: CMS832HHAKIFHIR
Other Identifiers: Short Name: CMS832FHIR (use: usual, ), UUID:ceeb6884-0dc4-4f4d-be48-01a6a998b8d2 (use: official, ), UUID:30ce82c3-6333-40f2-8d94-07b8830d15ff (use: official, ), Endorser: 3713e (use: official, ), Publisher: 832FHIR (use: official, )

Copyright/Legal: Limited proprietary coding is contained in the Measure specifications for user convenience. Users of proprietary code sets should obtain all necessary licenses from the owners of the code sets. American Institutes for Research(R), formerly IMPAQ International, disclaims all liability for use or accuracy of any third party codes contained in the specifications.

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

The measure assesses the number of inpatient hospitalizations for patients age 18 and older who have an acute kidney injury (stage 2 or greater) that occurred during the encounter. Acute kidney injury (AKI) stage 2 or greater is defined as a substantial increase in serum creatinine value, or by the initiation of kidney dialysis (continuous renal replacement therapy (CRRT), hemodialysis or peritoneal dialysis).

UNKNOWN

Title: Hospital Harm - Acute Kidney InjuryFHIR
Id: CMS832HHAKIFHIR
Version: 0.0.003
Url: Hospital Harm - Acute Kidney InjuryFHIR
Short Name Identifier:

CMS832FHIR

Version Independent Identifier:

urn:uuid:ceeb6884-0dc4-4f4d-be48-01a6a998b8d2

Version Specific Identifier:

urn:uuid:30ce82c3-6333-40f2-8d94-07b8830d15ff

Endorser (CMS Consensus Based Entity) Identifier:

3713e

Publisher (CMS) Identifier:

832FHIR

Effective Period: 2025-01-01..2025-12-31
Publisher: Centers for Medicare & Medicaid Services (CMS)
Author: American Institutes for Research (AIR)
Description:

The measure assesses the number of inpatient hospitalizations for patients age 18 and older who have an acute kidney injury (stage 2 or greater) that occurred during the encounter. Acute kidney injury (AKI) stage 2 or greater is defined as a substantial increase in serum creatinine value, or by the initiation of kidney dialysis (continuous renal replacement therapy (CRRT), hemodialysis or peritoneal dialysis).

Purpose:

UNKNOWN

Copyright:

Limited proprietary coding is contained in the Measure specifications for user convenience. Users of proprietary code sets should obtain all necessary licenses from the owners of the code sets. American Institutes for Research(R), formerly IMPAQ International, disclaims all liability for use or accuracy of any third party codes contained in the specifications.

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

Disclaimer:

This performance measure is not a clinical guideline and does not establish a standard of medical care, and has not been tested for all potential applications.

THE MEASURES AND SPECIFICATIONS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.

Due to technical limitations, registered trademarks are indicated by (R) or [R] and unregistered trademarks are indicated by (TM) or [TM].

Rationale:

This measure focuses on stage 2 or greater acute kidney injury as an outcome in the hospital inpatient setting. The incidence of AKI in general hospitalized patients is 10%–20%, and among critically ill patients, the incidence of AKI has been reported as high as 45–50%; in cardiac surgery patients it ranges from 30%-50% (Thongprayoon et al., 2020). Less severe acute kidney injury and acute kidney injury requiring dialysis affect approximately 2,000 to 3,000 and 200 to 300 per million population per year, respectively. Acute kidney injury may result in the need for dialysis, and is associated with an increased risk of mortality (Schwager et al., 2023; Wilson et al., 2013).

While not all instances of acute kidney injury are avoidable and may be due to natural progression of underlying illness or a complication of a necessary treatment such as chemotherapy, a proportion of acute kidney injury cases are preventable and treatable. The Kidney Disease: Improving Global Outcomes (KDIGO) guidelines suggest careful management of hemodynamic status, fluids, and vasoactive medications for the prevention of acute kidney injury (KDIGO, 2012). Several studies identified through systematic literature searches developed or evaluated the effectiveness of acute kidney injury electronic alert systems (Schwager et al., 2023; Selby et al., 2012; Ahmed et al., 2015; Porter et al., 2014; Wilson et al., 2014; Kirkendall et al., 2014; Cho et al., 2012). These studies used data elements for defining acute kidney injury that were already present and populated in the electronic health record (EHR). For acute kidney injury diagnosis, all except two were limited to using serum creatinine levels, suggesting that this is the most reliable and consistently available electronic data element for defining acute kidney injury.

Clinical recommendation statement:

Serum creatinine is an accepted proxy for acute kidney disease (Ostermann et al., 2020; KDIGO, 2012). It is cited by many guidelines for defining and monitoring acute kidney injury (Lameire et al., 2021; Ostermann et al., 2020; Lopes & Jorge, 2013; KDIGO, 2012). eGFR equations that incorporate creatinine and cystatin C but omit race are more accurate and lead to smaller differences between Black participants and non-Black participants than new equations without race with either creatinine or cystatin C alone (Inker et al., 2021). As a result, a new race-neutral eGFR equation that that measures serum creatinine or cystatin C incorporate age, sex, and race to estimate measured GFR has been developed and is recommended by the Task Force from the National Kidney Foundation and American Society of Nephrology (Inker et al., 2021; Diao et al., 2021; Delgado et al., 2021; Delgado et al., 2022). It was recommended by the Task Force to use within the measure a Chronic Kidney Disease Epidemiology Collaboration (CKD-EPI) creatinine equation refit without the race variable. This functionality has been available to all laboratories in the United States (Delgado et al., 2021; Delgado et al., 2022), and has acceptable performance characteristics and potential consequences that do not disproportionately affect any one group of individuals.

The KDIGO offers clinical practice guidelines for preventing and managing acute kidney injury:

FLUIDS 3.1.1: In the absence of hemorrhagic shock, we suggest using isotonic crystalloids rather than colloids (albumin or starches) as initial management for expansion of intravascular volume in patients at risk for acute kidney injury or with acute kidney injury. (Level 2, grade B)

VASOPRESSORS 3.1.2: We recommend the use of vasopressors in conjunction with fluids in patients with vasomotor shock with, or at risk for, acute kidney injury. (Level 1, grade C)

PROTOCOLIZED HEMODYNAMIC MANAGEMENT 3.1.3: We suggest using protocol-based management of hemodynamic and oxygenation parameters to prevent development or worsening of acute kidney injury in high-risk patients in the perioperative setting (2C) or in patients with septic shock. (Level 2, grade C)

In April 2019, KDIGO held a follow-up conference (Ostermann et al., 2020). The effectiveness of the 2012 KDIGO recommendations in preventing AKI was also noted to have been confirmed in small single-center randomized controlled trials (RCTs), such as the Prevention of AKI (PrevAKI) and the Biomarker Guided Intervention for Prevention of AKI (BigpAK) studies (Meersch et al., 2017; Göcze et al., 2018). In addition, results of RCTs have provided new data relevant to several facets of preventing and managing AKI, including early resuscitation, fluid therapy, prevention of contrast-associated AKI, and timing of acute renal replacement therapy (RRT) (Kellum et al., 2016; Nijssen et al., 2017; Self et al., 2018; Zarbock et al, 2016; Gaudry et al., 2016; Barbar et al., 2018).

Guidance (Usage): A patient characteristic of male or female sex is required as part of the initial population criteria, as sex is crucial to this measure. For example: - The eGFR estimating equation that is used to identify AKI is sex-specific; and - The reference ranges for the serum creatinine value are sex-specific, which matters because the serum creatinine must rise to a sex-specific abnormal value to be flagged as AKI. Exclude encounters that do not have at least two serum creatine values within 48 hours of arrival. Two values are needed within this timeframe to determine if the patient has AKI or moderate-to-severe renal dysfunction on arrival. For encounters for patients without harm, as identified by 2 times increase in serum creatinine, query for initiation of renal dialysis during hospitalization, defined by the start of dialysis occurring during the encounter. - If dialysis starts more than 48 hours after the start of the encounter, this meets numerator criteria. - If dialysis starts 48 hours or less after the start of the encounter, this meets denominator exclusion criteria. Encounters for patients with an increase in serum creatinine value of at least 0.3 mg/dL between the index serum creatinine and any subsequent serum creatinine taken within 48 hours of the encounter start are excluded. Due to the variability of decimal precision within programming languages and calculation tools, the value of >=0.3 mg/dL is expressed in the logic as >0.299 mg/dL. Note the measure is currently confined to using mg/dL as the unit of measurement for creatinine and mL/min as the unit of measurement for eGFR results. When reporting the first body temperature for risk adjustment, values from either Celsius or Fahrenheit readings are acceptable to report but Celsius readings are preferred. 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: CMS832v3. 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:
675a124146b6174510cff029
Initial Population: Inpatient hospitalizations that end during the measurement period for patients 18 years of age or older without an obstetrical or pregnancy related condition, with a length of stay of 48 hours or longer, and who had at least one serum creatinine value after 48 hours from the start of the hospitalization
Denominator: Equals Initial Population
Denominator Exclusion: Inpatient hospitalizations for patients with an increase in serum creatinine value of at least 0.3 mg/dL between the index serum creatinine and a subsequent serum creatinine taken within 48 hours of the encounter start. Inpatient hospitalizations for patients with the index eGFR value of <60 mL/min within 48 hours of the encounter start. Inpatient hospitalizations for patients who have less than two serum creatinine results within the first 48 hours of the encounter start. Inpatient hospitalizations for patients who have kidney dialysis (CRRT, hemodialysis or peritoneal dialysis) initiated 48 hours or less after the encounter start, and who do not have evidence of a 2 times increase in serum creatinine. Inpatient hospitalizations for patients with at least one specified diagnosis present on admission during the encounter that puts them at extremely high risk for AKI: - Hemolytic Uremic Syndrome (HUS) - Large Body Surface Area (BSA) Burns - Traumatic Avulsion of Kidney - Rapidly Progressive Nephritic Syndrome - Thrombotic Thrombocytopenic Purpura - Out of Hospital Cardiac Arrest (OHCA) Inpatient hospitalizations for patients who have at least one specified procedure that starts during the encounter that puts them at extremely high risk for AKI: - Extracorporeal membrane oxygenation (ECMO) - Intra-Aortic Balloon Pump - Resuscitative Endovascular Balloon Occlusion of the Aorta (REBOA) - Nephrectomy
Numerator: Inpatient hospitalizations for patients who develop AKI (stage 2 or greater) during the encounter, as evidenced by: A subsequent increase in serum creatinine value at least 2 times higher than the lowest serum creatinine value, and the increased value is greater than the highest sex-specific normal value for serum creatinine. Or: Kidney dialysis (CRRT, hemodialysis or peritoneal dialysis) initiated more than 48 hours after the start of the encounter. Evidence of a 2 times increase in serum creatinine is not required. Only one harm is counted per encounter.
Libraries:
CMS832HHAKIFHIR
Terminology and Other Dependencies:
  • Library/FHIRHelpers|4.4.000
  • Library/CQMCommon|2.2.000
  • Library/QICoreCommon|2.1.000
  • Observation Category Codes
  • Encounter Inpatient
  • Observation Services
  • Emergency Department Visit
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.21
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.33
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.199
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.12
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.19
  • Parameters:
    name use min max type
    Measurement Period In 0 1 Period
    Numerator Out 0 * Resource
    Denominator Out 0 * Resource
    Initial Population Out 0 * Resource
    Denominator Exclusion Out 0 * Resource
    DataRequirements:
    Resource Type Resource Elements Valueset Name Valueset
    Patient(QICorePatient)
    Encounter(QICoreEncounter) type status status.value period condition condition.reference condition.reference.value id id.value Observation Services Observation Services
    Encounter(QICoreEncounter) type status status.value period condition condition.reference condition.reference.value id id.value Emergency Department Visit Emergency Department Visit
    Encounter(QICoreEncounter) type period condition condition.reference condition.reference.value id id.value Encounter Inpatient Encounter Inpatient
    Observation(QICoreObservation) code effective value status status.value id id.value issued issued.value Creatinine Mass Per Volume http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.21
    Observation(QICoreObservation) code effective status status.value value id id.value Creatinine Mass Per Volume http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.21
    Observation(QICoreObservation) code effective status status.value value id id.value Creatinine Mass Per Volume http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.21
    Observation(QICoreObservation) code effective status status.value value id id.value Creatinine Mass Per Volume http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.21
    Condition(QICoreCondition) id id.value code
    Procedure(QICoreProcedure) code performed Hospital Based Dialysis Services http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.199
    Procedure(QICoreProcedure) code performed Hospital Based Dialysis Services http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.199
    Procedure(QICoreProcedure) code performed High Risk Procedures for AKI http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1248.19
    Direct Reference Codes:
    display code system
    Laboratory laboratory http://terminology.hl7.org/CodeSystem/observation-category
    Logic Definitions:
    Group Scoring Population Criteria Expression
    675a124146b6174510cff029 Group scoring: proportion
    Type:

    Outcome

    Rate Aggregation: None
    Improvement Notation:

    increase

    Initial Population
    define "Initial Population":
      "Encounter with Creatinine and without Obstetrical Conditions"
    Denominator
    define "Denominator":
      "Initial Population"
    Denominator Exclusion
    define "Denominator Exclusion":
      "Encounter with Less Than 2 Creatinine Results within 48 Hours of Arrival"
        union "Encounter with Index eGFR Less Than 60 within First 48 Hours"
        union "Encounter with 0.3 mg dL or More Increase in Creatinine"
        union "Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival without High Creatinine"
        union "Encounter with High Risk Diagnosis for AKI"
        union "Encounter with High Risk Procedures for AKI"
    Numerator
    define "Numerator":
      "Encounter with 2 Times Serum Creatinine Increase"
        union "Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival without High Creatinine"
    Library Name Name
    CMS832HHAKIFHIR Encounter with Age 18 and Length of Stay 48 Hours or More
    define "Encounter with Age 18 and Length of Stay 48 Hours or More":
      ["Encounter": "Encounter Inpatient"] InpatientEncounter
        where InpatientEncounter.period ends during day of "Measurement Period"
          and AgeInYearsAt(date from start of InpatientEncounter.period) >= 18
          and ( duration in hours of InpatientEncounter.hospitalizationWithObservation ( ) >= 48 )
    Library Name Name
    CMS832HHAKIFHIR Inpatient Encounter with Creatinine
    define "Inpatient Encounter with Creatinine":
      from
        "Encounter with Age 18 and Length of Stay 48 Hours or More" Encounter48Hours,
        ["Observation": "Creatinine Mass Per Volume"] CreatinineTest
        let HospitalizationPeriod: Encounter48Hours.hospitalizationWithObservation ( ),
        CreatinineTestStart: CreatinineTest.effective.earliest ( )
        where CreatinineTest.value is not null
          and CreatinineTestStart during Interval[start of HospitalizationPeriod + 48 hours, end of HospitalizationPeriod]
          and CreatinineTest.status in { 'final', 'amended', 'corrected' }
        return Encounter48Hours
    Library Name Name
    CMS832HHAKIFHIR Encounter with Creatinine and without Obstetrical Conditions
    define "Encounter with Creatinine and without Obstetrical Conditions":
      "Inpatient Encounter with Creatinine" EncounterWithCreatinine
        where not exists ( ( EncounterWithCreatinine.encounterDiagnosis ( ) ) EncounterDiagnosis
            where EncounterDiagnosis.code in "Obstetrics and VTE Obstetrics"
        )
    Library Name Name
    CMS832HHAKIFHIR Serum Creatinine Normal
    define "Serum Creatinine Normal":
      if ( Patient.gender = 'female' ) then 1.02 'mg/dL' 
        else if ( Patient.gender = 'male' ) then 1.18 'mg/dL' 
        else null
    Library Name Name
    CMS832HHAKIFHIR Qualifying Creatinine Lab Result by Time
    define "Qualifying Creatinine Lab Result by Time":
      from
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter,
        ["Observation": "Creatinine Mass Per Volume"] CreatinineTestByTime
        let CrEncId: QualifyingEncounter.id,
        CrHospPeriod: QualifyingEncounter.hospitalizationWithObservation ( ),
        CrLabId: CreatinineTestByTime.id,
        CrTime: CreatinineTestByTime.effective.earliest ( ),
        CrTimeIssued: CreatinineTestByTime.issued,
        CrResult: CreatinineTestByTime.value as Quantity,
        CrResultValue: CrResult.value,
        CrResultUnit: CrResult.unit
        where CrTime during CrHospPeriod
          and CreatinineTestByTime.isLaboratory ( )
          and CreatinineTestByTime.status in { 'final', 'amended', 'corrected' }
          and CrResultUnit = 'mg/dL'
          and CreatinineTestByTime.value is not null
          and CreatinineTestByTime.value as Quantity > 0 'mg/dL'
        return Tuple {
          CrEncInPtId: CrEncId,
          CrHospitalization: CrHospPeriod,
          CrLabObsId: CrLabId,
    //                    LabCategory: CreatinineTestByQuantity.isLaboratory(),
          
          CrLabObsCategory: if CreatinineTestByTime.isLaboratory ( ) then 'laboratory' 
            else CreatinineTestByTime.isLaboratory ( ),
          CrLabObsStatus: CreatinineTestByTime.status,
          CrLabResult: CrResult,
          CrLabResultUnit: CrResultUnit,
          CrLabResultValue: CrResultValue,
          CrLabTime: CrTime,
          CrLabTimeIssued: CrTimeIssued
        }
        sort by CrLabTime
    Library Name Name
    CMS832HHAKIFHIR Encounter with 1.5 Times Serum Creatinine Increase
    define "Encounter with 1.5 Times Serum Creatinine Increase":
      from
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter,
        ["Observation": "Creatinine Mass Per Volume"] HighCreatinineTest,
        ["Observation": "Creatinine Mass Per Volume"] LowCreatinineTest
        let LowCreatinineTestTime: LowCreatinineTest.effective.earliest ( ),
        HighCreatinineTestTime: HighCreatinineTest.effective.earliest ( ),
        HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation ( )
        where ( HighCreatinineTest.value > "Serum Creatinine Normal" )
          and LowCreatinineTest.status in { 'final', 'amended', 'corrected' }
          and HighCreatinineTest.status in { 'final', 'amended', 'corrected' }
          and HighCreatinineTest.value = "HighestSerumCreatinineResult"(QualifyingEncounter)
          and LowCreatinineTest.value = "LowestSerumCreatinineResult"(QualifyingEncounter)
          and "1.5IncreaseInCreatinine"(QualifyingEncounter) >= LowCreatinineTest.value
          and LowCreatinineTestTime 7 days or less before HighCreatinineTestTime
          and LowCreatinineTestTime during HospitalWithObservationPeriod
          and HighCreatinineTestTime during Interval[start of HospitalWithObservationPeriod + 48 hours, start of HospitalWithObservationPeriod + 30 days]
          and HighCreatinineTestTime during HospitalWithObservationPeriod
        return QualifyingEncounter
    Library Name Name
    CMS832HHAKIFHIR Encounter with 2 Times Serum Creatinine Increase
    /*
    define "Encounter with 1.5 Times Serum Creatinine Increase":
      from
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter,
        ["Observation": "Creatinine Mass Per Volume"] CreatinineTest
      let 
        LowestCreatinineTestWithin7DaysPrior: "LowestSerumCreatinineWithin7DaysPrior"(QualifyingEncounter, CreatinineTest),
        CreatinineTestTime: CreatinineTest.effective.earliest(),
        HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation()
      where 
        CreatinineTest.value >= LowestCreatinineTestWithin7DaysPrior * 1.5
        and CreatinineTest.value > "Serum Creatinine Normal"
        and CreatinineTestTime during Interval[start of HospitalWithObservationPeriod + 48 hours, start of HospitalWithObservationPeriod + 30 days]
      return QualifyingEncounter*/
    
    
    define "Encounter with 2 Times Serum Creatinine Increase":
      from
        "Encounter with 1.5 Times Serum Creatinine Increase" EncounterWithHighCreatinine,
        ["Observation": "Creatinine Mass Per Volume"] HighCreatinineTest,
        ["Observation": "Creatinine Mass Per Volume"] LowCreatinineTest
        let LowCreatinineTestTime: LowCreatinineTest.effective.earliest ( ),
        HighCreatinineTestTime: HighCreatinineTest.effective.earliest ( ),
        HospitalWithObservationPeriod: EncounterWithHighCreatinine.hospitalizationWithObservation ( )
        where ( HighCreatinineTest.value > "Serum Creatinine Normal" )
          and LowCreatinineTest.status in { 'final', 'amended', 'corrected' }
          and HighCreatinineTest.status in { 'final', 'amended', 'corrected' }
          and HighCreatinineTest.value = "HighestSerumCreatinineResult"(EncounterWithHighCreatinine)
          and LowCreatinineTest.value = "LowestSerumCreatinineResult"(EncounterWithHighCreatinine)
          and ( "2.0IncreaseInCreatinine"(EncounterWithHighCreatinine) as Quantity ) >= ( LowCreatinineTest.value as Quantity )
          and LowCreatinineTestTime 7 days or less before HighCreatinineTestTime
          and LowCreatinineTestTime during HospitalWithObservationPeriod
          and HighCreatinineTestTime during Interval[start of HospitalWithObservationPeriod + 48 hours, start of HospitalWithObservationPeriod + 30 days]
          and HighCreatinineTestTime during HospitalWithObservationPeriod
        return EncounterWithHighCreatinine
    Library Name Name
    CMS832HHAKIFHIR Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival
    define "Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival":
      from
        ["Procedure": "Hospital Based Dialysis Services"] Dialysis,
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        let HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation ( )
        where Dialysis.performed.toInterval ( ) starts during Interval[start of HospitalWithObservationPeriod + 48 hours, end of HospitalWithObservationPeriod]
          and Dialysis.performed.toInterval ( ) starts during HospitalWithObservationPeriod
        return QualifyingEncounter
    Library Name Name
    CMS832HHAKIFHIR Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival without High Creatinine
    define "Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival without High Creatinine":
      "Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival" EncounterWithDialysisAfter48Hours
        where not ( exists ( "Encounter with 2 Times Serum Creatinine Increase" EncounterWithHighCreatinine
              where ( EncounterWithHighCreatinine.period includes EncounterWithDialysisAfter48Hours.period )
          )
        )
    Library Name Name
    CMS832HHAKIFHIR Numerator
    define "Numerator":
      "Encounter with 2 Times Serum Creatinine Increase"
        union "Encounter with Kidney Dialysis Started More Than 48 Hours After Arrival without High Creatinine"
    Library Name Name
    CMS832HHAKIFHIR Initial Population
    define "Initial Population":
      "Encounter with Creatinine and without Obstetrical Conditions"
    Library Name Name
    CMS832HHAKIFHIR Denominator
    define "Denominator":
      "Initial Population"
    Library Name Name
    CMS832HHAKIFHIR Encounter with Less Than 2 Creatinine Results within 48 Hours of Arrival
    define "Encounter with Less Than 2 Creatinine Results within 48 Hours of Arrival":
      "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        where ( Count("CreatinineLabTestwithResultwithinFirst48Hours"(QualifyingEncounter)) < 2 )
    Library Name Name
    CMS832HHAKIFHIR Male Encounter with eGFR Less Than 60
    define "Male Encounter with eGFR Less Than 60":
      "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        where "MaleeGFR"(QualifyingEncounter) is not null
          and "MaleeGFR"(QualifyingEncounter) as Decimal < 60
    Library Name Name
    CMS832HHAKIFHIR Female Encounter with eGFR Less Than 60
    define "Female Encounter with eGFR Less Than 60":
      "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        where "FemaleeGFR"(QualifyingEncounter) is not null
          and "FemaleeGFR"(QualifyingEncounter) as Decimal < 60
    Library Name Name
    CMS832HHAKIFHIR Encounter with Index eGFR Less Than 60 within First 48 Hours
    define "Encounter with Index eGFR Less Than 60 within First 48 Hours":
      "Male Encounter with eGFR Less Than 60"
        union "Female Encounter with eGFR Less Than 60"
    Library Name Name
    CMS832HHAKIFHIR Increase of 0.3 or More Using Lowest Creatinine within 24 Hours
    define "Increase of 0.3 or More Using Lowest Creatinine within 24 Hours":
      from
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter,
        ["Observation": "Creatinine Mass Per Volume"] IndexCreatinineLabResult,
        ["Observation": "Creatinine Mass Per Volume"] SubsequentCreatinineLabResult
        let IndexCreatinineLabResultTime: IndexCreatinineLabResult.effective.earliest ( ),
        SubsequentCreatinineLabResultTime: SubsequentCreatinineLabResult.effective.earliest ( ),
        HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation ( )
        where IndexCreatinineLabResult.status in { 'final', 'amended', 'corrected' }
          and SubsequentCreatinineLabResult.status in { 'final', 'amended', 'corrected' }
          and ( ( SubsequentCreatinineLabResult.value as Quantity ) - ( IndexCreatinineLabResult.value as Quantity ) ) > 0.299 'mg/dL'
          and IndexCreatinineLabResult.value = "LowestSerumCreatinineResult"(QualifyingEncounter)
          and IndexCreatinineLabResultTime during Interval[SubsequentCreatinineLabResultTime - 48 hours, SubsequentCreatinineLabResultTime]
          and IndexCreatinineLabResultTime during HospitalWithObservationPeriod
          and IndexCreatinineLabResultTime during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 24 hours]
          and SubsequentCreatinineLabResultTime during HospitalWithObservationPeriod
          and SubsequentCreatinineLabResultTime during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 48 hours]
          and IndexCreatinineLabResult.id != SubsequentCreatinineLabResult.id
        return QualifyingEncounter
    Library Name Name
    CMS832HHAKIFHIR Increase of 0.3 or More Using First Creatinine within First 48 Hours
    define "Increase of 0.3 or More Using First Creatinine within First 48 Hours":
      from
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter,
        ["Observation": "Creatinine Mass Per Volume"] IndexCreatinineLabResult,
        ["Observation": "Creatinine Mass Per Volume"] SubsequentCreatinineLabResult
        let IndexCreatinineLabResultTime: IndexCreatinineLabResult.effective.earliest ( ),
        SubsequentCreatinineLabResultTime: SubsequentCreatinineLabResult.effective.earliest ( ),
        HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation ( )
        where IndexCreatinineLabResult.status in { 'final', 'amended', 'corrected' }
          and SubsequentCreatinineLabResult.status in { 'final', 'amended', 'corrected' }
          and ( ( SubsequentCreatinineLabResult.value as Quantity ) - ( IndexCreatinineLabResult.value as Quantity ) ) > 0.299 'mg/dL'
          and IndexCreatinineLabResult.value as Quantity = singleton from "EarliestSerumCreatinineResult"(QualifyingEncounter)
          and IndexCreatinineLabResultTime during Interval[SubsequentCreatinineLabResultTime - 48 hours, SubsequentCreatinineLabResultTime]
          and IndexCreatinineLabResultTime during HospitalWithObservationPeriod
          and SubsequentCreatinineLabResultTime during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 48 hours]
          and SubsequentCreatinineLabResultTime during HospitalWithObservationPeriod
          and IndexCreatinineLabResultTime during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 48 hours]
          and SubsequentCreatinineLabResultTime during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 48 hours]
          and IndexCreatinineLabResult.id != SubsequentCreatinineLabResult.id
        return QualifyingEncounter
    Library Name Name
    CMS832HHAKIFHIR Encounter with 0.3 mg dL or More Increase in Creatinine
    define "Encounter with 0.3 mg dL or More Increase in Creatinine":
      Coalesce("Increase of 0.3 or More Using Lowest Creatinine within 24 Hours", "Increase of 0.3 or More Using First Creatinine within First 48 Hours")
    Library Name Name
    CMS832HHAKIFHIR Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival
    define "Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival":
      from
        ["Procedure": "Hospital Based Dialysis Services"] Dialysis,
        "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        let HospitalWithObservationPeriod: QualifyingEncounter.hospitalizationWithObservation ( )
        where Dialysis.performed.toInterval ( ) starts during Interval[start of HospitalWithObservationPeriod, start of HospitalWithObservationPeriod + 48 hours]
          and Dialysis.performed.toInterval ( ) starts during HospitalWithObservationPeriod
        return QualifyingEncounter
    Library Name Name
    CMS832HHAKIFHIR Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival without High Creatinine
    define "Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival without High Creatinine":
      "Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival" EncounterWithKidneyDialysis48HoursOrAfter
        where not ( exists ( "Encounter with 2 Times Serum Creatinine Increase" EncounterWithHighCreatinine
              where ( EncounterWithHighCreatinine.period includes EncounterWithKidneyDialysis48HoursOrAfter.period )
          )
        )
    Library Name Name
    CMS832HHAKIFHIR Encounter with High Risk Diagnosis for AKI
    define "Encounter with High Risk Diagnosis for AKI":
      "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        where exists ( ( QualifyingEncounter.encounterDiagnosis ( ) ) EncounterDiagnosis
            where ( EncounterDiagnosis.code in "High Risk Diagnosis for AKI" )
        )
    Library Name Name
    CMS832HHAKIFHIR Encounter with High Risk Procedures for AKI
    define "Encounter with High Risk Procedures for AKI":
      "Encounter with Creatinine and without Obstetrical Conditions" QualifyingEncounter
        with ["Procedure": "High Risk Procedures for AKI"] HighRiskProcedures
          such that HighRiskProcedures.performed.toInterval ( ) starts during QualifyingEncounter.hospitalizationWithObservation ( )
    Library Name Name
    CMS832HHAKIFHIR Denominator Exclusion
    define "Denominator Exclusion":
      "Encounter with Less Than 2 Creatinine Results within 48 Hours of Arrival"
        union "Encounter with Index eGFR Less Than 60 within First 48 Hours"
        union "Encounter with 0.3 mg dL or More Increase in Creatinine"
        union "Encounter with Kidney Dialysis Started 48 Hours or Less After Arrival without High Creatinine"
        union "Encounter with High Risk Diagnosis for AKI"
        union "Encounter with High Risk Procedures for AKI"
    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]
    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 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
    CMS832HHAKIFHIR HighestSerumCreatinineResult
    define function "HighestSerumCreatinineResult"(QualifyingEncounter Encounter):
      ( Max((from
              "Qualifying Creatinine Lab Result by Time" LabTests
              let LabResult: LabTests.CrLabResult
              where LabTests.CrEncInPtId = QualifyingEncounter.id
          ).CrLabResult
        )
      )
    Library Name Name
    QICoreCommon isLaboratory
    /*
    @description: Returns true if the given observation is a laboratory observation
    */
    define fluent function isLaboratory(observation Observation):
      exists (observation.category C
        where C ~ "laboratory"
      )
    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
    CMS832HHAKIFHIR LowestSerumCreatinineResult
    define function "LowestSerumCreatinineResult"(QualifyingEncounter Encounter):
      ( Min((from
              "Qualifying Creatinine Lab Result by Time" LabTests
              let LabResult: LabTests.CrLabResult
              where LabTests.CrEncInPtId = QualifyingEncounter.id
          ).CrLabResult
        )
      )
    Library Name Name
    CMS832HHAKIFHIR 1.5IncreaseInCreatinine
    // following functions work with Cr result as Quantity (not decimal, but Quantity value is decimal)
    
    
    define function "1.5IncreaseInCreatinine"(QualifyingEncounter Encounter):
      "HighestSerumCreatinineResult"(QualifyingEncounter) / 1.5
    Library Name Name
    CMS832HHAKIFHIR 2.0IncreaseInCreatinine
    define function "2.0IncreaseInCreatinine"(QualifyingEncounter Encounter):
      "HighestSerumCreatinineResult"(QualifyingEncounter) / 2
    Library Name Name
    CMS832HHAKIFHIR CreatinineLabTestwithResultwithinFirst48Hours
    define function "CreatinineLabTestwithResultwithinFirst48Hours"(QualifyingEncounter Encounter):
      from
        ["Observation": "Creatinine Mass Per Volume"] CreatinineTest
        where CreatinineTest.value is not null
          and CreatinineTest.effective.earliest ( ) during Interval[start of QualifyingEncounter.hospitalizationWithObservation ( ), start of QualifyingEncounter.hospitalizationWithObservation ( ) + 48 hours]
          and CreatinineTest.effective.earliest ( ) during QualifyingEncounter.hospitalizationWithObservation ( )
          and CreatinineTest.status in { 'final', 'amended', 'corrected' }
        return CreatinineTest
    Library Name Name
    CMS832HHAKIFHIR MaleeGFR
    define function "MaleeGFR"(QualifyingEncounter Encounter):
      if Patient.gender = 'male' then ( 142 * Min({("IndexCreatinine"(QualifyingEncounter).value / 0.9), 1 }) ^ ( - 0.302 ) * Max({("IndexCreatinine"(QualifyingEncounter).value / 0.9), 1 }) ^ ( - 1.200 ) * 0.9938 ^ ( AgeInYearsAt(start of QualifyingEncounter.hospitalizationWithObservation()) ) ) 
        else null
    Library Name Name
    CMS832HHAKIFHIR FemaleeGFR
    // eGFR functions return as decimal value rather than Quantity
    
    
    define function "FemaleeGFR"(QualifyingEncounter Encounter):
      if Patient.gender = 'female' then ( 142 * Min({("IndexCreatinine"(QualifyingEncounter).value / 0.7), 1 }) ^ ( - 0.241 ) * Max({("IndexCreatinine"(QualifyingEncounter).value / 0.7), 1 }) ^ ( - 1.200 ) * 0.9938 ^ ( AgeInYearsAt(start of QualifyingEncounter.hospitalizationWithObservation()) ) * 1.012 ) 
        else null
    Library Name Name
    CMS832HHAKIFHIR EarliestSerumCreatinineResult
    define function "EarliestSerumCreatinineResult"(QualifyingEncounter Encounter):
      from
        "Qualifying Creatinine Lab Result by Time" LabTests
        let LabResult: LabTests.CrLabResult
        where ( "EarliestSerumCreatinineTime"(QualifyingEncounter) = LabTests.CrLabTime )
        return LabResult as Quantity
    Library Name Name
    CMS832HHAKIFHIR EarliestSerumCreatinineTime
    define function "EarliestSerumCreatinineTime"(QualifyingEncounter Encounter):
      ( Min((from
              "Qualifying Creatinine Lab Result by Time" LabTestsEarly
              let LabResultEarly: LabTestsEarly.CrLabResult
              where LabTestsEarly.CrEncInPtId = QualifyingEncounter.id
          ).CrLabTime
        )
      )