Chronic Disease Surveillance
0.1.0 - CI Build International flag

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

Measure: Diabetes: Hemoglobin A1c (HbA1c) Poor Control (> 9%)FHIR

Official URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Measure/DiabetesHemoglobinA1cHbA1cPoorControl9FHIR Version: 0.1.0
Draft as of 2025-09-25 Computable Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
Other Identifiers: short-name#CMS122v11 (use: usual, ), publisher#001 (use: official, ), http://hl7.org/fhir/cqi/ecqm/Measure/Identifier/guid#f04ee808-8ece-4936-8b26-fafa462e1594 (use: official, )

Copyright/Legal: This Physician Performance Measure (Measure) and related data specifications are owned and were developed by the National Committee for Quality Assurance (NCQA). 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. NCQA holds a copyright in the Measure. The Measure can be reproduced and distributed, without modification, for noncommercial purposes (e.g., use by healthcare providers in connection with their practices) without obtaining approval from NCQA. Commercial use is defined as the sale, licensing, or distribution of the Measure for commercial gain, or incorporation of the Measure into a product or service that is sold, licensed or distributed for commercial gain. All commercial uses or requests for modification must be approved by NCQA and are subject to a license at the discretion of NCQA. (C) 2012-2020 National Committee for Quality Assurance. All Rights Reserved.

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) contained in the Measure specifications is copyright 2004-2020 American Medical Association. LOINC(R) copyright 2004-2020 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2020 International Health Terminology Standards Development Organisation. ICD-10 copyright 2020 World Health Organization. All Rights Reserved.

Percentage of patients 18-75 years of age with diabetes who had hemoglobin A1c > 9.0% during the measurement period

Unknown

Knowledge Artifact Metadata
Name (machine-readable) DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
Title (human-readable) Diabetes: Hemoglobin A1c (HbA1c) Poor Control (> 9%)FHIR
Status Draft
Experimental false
Description

Percentage of patients 18-75 years of age with diabetes who had hemoglobin A1c > 9.0% during the measurement period

Purpose

Unknown

Effective Period 2024-01-01..2024-12-31
Measure Steward Clinical Quality Framework
Steward Contact Details http://cqframework.org
Copyright

This Physician Performance Measure (Measure) and related data specifications are owned and were developed by the National Committee for Quality Assurance (NCQA). 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. NCQA holds a copyright in the Measure. The Measure can be reproduced and distributed, without modification, for noncommercial purposes (e.g., use by healthcare providers in connection with their practices) without obtaining approval from NCQA. Commercial use is defined as the sale, licensing, or distribution of the Measure for commercial gain, or incorporation of the Measure into a product or service that is sold, licensed or distributed for commercial gain. All commercial uses or requests for modification must be approved by NCQA and are subject to a license at the discretion of NCQA. (C) 2012-2020 National Committee for Quality Assurance. All Rights Reserved.

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) contained in the Measure specifications is copyright 2004-2020 American Medical Association. LOINC(R) copyright 2004-2020 Regenstrief Institute, Inc. This material contains SNOMED Clinical Terms(R) (SNOMED CT[R]) copyright 2004-2020 International Health Terminology Standards Development Organisation. ICD-10 copyright 2020 World Health Organization. All Rights Reserved.

Measure Metadata
Version Number 0.1.0
Measure Scoring Proportion
Measure Type intermediateOutcome
Rationale

Diabetes is the seventh leading cause of death in the United States. In 2017, diabetes affected approximately 34 million Americans (10.5 percent of the U.S. population) and killed approximately 84,000 people (Centers for Disease Control and Prevention [CDC], 2020a). Diabetes is a long-lasting disease marked by high blood glucose levels, resulting from the body's inability to produce or use insulin properly (CDC, 2020a). People with diabetes are at increased risk of serious health complications including vision loss, heart disease, stroke, kidney damage, and amputation of feet or legs (CDC, 2018).

In 2017, diabetes cost the U.S. an estimated $327 billion: $237 billion in direct medical costs and $90 billion in reduced productivity. This is a 34 percent increase from the estimated $245 billion spent on diabetes in 2012 (American Diabetes Association [ADA], 2018).

Controlling A1c blood levels helps reduce the risk of microvascular complications (eye, kidney and nerve diseases) (ADA, 2020).

Clinical Recommendation Statement

American Diabetes Association (2020):

  • An A1C goal for many nonpregnant adults of <7% (53 mmol/mol) is appropriate. (Level of evidence: A)

  • On the basis of provider judgement and patient preference, achievement of lower A1C goals (such as <6.5%) may be acceptable if this can be achieved safely without significant hypoglycemia or other adverse effects of treatment. (Level of evidence: C)

  • Less stringent A1C goals (such as <8% [64 mmol/mol]) may be appropriate for patients with a history of severe hypoglycemia, limited life expectancy, advanced microvascular or macrovascular complications, extensive comorbid conditions, or long-standing diabetes in whom the goal is difficult to achieve despite diabetes self-management education, appropriate glucose monitoring, and effective doses of multiple glucose-lowering agents including insulin. (Level of evidence: B)

Improvement Notation Lower score indicates better quality
Guidance

If the HbA1c test result is in the medical record, the test can be used to determine numerator compliance.

Only patients with a diagnosis of Type 1 or Type 2 diabetes should be included in the denominator of this measure; patients with a diagnosis of secondary diabetes due to another condition should not be included.

This eCQM is a patient-based measure.

This version of the eCQM uses QDM version 5.5. Please refer to the eCQI resource center (https://ecqi.healthit.gov/qdm) for more information on the QDM.

Measure Population Criteria
Initial Population ID: F09F8D18-F787-46EA-8791-3D3EF50A4C72
Description:

Seen patients between 18 and 75 years of age with an active diabetes diagnosis

Logic Definition: Initial Population
Denominator ID: 66505C6C-AAB0-4232-B0CA-15FB438090F4
Description:

Seen patients between 18 and 75 years of age with an active diabetes diagnosis

Logic Definition: Denominator
Numerator ID: 95BCB9D4-86A8-43C1-BE29-7440A2ECE294
Description:

Patients whose most recent HbA1c > 9%

Logic Definition: Numerator
Denominator Exclusions ID: 6AD9B271-BBB4-4BB6-95B1-D1A7E50D812F
Description:

Patients in hospice or long term care, or with advanced illness or frailty

Logic Definition: Denominator Exclusions
Stratifier ID: stratifier-ethnicity
Code: Ethnicity
Description: Ethnicity (CDC Value Set)
Stratifier ID: stratifier-payer
Code: SDE Payer
Description: Payer
Stratifier ID: stratifier-race
Code: SDE Race
Description: Race (CDC Value Set)
Stratifier ID: stratifier-sex
Code: Sex [HL7.v3]
Description: Administrative sex
Stratifier ID: stratifier-age
Code: Age
Description: Age
Stratifier ID: stratifier-state-of-residence
Code: State, district or territory federal abbreviation
Description: State of residence
Stratifier ID: stratifier-postal-code-of-residence
Code: Postal code
Description: Postal code of residence
Stratifier ID: stratifier-food-insecurity-risk-status
Code: Food insecurity risk [HVS]
Description: Food insecurity risk status
Supplemental Data Elements
Supplemental Data Element ID: sde-ethnicity
Usage Code: Supplemental Data
Description: Ethnicity (CDC Value Set)
Logic Definition: SDE Ethnicity
Supplemental Data Element ID: sde-payer
Usage Code: Supplemental Data
Description: Payer
Logic Definition: SDE Payer
Supplemental Data Element ID: sde-race
Usage Code: Supplemental Data
Description: Race (CDC Value Set)
Logic Definition: SDE Race
Supplemental Data Element ID: sde-sex
Usage Code: Supplemental Data
Description: Administrative sex
Logic Definition: SDE Sex
Supplemental Data Element ID: sde-age
Usage Code: Supplemental Data
Description: Age
Logic Definition: SDE Age
Supplemental Data Element ID: sde-state-of-residence
Usage Code: Supplemental Data
Description: State of residence
Logic Definition: SDE State of Residence
Supplemental Data Element ID: sde-postal-code-of-residence
Usage Code: Supplemental Data
Description: Postal code of residence
Logic Definition: SDE Postal Code of Residence
Supplemental Data Element ID: sde-food-insecurity-risk-status
Usage Code: Supplemental Data
Description: Food insecurity risk status
Logic Definition: SDE Food Insecurity Risk Status
Measure Logic
Primary Library DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
Dependency Description: Library SDE
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/SupplementalDataElementsFHIR4|2.0.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/SupplementalDataElementsFHIR4|2.0.000
Dependency Description: Library FHIRHelpers
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRHelpers|4.1.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRHelpers|4.1.000
Dependency Description: Library SurveillanceDataElements
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/SurveillanceDataElementsFHIR4|1.0.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/SurveillanceDataElementsFHIR4|1.0.000
Dependency Description: Library AC
Resource: AlphoraCommon
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/AlphoraCommon
Dependency Description: Library FC
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRCommon|1.1.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/FHIRCommon|1.1.000
Dependency Description: Library Common
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/MATGlobalCommonFunctionsFHIR4|6.0.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/MATGlobalCommonFunctionsFHIR4|6.0.000
Dependency Description: Library Hospice
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/HospiceFHIR4|2.0.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/HospiceFHIR4|2.0.000
Dependency Description: Library Frailty
Resource: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/AdvancedIllnessandFrailtyExclusionECQMFHIR4|5.12.000
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/AdvancedIllnessandFrailtyExclusionECQMFHIR4|5.12.000
Dependency Description: Library PalliativeCare
Resource: PalliativeCareFHIR
Canonical URL: http://fhir.org/guides/cqf/aphl/chronic-ds/Library/PalliativeCareFHIR
Dependency Description: Code system ObservationCategoryCodes
Resource: Observation Category Codes
Canonical URL: http://terminology.hl7.org/CodeSystem/observation-category
Dependency Description: Code system CPT
Resource: http://www.ama-assn.org/go/cpt
Canonical URL: http://www.ama-assn.org/go/cpt
Dependency Description: Code system HCPCS
Resource: http://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets
Canonical URL: http://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets
Dependency Description: Code system ConditionClinicalStatusCodes
Resource: Condition Clinical Status Codes
Canonical URL: http://terminology.hl7.org/CodeSystem/condition-clinical
Dependency Description: Code system ConditionVerificationStatusCodes
Resource: ConditionVerificationStatus
Canonical URL: http://terminology.hl7.org/CodeSystem/condition-ver-status
Dependency Description: Code system LOINC
Resource: http://loinc.org
Canonical URL: http://loinc.org
Dependency Description: Code system SNOMEDCT
Resource: SNOMED CT (all versions)
Canonical URL: http://snomed.info/sct
Dependency Description: Value set HbA1c Laboratory Test
Resource: HbA1c Laboratory Test
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1013
Dependency Description: Value set Office Visit
Resource: Office Visit
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001
Dependency Description: Value set Annual Wellness Visit
Resource: Annual Wellness Visit
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1240
Dependency Description: Value set Preventive Care Services - Established Office Visit, 18 and Up
Resource: Preventive Care Services - Established Office Visit, 18 and Up
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1025
Dependency Description: Value set Preventive Care Services - Initial Office Visit, 18 and Up
Resource: Preventive Care Services-Initial Office Visit, 18 and Up
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1023
Dependency Description: Value set Home Healthcare Services
Resource: Home Healthcare Services
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1016
Dependency Description: Value set Nutrition Services
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1006
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1006
Dependency Description: Value set Telephone Visits
Resource: Telephone Visits
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1080
Dependency Description: Value set Diabetes
Resource: Diabetes
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.103.12.1001
Dependency Description: Value set Payer
Resource: Payer
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591
Dependency Description: Value set Encounter Inpatient
Resource: Encounter Inpatient
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.666.5.307
Dependency Description: Value set Hospice Encounter
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1003
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1003
Dependency Description: Value set Hospice Care Ambulatory
Resource: Hospice care ambulatory
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.15
Dependency Description: Value set Hospice Diagnosis
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1165
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1165
Dependency Description: Value set Frailty Device
Resource: Frailty Device
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.118.12.1300
Dependency Description: Value set Frailty Diagnosis
Resource: Frailty Diagnosis
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.113.12.1074
Dependency Description: Value set Frailty Encounter
Resource: Frailty Encounter
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1088
Dependency Description: Value set Frailty Symptom
Resource: Frailty Symptom
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.113.12.1075
Dependency Description: Value set Outpatient
Resource: Outpatient
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1087
Dependency Description: Value set Observation
Resource: Observation
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1086
Dependency Description: Value set Emergency Department Visit
Resource: Emergency Department Visit
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1010
Dependency Description: Value set Nonacute Inpatient
Resource: Nonacute Inpatient
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1084
Dependency Description: Value set Advanced Illness
Resource: Advanced Illness
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.110.12.1082
Dependency Description: Value set Acute Inpatient
Resource: Acute Inpatient
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1083
Dependency Description: Value set Dementia Medications
Resource: Dementia Medications
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.196.12.1510
Dependency Description: Value set Palliative Care Diagnosis
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1167
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1167
Dependency Description: Value set Palliative Care Encounter
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1090
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1090
Dependency Description: Value set Palliative Care Intervention
Resource: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1135
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1135
Direct Reference Code Display: laboratory
Code: laboratory
System: http://terminology.hl7.org/CodeSystem/observation-category
Direct Reference Code Display: Medical nutrition therapy; initial assessment and intervention, individual, face-to-face with the patient, each 15 minutes
Code: 97802
System: http://www.ama-assn.org/go/cpt
Direct Reference Code Display: Medical nutrition therapy; re-assessment and intervention, individual, face-to-face with the patient, each 15 minutes
Code: 97803
System: http://www.ama-assn.org/go/cpt
Direct Reference Code Display: Medical nutrition therapy; group (2 or more individual(s)), each 30 minutes
Code: 97804
System: http://www.ama-assn.org/go/cpt
Direct Reference Code Display: Medical nutrition therapy; reassessment and subsequent intervention(s) following second referral in same year for change in diagnosis, medical condition or treatment regimen (including additional hours needed for renal disease), individual, face to face with the patient, each 15 minutes
Code: G0270
System: http://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets
Direct Reference Code Display: Medical nutrition therapy, reassessment and subsequent intervention(s) following second referral in same year for change in diagnosis, medical condition, or treatment regimen (including additional hours needed for renal disease), group (2 or more individuals), each 30 minutes
Code: G0271
System: http://www.cms.gov/Medicare/Coding/HCPCSReleaseCodeSets
Direct Reference Code Code: active
System: http://terminology.hl7.org/CodeSystem/condition-clinical
Direct Reference Code Code: confirmed
System: http://terminology.hl7.org/CodeSystem/condition-ver-status
Direct Reference Code Code: recurrence
System: http://terminology.hl7.org/CodeSystem/condition-clinical
Direct Reference Code Code: relapse
System: http://terminology.hl7.org/CodeSystem/condition-clinical
Direct Reference Code Display: Food insecurity risk [HVS]
Code: 88124-3
System: http://loinc.org
Direct Reference Code Display: Discharge to home for hospice care (procedure)
Code: 428361000124107
System: http://snomed.info/sct
Direct Reference Code Display: Discharge to healthcare facility for hospice care (procedure)
Code: 428371000124100
System: http://snomed.info/sct
Direct Reference Code Display: Hospice care [Minimum Data Set]
Code: 45755-6
System: http://loinc.org
Direct Reference Code Display: Yes (qualifier value)
Code: 373066001
System: http://snomed.info/sct
Direct Reference Code Display: Housing status
Code: 71802-3
System: http://loinc.org
Direct Reference Code Display: Lives in a nursing home (finding)
Code: 160734000
System: http://snomed.info/sct
Direct Reference Code Display: Medical equipment used
Code: 98181-1
System: http://loinc.org
Direct Reference Code Display: Functional Assessment of Chronic Illness Therapy - Palliative Care Questionnaire (FACIT-Pal)
Code: 71007-9
System: http://loinc.org
Parameter Name: Measurement Period
Use: In
Min Cardinality: 0
Max Cardinality: 1
Type: Period
Parameter Name: SDE Sex
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: Coding
Parameter Name: SDE Postal Code of Residence
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: Numerator
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: Denominator
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: SDE Payer
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Resource
Parameter Name: SDE State of Residence
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: string
Parameter Name: SDE Food Insecurity Risk Status
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: CodeableConcept
Parameter Name: Initial Population
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: SDE Ethnicity
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Coding
Parameter Name: SDE Age
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: integer
Parameter Name: Denominator Exclusions
Use: Out
Min Cardinality: 0
Max Cardinality: 1
Type: boolean
Parameter Name: SDE Race
Use: Out
Min Cardinality: 0
Max Cardinality: *
Type: Coding
Measure Logic Data Requirements
Data Requirement Type: Patient
Profile(s): Patient
Must Support Elements: use, type, url, extension, value
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, value, effective, status, category
Code Filter(s):
Path: code
Code:
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, effective, value, status, category
Code Filter(s):
Path: code
Code:
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, value, effective, status, category
Code Filter(s):
Path: code
Code:
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, effective, status, category
Code Filter(s):
Path: code
ValueSet: Frailty Symptom
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, effective, status, category
Code Filter(s):
Path: code
Code:
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, status, category, effective
Code Filter(s):
Path: code
ValueSet: HbA1c Laboratory Test
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, status, category
Code Filter(s):
Path: code
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Office Visit
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Annual Wellness Visit
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Preventive Care Services - Established Office Visit, 18 and Up
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Preventive Care Services-Initial Office Visit, 18 and Up
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Home Healthcare Services
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1006
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
Code:
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Telephone Visits
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, hospitalization, hospitalization.dischargeDisposition, period, status
Code Filter(s):
Path: type
ValueSet: Encounter Inpatient
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1003
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Frailty Encounter
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Outpatient
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Observation
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Emergency Department Visit
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Nonacute Inpatient
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: Acute Inpatient
Data Requirement Type: Encounter
Profile(s): Encounter
Must Support Elements: type, period, status
Code Filter(s):
Path: type
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1090
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code, clinicalStatus, verificationStatus
Code Filter(s):
Path: code
ValueSet: Diabetes
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code, clinicalStatus, verificationStatus
Code Filter(s):
Path: code
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1165
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code, clinicalStatus, verificationStatus
Code Filter(s):
Path: code
ValueSet: Frailty Diagnosis
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code, clinicalStatus, verificationStatus
Code Filter(s):
Path: code
ValueSet: Advanced Illness
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code, clinicalStatus, verificationStatus
Code Filter(s):
Path: code
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.1167
Data Requirement Type: Coverage
Profile(s): Coverage
Must Support Elements: type, period
Code Filter(s):
Path: type
ValueSet: Payer
Data Requirement Type: ServiceRequest
Profile(s): ServiceRequest
Must Support Elements: code, authoredOn, status, intent, doNotPerform
Code Filter(s):
Path: code
ValueSet: Hospice care ambulatory
Data Requirement Type: Procedure
Profile(s): Procedure
Must Support Elements: code, performed, status
Code Filter(s):
Path: code
ValueSet: Hospice care ambulatory
Data Requirement Type: Procedure
Profile(s): Procedure
Must Support Elements: code, performed, status
Code Filter(s):
Path: code
ValueSet: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1135
Data Requirement Type: DeviceRequest
Profile(s): DeviceRequest
Must Support Elements: code, status, intent, authoredOn
Code Filter(s):
Path: code
ValueSet: Frailty Device
Data Requirement Type: MedicationRequest
Profile(s): MedicationRequest
Must Support Elements: medication, status, doNotPerform, intent, dosageInstruction
Code Filter(s):
Path: medication
ValueSet: Dementia Medications
Data Requirement Type: MedicationRequest
Profile(s): MedicationRequest
Must Support Elements: medication.reference, status, doNotPerform, intent, dosageInstruction
Data Requirement Type: Medication
Profile(s): Medication
Must Support Elements: id, code
Measure Logic Definitions
Logic Definition Library Name: SupplementalDataElementsFHIR4
define "SDE Sex":
  case
      when Patient.gender = 'male' then Code { code: 'M', system: 'http://hl7.org/fhir/v3/AdministrativeGender', display: 'Male' }
      when Patient.gender = 'female' then Code { code: 'F', system: 'http://hl7.org/fhir/v3/AdministrativeGender', display: 'Female' }
      else null
    end
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Sex":
  SDE."SDE Sex"
Logic Definition Library Name: SurveillanceDataElementsFHIR4
// Jurisdiction of residence (jurisdiction of the patient)
define "Most recent physical home address":
  First(
    Patient.address A
      where A.use = 'home'
        and A.type = 'physical'
      sort by end of period desc
  )
Logic Definition Library Name: SurveillanceDataElementsFHIR4
define "Postal Code of Residence":
  "Most recent physical home address".postalCode
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Postal Code of Residence":
  SurveillanceDataElements."Postal Code of Residence"
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Has HbA1c Lab Test":
  (AC.LaboratoryObservation([Observation: "HbA1c Laboratory Test"]))
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Most Recent HbA1c Lab Test":
  AC.MostRecent("Has HbA1c Lab Test" HbA1cTest
    where FC.ToInterval(HbA1cTest.effective) during "Measurement Period")
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Has Most Recent HbA1c Without Result":
  ("Most Recent HbA1c Lab Test" is not null)
    and ("Most Recent HbA1c Lab Test".value is null)
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Has Most Recent Elevated HbA1c":
  "Most Recent HbA1c Lab Test".value >= 9 '%'
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Has No Record Of HbA1c":
  not exists("Has HbA1c Lab Test")
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Numerator":
  "Has Most Recent HbA1c Without Result"
    or "Has Most Recent Elevated HbA1c"
    or "Has No Record Of HbA1c"
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Qualifying Encounters":
  (
    [Encounter: "Office Visit"]
	    union [Encounter: "Annual Wellness Visit"]
	    union [Encounter: "Preventive Care Services - Established Office Visit, 18 and Up"]
      union [Encounter: "Preventive Care Services - Initial Office Visit, 18 and Up"]
      union [Encounter: "Home Healthcare Services"]
      union [Encounter: "Nutrition Services"]
      union [Encounter: "Medical nutrition therapy; initial assessment and intervention, individual, face-to-face with the patient, each 15 minutes"]
      union [Encounter: "Medical nutrition therapy; re-assessment and intervention, individual, face-to-face with the patient, each 15 minutes"]
      union [Encounter: "Medical nutrition therapy; group (2 or more individual(s)), each 30 minutes"]
      union [Encounter: "Medical nutrition therapy; reassessment and subsequent intervention(s) following second referral in same year for change in diagnosis, medical condition or treatment regimen (including additional hours needed for renal disease), individual, face to face with the patient, each 15 minutes"]
      union [Encounter: "Medical nutrition therapy, reassessment and subsequent intervention(s) following second referral in same year for change in diagnosis, medical condition, or treatment regimen (including additional hours needed for renal disease), group (2 or more individuals), each 30 minutes"]
      union [Encounter: "Telephone Visits"]
  ) ValidEncounters
    where ValidEncounters.period during "Measurement Period"
	  and ValidEncounters.status ~ 'finished'
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Initial Population":
  AgeInYearsAt(end of "Measurement Period") in Interval[18, 75]
    and exists("Qualifying Encounters")
    and exists( (AC.QualifiedConditions([Condition: "Diabetes"])) Diabetes
      where FC.ToPrevalenceInterval(Diabetes) overlaps "Measurement Period" )
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Denominator":
  "Initial Population"
Logic Definition Library Name: SupplementalDataElementsFHIR4
define "SDE Payer":
  [Coverage: type in "Payer"] Payer
        return {
          code: Payer.type,
          period: Payer.period
        }
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Payer":
  SDE."SDE Payer"
Logic Definition Library Name: SurveillanceDataElementsFHIR4
define "State of Residence":
  "Most recent physical home address".state
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE State of Residence":
  SurveillanceDataElements."State of Residence"
Logic Definition Library Name: SurveillanceDataElementsFHIR4
// Jurisdiction of care (jurisdiction of the most recent encounter)
// TODO:
//define "Most recent address of care":

// NOTE: Included in eICR
// Occupational Data for Health - Past or Present Job
// http://hl7.org/fhir/us/odh/StructureDefinition-odh-PastOrPresentJob.html
// Observation: LOINC#11341-5, valueCodeableConcept in https://phinvads.cdc.gov/vads/ViewValueSet.action?oid=2.16.840.1.114222.4.11.7186

// Social Determinants of Health (SDOH)
// http://build.fhir.org/ig/HL7/fhir-sdoh-clinicalcare/StructureDefinition-SDOHCC-ObservationScreeningResponse.html
// Food insecurity risk: http://build.fhir.org/ig/HL7/fhir-sdoh-clinicalcare/Observation-SDOHCC-ObservationResponseHungerVitalSignQuestion3Example.html
// Observation: LOINC#88124-3, valueCodeableConcept in https://loinc.org/LL2510-7/ (At risk, No risk)
define "Food Insecurity Risk Status":
  First(
    [Observation: "Food insecurity risk [HVS]"] O
      sort by issued desc
  ).value as CodeableConcept
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Food Insecurity Risk Status":
  SurveillanceDataElements."Food Insecurity Risk Status"
Logic Definition Library Name: SupplementalDataElementsFHIR4
define "SDE Ethnicity":
  (flatten (
      Patient.extension Extension
        where Extension.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity'
          return Extension.extension
    )) E
      where E.url = 'ombCategory'
        or E.url = 'detailed'
      return E.value as Coding
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Ethnicity":
  SDE."SDE Ethnicity"
Logic Definition Library Name: SurveillanceDataElementsFHIR4
// Age
define "Age":
  AgeInYearsAt(end of "Measurement Period")
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Age":
  SurveillanceDataElements."Age"
Logic Definition Library Name: HospiceFHIR4
define "Has Hospice":
  exists(
    (AC.QualifiedEncounters([Encounter: "Encounter Inpatient"])) HospiceInp
      where (HospiceInp.hospitalization.dischargeDisposition ~ "Discharge to home for hospice care (procedure)"
        or HospiceInp.hospitalization.dischargeDisposition ~ "Discharge to healthcare facility for hospice care (procedure)")
      and FC.ToInterval(HospiceInp.period) ends during "Measurement Period"
  ) or exists(
    (AC.QualifiedEncounters([Encounter: "Hospice Encounter"])) HospiceEnc
      where FC.ToInterval(HospiceEnc.period) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedObservations([Observation: "Hospice care [Minimum Data Set]"])) HospiceObs
      where HospiceObs.value ~ ToConcept("Yes (qualifier value)")
        and FC.ToInterval(HospiceObs.effective) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedServiceRequests([ServiceRequest: "Hospice Care Ambulatory"])) HospiceSR
      where FC.ToInterval(HospiceSR.authoredOn) during "Measurement Period"
  ) or exists(
    (AC.QualifiedProcedures([Procedure: "Hospice Care Ambulatory"])) HospiceProc
      where FC.ToInterval(HospiceProc.performed) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedConditions([Condition: "Hospice Diagnosis"])) HospiceCareDiagnosis
      where FC.ToPrevalenceInterval(HospiceCareDiagnosis) overlaps "Measurement Period"
  )
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Lives In A Nursing Home":
  Last(
    (AC.QualifiedObservations([Observation: "Housing Status"])) HousingStatus
      where FC.ToInterval(HousingStatus.effective) ends on or before end of "Measurement Period"
        and HousingStatus.value ~ ToConcept("Lives In A Nursing Home (finding)")
    sort by issued ascending
  ) is not null
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Is Age 66 or Older Living Long Term in a Nursing Home":
  AgeInYearsAt(date from end of "Measurement Period") >= 66
    and "Lives In A Nursing Home"
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Has Criteria Indicating Frailty":
  exists(
    (AC.QualifiedDeviceRequests([DeviceRequest: "Frailty Device"])) FrailtyDeviceOrder
      where FrailtyDeviceOrder.authoredOn during day of "Measurement Period"
    ) 
    or exists(
        (AC.QualifiedObservations([Observation: "Medical Equipment Used"])) EquipmentUsed
          where EquipmentUsed.value in "Frailty Device"
            and FC.ToInterval(EquipmentUsed.effective) ends during day of "Measurement Period"
    )
    or exists(
      (AC.QualifiedConditions([Condition: "Frailty Diagnosis"])) FrailtyDiagnosis
        where FC.ToPrevalenceInterval(FrailtyDiagnosis) overlaps "Measurement Period"
    )
    or exists(
      (AC.QualifiedEncounters([Encounter: "Frailty Encounter"])) FrailtyEnc
        where FC.ToInterval(FrailtyEnc.period) overlaps "Measurement Period"
    )
    or exists(
      (AC.QualifiedObservations([Observation: "Frailty Symptom"])) FrailtySymptom
        where FC.ToInterval(FrailtySymptom.effective) overlaps "Measurement Period"
    )
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Up To One Year Prior Including Measurement Period":
  Interval[start of "Measurement Period" - 1 year, end of "Measurement Period"]
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Outpatient Encounters With Advanced Illness":
  ((AC.QualifiedEncounters([Encounter: "Outpatient"]))
    union (AC.QualifiedEncounters([Encounter: "Observation"]))
    union (AC.QualifiedEncounters([Encounter: "Emergency Department Visit"]))
    union (AC.QualifiedEncounters([Encounter: "Nonacute Inpatient"]))) OutpatientEnc
      with (AC.QualifiedConditions([Condition: "Advanced Illness"])) AdvanIll
        such that FC.ToPrevalenceInterval(AdvanIll) overlaps "Measurement Period"
      and FC.ToInterval(OutpatientEnc.period) overlaps "Up To One Year Prior Including Measurement Period"
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Has Two Outpatient Encounters With Advanced Illness on Different Dates of Service":
  from
    "Outpatient Encounters With Advanced Illness" OutpatientEncounter1,
    "Outpatient Encounters With Advanced Illness" OutpatientEncounter2
  where OutpatientEncounter2.period ends 1 day or more after day of end of OutpatientEncounter1.period
  return OutpatientEncounter1
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Has Inpatient Encounter With Advanced Illness":  
  (AC.QualifiedEncounters([Encounter: "Acute Inpatient"])) InpatientEnc
    with (AC.QualifiedConditions([Condition: "Advanced Illness"])) AdvanIll
      such that FC.ToPrevalenceInterval(AdvanIll) overlaps InpatientEnc.period
        and FC.ToInterval(InpatientEnc.period) overlaps "Up To One Year Prior Including Measurement Period"
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Has Dementia Medications In Year Before or During Measurement Period":
  (AC.QualifiedMedicationRequests([MedicationRequest: "Dementia Medications"])) DementiaMed
    where exists(
      DementiaMed.dosageInstruction dosage
      where exists(
        FC.ToTimingInterval(dosage.timing)) timing
        where timing overlaps "Up To One Year Prior Including Measurement Period")
Logic Definition Library Name: AdvancedIllnessandFrailtyExclusionECQMFHIR4
define "Is Age 66 or Older with Advanced Illness and Frailty":
  AgeInYearsAt(date from end of "Measurement Period") >= 66
    and "Has Criteria Indicating Frailty"
    and (
      exists("Has Two Outpatient Encounters With Advanced Illness on Different Dates of Service")
      or exists("Has Inpatient Encounter With Advanced Illness")
        or exists("Has Dementia Medications In Year Before or During Measurement Period")
    )
Logic Definition Library Name: PalliativeCareFHIR
define "Palliative Care in the Measurement Period":
  exists(
    (AC.QualifiedObservations([Observation: "Functional Assessment of Chronic Illness Therapy - Palliative Care Questionnaire (FACIT-Pal)"])) PalliativeObservation
      where FC.ToInterval(PalliativeObservation.effective) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedConditions([Condition: "Palliative Care Diagnosis"])) PalliativeDiagnosis
      where FC.ToPrevalenceInterval(PalliativeDiagnosis) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedEncounters([Encounter: "Palliative Care Encounter"])) PalliativeEncounter
      where FC.ToInterval(PalliativeEncounter.period) overlaps "Measurement Period"
  ) or exists(
    (AC.QualifiedProcedures([Procedure: "Palliative Care Intervention"])) PalliativeProcedure
      where FC.ToInterval(PalliativeProcedure.performed) overlaps "Measurement Period"
  )
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "Denominator Exclusions":
  Hospice."Has Hospice"
    or Frailty."Is Age 66 or Older Living Long Term in a Nursing Home"
    or Frailty."Is Age 66 or Older with Advanced Illness and Frailty"
    or PalliativeCare."Palliative Care in the Measurement Period"
Logic Definition Library Name: SupplementalDataElementsFHIR4
define "SDE Race":
  (flatten (
      Patient.extension Extension
        where Extension.url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race'
          return Extension.extension
    )) E
      where E.url = 'ombCategory'
        or E.url = 'detailed'
      return E.value as Coding
Logic Definition Library Name: DiabetesHemoglobinA1cHbA1cPoorControl9FHIR
define "SDE Race":
  SDE."SDE Race"
Logic Definition Library Name: FHIRHelpers
define function ToString(value AdministrativeGender): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value AddressUse): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value AddressType): value.value
Logic Definition Library Name: FHIRHelpers
define function ToInterval(period FHIR.Period):
    if period is null then
        null
    else
        if period."start" is null then
            Interval(period."start".value, period."end".value]
        else
            Interval[period."start".value, period."end".value]
Logic Definition Library Name: AlphoraCommon
define function MostRecent(observations List<Observation>):
  Last(
    observations O
      sort by start of FC.ToInterval(effective)
  )
Logic Definition Library Name: AlphoraCommon
define function LaboratoryObservation(value List<FHIR.Observation>):
  value Observation
  		where (
      //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown
      Observation.status ~ 'final'
			or Observation.status ~ 'amended'
			or Observation.status ~ 'corrected'
      and exists(Observation.category ObservationCategory
        where ( ObservationCategory ) ~ "laboratory" or (ObservationCategory) is null)
		)
Logic Definition Library Name: FHIRHelpers
define function ToString(value ObservationStatus): value.value
Logic Definition Library Name: FHIRHelpers
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
        }
Logic Definition Library Name: FHIRHelpers
define function ToCode(coding FHIR.Coding):
    if coding is null then
        null
    else
        System.Code {
          code: coding.code.value,
          system: coding.system.value,
          version: coding.version.value,
          display: coding.display.value
        }
Logic Definition Library Name: FHIRHelpers
define function ToQuantity(quantity FHIR.Quantity):
    case
        when quantity is null then null
        when quantity.value is null then null
        when quantity.comparator is not null then
            Message(null, true, 'FHIRHelpers.ToQuantity.ComparatorQuantityNotSupported', 'Error', 'FHIR Quantity value has a comparator and cannot be converted to a System.Quantity value.')
        when quantity.system is null or quantity.system.value = 'http://unitsofmeasure.org'
              or quantity.system.value = 'http://hl7.org/fhirpath/CodeSystem/calendar-units' then
            System.Quantity { value: quantity.value.value, unit: ToCalendarUnit(Coalesce(quantity.code.value, quantity.unit.value, '1')) }
        else
            Message(null, true, 'FHIRHelpers.ToQuantity.InvalidFHIRQuantity', 'Error', 'Invalid FHIR Quantity code: ' & quantity.unit.value & ' (' & quantity.system.value & '|' & quantity.code.value & ')')
    end
Logic Definition Library Name: FHIRHelpers
define function ToCalendarUnit(unit System.String):
    case unit
        when 'ms' then 'millisecond'
        when 's' then 'second'
        when 'min' then 'minute'
        when 'h' then 'hour'
        when 'd' then 'day'
        when 'wk' then 'week'
        when 'mo' then 'month'
        when 'a' then 'year'
        else unit
    end
Logic Definition Library Name: FHIRHelpers
define function ToString(value EncounterStatus): value.value
Logic Definition Library Name: AlphoraCommon
define function QualifiedConditions(value List<FHIR.Condition>):
  value Condition
    where (
      FHIRHelpers.ToConcept(Condition.clinicalStatus) ~ FC."active"
    )
    and (
      FHIRHelpers.ToConcept(Condition.verificationStatus) ~ FC."confirmed"
    )
Logic Definition Library Name: FHIRCommon
/*
@description: Returns an interval representing the normalized prevalence period of a given Condition resource.
@comment: Uses the ToInterval and ToAbatementInterval functions to determine the widest potential interval from
onset to abatement as specified in the given Condition.
*/
define function ToPrevalenceInterval(condition Condition):
if condition.clinicalStatus ~ "active"
  or condition.clinicalStatus ~ "recurrence"
  or condition.clinicalStatus ~ "relapse" then
  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition)]
else
  Interval[start of ToInterval(condition.onset), end of ToAbatementInterval(condition))
Logic Definition Library Name: FHIRCommon
/*
@description: Returns an interval representing the normalized Abatement of a given Condition resource.
@comment: NOTE: Due to the complexity of determining an interval from a String, this function will throw
a run-time exception if used with a Condition instance that has a String as the abatement value.
*/
define function ToAbatementInterval(condition Condition):
	if condition.abatement is FHIR.dateTime then
	  Interval[FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime), FHIRHelpers.ToDateTime(condition.abatement as FHIR.dateTime)]
	else if condition.abatement is FHIR.Period then
	  FHIRHelpers.ToInterval(condition.abatement as FHIR.Period)
	else if condition.abatement is FHIR.string then
    Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute an interval from a String value')
	else if condition.abatement is FHIR.Age then
		Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age),
			FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(condition.abatement as FHIR.Age) + 1 year)
	else if condition.abatement is FHIR.Range then
	  Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).low),
		  FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((condition.abatement as FHIR.Range).high) + 1 year)
	else if condition.abatement is FHIR.boolean then
	  Interval[end of ToInterval(condition.onset), condition.recordedDate)
	else null
Logic Definition Library Name: FHIRHelpers
define function ToDateTime(value dateTime): value.value
Logic Definition Library Name: FHIRHelpers
define function ToDate(value date): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value uri): value.value
Logic Definition Library Name: AlphoraCommon
/* Common Resource Qualifications and Negations */
define function QualifiedEncounters(value List<FHIR.Encounter>):
  value Encounter
    where (
      //planned | arrived | triaged | in-progress | onleave | finished | cancelled | entered-in-error | unknown
      Encounter.status ~ 'arrived'
      or Encounter.status ~ 'in-progress'
      or Encounter.status ~ 'finished'
      or Encounter.status ~ 'onleave'
      or Encounter.status ~ 'triaged'
    )
Logic Definition Library Name: FHIRCommon
/*
@description: Normalizes a value that is a choice of timing-valued types to an equivalent interval
@comment: Normalizes a choice type of FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instance, FHIR.string, FHIR.Age, or FHIR.Range 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 FHIR, allowing this function to be used across any resource.

The input can be provided as a dateTime, Period, Timing, instant, string, Age, or Range.
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 Period, the result is a DateTime Interval.
If the input is a Timing, an error is raised indicating a single interval cannot be computed from a Timing.
If the input is an instant, the result is a DateTime Interval beginning and ending on that instant.
If the input is a string, an error is raised indicating a single interval cannot be computed from a string.
If the input is an Age, the result is a DateTime Interval beginning when the patient was the given Age,
and ending immediately prior to when the patient was the given Age plus one year.
If the input is a Range, the result is a DateTime Interval beginning when the patient was the Age given
by the low end of the Range, and ending immediately prior to when the patient was the Age given by the
high end of the Range plus one year.

NOTE: Due to the
complexity of determining a single interval from a Timing or String type, this function will throw a run-time exception if it is used
with a Timing or String.
*/
define function ToInterval(choice Choice<FHIR.dateTime, FHIR.Period, FHIR.Timing, FHIR.instant, FHIR.string, FHIR.Age, FHIR.Range>):
  case
	  when choice is FHIR.dateTime then
    	Interval[FHIRHelpers.ToDateTime(choice as FHIR.dateTime), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]
		when choice is FHIR.Period then
  		FHIRHelpers.ToInterval(choice as FHIR.Period)
		when choice is FHIR.instant then
			Interval[FHIRHelpers.ToDateTime(choice as FHIR.instant), FHIRHelpers.ToDateTime(choice as FHIR.instant)]
		when choice is FHIR.Age then
		  Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age),
			  FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity(choice as FHIR.Age) + 1 year)
		when choice is FHIR.Range then
		  Interval[FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).low),
			  FHIRHelpers.ToDate(Patient.birthDate) + FHIRHelpers.ToQuantity((choice as FHIR.Range).high) + 1 year)
		when choice is FHIR.Timing then
			//Interval[FHIRHelpers.ToDateTime(choice as FHIR.timing), FHIRHelpers.ToDateTime(choice as FHIR.dateTime)]
		  Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute a single interval from a Timing type')
    when choice is FHIR.string then
      Message(null as Interval<DateTime>, true, '1', 'Error', 'Cannot compute an interval from a String value')
		else
			null as Interval<DateTime>
	end
Logic Definition Library Name: FHIRHelpers
define function ToDateTime(value instant): value.value
Logic Definition Library Name: AlphoraCommon
define function QualifiedObservations(value List<FHIR.Observation>):
  value Observation
		where (
      //registered | preliminary | final | amended | corrected | cancelled | entered-in-error | unknown
      Observation.status ~ 'final'
			or Observation.status ~ 'amended'
			or Observation.status ~ 'corrected'
		)
Logic Definition Library Name: AlphoraCommon
define function QualifiedServiceRequests(value List<FHIR.ServiceRequest>):
  value ServiceRequest
    where (
      //draft | active | on-hold | revoked | completed | entered-in-error | unknown
      ServiceRequest.status ~ 'active'
      or ServiceRequest.status ~ 'completed'
      and ServiceRequest.intent ~ 'order'
    )
    and (
      ServiceRequest.doNotPerform is null
      or ServiceRequest.doNotPerform = false
    )
Logic Definition Library Name: FHIRHelpers
define function ToString(value ServiceRequestStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value ServiceRequestIntent): value.value
Logic Definition Library Name: FHIRHelpers
define function ToBoolean(value boolean): value.value
Logic Definition Library Name: AlphoraCommon
define function QualifiedProcedures(value List<FHIR.Procedure>):
  value Procedure
    where (
      //preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown
      Procedure.status ~ 'completed'
    )
Logic Definition Library Name: FHIRHelpers
define function ToString(value ProcedureStatus): value.value
Logic Definition Library Name: AlphoraCommon
define function QualifiedDeviceRequests(value List<FHIR.DeviceRequest>):
  value DeviceRequest
    where (
      //draft | active | on-hold | revoked | completed | entered-in-error | unknown
      DeviceRequest.status ~ 'completed'
      or DeviceRequest.status ~ 'active'
      and DeviceRequest.intent ~ 'order'
    )
Logic Definition Library Name: FHIRHelpers
define function ToString(value DeviceRequestStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value RequestIntent): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value string): value.value
Logic Definition Library Name: AlphoraCommon
define function QualifiedMedicationRequests(value List<FHIR.MedicationRequest>):
  value MedicationRequest
    where (
      //active | on-hold | cancelled | completed | entered-in-error | stopped | draft | unknown
      (MedicationRequest.status ~ 'active'
        or MedicationRequest.status ~ 'completed'
      )
        and (
          MedicationRequest.doNotPerform is null
          or MedicationRequest.doNotPerform = false
        )
        and MedicationRequest.intent ~ 'order'
    )
Logic Definition Library Name: FHIRHelpers
define function ToString(value MedicationRequestStatus): value.value
Logic Definition Library Name: FHIRHelpers
define function ToString(value MedicationRequestIntent): value.value
Logic Definition Library Name: FHIRCommon
define function ToTimingInterval(timing FHIR.Timing):
  convert (
    NullToEmptyInterval(ToIntervalFromList(timing.event))
    union NullToEmptyInterval({ToInterval(timing.repeat.bounds as FHIR.Period)})
  ) to List<Interval<DateTime>> except { null }
Logic Definition Library Name: FHIRCommon
define function NullToEmptyInterval(value List<Interval<DateTime>>):
  if value is not null then value else { }
Logic Definition Library Name: FHIRCommon
define function ToIntervalFromList(value List<FHIR.dateTime>):
  value v
    return ToInterval(v)
Generated using version 0.4.6 of the sample-content-ig Liquid templates