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: Appropriate Use of DXA Scans in Women Under 65 Years Who Do Not Meet the Risk Factor Profile for Osteoporotic FractureFHIR

Official URL: https://madie.cms.gov/Measure/AppropriateDXAScansForWomenUnder65FHIR Version: 0.2.001
Draft as of 2024-12-18 Responsible: Centers for Medicare & Medicaid Services (CMS) Computable Name: AppropriateDXAScansForWomenUnder65FHIR
Other Identifiers: Short Name (use: usual, ), UUID:bf28f544-b8f0-49fd-8a67-ceafe0f0250e (use: official, ), UUID:2d4f7526-6eff-4629-8d25-568b00177ed5 (use: official, ), Endorser (use: official, ), Publisher (use: official, )

Copyright/Legal: This Physician Performance Measure (Measure) and related data specifications are owned and stewarded by the Centers for Medicare & Medicaid Services (CMS). This measure was developed under CMS Contract No. HHSM-500-2013-13011I, Task Order HHSM-500-TO0001. Mathematica and the National Committee for Quality Assurance (NCQA) supported development of this electronic measure. NCQA is not responsible for any use of the Measure. NCQA makes no representations, warranties, or endorsement about the quality of any organization or physician that uses or reports performance measures and NCQA has no liability to anyone who relies on such measures or specifications.

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. NCQA disclaims all liability for use or accuracy of any third-party codes contained in the specifications.

CPT(R) codes, descriptions and other data are copyright 2024. American Medical Association. All rights reserved. CPT is a trademark of the American Medical Association. Fee schedules, relative value units, conversion factors and/or related components are not assigned by the AMA, are not part of CPT, and the AMA is not recommending their use. The AMA does not directly or indirectly practice medicine or dispense medical services. The AMA assumes no liability for data contained or not contained herein. Applicable FARS/DFARS restrictions apply to government use.

The measure specifications contain coding from LOINC(R) (http://loinc.org). The LOINC table, LOINC codes, LOINC panels and form file, LOINC linguistic variants file, LOINC/RSNA Radiology Playbook, and LOINC/IEEE Medical Device Code Mapping Table are copyright 2004-2024 Regenstrief Institute, Inc. and the Logical Observation Identifiers Names and Codes (LOINC) Committee, and are available at no cost under the license at http://loinc.org/terms-of-use.

This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2023 International Health Terminology Standards Development Organisation.

ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

The Measure uses RxNorm, a standardized nomenclature and coding for clinical drugs and drug delivery devices, which is made publicly available courtesy of the U.S. National Library of Medicine (NLM), National Institutes of Health, Department of Health and Human Services. NLM is not responsible for the Measure and does not endorse or recommend this or any other product.

“HL7” is the registered trademark of Health Level Seven International.

Percentage of female patients 50 to 64 years of age without select risk factors for osteoporotic fracture who received an order for a dual-energy x-ray absorptiometry (DXA) scan during the measurement period

UNKNOWN

Title: Appropriate Use of DXA Scans in Women Under 65 Years Who Do Not Meet the Risk Factor Profile for Osteoporotic FractureFHIR
Id: AppropriateDXAScansForWomenUnder65FHIR
Version: 0.2.001
Url: Appropriate Use of DXA Scans in Women Under 65 Years Who Do Not Meet the Risk Factor Profile for Osteoporotic FractureFHIR
short-name identifier:

CMS249FHIR

version-independent identifier:

urn:uuid:bf28f544-b8f0-49fd-8a67-ceafe0f0250e

version-specific identifier:

urn:uuid:2d4f7526-6eff-4629-8d25-568b00177ed5

endorser (CMS Consensus Based Entity) identifier:

3475e

publisher (CMS) identifier:

249FHIR

Effective Period: 2025-01-01..2025-12-31
Status: draft
Publisher: Centers for Medicare & Medicaid Services (CMS)
Author: National Committee for Quality Assurance
Description:

Percentage of female patients 50 to 64 years of age without select risk factors for osteoporotic fracture who received an order for a dual-energy x-ray absorptiometry (DXA) scan during the measurement period

Purpose:

UNKNOWN

Copyright:

This Physician Performance Measure (Measure) and related data specifications are owned and stewarded by the Centers for Medicare & Medicaid Services (CMS). This measure was developed under CMS Contract No. HHSM-500-2013-13011I, Task Order HHSM-500-TO0001. Mathematica and the National Committee for Quality Assurance (NCQA) supported development of this electronic measure. NCQA is not responsible for any use of the Measure. NCQA makes no representations, warranties, or endorsement about the quality of any organization or physician that uses or reports performance measures and NCQA has no liability to anyone who relies on such measures or specifications.

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. NCQA disclaims all liability for use or accuracy of any third-party codes contained in the specifications.

CPT(R) codes, descriptions and other data are copyright 2024. American Medical Association. All rights reserved. CPT is a trademark of the American Medical Association. Fee schedules, relative value units, conversion factors and/or related components are not assigned by the AMA, are not part of CPT, and the AMA is not recommending their use. The AMA does not directly or indirectly practice medicine or dispense medical services. The AMA assumes no liability for data contained or not contained herein. Applicable FARS/DFARS restrictions apply to government use.

The measure specifications contain coding from LOINC(R) (http://loinc.org). The LOINC table, LOINC codes, LOINC panels and form file, LOINC linguistic variants file, LOINC/RSNA Radiology Playbook, and LOINC/IEEE Medical Device Code Mapping Table are copyright 2004-2024 Regenstrief Institute, Inc. and the Logical Observation Identifiers Names and Codes (LOINC) Committee, and are available at no cost under the license at http://loinc.org/terms-of-use.

This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2023 International Health Terminology Standards Development Organisation.

ICD-10 copyright 2024 World Health Organization. All Rights Reserved.

The Measure uses RxNorm, a standardized nomenclature and coding for clinical drugs and drug delivery devices, which is made publicly available courtesy of the U.S. National Library of Medicine (NLM), National Institutes of Health, Department of Health and Human Services. NLM is not responsible for the Measure and does not endorse or recommend this or any other product.

“HL7” is the registered trademark of Health Level Seven International.

Disclaimer:

The 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 MEASURE 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].

Scoring:

Proportion

Rationale:

This measure is expected to increase recording of patient risk for fracture data and decrease the amount of inappropriate DXA scans. Current osteoporosis guidelines recommend using bone measurement testing to assess osteoporosis risk in women 65 years and older. In postmenopausal women younger than age 65, guidelines recommend using a formal clinical risk assessment tool to establish a patient's risk for osteoporosis, in order to determine whether to screen a patient for osteoporosis using bone measurement testing. Clinical information, such as age, body mass index (BMI), parental hip fracture history, and alcohol use, can be used to determine a woman's fracture risk (U.S. Preventive Services Task Force [USPSTF], 2018). Additionally, there are potentially avoidable harms associated with screening for osteoporosis in general, including exposure to radiation, false positive exams, and resulting side effects from unnecessary osteoporosis medications, which add costs to an already burdened health care system (Lim, Hoeksema, & Sherin, 2009).

Clinical recommendation statement:

USPSTF 2018: "The USPSTF recommends screening for osteoporosis with bone measurement testing to prevent osteoporotic fractures in women 65 years and older." This is a B recommendation.

"The USPSTF concludes that the current evidence is insufficient to assess the balance of benefits and harms of screening for osteoporosis to prevent osteoporotic fractures in men." This is an I statement.

"The USPSTF recommends screening for osteoporosis with bone measurement testing to prevent osteoporotic fractures in postmenopausal women younger than 65 years who are at increased risk of osteoporosis, as determined by a formal clinical risk assessment tool." This is a B recommendation. "For postmenopausal women younger than 65 years who have at least 1 risk factor, a reasonable approach to determine who should be screened with bone measurement testing is to use a clinical risk assessment tool."

"Several tools are available to assess osteoporosis risk: the Simple Calculated Osteoporosis Risk Estimate (SCORE; Merck), Osteoporosis Risk Assessment Instrument (ORAI), Osteoporosis Index of Risk (OSIRIS), and the Osteoporosis Self-Assessment Tool (OST). These tools seem to perform similarly and are moderately accurate at predicting osteoporosis. The Fracture Risk Assessment (FRAX) tool (University of Sheffield), which assesses a person's 10-year risk of fracture, is also a commonly used tool."

"Because the benefits of treatment are greater in persons at higher risk of fracture, one approach is to perform bone measurement testing in postmenopausal women younger than 65 years who have a 10-year FRAX risk of major osteoporotic fracture (MOF) (without DXA) greater than that of a 65-year-old white woman without major risk factors. For example, in the United States, a 65-year-old white woman of mean height and weight without major risk factors has a 10-year FRAX risk of MOF of 8.4%."

Guidance (Usage): Patients are excluded from the measure if they have one or more risk factors for osteoporosis, including a result indicating that the patient should be considered for bone density testing on one of the following risk assessment instruments: - 10-year probability of major osteoporotic fracture of 8.4 percent or higher as determined by the FRAX - ORAI score of >=9 - OSIRIS score of <1 - OST score of <2 This eCQM is a patient-based measure. This FHIR-based measure has been derived from the QDM-based measure:  CMS249v7. 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:
66460da2a7a1805d3b737654
Initial Population: Female patients ages 50 to 63 years at the start of the measurement period with an encounter during the measurement period
Denominator: Equals Initial Population
Denominator Exclusion: Exclude patients with one of the following risk factors. Risk factors are grouped by when they occur in relation to the measurement period. The following risk factors must be active during the measurement period: BMI <= 20 kg/m2 (must be the first BMI of the measurement period) Alcohol consumption (> two units per day (one unit is 12 oz. of beer, 4 oz. of wine, or 1 oz. of liquor)) The following risk factors may occur at any time in the patient's history prior to the start of the measurement period: Osteoporosis Osteopenia Gastric bypass Aromatase inhibitors Documentation of history of hip fracture in parent The following risk factors may occur at any time in the patient's history or during the measurement period: Glucocorticoids [cumulative medication duration >= 90 days] Osteoporotic fracture Malabsorption Syndromes: celiac disease, inflammatory bowel disease, ulcerative colitis, Crohn's disease, cystic fibrosis, malabsorption Chronic malnutrition Chronic liver disease Rheumatoid arthritis Hyperthyroidism Type I Diabetes End stage renal disease Osteogenesis imperfecta Ankylosing spondylitis Psoriatic arthritis Ehlers-Danlos syndrome Cushing's syndrome Hyperparathyroidism Marfan syndrome Lupus Chemotherapy Multiple myeloma Premature menopause Double or bilateral oophorectomy Eating disorder Amenorrhea Organ transplant
Numerator: Female patients who received an order for at least one DXA scan in the measurement period
Numerator Exclusion: Exclude patients with a result on one of the following tools, which indicates the patient should be considered for bone density testing, anytime in the patient’s history prior to the time of the first DXA scan during the measurement period: FRAX[R] ten-year probability of all major osteoporosis related fracture >= 8.4 percent ORAI score of >=9 OSIRIS score of <1 OST score of <2
Libraries:
AppropriateDXAScansForWomenUnder65FHIR
Terminology and Other Dependencies:
  • Library/Status|1.8.000
  • Library/QICoreCommon|2.1.000
  • Library/FHIRHelpers|4.4.000
  • Library/CumulativeMedicationDuration|4.1.000
  • Current Procedural Terminology (CPT®)
  • Observation Category Codes
  • Logical Observation Identifiers, Names and Codes (LOINC)
  • SNOMED CT (all versions)
  • DXA (Dual energy Xray Absorptiometry) Scan
  • Office Visit
  • Preventive Care Services - Established Office Visit, 18 and Up
  • Preventive Care Services-Initial Office Visit, 18 and Up
  • Outpatient Consultation
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089
  • Telephone Visits
  • Osteoporosis
  • Osteopenia
  • Gastric Bypass Surgery
  • Aromatase Inhibitors
  • History of hip fracture in parent
  • Glucocorticoids (oral only)
  • Osteoporotic Fractures
  • Malabsorption Syndromes
  • Chronic Malnutrition
  • Chronic Liver Disease
  • Rheumatoid Arthritis
  • Hyperthyroidism
  • Type 1 Diabetes
  • End Stage Renal Disease
  • Osteogenesis Imperfecta
  • Ankylosing Spondylitis
  • Psoriatic Arthritis
  • Ehlers Danlos Syndrome
  • Cushings Syndrome
  • Hyperparathyroidism
  • Marfan's Syndrome
  • Lupus
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1011
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1013
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1039
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1022
  • Chemotherapy
  • Bilateral Oophorectomy
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1048
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1035
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1032
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1028
  • Major Organ Transplant Other Than Kidney
  • Kidney Transplant
  • Bone Marrow Transplant
  • Parameters:
    name use min max type
    Measurement Period In 0 1 Period
    ErrorLevel In 0 1 string
    Numerator Out 0 1 boolean
    Denominator Out 0 1 boolean
    Initial Population Out 0 1 boolean
    Denominator Exclusions Out 0 1 boolean
    Numerator Exclusion Out 0 1 boolean
    DataRequirements:
    Resource Type Resource Elements Valueset Name Valueset
    Patient(QICorePatient)
    ServiceRequest(QICoreServiceRequest) code authoredOn authoredOn.value status status.value intent intent.value DXA (Dual energy Xray Absorptiometry) Scan DXA (Dual energy Xray Absorptiometry) Scan
    Encounter(QICoreEncounter) type status status.value period
    Encounter(QICoreEncounter) type status status.value period Office Visit Office Visit
    Encounter(QICoreEncounter) type status status.value period Preventive Care Services Established Office Visit, 18 and Up Preventive Care Services - Established Office Visit, 18 and Up
    Encounter(QICoreEncounter) type status status.value period Preventive Care Services Initial Office Visit, 18 and Up Preventive Care Services-Initial Office Visit, 18 and Up
    Encounter(QICoreEncounter) type status status.value period Outpatient Consultation Outpatient Consultation
    Encounter(QICoreEncounter) type status status.value period Virtual Encounter http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1089
    Encounter(QICoreEncounter) type status status.value period Telephone Visits Telephone Visits
    Observation(Observation Body Mass Index Profile) effective value status status.value
    Observation(QICoreObservation) code effective value status status.value category
    Observation(QICoreObservation) code effective status status.value category History of hip fracture in parent History of hip fracture in parent
    Observation(QICoreObservation) code value status status.value category effective
    Observation(QICoreObservation) code value status status.value category effective
    Observation(QICoreObservation) code value status status.value category effective
    Observation(QICoreObservation) code value status status.value category effective
    Condition(QICoreCondition) code Osteoporosis Without Current Fracture Osteoporosis
    Condition(QICoreCondition) code Osteopenia Osteopenia
    Condition(QICoreCondition) code Osteoporosis With Current Fracture Osteoporotic Fractures
    Condition(QICoreCondition) code Malabsorption Syndromes Malabsorption Syndromes
    Condition(QICoreCondition) code Chronic Malnutrition Chronic Malnutrition
    Condition(QICoreCondition) code Chronic Liver Disease Chronic Liver Disease
    Condition(QICoreCondition) code Rheumatoid Arthritis Rheumatoid Arthritis
    Condition(QICoreCondition) code Hyperthyroidism Hyperthyroidism
    Condition(QICoreCondition) code Type 1 Diabetes Type 1 Diabetes
    Condition(QICoreCondition) code End Stage Renal Disease End Stage Renal Disease
    Condition(QICoreCondition) code Osteogenesis Imperfecta Osteogenesis Imperfecta
    Condition(QICoreCondition) code Ankylosing Spondylitis Ankylosing Spondylitis
    Condition(QICoreCondition) code Psoriatic Arthritis Psoriatic Arthritis
    Condition(QICoreCondition) code Ehlers Danlos Syndrome Ehlers Danlos Syndrome
    Condition(QICoreCondition) code Cushings Syndrome Cushings Syndrome
    Condition(QICoreCondition) code Hyperparathyroidism Hyperparathyroidism
    Condition(QICoreCondition) code Marfan's Syndrome Marfan's Syndrome
    Condition(QICoreCondition) code Lupus Lupus
    Condition(QICoreCondition) code Multiple Myeloma http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1011
    Condition(QICoreCondition) code Premature Menopause http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1013
    Condition(QICoreCondition) code Eating Disorders http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1039
    Condition(QICoreCondition) code Amenorrhea http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1022
    Procedure(QICoreProcedure) code performed status status.value Gastric Bypass Surgery Gastric Bypass Surgery
    Procedure(QICoreProcedure) code status status.value performed Bilateral Oophorectomy Bilateral Oophorectomy
    Procedure(QICoreProcedure) code status status.value performed Evidence of Bilateral Oophorectomy http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1048
    Procedure(QICoreProcedure) code status status.value performed Unilateral Oophorectomy Right http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1032
    Procedure(QICoreProcedure) code bodySite status status.value performed Unilateral Oophorectomy, Unspecified Laterality http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1035
    Procedure(QICoreProcedure) code status status.value performed Unilateral Oophorectomy Left http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1028
    Procedure(QICoreProcedure) code status status.value performed Major Transplant Major Organ Transplant Other Than Kidney
    Procedure(QICoreProcedure) code status status.value performed Kidney Transplant Kidney Transplant
    Procedure(QICoreProcedure) code status status.value performed Bone Marrow Transplant Bone Marrow Transplant
    Procedure(QICoreProcedure) code status status.value performed Chemotherapy Chemotherapy
    Medication(QICoreMedication) id
    Medication(QICoreMedication) id
    Medication(QICoreMedication) id
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value dosageInstruction dispenseRequest dispenseRequest.expectedSupplyDuration dispenseRequest.quantity dispenseRequest.numberOfRepeatsAllowed dispenseRequest.numberOfRepeatsAllowed.value authoredOn authoredOn.value dispenseRequest.validityPeriod Aromatase Inhibitors Aromatase Inhibitors
    MedicationRequest(QICoreMedicationRequest) medication.reference status status.value intent intent.value dosageInstruction dispenseRequest dispenseRequest.expectedSupplyDuration dispenseRequest.quantity dispenseRequest.numberOfRepeatsAllowed dispenseRequest.numberOfRepeatsAllowed.value authoredOn authoredOn.value dispenseRequest.validityPeriod
    MedicationRequest(QICoreMedicationRequest) medication status status.value intent intent.value dosageInstruction dispenseRequest dispenseRequest.expectedSupplyDuration dispenseRequest.quantity dispenseRequest.numberOfRepeatsAllowed dispenseRequest.numberOfRepeatsAllowed.value authoredOn authoredOn.value dispenseRequest.validityPeriod Glucocorticoids (oral only) Glucocorticoids (oral only)
    Direct Reference Codes:
    display code system
    Unlisted preventive medicine service 99429 http://www.ama-assn.org/go/cpt
    survey survey http://terminology.hl7.org/CodeSystem/observation-category
    Alcoholic drinks per day 74013-4 http://loinc.org
    Right (qualifier value) 24028007 http://snomed.info/sct
    Left (qualifier value) 7771000 http://snomed.info/sct
    Major osteoporotic fracture 10-year probability [Likelihood] Fracture Risk Assessment 90265-0 http://loinc.org
    Osteoporosis Risk Assessment Instrument 98139-9 http://loinc.org
    Osteoporosis Index of Risk panel 98133-2 http://loinc.org
    Osteoporosis Self-Assessment Tool 98146-4 http://loinc.org
    Logic Definitions:
    Group Scoring Population Criteria Expression
    66460da2a7a1805d3b737654 Group scoring: proportion Measure scoring:

    Proportion

    Type:

    Process

    Rate Aggregation: None
    Improvement Notation:

    increase

    Initial Population
    define "Initial Population":
      AgeInYearsAt(date from start of "Measurement Period") in Interval[50, 63]
        and Patient.gender = 'female'
        and exists "Qualifying Encounter"
    Denominator
    define "Denominator":
      "Initial Population"
    Denominator Exclusion
    define "Denominator Exclusions":
      "Has Risk Factor Active During the Measurement Period"
        or "Has Risk Factor Any Time in History Prior to Measurement Period"
        or "Has Risk Factor Any Time in History or During Measurement Period"
    Numerator
    define "Numerator":
      exists "DXA Scan Order During Measurement Period"
    Numerator Exclusion
    define "Numerator Exclusion":
      exists "Osteoporosis Fracture Risk Assessment Prior to First DXA Scan"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR DXA Scan Order During Measurement Period
    define "DXA Scan Order During Measurement Period":
      ( ( [ServiceRequest: "DXA (Dual energy Xray Absorptiometry) Scan"] ).isDiagnosticStudyOrder ( ) ) DXA
        where DXA.authoredOn.toInterval ( ) during "Measurement Period"
        // and DXA.doNotPerform is not true
        // https://oncprojectracking.healthit.gov/support/browse/CQLIT-447 
        
        
        sort by authoredOn asc
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Numerator
    define "Numerator":
      exists "DXA Scan Order During Measurement Period"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Qualifying Encounter
    define "Qualifying Encounter":
      ( ( [Encounter: "Office Visit"]
          union [Encounter: "Preventive Care Services Established Office Visit, 18 and Up"]
          union ( [Encounter] E
              where exists ( ( E.type ) T
                  where T ~ "Unlisted preventive medicine service"
              )
          )
          union [Encounter: "Preventive Care Services Initial Office Visit, 18 and Up"]
          union [Encounter: "Outpatient Consultation"]
          union [Encounter: "Virtual Encounter"]
          union [Encounter: "Telephone Visits"]
      ).isEncounterPerformed ( ) ) ValidEncounters
        where ValidEncounters.period.toInterval ( ) during day of "Measurement Period"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Initial Population
    define "Initial Population":
      AgeInYearsAt(date from start of "Measurement Period") in Interval[50, 63]
        and Patient.gender = 'female'
        and exists "Qualifying Encounter"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Denominator
    define "Denominator":
      "Initial Population"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR First BMI in Measurement Period
    define "First BMI in Measurement Period":
      First(((["observation-bmi"]).isObservationBMI()) BMIRatio
          where BMIRatio.effective.toInterval() during "Measurement Period"
            and BMIRatio.value as Quantity is not null
          sort by start of effective.toInterval()
      )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR First BMI in Measurement Period Less Than or Equal to 20 kg m2
    define "First BMI in Measurement Period Less Than or Equal to 20 kg m2":
      "First BMI in Measurement Period" FirstBMI
        where FirstBMI.value as Quantity <= 20 'kg/m2'
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR First Average Number of Drinks Assessments Indicating More Than Two Per Day
    define "First Average Number of Drinks Assessments Indicating More Than Two Per Day":
      First((([Observation: "Alcoholic drinks per day"]).isAssessmentPerformed()) AverageDrinks
          where start of AverageDrinks.effective.toInterval() during "Measurement Period"
            and AverageDrinks.value as Quantity > 2 '{drinks}/d'
          sort by start of effective.toInterval()
      )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has Risk Factor Active During the Measurement Period
    define "Has Risk Factor Active During the Measurement Period":
      "First BMI in Measurement Period Less Than or Equal to 20 kg m2" is not null
        or "First Average Number of Drinks Assessments Indicating More Than Two Per Day" is not null
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has Risk Factor Any Time in History Prior to Measurement Period
    define "Has Risk Factor Any Time in History Prior to Measurement Period":
      exists ( ( [Condition: "Osteoporosis Without Current Fracture"] OsteoporosisDiagnosis
            where OsteoporosisDiagnosis.prevalenceInterval ( ) starts before start of "Measurement Period"
        )
          union ( [Condition: "Osteopenia"] OsteopeniaDiagnosis
              where OsteopeniaDiagnosis.prevalenceInterval ( ) starts before start of "Measurement Period"
          )
          union ( ( ( ( [Procedure: "Gastric Bypass Surgery"] ).isProcedurePerformed ( ) ) GastricBypass
                where GastricBypass.performed.toInterval ( ) ends before start of "Measurement Period"
            )
              union ( ( ( [MedicationRequest: "Aromatase Inhibitors"] ).isMedicationActive ( ) ) AromataseInhibitorActive
                  where CMD."MedicationRequestPeriod" ( AromataseInhibitorActive ) starts before start of "Measurement Period"
              )
              union ( ( ( [MedicationRequest: "Aromatase Inhibitors"] ).isMedicationOrder ( ) ) AromataseInhibitorOrder
                  where AromataseInhibitorOrder.authoredOn.toInterval ( ) before start of "Measurement Period"
              )
              union ( ( [Observation: "History of hip fracture in parent"] ).isAssessmentPerformed ( ) ) ParentFractureHistory
                where start of ParentFractureHistory.effective.toInterval ( ) before start of "Measurement Period"
          )
      )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Glucocorticoid Active Medication Days
    define "Glucocorticoid Active Medication Days":
      ( ( ( ( [MedicationRequest: "Glucocorticoids (oral only)"] ).isMedicationActive ( ) ) OralGlucocorticoid
          where ( OralGlucocorticoid ).medicationRequestPeriod ( ) starts before end of "Measurement Period" ) Glucocorticoid
          return ( Glucocorticoid ).medicationRequestPeriod ( )
            intersect Interval[Patient.birthDate, date from end of "Measurement Period"]
      ).cumulativeDuration ( )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has 90 or More Active Glucocorticoid Medication Days
    define "Has 90 or More Active Glucocorticoid Medication Days":
      "Glucocorticoid Active Medication Days" >= 90
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has Double or Bilateral Oophorectomy
    define "Has Double or Bilateral Oophorectomy":
      exists ( ( [Procedure: "Bilateral Oophorectomy"] ).procedureInPatientHistory ( ) )
        or exists ( ( [Procedure: "Evidence of Bilateral Oophorectomy"] ).procedureInPatientHistory ( ) )
        or ( exists ( ( ( [Procedure: "Unilateral Oophorectomy, Unspecified Laterality"] UnilateralOophorectomy
                  where exists ( UnilateralOophorectomy.bodySite C
                      where C ~ "Right (qualifier value)"
                  )
              )
                union [Procedure: "Unilateral Oophorectomy Right"]
            ).procedureInPatientHistory ( )
          )
            and exists ( ( ( [Procedure: "Unilateral Oophorectomy, Unspecified Laterality"] UnilateralOophorectomy
                    where exists ( UnilateralOophorectomy.bodySite D
                        where D ~ "Left (qualifier value)"
                    )
                )
                  union [Procedure: "Unilateral Oophorectomy Left"]
              ).procedureInPatientHistory ( )
            )
        )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has Organ Transplants
    define "Has Organ Transplants":
      exists ( [Procedure: "Major Transplant"]
          union [Procedure: "Kidney Transplant"]
          union [Procedure: "Bone Marrow Transplant"]
      ).procedureInPatientHistory ( )
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Has Risk Factor Any Time in History or During Measurement Period
    define "Has Risk Factor Any Time in History or During Measurement Period":
      "Has 90 or More Active Glucocorticoid Medication Days"
        or exists ( [Condition: "Osteoporosis With Current Fracture"]
            union [Condition: "Malabsorption Syndromes"]
            union [Condition: "Chronic Malnutrition"]
            union [Condition: "Chronic Liver Disease"]
            union [Condition: "Rheumatoid Arthritis"]
            union [Condition: "Hyperthyroidism"]
            union [Condition: "Type 1 Diabetes"]
            union [Condition: "End Stage Renal Disease"]
            union [Condition: "Osteogenesis Imperfecta"]
            union [Condition: "Ankylosing Spondylitis"]
            union [Condition: "Psoriatic Arthritis"]
            union [Condition: "Ehlers Danlos Syndrome"]
            union [Condition: "Cushings Syndrome"]
            union [Condition: "Hyperparathyroidism"]
            union [Condition: "Marfan's Syndrome"]
            union [Condition: "Lupus"]
            union [Condition: "Multiple Myeloma"]
            union [Condition: "Premature Menopause"]
            union [Condition: "Eating Disorders"]
            union [Condition: "Amenorrhea"]
        ).diagnosisInPatientHistory ( )
        or exists ( [Procedure: "Chemotherapy"] ).procedureInPatientHistory ( )
        or "Has Double or Bilateral Oophorectomy"
        or "Has Organ Transplants"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Denominator Exclusions
    define "Denominator Exclusions":
      "Has Risk Factor Active During the Measurement Period"
        or "Has Risk Factor Any Time in History Prior to Measurement Period"
        or "Has Risk Factor Any Time in History or During Measurement Period"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Osteoporosis Fracture Risk Assessment Prior to First DXA Scan
    define "Osteoporosis Fracture Risk Assessment Prior to First DXA Scan":
      ( ( ( ( [Observation: "Major osteoporotic fracture 10-year probability [Likelihood] Fracture Risk Assessment"] ).isAssessmentPerformed ( ) ) FRAX
          where FRAX.value >= 8.4 '%'
      )
        union ( ( ( [Observation: "Osteoporosis Risk Assessment Instrument"] ).isAssessmentPerformed ( ) ) ORAI
            where ORAI.value as Integer >= 9
        )
        union ( ( ( [Observation: "Osteoporosis Index of Risk panel"] ).isAssessmentPerformed ( ) ) OSIRIS
            where OSIRIS.value as Quantity < 1.0
        )
        union ( ( ( [Observation: "Osteoporosis Self-Assessment Tool"] ).isAssessmentPerformed ( ) ) OST
            where OST.value as Quantity < 2.0
        ) ) RiskAssessment
        where start of RiskAssessment.effective.toInterval ( ) before First("DXA Scan Order During Measurement Period").authoredOn
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR Numerator Exclusion
    define "Numerator Exclusion":
      exists "Osteoporosis Fracture Risk Assessment Prior to First DXA Scan"
    Library Name Name
    Status isDiagnosticStudyOrder
    //Diagnostic Study, Order: active and completed only
    define fluent function isDiagnosticStudyOrder(ServiceRequest List<ServiceRequest>):
      ServiceRequest S
        where S.status in { 'active', 'completed' }
          and S.intent = 'order'
    Library Name Name
    QICoreCommon toInterval
    /*
    @description: Normalizes a value that is a choice of timing-valued types to an equivalent interval
    @comment: Normalizes a choice type of DateTime, Quanitty, Interval<DateTime>, or Interval<Quantity> types
    to an equivalent interval. This selection of choice types is a superset of the majority of choice types that are used as possible
    representations for timing-valued elements in QICore, allowing this function to be used across any resource.
    The input can be provided as a DateTime, Quantity, Interval<DateTime> or Interval<Quantity>.
    The intent of this function is to provide a clear and concise mechanism to treat single
    elements that have multiple possible representations as intervals so that logic doesn't have to account
    for the variability. More complex calculations (such as medication request period or dispense period
    calculation) need specific guidance and consideration. That guidance may make use of this function, but
    the focus of this function is on single element calculations where the semantics are unambiguous.
    If the input is a DateTime, the result a DateTime Interval beginning and ending on that DateTime.
    If the input is a Quantity, the quantity is expected to be a calendar-duration interpreted as an Age,
    and the result is a DateTime Interval beginning on the Date the patient turned that age and ending immediately before one year later.
    If the input is a DateTime Interval, the result is the input.
    If the input is a Quantity Interval, the quantities are expected to be calendar-durations interpreted as an Age, and the result
    is a DateTime Interval beginning on the date the patient turned the age given as the start of the quantity interval, and ending
    immediately before one year later than the date the patient turned the age given as the end of the quantity interval.
    If the input is a Timing, an error will be thrown indicating that Timing calculations are not implemented. Any other input will reslt in a null DateTime Interval
    */
    define fluent function toInterval(choice Choice<DateTime, Quantity, Interval<DateTime>, Interval<Quantity>, Timing>):
      case
    	  when choice is DateTime then
        	Interval[choice as DateTime, choice as DateTime]
    		when choice is Interval<DateTime> then
      		choice as Interval<DateTime>
    		when choice is Quantity then
    		  Interval[Patient.birthDate + (choice as Quantity),
    			  Patient.birthDate + (choice as Quantity) + 1 year)
    		when choice is Interval<Quantity> then
    		  Interval[Patient.birthDate + (choice.low as Quantity),
    			  Patient.birthDate + (choice.high as Quantity) + 1 year)
    		when choice is Timing then
          Message(null, true, 'NOT_IMPLEMENTED', 'Error', 'Calculation of an interval from a Timing value is not supported') as Interval<DateTime>
    		else
    			null as Interval<DateTime>
    	end
    Library Name Name
    Status isEncounterPerformed
    //Encounter, Performed
    //General usage unless required otherwise by measure intent (e.g., follow-up encounters)
    define fluent function isEncounterPerformed(Enc List<Encounter>):
      Enc E
        where E.status in {'finished', 'arrived', 'triaged', 'in-progress', 'onleave'}
    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
    Status isObservationBMI
    define fluent function isObservationBMI(Obs List<"QICore.observation-bmi">):
      Obs O
        where O.status in { 'final', 'amended', 'corrected' }
    Library Name Name
    Status isAssessmentPerformed
    //This library contains functions that are based on QDM 5.6 to QICore 4.1.1 March 2023 (https://github.com/cqframework/CQL-Formatting-and-Usage-Wiki/wiki/Authoring-Patterns---QICore-v4.1.1). The functions may appear similar to some QICoreCommon functions but different in that they have constraints that are relevant for measures authored by NCQA.
    
    //Assessment, Performed
    define fluent function isAssessmentPerformed(Obs List<Observation>):
      Obs O
        where O.status in { 'final', 'amended', 'corrected' }
              and exists ( O.category ObservationCategory
              where ( ObservationCategory ) ~ "survey"
          )
    Library Name Name
    QICoreCommon prevalenceInterval
    /*
    @description: Returns an interval representing the normalized prevalence period of a given Condition.
    @comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from
    onset to abatement as specified in the given Condition. If the condition is active, or has an abatement date the resulting 
    interval will have a closed ending boundary. Otherwise, the resulting interval will have an open ending boundary.
    */
    define fluent function prevalenceInterval(condition Condition):
    if condition.clinicalStatus ~ "active"
      or condition.clinicalStatus ~ "recurrence"
      or condition.clinicalStatus ~ "relapse" then
      Interval[start of condition.onset.toInterval(), end of condition.abatementInterval()]
    else
        (end of condition.abatementInterval()) abatementDate
        return if abatementDate is null then
          Interval[start of condition.onset.toInterval(), abatementDate)
        else
          Interval[start of condition.onset.toInterval(), abatementDate]
    Library Name Name
    Status isProcedurePerformed
    //Procedure, Performed
    define fluent function isProcedurePerformed(Proc List<Procedure>):
      Proc P
        where P.status ~ 'completed'
    Library Name Name
    Status isMedicationActive
    //Medication, Active
    define fluent function isMedicationActive(MedicationRequest List<MedicationRequest>):
      MedicationRequest M
        where M.status = 'active'
          and M.intent = 'order'
    Library Name Name
    CumulativeMedicationDuration MedicationRequestPeriod
    /*
    Now that we have a ToDaily function, we can approach calculation of the
    duration of medication for an order. First, consider the definitions
    for each element:
    * 1 and only 1 dosageInstruction
    * 1 and only 1 doseAndRate
    * 1 timing with 1 repeat
    * frequency, frequencyMax, defaulting to 1
    * period, periodUnit, defaulting to 1 'd'
    * doseQuantity or doseRange
    * timeOfDay
    * authoredOn: The date the prescription was written
    * dispenseRequest.validityPeriod: Time period supply is authorized for
    * dispenseRequest.quantity: amount of medication supplied per dispense
    * dispenseRequest.numberOfRepeatsAllowed: number of refills authorized
    * dispenseRequest.expectedSupplyDuration: number of days supply per dispense
    * dosageInstruction.timing.repeat.boundsDuration: total duration of the repeat
    * dosageInstruction.timing.repeat.boundsRange: range of durations of the repeat
    * dosageInstruction.timing.repeat.boundsPeriod: period bounds of the repeat
    * dosageInstruction.timing.repeat.count: number of times to repeat
    * dosageInstruction.timing.repeat.countMax: maximum number of times to repeat
    * dosageInstruction.timing.repeat.frequency: event occurs frequency times per period
    * dosageInstruction.timing.repeat.frequencyMax: event occurs up to frequencyMax times per period
    * dosageInstruction.timing.repeat.period: event occurs frequency times per period
    * dosageInstruction.timing.repeat.periodMax: upper limit of period
    * dosageInstruction.timing.repeat.periodUnit: period duration (s | min | h | d | wk | mo | a)
    * dosageInstruction.timing.repeat.timeOfDay: time of day for the event (0..*)
    * dosageInstruction.timing.repeat.when: event timing (HS | WAKE | C | CM | CD | CV | AC | ACM...)
    * dosageInstruction.timing.code: BID | TID | QID | AM | PM | QD | QOD...
    * dosageInstruction.asNeeded
    * dosageInstruction.doseAndRate.doseQuantity
    * dosageInstruction.doseAndRate.doseRange
    If expectedSupplyDuration is present, then the duration is
        expectedSupplyDuration * (1 + numberOfRepeatsAllowed)
    If expectedSupplyDuration is not present, then it must be calculated based on the quantity, dosage, and frequency:
        (quantity / (dosage * frequency)) * (1 + numberOfRepeatsAllowed)
        dosage: Coalesce(end of doseAndRate.doseRange, doseAndRate.doseQuantity)
        frequency: Coalesce(frequencyMax, frequency)
        period: Quantity(period, periodUnit)
    If expectedSupplyDuration is not present and cannot be calculated, and the boundsPeriod is present (and completely specified), we can use that directly
        dosage.timing.repeat.boundsPeriod
    This calculation results in a number of days, which can then be turned into a period by anchoring that to the
    start of the validityPeriod or the authoredOn:
        Interval[earliestDispensable, earliestDispensable + expectedSupplyDuration - 1]
        earliestDispensable: Coalesce(start of validityPeriod, authoredOn)
    The following function illustrates this completely:
    */
    
    /*
    Calculates the Medication Period for a single MedicationRequest.
    MedicationRequest instances provided to this function are expected
    to conform to the [MMEMedicationRequest](http://build.fhir.org/ig/cqframework/opioid-mme-r4/StructureDefinition-mmemedicationrequest.html)
    profile, which expects:
    * 1 and only 1 dosageInstruction, multiple dosageInstruction elements will result in an error
    * 1 and only 1 doseAndRate, multiple doseAndRate elements will result in an error
    * 1 timing with 1 repeat, missing timing or repeat elements will result in a null
    * frequency, frequencyMax, defaulting to 1
    * period, periodUnit, defaulting to 1 'd'
    * timeOfDay
    * doseQuantity or doseRange, missing doseQuantity and doseRange will result in a null
    Note that MedicationRequest status is not considered by this calculation, as the
    list of MedicationRequest instances provided to this function should already have
    considered appropriate statuses, depending on the use case, typically `completed`.
    */
    define function MedicationRequestPeriod(Request "MedicationRequest"):
      Request R
        let
          dosage: singleton from R.dosageInstruction,
          doseAndRate: singleton from dosage.doseAndRate,
          timing: dosage.timing,
          frequency: Coalesce(timing.repeat.frequencyMax, timing.repeat.frequency),
          period: Quantity(timing.repeat.period, timing.repeat.periodUnit),
          doseRange: doseAndRate.dose,
          doseQuantity: doseAndRate.dose,
          dose: Coalesce(end of doseRange, doseQuantity),
          dosesPerDay: Coalesce(ToDaily(frequency, period), Count(timing.repeat.timeOfDay), 1.0),
          boundsPeriod: timing.repeat.bounds as Interval<DateTime>,
          daysSupply: (convert R.dispenseRequest.expectedSupplyDuration to days).value,
          quantity: R.dispenseRequest.quantity,
          refills: Coalesce(R.dispenseRequest.numberOfRepeatsAllowed, 0),
          startDate:
            Coalesce(
              date from start of boundsPeriod,
              date from R.authoredOn,
              date from start of R.dispenseRequest.validityPeriod
            ),
          totalDaysSupplied: Coalesce(daysSupply, quantity.value / (dose.value * dosesPerDay)) * (1 + refills)
        return
          if startDate is not null and totalDaysSupplied is not null then
            Interval[startDate, startDate + Quantity(totalDaysSupplied - 1, 'day') ]
          else if startDate is not null and boundsPeriod."high" is not null then
            Interval[startDate, date from end of boundsPeriod]
          else
            null
    Library Name Name
    CumulativeMedicationDuration Quantity
    /**********************************************************************/
    /* Functions in this region are copied from opioid-mme-r4             */
    /**********************************************************************/
    
    define function Quantity(value Decimal, unit String):
      if value is not null then
        System.Quantity { value: value, unit: unit }
      else
        null
    Library Name Name
    CumulativeMedicationDuration ToDaily
    /*
     Goal is to get to number of days
     Two broad approaches to the calculation:
      1) Based on supply and frequency, calculate the number of expected days the medication will cover/has covered
      2) Based on relevant period, determine a covered interval and calculate the length of that interval in days
    This topic covers several use cases and illustrates how to calculate Cumulative
    Medication Duration for each type of medication resource using the supply and
    frequency approach.
    */
    
    /*
      For the first approach, we need to get from frequency to a frequency/day
      So we define ToDaily
    */
    
    /*
      Calculates daily frequency given frequency within a period
    */
    define function ToDaily(frequency System.Integer, period System.Quantity):
      case period.unit
        when 'h' then frequency * (24.0 / period.value)
        when 'min' then frequency * (24.0 / period.value) * 60
        when 's' then frequency * (24.0 / period.value) * 60 * 60
        when 'd' then frequency * (24.0 / period.value) / 24
        when 'wk' then frequency * (24.0 / period.value) / (24 * 7)
        when 'mo' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */
        when 'a' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */
        when 'hour' then frequency * (24.0 / period.value)
        when 'minute' then frequency * (24.0 / period.value) * 60
        when 'second' then frequency * (24.0 / period.value) * 60 * 60
        when 'day' then frequency * (24.0 / period.value) / 24
        when 'week' then frequency * (24.0 / period.value) / (24 * 7)
        when 'month' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */
        when 'year' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */
        when 'hours' then frequency * (24.0 / period.value)
        when 'minutes' then frequency * (24.0 / period.value) * 60
        when 'seconds' then frequency * (24.0 / period.value) * 60 * 60
        when 'days' then frequency * (24.0 / period.value) / 24
        when 'weeks' then frequency * (24.0 / period.value) / (24 * 7)
        when 'months' then frequency * (24.0 / period.value) / (24 * 30) /* assuming 30 days in month */
        when 'years' then frequency * (24.0 / period.value) / (24 * 365) /* assuming 365 days in year */
        else Message(null, true, 'CMDLogic.ToDaily.UnknownUnit', ErrorLevel, 'Unknown unit ' & period.unit)
      end
    Library Name Name
    Status isMedicationOrder
    //Medication, Order: active and completed only
    define fluent function isMedicationOrder(MedicationRequest List<MedicationRequest>):
      MedicationRequest M
        where M.status in { 'active', 'completed' }
          and M.intent = 'order'
    Library Name Name
    CumulativeMedicationDuration cumulativeDuration
    /*
    Now that we have functions for determining the medication period for individual
    prescriptions, administrations, and dispenses, we can combine those using
    an overall cumulative medication duration calculation.
    There are two broad approaches to calculating cumulative duration, one that _collapses_
    overlapping intervals so that calculations are not duplicated, and one that _rolls out_
    overlapping intervals so that the durations are laid end-to-end.
    First, we define a function that simply calculates CumulativeDuration of a set of
    intervals:
    */
    define fluent function cumulativeDuration(Intervals List<Interval<Date>>):
       if Intervals is not null then ( Sum((collapse Intervals per day)X
            return all(difference in days between start of X and 
              end of X
            )+ 1
        )
      ) 
        else null
    Library Name Name
    CumulativeMedicationDuration medicationRequestPeriod
    define fluent function medicationRequestPeriod(Request "MedicationRequest"):
      Request R
        let
          dosage: singleton from R.dosageInstruction,
          doseAndRate: singleton from dosage.doseAndRate,
          timing: dosage.timing,
          frequency: Coalesce(timing.repeat.frequencyMax, timing.repeat.frequency),
          period: Quantity(timing.repeat.period, timing.repeat.periodUnit),
          doseRange: doseAndRate.dose,
          doseQuantity: doseAndRate.dose,
          dose: Coalesce(end of doseRange, doseQuantity),
          dosesPerDay: Coalesce(ToDaily(frequency, period), Count(timing.repeat.timeOfDay), 1.0),
          boundsPeriod: timing.repeat.bounds as Interval<DateTime>,
          daysSupply: (convert R.dispenseRequest.expectedSupplyDuration to days).value,
          quantity: R.dispenseRequest.quantity,
          refills: Coalesce(R.dispenseRequest.numberOfRepeatsAllowed, 0),
          startDate:
            Coalesce(
              date from start of boundsPeriod,
              date from R.authoredOn,
              date from start of R.dispenseRequest.validityPeriod
            ),
          totalDaysSupplied: Coalesce(daysSupply, quantity.value / (dose.value * dosesPerDay)) * (1 + refills)
        return
          if startDate is not null and totalDaysSupplied is not null then
            Interval[startDate, startDate + Quantity(totalDaysSupplied - 1, 'day') ]
          else if startDate is not null and boundsPeriod."high" is not null then
            Interval[startDate, date from end of boundsPeriod]
          else
            null
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR diagnosisInPatientHistory
    define fluent function "diagnosisInPatientHistory"(Condition List<"Condition">):
      ( Condition ) Dx
        where Dx.prevalenceInterval ( ) starts on or before day of end of "Measurement Period"
    Library Name Name
    AppropriateDXAScansForWomenUnder65FHIR procedureInPatientHistory
    define fluent function "procedureInPatientHistory"(Procedure List<"Procedure">):
      ( ( Procedure ).isProcedurePerformed ( ) ) Proc
        where Proc.performed.toInterval ( ) ends on or before day of end of "Measurement Period"