eCQM QICore Content Implementation Guide
2025.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 2025.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-2025/ and changes regularly. See the Directory of published versions

Library: CMS22FHIRPCSBPScreeningFollowUp

Official URL: https://madie.cms.gov/Library/CMS22FHIRPCSBPScreeningFollowUp Version: 0.3.000
Active as of 2025-04-28 Responsible: American Institutes for Research (AIR) Computable Name: CMS22FHIRPCSBPScreeningFollowUp
Other Identifiers: https://madie.cms.gov/login#CMS22FHIRPCSBPScreeningFollowUp (use: official, )

CMS22FHIRPCSBPScreeningFollowUp

Title: CMS22FHIRPCSBPScreeningFollowUp
Id: CMS22FHIRPCSBPScreeningFollowUp
Version: 0.3.000
Url: https://madie.cms.gov/Library/CMS22FHIRPCSBPScreeningFollowUp
official

CMS22FHIRPCSBPScreeningFollowUp

Type:

system: http://terminology.hl7.org/CodeSystem/library-type

code: logic-library

Date: 2025-04-28T21:31:32+00:00
Publisher: American Institutes for Research (AIR)
Description: CMS22FHIRPCSBPScreeningFollowUp
Related Artifacts:

Dependencies

  • https://madie.cms.gov/Library/SupplementalDataElements|5.1.000
  • https://madie.cms.gov/Library/FHIRHelpers|4.4.000
  • https://madie.cms.gov/Library/QICoreCommon|4.0.000
  • http://terminology.hl7.org/CodeSystem/v3-ActCode
  • http://loinc.org
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1920
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.125
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1581
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1510
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1515
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1518
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1583
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1580
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1047.514
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1578
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1482
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.1577
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.263
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1582
  • http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1007
Data Requirements:
TypeProfileMSCode Filter
Patient http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-patient ;;
Observation http://hl7.org/fhir/us/core/StructureDefinition/us-core-blood-pressure ;;;;
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1581
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1510
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1515
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1518
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1583
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.125
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1578
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code

system: http://loinc.org

code: 34534-8

display: EKG 12 channel panel

ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code

system: http://loinc.org

code: 11524-6

display: EKG study

ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1482
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicerequest ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1580
Encounter http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter ;;;;; code filter:
path: type
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1920
MedicationRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest ; code filter:
path: medication
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.1577
MedicationRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationrequest ;
Medication http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medication ;;
Coverage http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-coverage ;; code filter:
path: type
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591
Condition http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-condition-problems-health-concerns ; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.263
Observation http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-observationcancelled ; code filter:
path: code

system: http://loinc.org

code: 85354-9

display: Blood pressure panel with all children optional

Observation http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-observationcancelled ; code filter:
path: code

system: http://loinc.org

code: 8480-6

display: Systolic blood pressure

Observation http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-observationcancelled ; code filter:
path: code

system: http://loinc.org

code: 8462-4

display: Diastolic blood pressure

ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1581
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1581
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1510
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1510
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1515
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1515
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1518
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1518
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1583
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1583
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.125
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.125
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code

system: http://loinc.org

code: 34534-8

display: EKG 12 channel panel

ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code

system: http://loinc.org

code: 11524-6

display: EKG study

ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1482
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1482
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1580
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1580
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1578
ServiceRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-servicenotrequested ;;;;;; code filter:
path: code
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1578
MedicationRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationnotrequested ;;; code filter:
path: medication
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.1577
MedicationRequest http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-medicationnotrequested ;;; code filter:
path: medication
value set: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.1577
Content: text/cql
library CMS22FHIRPCSBPScreeningFollowUp version '0.3.000'

using QICore version '6.0.0'
using USCore version '6.1.0'

include FHIRHelpers version '4.4.000' called FHIRHelpers
include SupplementalDataElements version '5.1.000' called SDE
include QICoreCommon version '4.0.000' called QICoreCommon

codesystem "ActCode": 'http://terminology.hl7.org/CodeSystem/v3-ActCode'
codesystem "LOINC": 'http://loinc.org'
codesystem "SNOMEDCT": 'http://snomed.info/sct'

valueset "Diagnosis of Hypertension": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.263'
valueset "Dietary Recommendations": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1515'
valueset "Encounter to Screen for Blood Pressure": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1920'
valueset "Finding of Elevated Blood Pressure or Hypertension": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1047.514'
valueset "Follow Up Within 4 Weeks": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1578'
valueset "Follow Up Within 6 Months": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1108.125'
valueset "Laboratory Tests for Hypertension": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1482'
valueset "Lifestyle Recommendation": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1581'
valueset "Medical Reason": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1007'
valueset "Patient Declined": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1582'
valueset "Pharmacologic Therapy for Hypertension": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.1577'
valueset "Recommendation to Increase Physical Activity": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1518'
valueset "Referral or Counseling for Alcohol Consumption": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1583'
valueset "Referral to Primary Care or Alternate Provider": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.1580'
valueset "Weight Reduction Recommended": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1510'

code "Blood pressure panel with all children optional": '85354-9' from "LOINC" display 'Blood pressure panel with all children optional'
code "Diastolic blood pressure": '8462-4' from "LOINC" display 'Diastolic blood pressure'
code "12 lead EKG panel": '34534-8' from "LOINC" display 'EKG 12 channel panel'
code "EKG study": '11524-6' from "LOINC" display 'EKG study'
code "Systolic blood pressure": '8480-6' from "LOINC" display 'Systolic blood pressure'
code "virtual": 'VR' from "ActCode" display 'virtual'

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Initial Population":
  "Qualifying Encounter during Measurement Period" QualifyingEncounter
    where AgeInYearsAt(date from start of "Measurement Period") >= 18

define "Denominator":
  "Initial Population"

define "Denominator Exclusions":
  "Qualifying Encounter during Measurement Period" QualifyingEncounter
    with [ConditionProblemsHealthConcerns: "Diagnosis of Hypertension"] Hypertension
      such that ( Hypertension.isProblemListItem ( )
          or Hypertension.isHealthConcern ( )
      )
        and Hypertension.prevalenceInterval ( ) starts before or on day of QualifyingEncounter.period

define "Numerator":
  "Encounter with Normal Blood Pressure Reading"
    union ( "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80 and Interventions" )
    union ( "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80 and Interventions" )
    union ( "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 and Interventions" )
    union ( "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 and Interventions" )

define "Denominator Exceptions":
  "Encounter with Medical Reason for Not Obtaining or Patient Declined Blood Pressure Measurement"
    union "Encounter with Order for Hypertension Follow Up Declined by Patient"

define "Follow up with Rescreen Within 6 Months":
  [ServiceRequest: "Follow Up Within 6 Months"] FollowUp
    where FollowUp.intent ~ 'order'

define "Laboratory Test or ECG for Hypertension":
  ( [ServiceRequest: "12 lead EKG panel"]
    union [ServiceRequest: "EKG study"]
    union [ServiceRequest: "Laboratory Tests for Hypertension"] ) EKGLab
    where EKGLab.intent ~ 'order'

define "NonPharmacological Interventions":
  ( [ServiceRequest: "Lifestyle Recommendation"]
    union [ServiceRequest: "Weight Reduction Recommended"]
    union [ServiceRequest: "Dietary Recommendations"]
    union [ServiceRequest: "Recommendation to Increase Physical Activity"]
    union [ServiceRequest: "Referral or Counseling for Alcohol Consumption"] ) NonPharmaInterventions
    where NonPharmaInterventions.intent ~ 'order'

define "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80 and Interventions":
  "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80" FirstHTNEncounter
    with "First Hypertensive Reading Interventions or Referral to Alternate Professional" FirstHTNIntervention
      such that FirstHTNIntervention.authoredOn during day of FirstHTNEncounter.period

define "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 and Interventions":
  ( "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89" SecondHTNEncounterReading
      with "Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 and Interventions" EncounterInterventions
        such that EncounterInterventions.authoredOn during day of SecondHTNEncounterReading.period
  )
    union ( "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89" SecondHTNEncounterReading
        with "Referral to Alternate or Primary Healthcare Professional for Hypertensive Reading" ReferralForHTN
          such that ReferralForHTN.authoredOn during day of SecondHTNEncounterReading.period
    )

define "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 and Interventions":
  ( "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90" SecondHTNEncounterReading140Over90
      with "Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 Interventions" SecondHTN140Over90Interventions
        such that SecondHTN140Over90Interventions.authoredOn during day of SecondHTNEncounterReading140Over90.period
  )
    union "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90" SecondHTNEncounterReading140Over90
      with "Referral to Alternate or Primary Healthcare Professional for Hypertensive Reading" ReferralToProfessional
        such that ReferralToProfessional.authoredOn during day of SecondHTNEncounterReading140Over90.period

define "First Hypertensive Reading Interventions or Referral to Alternate Professional":
  ( [ServiceRequest: "Follow Up Within 4 Weeks"] FourWeekRescreen
      with "NonPharmacological Interventions" NonPharmInterventionsHTN
        such that FourWeekRescreen.authoredOn during day of "Measurement Period"
          and NonPharmInterventionsHTN.authoredOn during day of "Measurement Period"
          and FourWeekRescreen.intent ~ 'order'
  )
    union ( "Referral to Alternate or Primary Healthcare Professional for Hypertensive Reading" )

define "Referral to Alternate or Primary Healthcare Professional for Hypertensive Reading":
  [ServiceRequest: "Referral to Primary Care or Alternate Provider"] Referral
    where Referral.reasonCode in "Finding of Elevated Blood Pressure or Hypertension"
      and Referral.intent ~ 'order'

define "Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 Interventions":
  ( [ServiceRequest: "Follow Up Within 4 Weeks"] WeeksRescreen
      with "Laboratory Test or ECG for Hypertension" ECGLabTest
        such that WeeksRescreen.authoredOn during day of "Measurement Period"
          and ECGLabTest.authoredOn during day of "Measurement Period"
          and WeeksRescreen.intent ~ 'order'
          and ECGLabTest.intent ~ 'order'
      with "NonPharmacological Interventions" HTNInterventions
        such that HTNInterventions.authoredOn during day of "Measurement Period"
      with ["MedicationRequest": "Pharmacologic Therapy for Hypertension"] Medications
        such that Medications.authoredOn during day of "Measurement Period"
          and Medications.status ~ 'active'
  )

define "Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 and Interventions":
  "Follow up with Rescreen Within 6 Months" Rescreen2to6
    with "Laboratory Test or ECG for Hypertension" LabECGIntervention
      such that Rescreen2to6.authoredOn during day of "Measurement Period"
        and LabECGIntervention.authoredOn during day of "Measurement Period"
    with "NonPharmacological Interventions" NonPharmSecondIntervention
      such that NonPharmSecondIntervention.authoredOn during day of "Measurement Period"

define "Qualifying Encounter during Measurement Period":
  [Encounter: "Encounter to Screen for Blood Pressure"] ValidEncounter
    where ValidEncounter.period during day of "Measurement Period"
      and ValidEncounter.status ~ 'finished'
      and ValidEncounter.class !~ "virtual"

define "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80 and Interventions":
  ( "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80" ElevatedEncounter
      with "Follow up with Rescreen Within 6 Months" Twoto6MonthRescreen
        such that Twoto6MonthRescreen.authoredOn during day of ElevatedEncounter.period
      with "NonPharmacological Interventions" NonPharmInterventions
        such that NonPharmInterventions.authoredOn during day of ElevatedEncounter.period
  )
    union ( "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80" ElevatedEncounter
        with "Referral to Alternate or Primary Healthcare Professional for Hypertensive Reading" Referral
          such that Referral.authoredOn during day of ElevatedEncounter.period
    )

define "Encounter with Normal Blood Pressure Reading":
  "Qualifying Encounter during Measurement Period" QualifyingEncounter
    let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
        where BloodPressure.effective.toInterval() ends during QualifyingEncounter.period
          and BloodPressure.status in { 'final', 'amended', 'corrected' }
        sort by start of effective.toInterval()
    )
    where ( singleton from ( EncounterLastBP.component C
          where C.code ~ "Systolic blood pressure"
      )
    ).value in Interval[1 'mm[Hg]', 120 'mm[Hg]' )
      and ( singleton from ( EncounterLastBP.component C
            where C.code ~ "Diastolic blood pressure"
        )
      ).value in Interval[1 'mm[Hg]', 80 'mm[Hg]' )

define "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80":
  "Qualifying Encounter during Measurement Period" QualifyingEncounter
    let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
        where BloodPressure.effective.toInterval() ends during QualifyingEncounter.period
          and BloodPressure.status in { 'final', 'amended', 'corrected' }
        sort by start of effective.toInterval()
    )
    where ( ( singleton from ( EncounterLastBP.component C
            where C.code ~ "Systolic blood pressure"
        )
      ).value in Interval[120 'mm[Hg]', 129 'mm[Hg]']
        and ( singleton from ( EncounterLastBP.component C
              where C.code ~ "Diastolic blood pressure"
          )
        ).value in Interval[1 'mm[Hg]', 80 'mm[Hg]' )
    )

define "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90":
  ( "Qualifying Encounter during Measurement Period" QualifyingEncounter
      let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
          where BloodPressure.effective.toInterval() ends during QualifyingEncounter.period
            and BloodPressure.status in { 'final', 'amended', 'corrected' }
          sort by start of effective.toInterval()
      )
      where ( ( singleton from ( EncounterLastBP.component C
              where C.code ~ "Systolic blood pressure"
          )
        ).value > 0 'mm[Hg]'
          and ( singleton from ( EncounterLastBP.component C
                where C.code ~ "Diastolic blood pressure"
            )
          ).value > 0 'mm[Hg]'
          and ( ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Systolic blood pressure"
              )
            ).value >= 140 'mm[Hg]'
              or ( singleton from ( EncounterLastBP.component C
                    where C.code ~ "Diastolic blood pressure"
                )
              ).value >= 90 'mm[Hg]'
          )
      )
        and ( exists "Encounter with Hypertensive Reading Within Year Prior" )
  )

define "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89":
  ( "Qualifying Encounter during Measurement Period" QualifyingEncounter
      let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
          where BloodPressure.effective.toInterval() ends during day of QualifyingEncounter.period
            and BloodPressure.status in { 'final', 'amended', 'corrected' }
          sort by start of effective.toInterval()
      )
      where ( ( ( singleton from ( EncounterLastBP.component C
                where C.code ~ "Systolic blood pressure"
            )
          ).value in Interval[130 'mm[Hg]', 139 'mm[Hg]']
            or ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Diastolic blood pressure"
              )
            ).value in Interval[80 'mm[Hg]', 89 'mm[Hg]']
        )
          and not ( ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Systolic blood pressure"
              )
            ).value >= 140 'mm[Hg]'
              or ( singleton from ( EncounterLastBP.component C
                    where C.code ~ "Diastolic blood pressure"
                )
              ).value >= 90 'mm[Hg]'
          )
      )
        and ( exists "Encounter with Hypertensive Reading Within Year Prior" )
  )

define "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80":
  ( "Qualifying Encounter during Measurement Period" QualifyingEncounter
      let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
          where BloodPressure.effective.toInterval() ends during day of QualifyingEncounter.period
          sort by start of effective.toInterval()
      )
      where ( ( ( singleton from ( EncounterLastBP.component C
                where C.code ~ "Systolic blood pressure"
            )
          ).value > 0 'mm[Hg]'
            and ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Diastolic blood pressure"
              )
            ).value > 0 'mm[Hg]'
        )
          and ( ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Systolic blood pressure"
              )
            ).value >= 130 'mm[Hg]'
              or ( singleton from ( EncounterLastBP.component C
                    where C.code ~ "Diastolic blood pressure"
                )
              ).value >= 80 'mm[Hg]'
          )
      )
  )
    except "Encounter with Hypertensive Reading Within Year Prior"

define "Encounter with Hypertensive Reading Within Year Prior":
  ( "Qualifying Encounter during Measurement Period" QualifyingEncounter
      let EncounterLastBP: Last([USCoreBloodPressureProfile] BloodPressure
          where BloodPressure.effective.toInterval() ends 1 year or less before or on start of QualifyingEncounter.period
            and BloodPressure.status in { 'final', 'amended', 'corrected' }
          sort by start of effective.toInterval()
      )
      where ( ( singleton from ( EncounterLastBP.component C
              where C.code ~ "Systolic blood pressure"
          )
        ).value > 0 'mm[Hg]'
          and ( singleton from ( EncounterLastBP.component C
                where C.code ~ "Diastolic blood pressure"
            )
          ).value > 0 'mm[Hg]'
          and ( ( singleton from ( EncounterLastBP.component C
                  where C.code ~ "Systolic blood pressure"
              )
            ).value >= 130 'mm[Hg]'
              or ( singleton from ( EncounterLastBP.component C
                    where C.code ~ "Diastolic blood pressure"
                )
              ).value >= 80 'mm[Hg]'
          )
      )
  )

define "NonPharmacological Intervention Not Ordered":
  ( [ServiceNotRequested: "Lifestyle Recommendation"]
    union [ServiceNotRequested: "Weight Reduction Recommended"]
    union [ServiceNotRequested: "Dietary Recommendations"]
    union [ServiceNotRequested: "Recommendation to Increase Physical Activity"]
    union [ServiceNotRequested: "Referral or Counseling for Alcohol Consumption"] ) NonPharmIntervention
    where NonPharmIntervention.status = 'completed'
      and NonPharmIntervention.reasonRefused in "Patient Declined"

define "Encounter with Medical Reason for Not Obtaining or Patient Declined Blood Pressure Measurement":
  "Qualifying Encounter during Measurement Period" QualifyingEncounter
    with ( [ObservationCancelled: code ~ "Blood pressure panel with all children optional"]
      union [ObservationCancelled: code ~ "Systolic blood pressure"]
      union [ObservationCancelled: code ~ "Diastolic blood pressure"] ) NoBPScreen
      such that NoBPScreen.issued during day of QualifyingEncounter.period
        and NoBPScreen.status = 'cancelled'
        and ( NoBPScreen.notDoneReason in "Patient Declined"
            or NoBPScreen.notDoneReason in "Medical Reason"
        )

define "Encounter with Order for Hypertension Follow Up Declined by Patient":
  ( ( "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80" ElevatedBPEncounter
        with ( [ServiceNotRequested: "Referral to Primary Care or Alternate Provider"]
          union [ServiceNotRequested: "Follow Up Within 6 Months"] ) ElevatedBPDeclinedInterventions
          such that ElevatedBPDeclinedInterventions.authoredOn during day of ElevatedBPEncounter.period
            and ElevatedBPDeclinedInterventions.status = 'completed'
            and ElevatedBPDeclinedInterventions.reasonRefused in "Patient Declined"
    )
      union ( "Encounter with Elevated Blood Pressure Reading SBP 120 to 129 AND DBP less than 80" ElevatedBPEncounter
          with "NonPharmacological Intervention Not Ordered" NotOrdered
            such that NotOrdered.authoredOn during day of ElevatedBPEncounter.period
      )
      union ( "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80" FirstHTNEncounter
          with ( [ServiceNotRequested: "Follow Up Within 4 Weeks"]
            union [ServiceNotRequested: "Referral to Primary Care or Alternate Provider"] ) FirstHTNDeclinedInterventions
            such that FirstHTNDeclinedInterventions.authoredOn during day of FirstHTNEncounter.period
              and FirstHTNDeclinedInterventions.status = 'completed'
              and FirstHTNDeclinedInterventions.reasonRefused in "Patient Declined"
      )
      union ( "Encounter with First Hypertensive Reading SBP Greater than or Equal to 130 OR DBP Greater than or Equal to 80" FirstHTNEncounter
          with "NonPharmacological Intervention Not Ordered" NoNonPharm
            such that NoNonPharm.authoredOn during day of FirstHTNEncounter.period
      )
      union ( "Encounter with Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89" SecondHTNEncounter
          with "Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 Interventions Declined" SecondHTNDeclinedInterventions
            such that SecondHTNDeclinedInterventions.authoredOn during day of SecondHTNEncounter.period
      )
      union ( "Encounter with Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90" SecondHTN140Over90Encounter
          with "Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 Interventions Declined" SecondHTN140Over90DeclinedInterventions
            such that SecondHTN140Over90DeclinedInterventions.authoredOn during day of SecondHTN140Over90Encounter.period
      )
  )

define "Second Hypertensive Reading SBP 130 to 139 OR DBP 80 to 89 Interventions Declined":
  ( ( [ServiceNotRequested: "Referral to Primary Care or Alternate Provider"]
      union [ServiceNotRequested: "Follow Up Within 6 Months"] ) SecondHTNDeclinedReferralAndFollowUp
      where SecondHTNDeclinedReferralAndFollowUp.status = 'completed'
        and SecondHTNDeclinedReferralAndFollowUp.reasonRefused in "Patient Declined"
  )
    union "Laboratory Test or ECG for Hypertension Not Ordered"
    union "NonPharmacological Intervention Not Ordered"

define "Second Hypertensive Reading SBP Greater than or Equal to 140 OR DBP Greater than or Equal to 90 Interventions Declined":
  ( ( ( [ServiceNotRequested: "Referral to Primary Care or Alternate Provider"]
        union [ServiceNotRequested: "Follow Up Within 4 Weeks"] ) SecondHTN140Over90ReferralFollowUpNotDone
        where SecondHTN140Over90ReferralFollowUpNotDone.status = 'completed'
          and SecondHTN140Over90ReferralFollowUpNotDone.reasonRefused in "Patient Declined"
    )
      union ( [MedicationNotRequested: "Pharmacologic Therapy for Hypertension"] MedicationRequestNotOrdered
          where MedicationRequestNotOrdered.status = 'completed'
      )
      union "Laboratory Test or ECG for Hypertension Not Ordered"
      union "NonPharmacological Intervention Not Ordered"
  )

define "Laboratory Test or ECG for Hypertension Not Ordered":
  ( [ServiceNotRequested: code = "12 lead EKG panel"]
    union [ServiceNotRequested: code = "EKG study"]
    union [ServiceNotRequested: "Laboratory Tests for Hypertension"] ) LabECGNotDone
    where exists ( LabECGNotDone.extension E
        where E.url = 'http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-doNotPerformReason'
          and E.value as Concept in "Patient Declined"
    )

define "SDE Ethnicity":
  SDE."SDE Ethnicity"

define "SDE Payer":
  SDE."SDE Payer"

define "SDE Race":
  SDE."SDE Race"

define "SDE Sex":
  SDE."SDE Sex"