diff --git a/models/quality_measures/final/quality_measures__summary_long.sql b/models/quality_measures/final/quality_measures__summary_long.sql index 91f43f0a0..a8243d206 100644 --- a/models/quality_measures/final/quality_measures__summary_long.sql +++ b/models/quality_measures/final/quality_measures__summary_long.sql @@ -9,17 +9,7 @@ with union_measures as ( {{ dbt_utils.union_relations( relations=[ - ref('quality_measures__int_nqf2372_long') - , ref('quality_measures__int_nqf0034_long') - , ref('quality_measures__int_nqf0059_long') - , ref('quality_measures__int_cqm236_long') - , ref('quality_measures__int_nqf0053_long') - , ref('quality_measures__int_cbe0055_long') - , ref('quality_measures__int_nqf0097_long') - , ref('quality_measures__int_cqm438_long') - , ref('quality_measures__int_nqf0041_long') - , ref('quality_measures__int_cbe0101_long') - , ref('quality_measures__int_cqm48_long') + ref('quality_measures__int_cqm438_long') , ref('quality_measures__int_cqm130_long') , ref('quality_measures__int_nqf0420_long') , ref('quality_measures__int_adh_diabetes_long') diff --git a/models/quality_measures/final/quality_measures__summary_wide.sql b/models/quality_measures/final/quality_measures__summary_wide.sql index 681a48c83..8080f1a3d 100644 --- a/models/quality_measures/final/quality_measures__summary_wide.sql +++ b/models/quality_measures/final/quality_measures__summary_wide.sql @@ -20,76 +20,6 @@ with measures_long as ( ) -, nqf_2372 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF2372' - -) - -, nqf_0034 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF0034' - -) - -, nqf_0059 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF0059' - -) - -, cqm_236 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'CQM236' - -) - -, nqf_0053 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF0053' - -) - -, cbe_0055 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'CBE0055' - -) - -, nqf_0097 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF0097' - -) - , cqm_438 as ( select @@ -100,36 +30,6 @@ with measures_long as ( ) -, nqf_0041 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'NQF0041' - -) - -, cbe_0101 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'CBE0101' - -) - -, cqm_48 as ( - - select - patient_id - , performance_flag - from measures_long - where measure_id = 'CQM48' - -) - , cqm_130 as ( select @@ -194,17 +94,7 @@ with measures_long as ( select measures_long.patient_id - , max(nqf_2372.performance_flag) as nqf_2372 - , max(nqf_0034.performance_flag) as nqf_0034 - , max(nqf_0059.performance_flag) as nqf_0059 - , max(cqm_236.performance_flag) as cqm_236 - , max(nqf_0053.performance_flag) as nqf_0053 - , max(cbe_0055.performance_flag) as cbe_0055 - , max(nqf_0097.performance_flag) as nqf_0097 , max(cqm_438.performance_flag) as cqm_438 - , max(nqf_0041.performance_flag) as nqf_0041 - , max(cbe_0101.performance_flag) as cbe_0101 - , max(cqm_48.performance_flag) as cqm_48 , max(cqm_130.performance_flag) as cqm_130 , max(nqf_0420.performance_flag) as nqf_0420 , max(adh_diabetes.performance_flag) as adh_diabetes @@ -212,28 +102,8 @@ with measures_long as ( , max(supd.performance_flag) as supd , max(adh_statins.performance_flag) as adh_statins from measures_long - left join nqf_2372 - on measures_long.patient_id = nqf_2372.patient_id - left join nqf_0034 - on measures_long.patient_id = nqf_0034.patient_id - left join nqf_0059 - on measures_long.patient_id = nqf_0059.patient_id - left join cqm_236 - on measures_long.patient_id = cqm_236.patient_id - left join nqf_0053 - on measures_long.patient_id = nqf_0053.patient_id - left join cbe_0055 - on measures_long.patient_id = cbe_0055.patient_id - left join nqf_0097 - on measures_long.patient_id = nqf_0097.patient_id left join cqm_438 on measures_long.patient_id = cqm_438.patient_id - left join nqf_0041 - on measures_long.patient_id = nqf_0041.patient_id - left join cbe_0101 - on measures_long.patient_id = cbe_0101.patient_id - left join cqm_48 - on measures_long.patient_id = cqm_48.patient_id left join cqm_130 on measures_long.patient_id = cqm_130.patient_id left join nqf_0420 @@ -254,17 +124,7 @@ with measures_long as ( select cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(nqf_2372 as integer) as nqf_2372 - , cast(nqf_0034 as integer) as nqf_0034 - , cast(nqf_0059 as integer) as nqf_0059 - , cast(cqm_236 as integer) as cqm_236 - , cast(nqf_0053 as integer) as nqf_0053 - , cast(cbe_0055 as integer) as cbe_0055 - , cast(nqf_0097 as integer) as nqf_0097 - , cast(cqm_438 as integer) as cqm_438 - , cast(nqf_0041 as integer) as nqf_0041 - , cast(cbe_0101 as integer) as cbe_0101 - , cast(cqm_48 as integer) as cqm_48 + , cast(cqm_438 as integer) as cqm_438 , cast(cqm_130 as integer) as cqm_130 , cast(nqf_0420 as integer) as nqf_0420 , cast(adh_diabetes as integer) as adh_diabetes @@ -277,22 +137,12 @@ with measures_long as ( select patient_id - , nqf_2372 - , nqf_0034 - , nqf_0059 - , cqm_236 - , nqf_0053 - , cbe_0055 - , nqf_0097 - , cqm_438 - , nqf_0041 - , cbe_0101 - , cqm_48 - , cqm_130 - , nqf_0420 , adh_diabetes , adh_ras - , supd , adh_statins + , cqm_130 + , cqm_438 + , nqf_0420 + , supd , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types +from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055__performance_period.sql b/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055__performance_period.sql deleted file mode 100644 index 4835de186..000000000 --- a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055__performance_period.sql +++ /dev/null @@ -1,69 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'CBE0055') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'CBE0055') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'CBE0055') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end - -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_denominator.sql b/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_denominator.sql deleted file mode 100644 index cde0c6d40..000000000 --- a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_denominator.sql +++ /dev/null @@ -1,209 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'office visit' - , 'home healthcare services' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services initial office visit, 18 and up' - , 'annual wellness visit' - , 'telephone visits' - , 'outpatient' - , 'observation' - , 'diabetes visit' - , 'ophthalmological services' - , 'diabetic retinopathy' - ) - -) - -, visits_encounters as ( - - select patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ref('quality_measures__stg_core__encounter')}} encounter - inner join {{ref('quality_measures__int_cbe0055__performance_period')}} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ref('quality_measures__stg_core__procedure')}} procs - inner join {{ref('quality_measures__int_cbe0055__performance_period')}} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procs.normalized_code,procs.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_cbe0055__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code= visit_codes.code - -) - -, all_encounters as ( - - select *, 'v' as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id,min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, diabetics_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'diabetes' - ) - -) - -, conditions as ( - - select - patient_id - , claim_id - , encounter_id - , recorded_date - , source_code - , source_code_type - , normalized_code - , normalized_code_type - from {{ ref('quality_measures__stg_core__condition')}} - -) - -, diabetic_conditions as ( - - select - conditions.patient_id - , conditions.claim_id - , conditions.encounter_id - , conditions.recorded_date - , conditions.source_code - , conditions.source_code_type - from conditions - inner join diabetics_codes - on coalesce(conditions.normalized_code_type, conditions.source_code_type) = diabetics_codes.code_system - and coalesce(conditions.normalized_code, conditions.source_code) = diabetics_codes.code - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8760.0) as min_age - , max_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - -, qualifying_patients as ( - - select - distinct - diabetic_conditions.patient_id - , patients_with_age.max_age as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from diabetic_conditions - left join patients_with_age - on diabetic_conditions.patient_id = patients_with_age.patient_id - cross join {{ref('quality_measures__int_cbe0055__performance_period')}} pp - where max_age >= 18 and min_age <= 75 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_exclusions.sql b/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_exclusions.sql deleted file mode 100644 index 91c7e5b6a..000000000 --- a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_exclusions.sql +++ /dev/null @@ -1,219 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_cbe0055__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_cbe0055__performance_period') }} - -) -{%- endset -%} - -with frailty as ( - - select - * - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - - -) --- advanced illness end - -, exclusions as ( - - select * from valid_advanced_illness_exclusions - union all - select * from valid_dementia_exclusions - union all - select * from valid_hospice_palliative - union all - select * from valid_institutional_snp - -) - -, combined_exclusions as ( - - select - exclusions.* - , denominator.age - from exclusions - inner join {{ref('quality_measures__int_cbe0055_denominator')}} as denominator - on exclusions.patient_id = denominator.patient_id - -) - -, valid_exclusions as ( - - select - * - from combined_exclusions - where exclusion_type != 'hospice_palliative' - and age >= 66 - - union all - - select - * - from combined_exclusions - where exclusion_type = 'hospice_palliative' - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_long.sql b/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_long.sql deleted file mode 100644 index 72d16b15b..000000000 --- a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_long.sql +++ /dev/null @@ -1,152 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_cbe0055_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_cbe0055_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_cbe0055_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_numerator.sql b/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_numerator.sql deleted file mode 100644 index 8b4e3d479..000000000 --- a/models/quality_measures/intermediate/cbe0055_diabetes_eye_exam/quality_measures__int_cbe0055_numerator.sql +++ /dev/null @@ -1,112 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_cbe0055_denominator') }} - -) - -, retina_test_code as ( - - select - code - , code_system - , concept_name - from {{ref('quality_measures__value_sets')}} - where lower(concept_name) in ( - 'diabetic retinal eye exam met' - , 'retinal or dilated eye exam' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, qualifying_patients as ( - - select - procedures.patient_id - , procedures.procedure_date as evidence_date - from procedures - inner join {{ ref('quality_measures__int_cbe0055__performance_period') }} pp - on procedure_date between - performance_period_begin and performance_period_end - inner join retina_test_code - on procedures.code = retina_test_code.code - and procedures.code_type = retina_test_code.code_system - -) - -, qualifying_patients_with_denominator as ( - - select - qualifying_patients.patient_id - , qualifying_patients.evidence_date - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , cast('1' as integer) as numerator_flag - from qualifying_patients - inner join denominator - on qualifying_patients.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from qualifying_patients_with_denominator - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101__performance_period.sql b/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101__performance_period.sql deleted file mode 100644 index d7f245795..000000000 --- a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101__performance_period.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'CBE0101') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'CBE0101') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'CBE0101') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ - -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end - -) - -/* - set performance period begin to following day of 1 year prior -*/ - -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_denominator.sql b/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_denominator.sql deleted file mode 100644 index fb4309f5a..000000000 --- a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_denominator.sql +++ /dev/null @@ -1,278 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'annual wellness visit' - , 'audiology visit' - , 'home healthcare services' - , 'nursing facility visit' - , 'occupational therapy evaluation' - , 'office visit' - , 'physical therapy evaluation' - , 'online assessments' - , 'telephone visits' - , 'care services in long term residential facility' - , 'discharge services nursing facility' - , 'encounter inpatient' - , 'ophthalmological services' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services individual counseling' - , 'preventive care services initial office visit, 18 and up' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, visits_encounters as ( - - select patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ ref('quality_measures__stg_core__encounter') }} encounter - inner join {{ ref('quality_measures__int_cbe0101__performance_period') }} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from procedures - inner join {{ ref('quality_measures__int_cbe0101__performance_period') }} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on procedures.code = visit_codes.code - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from medical_claim - inner join {{ ref('quality_measures__int_cbe0101__performance_period') }} as pp - on coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code = visit_codes.code - -) - -, all_encounters as ( - - select *, 'v' as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id, min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - , coalesce(min(proc_enc),'')) - , coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as age - , max_date - , qualifying_types - from {{ ref('quality_measures__stg_core__patient') }} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - -, falls_screening_code as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where code = '1100F' - /* - Patient screened for future fall risk; documentation of two or more falls in the past year - or any fall with injury in the past year - */ -) - -, qualifying_procedures as ( - - select - patient_id - , procedure_date as evidence_date - from procedures - inner join falls_screening_code - on procedures.code = falls_screening_code.code - and procedures.code_type = falls_screening_code.code_system - -) - -, qualifying_claims as ( - - select - patient_id - , coalesce(claim_end_date, claim_start_date) as evidence_date - from medical_claim - inner join falls_screening_code - on medical_claim.hcpcs_code = falls_screening_code.code - and lower(falls_screening_code.code_system) = 'hcpcs' - -) - -, qualifying_cares as ( - - select - patient_id - , evidence_date - from qualifying_procedures - - union all - - select - patient_id - , evidence_date - from qualifying_claims - -) - -, qualifying_cares_past_year as ( - - select - patient_id - , evidence_date - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - from qualifying_cares - inner join {{ ref('quality_measures__int_cbe0101__performance_period') }} pp - on evidence_date between pp.performance_period_begin and pp.performance_period_end - /* - code 1100F is reported if there are two or more falls in the last year itself, - so if it's reported in performance year, it indicates the falls in the last year - */ - -) - -, qualifying_patients as ( - - select - qualifying_cares_past_year.patient_id - , patients_with_age.age - , max_date as encounter_date - , qualifying_cares_past_year.performance_period_begin - , qualifying_cares_past_year.performance_period_end - , qualifying_cares_past_year.measure_id - , qualifying_cares_past_year.measure_name - , qualifying_cares_past_year.measure_version - , 1 as denominator_flag - from qualifying_cares_past_year - left join patients_with_age - on qualifying_cares_past_year.patient_id = patients_with_age.patient_id - where age >= 65 - -) - - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(encounter_date as date) as encounter_date - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , encounter_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_exclusions.sql b/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_exclusions.sql deleted file mode 100644 index d374eb08a..000000000 --- a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_exclusions.sql +++ /dev/null @@ -1,180 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - - select - performance_period_begin - from {{ ref('quality_measures__int_cbe0101__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - - select - performance_period_end - from {{ ref('quality_measures__int_cbe0101__performance_period') }} - -) -{%- endset -%} - -with denominator as ( - - select - patient_id - from {{ ref('quality_measures__int_cbe0101_denominator') }} - -) - -, exclusion_code as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where code = '0518F' - -- further 1P modifier are only excluded -) - -, hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_hospice as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from hospice_palliative - where lower(exclusion_reason) in ( - 'hospice encounter' - , 'hospice care ambulatory' - , 'hospice diagnosis' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - , modifier_1 - , modifier_2 - , modifier_3 - , modifier_4 - , modifier_5 - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, exclusion_procedures as ( - - select - patient_id - , procedure_date as exclusion_date - , 'Limited Mobility' as exclusion_reason - from procedures - inner join exclusion_code - on procedures.code = exclusion_code.code - and procedures.code_type = exclusion_code.code_system - where '1P' in (modifier_1, modifier_2, modifier_3, modifier_4, modifier_5) - -) - -, exclusion_claims as ( - - select - patient_id - , coalesce(claim_end_date, claim_start_date) as exclusion_date - , 'Limited mobility' as exclusion_reason - from {{ ref('quality_measures__stg_medical_claim') }} medical_claim - inner join exclusion_code - on medical_claim.hcpcs_code = exclusion_code.code - and lower(exclusion_code.code_system) = 'hcpcs' - where '1P' in (hcpcs_modifier_1, hcpcs_modifier_2, hcpcs_modifier_3, hcpcs_modifier_4, hcpcs_modifier_5) - -) - -, exclusion_patients as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from valid_hospice - - union all - - select - patient_id - , exclusion_date - , exclusion_reason - from exclusion_procedures - - union all - - select - patient_id - , exclusion_date - , exclusion_reason - from exclusion_claims - -) - -, combined_exclusions as ( - - select - exclusion_patients.patient_id - , exclusion_patients.exclusion_date - , exclusion_patients.exclusion_reason - from exclusion_patients - inner join denominator - on exclusion_patients.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(1 as integer) as exclusion_flag - from combined_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_long.sql b/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_long.sql deleted file mode 100644 index e774b8e56..000000000 --- a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_long.sql +++ /dev/null @@ -1,152 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_cbe0101_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_cbe0101_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_cbe0101_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_numerator.sql b/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_numerator.sql deleted file mode 100644 index 03c4f6251..000000000 --- a/models/quality_measures/intermediate/cbe0101_falls_plan_of_care/quality_measures__int_cbe0101_numerator.sql +++ /dev/null @@ -1,147 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , encounter_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_cbe0101_denominator') }} - -) - -, fallcare_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where code = '0518F' -- Falls plan of care documented - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, qualifying_procedures as ( - - select - patient_id - , procedure_date as evidence_date - from procedures - inner join fallcare_codes - on procedures.code = fallcare_codes.code - and procedures.code_type = fallcare_codes.code_system - -) - -, qualifying_claims as ( - - select - patient_id - , coalesce(claim_end_date, claim_start_date) as evidence_date - from {{ ref('quality_measures__stg_medical_claim') }} medical_claim - inner join fallcare_codes - on medical_claim.hcpcs_code = fallcare_codes.code - and lower(fallcare_codes.code_system) = 'hcpcs' - -) - -, qualifying_cares as ( - - select - patient_id - , evidence_date - from qualifying_procedures - - union all - - select - patient_id - , evidence_date - from qualifying_claims - -) - -, combined_qualifying_patients as ( - - select - qualifying_cares.patient_id - , qualifying_cares.evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , 1 as numerator_flag - from qualifying_cares - inner join denominator - on qualifying_cares.patient_id = denominator.patient_id - where evidence_date between - {{ dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "denominator.encounter_date" - ) - }} - and - denominator.encounter_date -- within last 12 months of falls screening visit - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from combined_qualifying_patients - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236__performance_period.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236__performance_period.sql deleted file mode 100644 index f3cb1a90d..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236__performance_period.sql +++ /dev/null @@ -1,74 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} - -(select id -from {{ ref('quality_measures__measures') }} -where id = 'CQM236') - -{%- endset -%} - -{%- set measure_name -%} - -(select name -from {{ ref('quality_measures__measures') }} -where id = 'CQM236') - -{%- endset -%} - -{%- set measure_version -%} - -(select version -from {{ ref('quality_measures__measures') }} -where id = 'CQM236') - -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_denominator.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_denominator.sql deleted file mode 100644 index 7a2ef6efa..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_denominator.sql +++ /dev/null @@ -1,223 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'office visit' - , 'home healthcare services' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services initial office visit, 18 and up' - , 'annual wellness visit' - , 'telephone visits' - , 'emergency department evaluation and management visit' - ) - -) - -, visits_encounters as ( - - select - patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ref('quality_measures__stg_core__encounter')}} encounter - inner join {{ref('quality_measures__int_cqm236__performance_period')}} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'outpatient' - , 'nonacute inpatient' - , 'encounter inpatient' - , 'acute_inpatient' - , 'emergency_department' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ref('quality_measures__stg_core__procedure')}} procs - inner join {{ref('quality_measures__int_cqm236__performance_period')}} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procs.normalized_code,procs.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_cqm236__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code= visit_codes.code - -) - -, all_encounters as ( - - select *, 'v' as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select - patient_id - , min(min_date) min_date - , max(max_date) max_date - , concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, hypertension_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'essential hypertension' - ) - -) - -, conditions as ( - - select - patient_id - , claim_id - , encounter_id - , recorded_date - , source_code - , source_code_type - , normalized_code - , normalized_code_type - from {{ ref('quality_measures__stg_core__condition')}} - -) - -, hypertension_conditions as ( - - select - conditions.patient_id - , conditions.claim_id - , conditions.encounter_id - , conditions.recorded_date - , conditions.source_code - , conditions.source_code_type - from conditions - inner join hypertension_codes - on coalesce(conditions.normalized_code_type, conditions.source_code_type) = hypertension_codes.code_system - and coalesce(conditions.normalized_code, conditions.source_code) = hypertension_codes.code - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8760.0) as min_age - , max_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - --- Patients 18-85 years of age who had a visit and diagnosis of essential hypertension starting before and continuing into, or starting during the first six months of the measurement period. -, qualifying_patients as ( - - select - distinct - hypertension_conditions.patient_id - , hypertension_conditions.recorded_date - , patients_with_age.max_age as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from hypertension_conditions - left join patients_with_age - on hypertension_conditions.patient_id = patients_with_age.patient_id - cross join {{ref('quality_measures__int_cqm236__performance_period')}} pp - where max_age >= 18 and min_age <= 85 - and hypertension_conditions.recorded_date between - {{ dbt.dateadd ( - datepart = "month" - , interval = -12 - , from_date_or_timestamp = "performance_period_begin" - ) - }} - and - {{ dbt.dateadd ( - datepart = "month" - , interval = +6 - , from_date_or_timestamp = "performance_period_begin" - )}} - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclude_procedures_observations.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclude_procedures_observations.sql deleted file mode 100644 index d7c61e2d1..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclude_procedures_observations.sql +++ /dev/null @@ -1,177 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',false)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , age - , performance_period_begin - , performance_period_end - from {{ ref('quality_measures__int_cqm236_denominator') }} - -) - - -, conditions as ( - - select - patient_id - , claim_id - , recorded_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__condition') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, exclusion_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets')}} - where lower(concept_name) in ( - 'dialysis services' - , 'end stage renal disease' - , 'esrd monthly outpatient services' - , 'kidney transplant' - , 'kidney transplant recipient' - , 'pregnancy' - ) - -) - -, condition_exclusions as ( - - select - conditions.patient_id - , conditions.claim_id - , conditions.recorded_date - , exclusion_codes.concept_name - from conditions - inner join exclusion_codes - on conditions.code = exclusion_codes.code - and conditions.code_type = exclusion_codes.code_system - -) - -, procedure_exclusions as ( - - select - procedures.patient_id - , procedures.procedure_date - , exclusion_codes.concept_name - from procedures - inner join exclusion_codes - on procedures.code = exclusion_codes.code - and procedures.code_type = exclusion_codes.code_system - -) - -, exclusions_unioned as ( - - select - patient_id - , recorded_date as exclusion_date - , concept_name as exclusion_reason - from condition_exclusions - - union all - - select - patient_id - , procedure_date as exclusion_date - , concept_name as exclusion_reason - from procedure_exclusions - -) - -, excluded_patients as ( - - select - exclusions_unioned.patient_id - , exclusions_unioned.exclusion_date - , exclusions_unioned.exclusion_reason - , case - when exclusion_reason = 'pregnancy' then 1 - else 0 - end as is_pregnant - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.age - from exclusions_unioned - inner join denominator - on exclusions_unioned.patient_id = denominator.patient_id - -) - -, exclusions_filtered as ( - - select - patient_id - , age - , exclusion_date - , exclusion_reason - from excluded_patients - where is_pregnant = 1 - and exclusion_date between performance_period_begin and performance_period_end - - union all - - select - patient_id - , age - , exclusion_date - , exclusion_reason - from excluded_patients - where is_pregnant = 0 - and exclusion_date between performance_period_begin and performance_period_end - or (exclusion_date between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp="performance_period_begin") }} - and performance_period_end) - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , age - , 'measure specific exclusion for observation procedure' as exclusion_type - , '{{ var('tuva_last_run')}}' as tuva_last_run -from - exclusions_filtered diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclusions.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclusions.sql deleted file mode 100644 index da9853396..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_exclusions.sql +++ /dev/null @@ -1,275 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_cqm236__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_cqm236__performance_period') }} - -) -{%- endset -%} - -with frailty as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, denominator as ( - - select - patient_id - , age - from {{ref('quality_measures__int_cqm236_denominator')}} - -) --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - - -) --- advanced illness end - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, measure_specific_procedure_observation_exclusion as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - , age - from {{ref('quality_measures__int_cqm236_exclude_procedures_observations')}} - -) - -, exclusions as ( - - select * - from valid_advanced_illness_exclusions - - union all - - select * - from valid_dementia_exclusions - - union all - - select * - from valid_hospice_palliative - - union all - - select * - from valid_institutional_snp - - union all - - select * - from valid_dementia_exclusions - -) - -, combined_exclusions as ( - - select - exclusions.* - , denominator.age - from exclusions - inner join denominator - on exclusions.patient_id = denominator.patient_id - -) - -, frailty_exclusion_older_than_80 as ( - - select - frailty.patient_id - , frailty.exclusion_date - , frailty.exclusion_reason - , 'measure specific exclusion for patients older than 80' as exclusion_type - , denominator.age - from frailty - inner join denominator - on frailty.patient_id = denominator.patient_id - where denominator.age >= 81 - -) - -, valid_exclusions as ( - - select * from combined_exclusions - where exclusion_type != 'hospice_palliative' - and age >= 66 - - union all - - select * from combined_exclusions - where exclusion_type = 'hospice_palliative' - - union all - - select * from frailty_exclusion_older_than_80 - - union all - - select * from measure_specific_procedure_observation_exclusion - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_long.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_long.sql deleted file mode 100644 index 47261d234..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_long.sql +++ /dev/null @@ -1,150 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_cqm236_denominator') }} - -) - -, numerator as ( - - select - patient_id - , observation_date - from {{ ref('quality_measures__int_cqm236_numerator') }} - where numerator_flag = 1 - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_cqm236_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.observation_date - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.observation_date is null then 1 else 0 end, - numerator.observation_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , observation_date - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(observation_date as date) as evidence_date - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_numerator.sql b/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_numerator.sql deleted file mode 100644 index b63d0bd2a..000000000 --- a/models/quality_measures/intermediate/cqm236_controlling_blood_pressure/quality_measures__int_cqm236_numerator.sql +++ /dev/null @@ -1,548 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with controlled_bp_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'most recent systolic blood pressure < 140 mmhg' --G8752 hcpcs - , 'most recent diastolic blood pressure < 90 mmhg' --G8754 hcpcs - ) - -) - -, denominator as ( - - select - patient_id - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - from {{ ref('quality_measures__int_cqm236_denominator') }} - -) - -, encounters as ( - - select - patient_id - , encounter_type - , encounter_start_date - , encounter_end_date - from {{ ref('quality_measures__stg_core__encounter') }} - -) - -, observations as ( - - select - patient_id - , observation_date - , normalized_code - , normalized_description - , result - from {{ ref('quality_measures__stg_core__observation') }} - where lower(normalized_description) in - ( - 'systolic blood pressure' - , 'diastolic blood pressure' - ) - and normalized_code not in ( - '99473' -- Self-measured blood pressure using a device validated for clinical accuracy; patient education/training and device calibration - , '99474' -- Separate self-measurements of two readings one minute apart, twice daily over a 30-day period (minimum of 12 readings), collection of data reported by the patient and/or caregiver to the physician or other qualified health care professional, with report of average systolic and diastolic pressures and subsequent communication of a treatment plan to the patient - ) - {% if target.type == 'duckdb' %} - and try_cast('result' as numeric) is not null - {% else %} - and {{ dbt.safe_cast("result", api.Column.translate_type("numeric")) }} is not null - {% endif %} - -) - -, labs as ( - - select - patient_id - , result_date - , collection_date - , result - , normalized_code - from {{ref('quality_measures__stg_core__lab_result')}} - where normalized_code in - ('8480-6' --systolic - ,'8462-4') --diastolic - and - normalized_code_type = 'loinc' - {% if target.type == 'duckdb' %} - and try_cast('result' as numeric) is not null - {% else %} - and {{ dbt.safe_cast("result", api.Column.translate_type("numeric")) }} is not null - {% endif %} - -) - -, all_procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, all_medical_claims as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, controlled_bp_procedures as ( - - select - all_procedures.patient_id - , all_procedures.procedure_date as evidence_date - , controlled_bp_codes.code - from all_procedures - inner join controlled_bp_codes - on all_procedures.code_type = controlled_bp_codes.code_system - and all_procedures.code = controlled_bp_codes.code - -) - -, controlled_bp_medical_claims as ( - - select - all_medical_claims.patient_id - , coalesce(all_medical_claims.claim_end_date, all_medical_claims.claim_start_date) as evidence_date - , controlled_bp_codes.code - from all_medical_claims - inner join controlled_bp_codes - on all_medical_claims.hcpcs_code = controlled_bp_codes.code - and controlled_bp_codes.code_system = 'hcpcs' - -) - -, controlled_bp_patients_proc_claims as ( - - select - patient_id - , evidence_date - , code - from controlled_bp_procedures - - union all - - select - patient_id - , evidence_date - , code - from controlled_bp_medical_claims - -) - -, controlled_bp_within_range_proc_claims as ( - - select - controlled_bp_patients_proc_claims.patient_id - , controlled_bp_patients_proc_claims.evidence_date - , controlled_bp_patients_proc_claims.code - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.performance_period_begin - , denominator.performance_period_end - from controlled_bp_patients_proc_claims - inner join denominator - on controlled_bp_patients_proc_claims.patient_id = denominator.patient_id - and controlled_bp_patients_proc_claims.evidence_date between - denominator.performance_period_begin and denominator.performance_period_end - -) - -, procedure_claims_w_encounters as ( - - select - controlled_bp_within_range_proc_claims.patient_id - , controlled_bp_within_range_proc_claims.evidence_date - , controlled_bp_within_range_proc_claims.code - , case - when lower(encounters.encounter_type) in ( - 'emergency department' - , 'acute inpatient' - ) - then 0 - else 1 - end as is_valid_procedure_claims - , controlled_bp_within_range_proc_claims.measure_id - , controlled_bp_within_range_proc_claims.measure_name - , controlled_bp_within_range_proc_claims.measure_version - , controlled_bp_within_range_proc_claims.performance_period_begin - , controlled_bp_within_range_proc_claims.performance_period_end - from controlled_bp_within_range_proc_claims - left join encounters - on controlled_bp_within_range_proc_claims.patient_id = encounters.patient_id - and controlled_bp_within_range_proc_claims.evidence_date between - encounters.encounter_start_date and encounters.encounter_end_date - -) - -, valid_procedures_and_claims as ( - - select - patient_id - , evidence_date - , code - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - from procedure_claims_w_encounters - where is_valid_procedure_claims = 1 - -) - -, systolic_bp_from_procedure_claims as ( - - select - patient_id - , evidence_date - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - from valid_procedures_and_claims - where code = 'G8752' --systolic - -) - -, diastolic_bp_from_procedure_claims as ( - - select - patient_id - , evidence_date - from valid_procedures_and_claims - where code = 'G8754' --diastolic - -) - -, qualifying_controlled_bp_proc_claims as ( - - select - systolic_bp_from_procedure_claims.patient_id - , systolic_bp_from_procedure_claims.evidence_date - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - from systolic_bp_from_procedure_claims - inner join diastolic_bp_from_procedure_claims - on systolic_bp_from_procedure_claims.patient_id = diastolic_bp_from_procedure_claims.patient_id - and systolic_bp_from_procedure_claims.evidence_date = diastolic_bp_from_procedure_claims.evidence_date - -) - -, observations_within_range as ( - - select - observations.patient_id - , observations.observation_date - , observations.normalized_code - , observations.normalized_description - , observations.result - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.performance_period_begin - , denominator.performance_period_end - from observations - inner join denominator - on observations.patient_id = denominator.patient_id - and observations.observation_date between - denominator.performance_period_begin and denominator.performance_period_end - -) - -, labs_within_range as ( - - select - labs.patient_id - , labs.normalized_code - , coalesce(labs.result_date, labs.collection_date) as observation_date - , labs.result - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.performance_period_begin - , denominator.performance_period_end - from labs - inner join denominator - on labs.patient_id = denominator.patient_id - and coalesce(labs.result_date,labs.collection_date) between - denominator.performance_period_begin and denominator.performance_period_end - -) - -, observations_with_encounters as ( - - select - observations_within_range.patient_id - , observations_within_range.observation_date - , observations_within_range.normalized_description - , observations_within_range.result - , observations_within_range.normalized_code - , case - when lower(encounters.encounter_type) in ( - 'emergency department' - , 'acute inpatient' - ) - then 0 - else 1 - end as is_valid_encounter_observation - , observations_within_range.measure_id - , observations_within_range.measure_name - , observations_within_range.measure_version - , observations_within_range.performance_period_begin - , observations_within_range.performance_period_end - from observations_within_range - left join encounters - on observations_within_range.patient_id = encounters.patient_id - and observations_within_range.observation_date between - encounters.encounter_start_date and encounters.encounter_end_date - -) - -, labs_with_encounters as ( - - select - labs_within_range.patient_id - , labs_within_range.normalized_code - , labs_within_range.observation_date - , labs_within_range.result - , case - when lower(encounters.encounter_type) in ( - 'emergency department' - , 'acute inpatient' - ) - then 0 - else 1 - end as is_valid_encounter_labs - , labs_within_range.measure_id - , labs_within_range.measure_name - , labs_within_range.measure_version - , labs_within_range.performance_period_begin - , labs_within_range.performance_period_end - from labs_within_range - left join encounters - on labs_within_range.patient_id = encounters.patient_id - and labs_within_range.observation_date between - encounters.encounter_start_date and encounters.encounter_end_date - -) - -, obs_and_labs as ( - - select - patient_id - , observation_date - {% if target.type == 'fabric' %} - , try_cast(result as {{ dbt.type_float() }}) as bp_reading - {% else %} - , cast(result as {{ dbt.type_float() }}) as bp_reading - {% endif %} - , normalized_description - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - , normalized_code - from observations_with_encounters - where is_valid_encounter_observation = 1 - - union all - - select - patient_id - , observation_date - {% if target.type == 'fabric' %} - , try_cast(result as {{ dbt.type_float() }}) as bp_reading - {% else %} - , cast(result as {{ dbt.type_float() }}) as bp_reading - {% endif %} - , cast(null as {{ dbt.type_string() }}) as normalized_description - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - , normalized_code - from labs_with_encounters labs - where is_valid_encounter_labs = 1 - -) - -, systolic_bp as ( - - select - patient_id - , observation_date - , bp_reading - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - , row_number() over(partition by patient_id order by observation_date desc, bp_reading asc) as rn - from obs_and_labs - where lower(normalized_description) = 'systolic blood pressure' - or - normalized_code = '8480-6' - -) - -, diastolic_bp as ( - - select - patient_id - , observation_date - , bp_reading - , row_number() over(partition by patient_id order by observation_date desc, bp_reading asc) as rn - from obs_and_labs - where lower(normalized_description) = 'diastolic blood pressure' - or - normalized_code = '8462-4' - -) - -, least_recent_systolic_bp as ( - - select - patient_id - , observation_date - , bp_reading as systolic_bp - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - from systolic_bp - where rn = 1 - -) - -, least_recent_diastolic_bp as ( - - select - patient_id - , observation_date - , bp_reading as diastolic_bp - from diastolic_bp - where rn = 1 - -) - -, patients_with_bp_readings as ( - - select - least_recent_systolic_bp.patient_id - , least_recent_systolic_bp.systolic_bp - , least_recent_diastolic_bp.diastolic_bp - , least_recent_systolic_bp.observation_date - , least_recent_systolic_bp.measure_id - , least_recent_systolic_bp.measure_name - , least_recent_systolic_bp.measure_version - , least_recent_systolic_bp.performance_period_begin - , least_recent_systolic_bp.performance_period_end - from least_recent_systolic_bp - inner join least_recent_diastolic_bp - on least_recent_systolic_bp.patient_id = least_recent_diastolic_bp.patient_id - and least_recent_systolic_bp.observation_date = least_recent_diastolic_bp.observation_date - -) - -, numerator as ( - - select - patient_id - , observation_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , case - when systolic_bp < 140.0 and diastolic_bp < 90.0 - then 1 - else 0 - end as numerator_flag - from patients_with_bp_readings - - union all - - select - patient_id - , evidence_date as observation_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , 1 as numerator_flag - from qualifying_controlled_bp_proc_claims - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(observation_date as date) as observation_date - , cast(numerator_flag as integer) as numerator_flag - from numerator - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , observation_date - , numerator_flag -from add_data_types diff --git a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48__performance_period.sql b/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48__performance_period.sql deleted file mode 100644 index c468ad620..000000000 --- a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48__performance_period.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'CQM48') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'CQM48') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'CQM48') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ - -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end - -) - -/* - set performance period begin to following day of 1 year prior -*/ - -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_denominator.sql b/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_denominator.sql deleted file mode 100644 index a81cca24e..000000000 --- a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_denominator.sql +++ /dev/null @@ -1,195 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'occupational therapy evaluation' - , 'office visit' - , 'outpatient' - , 'physical therapy evaluation' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, visits_encounters as ( - - select patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ ref('quality_measures__stg_core__encounter') }} encounter - inner join {{ ref('quality_measures__int_cqm48__performance_period') }} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from procedures - inner join {{ ref('quality_measures__int_cqm48__performance_period') }} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on procedures.code = visit_codes.code - and procedures.code_type = visit_codes.code_system - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from medical_claim - inner join {{ ref('quality_measures__int_cqm48__performance_period') }} as pp - on coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code = visit_codes.code - and visit_codes.code_system = 'hcpcs' - -) - -, all_encounters as ( - - select *, 'v' as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id, min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - , coalesce(min(proc_enc),'')) - , coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as age - , max_date - , qualifying_types - from {{ ref('quality_measures__stg_core__patient') }} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.sex = 'female' - and p.death_date is null - -) - -, qualifying_patients as ( - - select - distinct - patients_with_age.patient_id - , patients_with_age.age - , patients_with_age.max_date as encounter_date - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from patients_with_age - cross join {{ ref('quality_measures__int_cqm48__performance_period') }} pp - where age >= 65 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(encounter_date as date) as encounter_date - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , encounter_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_exclusions.sql b/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_exclusions.sql deleted file mode 100644 index 5cad9a0f0..000000000 --- a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_exclusions.sql +++ /dev/null @@ -1,66 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_cqm48__performance_period') }} -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_cqm48__performance_period') }} -) -{%- endset -%} - -with valid_hospice_exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - and lower(exclusion_reason) in ( - 'hospice encounter' - ) - -) - -, combined_exclusions as ( - - select - valid_hospice_exclusions.patient_id - , valid_hospice_exclusions.exclusion_date - , valid_hospice_exclusions.exclusion_reason - from valid_hospice_exclusions - inner join {{ ref('quality_measures__int_cqm48_denominator') }} as denominator - on valid_hospice_exclusions.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(1 as integer) as exclusion_flag - from combined_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_long.sql b/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_long.sql deleted file mode 100644 index da3701c83..000000000 --- a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_long.sql +++ /dev/null @@ -1,152 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_cqm48_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_cqm48_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_cqm48_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_numerator.sql b/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_numerator.sql deleted file mode 100644 index 55e5e8a6e..000000000 --- a/models/quality_measures/intermediate/cqm48_urinary_incontinence/quality_measures__int_cqm48_numerator.sql +++ /dev/null @@ -1,149 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , encounter_date - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_cqm48_denominator') }} - -) - -, involuntary_urination_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'presence or absence of urinary incontinence assessed' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, qualifying_procedures as ( - - select - patient_id - , procedure_date as evidence_date - from procedures - inner join involuntary_urination_codes - on procedures.code = involuntary_urination_codes.code - and procedures.code_type = involuntary_urination_codes.code_system - -) - -, qualifying_claims as ( - - select - patient_id - , coalesce(claim_end_date, claim_start_date) as evidence_date - from {{ ref('quality_measures__stg_medical_claim') }} medical_claim - inner join involuntary_urination_codes - on medical_claim.hcpcs_code = involuntary_urination_codes.code - and lower(involuntary_urination_codes.code_system) = 'hcpcs' - -) - -, qualifying_cares as ( - - select - patient_id - , evidence_date - from qualifying_procedures - - union all - - select - patient_id - , evidence_date - from qualifying_claims - -) - -, combined_qualifying_patients as ( - - select - qualifying_cares.patient_id - , qualifying_cares.evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , 1 as numerator_flag - from qualifying_cares - inner join denominator - on qualifying_cares.patient_id = denominator.patient_id - where evidence_date between - {{ dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "denominator.encounter_date" - ) - }} - and - denominator.encounter_date -- within last 12 months of visit - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from combined_qualifying_patients - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034__performance_period.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034__performance_period.sql deleted file mode 100644 index abaad1af2..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034__performance_period.sql +++ /dev/null @@ -1,95 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -/* - set performance lookback periods for each type of test - - during the measurement period: - - Fecal occult blood test (FOBT) during the measurement period - - during the measurement period or the two years prior: - - Fecal immunochemical DNA test (FIT-DNA) - - during the measurement period or the four years prior: - - Flexible sigmoidoscopy - - Computed tomography (CT) colonography - - during the measurement period or the nine years prior: - - Colonoscopy - -*/ -, period_lookback as ( - - select - performance_period_end - , performance_period_begin - , {{ dbt.dateadd( - datepart = "year" - , interval = -2 - , from_date_or_timestamp = "performance_period_end" - ) }} as performance_period_begin_1yp - , {{ dbt.dateadd( - datepart = "year" - , interval = -3 - , from_date_or_timestamp = "performance_period_end" - ) }} as performance_period_begin_2yp - , {{ dbt.dateadd( - datepart = "year" - , interval = -5 - , from_date_or_timestamp = "performance_period_end" - ) }} as performance_period_begin_4yp - , {{ dbt.dateadd( - datepart = "year" - , interval = -10 - , from_date_or_timestamp = "performance_period_end" - ) }} as performance_period_begin_9yp - from period_begin - -) - -select - cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(performance_period_begin_1yp as date) as performance_period_begin_1yp - , cast(performance_period_begin_2yp as date) as performance_period_begin_2yp - , cast(performance_period_begin_4yp as date) as performance_period_begin_4yp - , cast(performance_period_begin_9yp as date) as performance_period_begin_9yp -from period_lookback \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_denominator.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_denominator.sql deleted file mode 100644 index 13721a735..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_denominator.sql +++ /dev/null @@ -1,136 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -/* -DENOMINATOR: -Patients 45-75 years of age with a visit during the measurement period -DENOMINATOR NOTE: To assess the age for exclusions, the patient’s age on the date of the encounter -should be used -*Signifies that this CPT Category I code is a non-covered service under the Medicare Part B Physician Fee -Schedule (PFS). These non-covered services should be counted in the denominator population for MIPS -CQMs. -Denominator Criteria (Eligible Cases): -Patients 45 to 75 years of age on date of encounter -AND -Patient encounter during the performance period (CPT or HCPCS): 99202, 99203, 99204, 99205, -99212, 99213, 99214, 99215, 99341, 99342, 99344, 99345, 99347, 99348, 99349, 99350, 99386*, 99387*, -99396*, 99397*, G0438, G0439 -*/ - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'office visit' - , 'home healthcare services' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services initial office visit, 18 and up' - , 'annual wellness visit' - , 'telephone visits' - , 'online assessments' - ) - -) - -, visits_encounters as ( - - select - patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ ref('quality_measures__stg_core__encounter') }} encounter - inner join {{ ref('quality_measures__int_nqf0034__performance_period') }} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where encounter_type in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ ref('quality_measures__stg_core__procedure') }} procs - inner join {{ ref('quality_measures__int_nqf0034__performance_period') }} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procs.normalized_code,procs.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_nqf0034__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code= visit_codes.code - -) - -, all_encounters as ( - - select *, 'v' as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id, min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8766.0) as min_age - , max_date - ,floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8766.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null -- ensures deceased patients are not included - -) - -select - patient_id - , min_age - , max_age - , qualifying_types -from patients_with_age -where max_age >= 45 and min_age <= 75 \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclude_colectomy_cancer.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclude_colectomy_cancer.sql deleted file mode 100644 index d1c920903..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclude_colectomy_cancer.sql +++ /dev/null @@ -1,200 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -/* -DENOMINATOR EXCLUSIONS: -Patients with a diagnosis or past history of total colectomy or colorectal cancer: G9711 -*/ - - -with exclusion_codes as ( - - select - code - , case code_system - when 'SNOMEDCT' then 'snomed-ct' - when 'ICD9CM' then 'icd-9-cm' - when 'ICD10CM' then 'icd-10-cm' - when 'CPT' then 'hcpcs' - when 'ICD10PCS' then 'icd-10-pcs' - else lower(code_system) - end as code_system - , concept_name - From {{ref('quality_measures__value_sets')}} - where lower(concept_name) in ( - 'malignant neoplasm of colon' - , 'total colectomy' - ) - -) - -, conditions as ( - - select - patient_id - , claim_id - , recorded_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__condition') }} - -) - -, medical_claim as ( - - select - patient_id - , claim_id - , claim_start_date - , claim_end_date - , hcpcs_code - , place_of_service_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, observations as ( - - select - patient_id - , observation_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__observation') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, condition_exclusions as ( - - select - conditions.patient_id - , conditions.claim_id - , conditions.recorded_date - , exclusion_codes.concept_name as concept_name - from conditions - inner join exclusion_codes - on conditions.code = exclusion_codes.code - and conditions.code_type = exclusion_codes.code_system - -) - -, med_claim_exclusions as ( - - select - medical_claim.patient_id - , medical_claim.claim_id - , medical_claim.claim_start_date - , medical_claim.claim_end_date - , medical_claim.hcpcs_code - , exclusion_codes.concept_name as concept_name - from medical_claim - inner join exclusion_codes - on medical_claim.hcpcs_code = exclusion_codes.code - where exclusion_codes.code_system = 'hcpcs' - -) - -, observation_exclusions as ( - - select - observations.patient_id - , observations.observation_date - , exclusion_codes.concept_name as concept_name - from observations - inner join exclusion_codes - on observations.code = exclusion_codes.code - and observations.code_type = exclusion_codes.code_system - -) - -, procedure_exclusions as ( - - select - procedures.patient_id - , procedures.procedure_date - , exclusion_codes.concept_name as concept_name - from procedures - inner join exclusion_codes - on procedures.code = exclusion_codes.code - and procedures.code_type = exclusion_codes.code_system - -) - -, patients_with_exclusions as( - select patient_id - , recorded_date as exclusion_date - , concept_name as exclusion_reason - from condition_exclusions - - union all - - select patient_id - , coalesce(claim_end_date, claim_start_date) as exclusion_date - , concept_name as exclusion_reason - from med_claim_exclusions - - union all - - select patient_id - , observation_date as exclusion_date - , concept_name as exclusion_reason - from observation_exclusions - - union all - - select patient_id - , procedure_date as exclusion_date - , concept_name as exclusion_reason - from procedure_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , 'measure specific exclusion for historical record of colectomy cancer' as exclusion_type - , '{{ var('tuva_last_run')}}' as tuva_last_run -from patients_with_exclusions \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclusions.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclusions.sql deleted file mode 100644 index 48c7daab3..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_exclusions.sql +++ /dev/null @@ -1,269 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_nqf0034__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_nqf0034__performance_period') }} - -) -{%- endset -%} - -with frailty as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, denominator as ( - - select - patient_id - , max_age as age - from {{ref('quality_measures__int_nqf0034_denominator')}} - -) --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - - -) --- advanced illness end - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - and lower(exclusion_reason) in - ( - 'palliative care encounter' - , 'palliative care intervention' - , 'hospice care ambulatory' - , 'hospice encounter' - ) - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, measure_specific_colectomy_colorectal_cancer_exclusion as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_nqf0034_exclude_colectomy_cancer')}} - -) - -, exclusions as ( - - select * - from valid_advanced_illness_exclusions - - union all - - select * - from valid_dementia_exclusions - - union all - - select * - from valid_hospice_palliative - - union all - - select * - from valid_institutional_snp - - union all - - select * - from valid_dementia_exclusions - - union all - - select * - from measure_specific_colectomy_colorectal_cancer_exclusion - -) - -, combined_exclusions as ( - - select - exclusions.* - , denominator.age - from exclusions - inner join denominator - on exclusions.patient_id = denominator.patient_id - -) - -, valid_exclusions as ( - - select * from combined_exclusions - where exclusion_type not in ( - 'measure specific exclusion for historical record of colectomy cancer' - , 'hospice_palliative' - ) - and age >= 66 - - union all - - select * from combined_exclusions --age irrelvant exclusions - where exclusion_type in ( - 'measure specific exclusion for historical record of colectomy cancer' - , 'hospice_palliative' - ) - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_long.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_long.sql deleted file mode 100644 index a61e57ed6..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_long.sql +++ /dev/null @@ -1,193 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - - -{%- set measure_id -%} -( - select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF0034' - ) -{%- endset -%} - -{%- set measure_name -%} -( - - select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF0034' - - ) -{%- endset -%} - -{%- set measure_version -%} -( - select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF0034' - - ) -{%- endset -%} - - - -with denominator as ( - - select - patient_id - from {{ ref('quality_measures__int_nqf0034_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - from {{ ref('quality_measures__int_nqf0034_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf0034_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , exclusions.exclusion_date - , exclusions.exclusion_reason - , pp.performance_period_begin - , pp.performance_period_end - , {{ measure_id }} as measure_id - , {{ measure_name }} as measure_name - , {{ measure_version }} as measure_version - from denominator - inner join {{ref('quality_measures__int_nqf0034__performance_period')}} pp - on 1 = 1 - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, add_rownum as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , row_number() over( - partition by - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - order by - case when evidence_date is null then 1 else 0 end, - evidence_date desc - , case when exclusion_date is null then 1 else 0 end, - exclusion_date desc - ) as row_num - from measure_flags - -) - -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from add_rownum - where row_num = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_numerator.sql b/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_numerator.sql deleted file mode 100644 index a0ef11f3a..000000000 --- a/models/quality_measures/intermediate/nqf0034_colorectal_cancer_screening/quality_measures__int_nqf0034_numerator.sql +++ /dev/null @@ -1,283 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - - -/* -Patients with one or more screenings for colorectal cancer. Appropriate screenings are defined by any one of the -following criteria: -- Fecal occult blood test (FOBT) during the measurement period -- Flexible sigmoidoscopy during the measurement period or the four years prior to the measurement period -- Colonoscopy during the measurement period or the nine years prior to the measurement period -- Computed tomography (CT) colonography during the measurement period or the four years prior to the -measurement period. -- Fecal immunochemical DNA test (FIT-DNA) during the measurement period or the two years prior to the -measurement period. - -*/ - -with denominator as ( - - select - patient_id - from {{ ref('quality_measures__int_nqf0034_denominator') }} - -) - -, screening_codes as ( - - select - code - , case code_system - when 'SNOMEDCT' then 'snomed-ct' - when 'ICD9CM' then 'icd-9-cm' - when 'ICD10CM' then 'icd-10-cm' - when 'CPT' then 'hcpcs' - when 'ICD10PCS' then 'icd-10-pcs' - else lower(code_system) - end as code_system - , concept_name - from {{ref('quality_measures__value_sets')}} - where lower(concept_name) in ( - 'fecal occult blood test (fobt)' -- mp - , 'flexible sigmoidoscopy' --mp+4 - , 'colonoscopy' -- mp+9 - , 'ct colonography' -- mp+4 - , 'sdna fit test' -- mp+2 - ) - -) - -, screening_periods as ( - - select - code - , code_system - , concept_name - , case concept_name - when 'Fecal Occult Blood Test (FOBT)' then pp.performance_period_begin --mp - when 'Flexible Sigmoidoscopy' then pp.performance_period_begin_4yp --mp+4 - when 'Colonoscopy' then pp.performance_period_begin_9yp -- mp+9 - when 'CT Colonography' then pp.performance_period_begin_4yp -- mp+4 - when 'sDNA FIT Test' then pp.performance_period_begin_2yp -- mp+2 - else pp.performance_period_begin - end as effective_performance_period_begin - , performance_period_end - from screening_codes - inner join {{ref('quality_measures__int_nqf0034__performance_period')}} pp - on 1 = 1 - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, observations as ( - - select - patient_id - , observation_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__observation') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, labs as ( - - select - patient_id - , result_date - , collection_date - , source_code_type - , source_code - , normalized_code_type - , normalized_code - from {{ ref('quality_measures__stg_core__lab_result')}} - -) - -, qualifying_claims as ( - - select - medical_claim.patient_id - , coalesce( medical_claim.claim_start_date, medical_claim.claim_end_date) as claim_date - , screening_codes.concept_name - from medical_claim - inner join screening_periods - on medical_claim.claim_start_date between screening_periods.effective_performance_period_begin and screening_periods.performance_period_end - or medical_claim.claim_end_date between screening_periods.effective_performance_period_begin and screening_periods.performance_period_end - inner join screening_codes - on medical_claim.hcpcs_code = screening_codes.code - where screening_codes.code_system in ('hcpcs', 'cpt' ) - -) - -, qualifying_observations as ( - - select - observations.patient_id - , observations.observation_date - , screening_codes.concept_name - from observations - inner join screening_periods - on observations.observation_date between screening_periods.effective_performance_period_begin and screening_periods.performance_period_end - inner join screening_codes - on observations.code = screening_codes.code - and observations.code_type = screening_codes.code_system -) - -, qualifying_procedures as ( - - select - procedures.patient_id - , procedures.procedure_date - , screening_codes.concept_name - from procedures - inner join screening_periods - on procedures.procedure_date between screening_periods.effective_performance_period_begin and screening_periods.performance_period_end - inner join screening_codes - on procedures.code = screening_codes.code - and procedures.code_type = screening_codes.code_system - -) - -, normalized_code_labs as ( - select - patient_id - , coalesce(collection_date, result_date) as lab_date - , screening_codes.concept_name - from labs - inner join screening_periods - on coalesce(labs.collection_date, labs.result_date) >= screening_periods.effective_performance_period_begin - and coalesce(labs.collection_date, labs.result_date) <= screening_periods.performance_period_end - inner join screening_codes - on labs.normalized_code = screening_codes.code - and labs.normalized_code_type = screening_codes.code_system -) - -, source_code_labs as ( - - select - patient_id - , coalesce(collection_date, result_date) as lab_date - , screening_codes.concept_name - from labs - inner join screening_periods - on coalesce(labs.collection_date, labs.result_date) >= screening_periods.effective_performance_period_begin - and coalesce(labs.collection_date, labs.result_date) <= screening_periods.performance_period_end - inner join screening_codes - on labs.source_code = screening_codes.code - and labs.source_code_type = screening_codes.code_system - -) - -, qualifying_labs_union as ( - - select - patient_id - , lab_date - , concept_name - from normalized_code_labs - - union all - - select - patient_id - , lab_date - , concept_name - from source_code_labs - -) - -, qualifying_labs as ( - - select distinct - patient_id - , lab_date - , concept_name - from qualifying_labs_union - -) - -, qualifying_events as ( - - select - patient_id - , claim_date as evidence_date - , concept_name as evidence - from qualifying_claims - - union all - - select - patient_id - , observation_date as evidence_date - , concept_name as evidence - from qualifying_observations - - union all - - select - patient_id - , procedure_date as evidence_date - , concept_name as evidence - from qualifying_procedures - - union all - - select - patient_id - , lab_date as evidence_date - , concept_name as evidence - from qualifying_labs - -) - -select - cast( qualifying_events.patient_id as {{ dbt.type_string() }}) as patient_id - , cast( evidence_date as date) as evidence_date - , cast( evidence as {{ dbt.type_string() }}) as evidence -from qualifying_events -inner join denominator - on qualifying_events.patient_id = denominator.patient_id diff --git a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041__performance_period.sql b/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041__performance_period.sql deleted file mode 100644 index e6397856a..000000000 --- a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041__performance_period.sql +++ /dev/null @@ -1,98 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF0041') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF0041') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF0041') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided - - set quality_measures_period_end to december end for last quarter measurement period - - set quality_measures_period_end to march end for first quarter measurement period -*/ - -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end - -) - -/* - set performance period begin to following day of 3 months prior - for visits in influenza season -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "month" - , interval = -3 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -/* - lookback_period for august of either current or previous year - for immunization qualifying date -*/ -, lookback_period as ( - - select - * - , case - when {{ date_part('month', 'performance_period_end') | as_number }} between 1 and 8 - then {{ dbt.concat([ - "(cast(" ~ - date_part('year', 'performance_period_end') ~ - " as integer) - 1)", - "'-08-01'" - ]) }} - else {{ dbt.concat([ - date_part('year', 'performance_period_end'), - "'-08-01'" - ]) }} - end as lookback_period_august - from period_begin - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(lookback_period_august as date) as lookback_period_august -from lookback_period diff --git a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_denominator.sql b/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_denominator.sql deleted file mode 100644 index 57fe8690b..000000000 --- a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_denominator.sql +++ /dev/null @@ -1,170 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'annual wellness visit' - , 'discharge services nursing facility' - , 'hemodialysis' - , 'home healthcare services' - , 'nursing facility visit' - , 'office visit' - , 'outpatient consultation' - , 'peritoneal dialysis' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services group counseling' - , 'preventive care services individual counseling' - , 'preventive care services initial office visit, 18 and up' - , 'preventive care services, initial office visit, 0 to 17' - , 'preventive care, established office visit, 0 to 17' - , 'online assessments' - , 'patient provider interaction' - , 'telephone visits' - ) - -) - -, visits_encounters as ( - - select patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ ref('quality_measures__stg_core__encounter') }} encounter - inner join {{ ref('quality_measures__int_nqf0041__performance_period') }} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ ref('quality_measures__stg_core__procedure') }} procedures - inner join {{ ref('quality_measures__int_nqf0041__performance_period') }} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procedures.normalized_code,procedures.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ ref('quality_measures__stg_medical_claim') }} medical_claim - inner join {{ ref('quality_measures__int_nqf0041__performance_period') }} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code = visit_codes.code - -) - -, all_encounters as ( - - select *, 'v' as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - - union all - - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id, min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - , coalesce(min(proc_enc),'')) - , coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , ({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as age_in_decimal_point - , max_date - , qualifying_types - from {{ ref('quality_measures__stg_core__patient') }} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - -, qualifying_patients as ( - - select - distinct - patients_with_age.patient_id - , patients_with_age.age_in_decimal_point as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from patients_with_age - cross join {{ ref('quality_measures__int_nqf0041__performance_period') }} pp - where age_in_decimal_point >= 0.5 --filters patients aged 6 months or older - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , round(cast(age as {{ dbt.type_numeric() }}), 1) as age -- ensures age is seen in one decimal point - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_exclusions.sql b/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_exclusions.sql deleted file mode 100644 index 47da89892..000000000 --- a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_exclusions.sql +++ /dev/null @@ -1,191 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - - select - performance_period_begin - from {{ ref('quality_measures__int_nqf0041__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - - select - performance_period_end - from {{ ref('quality_measures__int_nqf0041__performance_period') }} - -) -{%- endset -%} - -with denominator as ( - - select - patient_id - from {{ ref('quality_measures__int_nqf0041_denominator') }} - -) - -, exclusion_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'influenza immunization not ordered or administered reason documented' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - where procedure_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - where coalesce(claim_end_date, claim_start_date) between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, procedure_exclusions as ( - - select - procedures.patient_id - , procedures.procedure_date - , exclusion_codes.concept_name as concept_name - from procedures - inner join exclusion_codes - on procedures.code = exclusion_codes.code - and procedures.code_type = exclusion_codes.code_system - -) - -, med_claim_exclusions as ( - - select - medical_claim.patient_id - , coalesce(medical_claim.claim_end_date, medical_claim.claim_start_date) as exclusion_date - , medical_claim.hcpcs_code - , exclusion_codes.concept_name as concept_name - from medical_claim - inner join exclusion_codes - on medical_claim.hcpcs_code = exclusion_codes.code - and exclusion_codes.code_system = 'hcpcs' - -) - -, hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ ref('quality_measures__int_shared_exclusions_hospice_palliative') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from hospice_palliative - where exclusion_reason in ( - 'hospice care ambulatory' - , 'hospice encounter' - ) - -) - -, valid_exclusions as ( - - select - patient_id - , procedure_date as exclusion_date - , concept_name as exclusion_reason - from procedure_exclusions - - union all - - select - patient_id - , exclusion_date - , concept_name as exclusion_reason - from med_claim_exclusions - - union all - - select - patient_id - , exclusion_date - , exclusion_reason - from valid_hospice_palliative - -) - -, combined_exclusions as ( - - select - valid_exclusions.patient_id - , valid_exclusions.exclusion_date - , valid_exclusions.exclusion_reason - from valid_exclusions - inner join denominator - on valid_exclusions.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(1 as integer) as exclusion_flag - from combined_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_long.sql b/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_long.sql deleted file mode 100644 index 27586ae77..000000000 --- a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_long.sql +++ /dev/null @@ -1,152 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_nqf0041_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_nqf0041_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf0041_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_numerator.sql b/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_numerator.sql deleted file mode 100644 index 69c3ebaa5..000000000 --- a/models/quality_measures/intermediate/nqf0041_influenza_immunization/quality_measures__int_nqf0041_numerator.sql +++ /dev/null @@ -1,146 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_nqf0041_denominator') }} - -) - -, influenza_vaccination_code as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'influenza vaccination' - , 'influenza vaccine' - , 'influenza virus laiv immunization' - , 'influenza virus laiv procedure' - ) - -) - -, procedure_vaccination as ( - - select - patient_id - , procedure_date - from {{ ref('quality_measures__stg_core__procedure') }} as procedures - inner join influenza_vaccination_code - on coalesce(procedures.normalized_code, procedures.source_code) = influenza_vaccination_code.code - and coalesce(procedures.normalized_code_type, procedures.source_code_type) = influenza_vaccination_code.code_system - -) - -, claims_vaccination as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ ref('quality_measures__stg_medical_claim') }} medical_claim - inner join influenza_vaccination_code - on medical_claim.hcpcs_code = influenza_vaccination_code.code - -) - -, qualifying_procedures as ( - - select - procedure_vaccination.patient_id - , procedure_vaccination.procedure_date as evidence_date - from procedure_vaccination - inner join {{ ref('quality_measures__int_nqf0041__performance_period') }} pp - on procedure_date between - pp.lookback_period_august and - pp.performance_period_end - -) - -, qualifying_claims as ( - - select - claims_vaccination.patient_id - , claims_vaccination.max_date as evidence_date - from claims_vaccination - inner join {{ ref('quality_measures__int_nqf0041__performance_period') }} pp - on max_date between - pp.lookback_period_august and - pp.performance_period_end - -) - -, qualified_patients as ( - - select - patient_id - , evidence_date - from qualifying_procedures - - union all - - select - patient_id - , evidence_date - from qualifying_claims - -) - -, combined_qualifying_patients as ( - - select - qualified_patients.patient_id - , qualified_patients.evidence_date - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.performance_period_begin - , denominator.performance_period_end - , 1 as numerator_flag - from qualified_patients - inner join denominator - on qualified_patients.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from combined_qualifying_patients - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053__performance_period.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053__performance_period.sql deleted file mode 100644 index f90070052..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053__performance_period.sql +++ /dev/null @@ -1,89 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF0053') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF0053') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF0053') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - --- lookback_period for last june 30 and december 31 -, lookback_period as ( - -SELECT - * - , case - when performance_period_end >= cast(({{ dbt.concat([date_part('year', 'performance_period_end'), "'-06-30'"]) }}) as date) - then {{ dbt.concat([date_part('year', 'performance_period_end'), "'-06-30'"]) }} - else {{ dbt.concat([date_part('year', 'performance_period_begin'), "'-06-30'"]) }} - end as lookback_period_june - , case - when performance_period_end >= cast(({{ dbt.concat([date_part('year', 'performance_period_end'), "'-12-31'"]) }}) as date) - then {{ dbt.concat([date_part('year', 'performance_period_end'), "'-12-31'"]) }} - else {{ dbt.concat([date_part('year', 'performance_period_begin'), "'-12-31'"]) }} - end as lookback_period_december -FROM period_begin - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(lookback_period_june as date) as lookback_period_june - , cast(lookback_period_december as date) as lookback_period_december -from lookback_period diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_denominator.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_denominator.sql deleted file mode 100644 index 3465b19f4..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_denominator.sql +++ /dev/null @@ -1,311 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} as value_sets - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, visits_encounters as ( - - select - patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - , encounter_type - from {{ref('quality_measures__stg_core__encounter')}} as encounter - inner join {{ ref('quality_measures__int_nqf0053__performance_period') }} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ref('quality_measures__stg_core__procedure')}} procs - inner join {{ref('quality_measures__int_nqf0053__performance_period')}} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procs.normalized_code,procs.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - , place_of_service_code - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_nqf0053__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code= visit_codes.code - -) - -, all_encounters as ( - - select - patient_id - , min_date - , max_date - , 'v' as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - union all - select - patient_id - , min_date - , max_date - , cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - union all - select - patient_id - , min_date - , max_date - , cast(null as {{ dbt.type_string() }}) as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select - patient_id - , min(min_date) min_date - , max(max_date) max_date - , concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, bone_fracture_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) = 'fracture diagnoses' - -) - -, conditions as ( - - select - patient_id - , claim_id - , encounter_id - , recorded_date - , source_code - , source_code_type - , normalized_code - , normalized_code_type - from {{ ref('quality_measures__stg_core__condition')}} - -) - -, bone_fracture_conditions as ( - - select - conditions.patient_id - , conditions.claim_id - , conditions.encounter_id - , conditions.recorded_date - , conditions.source_code - , conditions.source_code_type - from conditions - inner join bone_fracture_codes - on coalesce(conditions.normalized_code_type, conditions.source_code_type) = bone_fracture_codes.code_system - and coalesce(conditions.normalized_code, conditions.source_code) = bone_fracture_codes.code - -) - -, patients_with_age as ( - - select - patient.patient_id - , patient.sex - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8760.0) as min_age - , max_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} patient - inner join encounters_by_patient e - on patient.patient_id = e.patient_id - where patient.death_date is null - -) - -, qualifying_patients_w_fractures as ( - - select - distinct - bone_fracture_conditions.patient_id - , bone_fracture_conditions.recorded_date - , patients_with_age.max_age as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from bone_fracture_conditions - left join patients_with_age - on bone_fracture_conditions.patient_id = patients_with_age.patient_id - cross join {{ref('quality_measures__int_nqf0053__performance_period')}} pp - where max_age >= 50 and min_age <= 85 - and bone_fracture_conditions.recorded_date between - {{ dbt.dateadd ( - datepart = "month" - , interval = -6 - , from_date_or_timestamp = "performance_period_begin" - ) - }} - and - pp.lookback_period_june - and lower(patients_with_age.sex) = 'female' - -) - -, fracture_procedures as ( - - select - procedures.* - from procedures - inner join visit_codes - on procedures.code = visit_codes.code - and procedures.code_type = visit_codes.code_system - inner join {{ ref('quality_measures__int_nqf0053__performance_period') }} as pp - on procedures.procedure_date - between pp.performance_period_begin and pp.performance_period_end - where lower(visit_codes.concept_name) = 'fracture procedures' - -) - -, qualifying_patients_w_encounter as ( - - select - qualifying_patients_w_fractures.* - from qualifying_patients_w_fractures - inner join visits_encounters - on qualifying_patients_w_fractures.patient_id = visits_encounters.patient_id - where - lower(visits_encounters.encounter_type) in ( - 'acute inpatient' - , 'annual wellness visit' - , 'emergency department visit' - , 'emergency department' - , 'home healthcare services' - , 'office visit' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services initial office visit, 18 and up' - , 'emergency department evaluation and management visit' - , 'outpatient' - ) -) - -, qualifying_patients_w_procedure as ( - - select - qualifying_patients_w_fractures.* - from qualifying_patients_w_fractures - inner join fracture_procedures - on qualifying_patients_w_fractures.patient_id = fracture_procedures.patient_id - -) - -, qualifying_patients as ( - - select - distinct - qualifying_patients_w_encounter.* - from qualifying_patients_w_encounter - left join qualifying_patients_w_procedure - on qualifying_patients_w_encounter.patient_id = qualifying_patients_w_procedure.patient_id - left join claims_encounters - on qualifying_patients_w_encounter.patient_id = claims_encounters.patient_id - where (cast(claims_encounters.place_of_service_code as {{ dbt.type_string() }}) not in ('21') - or claims_encounters.patient_id is null) - - union all - - select - distinct - qualifying_patients_w_procedure.* - from qualifying_patients_w_procedure - left join qualifying_patients_w_encounter - on qualifying_patients_w_encounter.patient_id = qualifying_patients_w_procedure.patient_id - where qualifying_patients_w_encounter.patient_id is null - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(recorded_date as date) as recorded_date - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , recorded_date - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclude_procedures_medications.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclude_procedures_medications.sql deleted file mode 100644 index 03e9df78f..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclude_procedures_medications.sql +++ /dev/null @@ -1,221 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - from {{ ref('quality_measures__int_nqf0053_denominator')}} - -) - -, value_sets as ( - - select - concept_name - , code - , code_system - from {{ ref('quality_measures__value_sets')}} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, pharmacy_claims as ( - - select - patient_id - , dispensing_date - , ndc_code - from {{ ref('quality_measures__stg_pharmacy_claim') }} - -) - -, medications as ( - - select - patient_id - , encounter_id - , prescribing_date - , dispensing_date - , source_code - , source_code_type - from {{ ref('quality_measures__stg_core__medication') }} - -) - -, bone_density_test_codes as ( - - select - concept_name - , code - , code_system - from value_sets - where lower(concept_name) in ( - 'bone mineral density test' - , 'bone mineral density tests cpt' - , 'bone mineral density tests hcpcs' - , 'bone mineral density tests icd10pcs' - , 'dexa dual energy xray absorptiometry, bone density' - ) - -) - -, osteoporosis_medication_codes as ( - - select - code - , code_system - , concept_name - from value_sets - where lower(concept_name) in - ( - 'osteoporosis medications for urology care' - , 'osteoporosis medication' - , 'bisphosphonates' - ) - -) - -, bone_density_test_procedures as ( - - select - procedures.* - , bone_density_test_codes.concept_name - from procedures - inner join bone_density_test_codes - on procedures.code = bone_density_test_codes.code - and procedures.code_type = bone_density_test_codes.code_system - -) - -, osteoporosis_pharmacy_claims as ( - - select - pharmacy_claims.patient_id - , pharmacy_claims.dispensing_date - , pharmacy_claims.ndc_code - , osteoporosis_medication_codes.concept_name - from pharmacy_claims - inner join osteoporosis_medication_codes - on pharmacy_claims.ndc_code = osteoporosis_medication_codes.code - and lower(osteoporosis_medication_codes.code_system) = 'ndc' - -) - -, osteoporosis_medications as ( - - select - medications.patient_id - , medications.encounter_id - , medications.prescribing_date - , medications.dispensing_date - , medications.source_code - , medications.source_code_type - , osteoporosis_medication_codes.concept_name - from medications - inner join osteoporosis_medication_codes - on medications.source_code = osteoporosis_medication_codes.code - and medications.source_code_type = osteoporosis_medication_codes.code_system - -) - -, valid_osteoporosis_medications_procedures as ( - - select - denominator.patient_id - , osteoporosis_pharmacy_claims.concept_name as exclusion_reason - , osteoporosis_pharmacy_claims.dispensing_date as exclusion_date - from denominator - inner join osteoporosis_pharmacy_claims - on denominator.patient_id = osteoporosis_pharmacy_claims.patient_id - where osteoporosis_pharmacy_claims.dispensing_date - between - {{ dbt.dateadd ( - datepart = "month" - , interval = -12 - , from_date_or_timestamp = "denominator.performance_period_begin" - )}} - and denominator.performance_period_begin - - union all - - select - denominator.patient_id - , osteoporosis_medications.concept_name as exclusion_reason - , coalesce(osteoporosis_medications.prescribing_date, osteoporosis_medications.dispensing_date) as exclusion_date - from denominator - inner join osteoporosis_medications - on denominator.patient_id = osteoporosis_medications.patient_id - and coalesce(osteoporosis_medications.prescribing_date, osteoporosis_medications.dispensing_date) - between - {{ dbt.dateadd ( - datepart = "month" - , interval = -12 - , from_date_or_timestamp = "denominator.performance_period_begin" - )}} - and denominator.performance_period_begin - -) - -, valid_tests_performed as ( - - select - denominator.patient_id - , bone_density_test_procedures.concept_name as exclusion_reason - , procedure_date as exclusion_date - from denominator - inner join bone_density_test_procedures - on denominator.patient_id = bone_density_test_procedures.patient_id - where bone_density_test_procedures.procedure_date - between - {{ dbt.dateadd ( - datepart = "year" - , interval = -2 - , from_date_or_timestamp = "denominator.performance_period_begin" - )}} - and denominator.performance_period_begin - -) - -, valid_exclusions as ( - - select * from valid_tests_performed - - union all - - select * from valid_osteoporosis_medications_procedures - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , 'measure specific exclusion for procedure medication' as exclusion_type - , '{{ var('tuva_last_run')}}' as tuva_last_run -from - valid_exclusions \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions.sql deleted file mode 100644 index 2e500aa4e..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions.sql +++ /dev/null @@ -1,79 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with - -combined_exclusions as ( - - select - exclusions.* - , denominator.age - from {{ ref('quality_measures__int_nqf0053_exclusions_stage_1') }} as exclusions - inner join {{ref('quality_measures__int_nqf0053_denominator')}} as denominator - on exclusions.patient_id = denominator.patient_id - -) - -, valid_exclusions as ( - - select - * - from combined_exclusions - where exclusion_type = 'institutional_snp' - and age >= 66 - - union all - - select - * - from combined_exclusions - where exclusion_type in - ( - 'advanced_illness' - , 'dementia' - ) - and age between 66 and 80 - - union all - - select - * - from combined_exclusions - where exclusion_type = 'measure specific exclusion for defined window' - and age >= 81 - - union all - - select - * - from combined_exclusions - where exclusion_type in - ( - 'measure specific exclusion for procedure medication' - , 'hospice_palliative' - ) - -) - - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions_stage_1.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions_stage_1.sql deleted file mode 100644 index bce97e044..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_exclusions_stage_1.sql +++ /dev/null @@ -1,250 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_nqf0053__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_nqf0053__performance_period') }} - -) -{%- endset -%} - -{%- set lookback_period_december -%} -( - select - lookback_period_december - from {{ ref('quality_measures__int_nqf0053__performance_period') }} - -) -{%- endset -%} - - -with frailty as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, frailty_within_defined_window as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between - {{ dbt.dateadd ( - datepart = "month" - , interval = -6 - , from_date_or_timestamp = performance_period_begin - ) - }} - and {{ lookback_period_december }} - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, exclusion_procedure_and_medication as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_nqf0053_exclude_procedures_medications')}} - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between - {{dbt.dateadd( - datepart = "month" - , interval = -6 - , from_date_or_timestamp = performance_period_begin - ) - }} - - and {{ lookback_period_december }} - -) - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - - -) --- advanced illness end - -, frailty_patients_within_defined_window as ( - - select - frailty_within_defined_window.patient_id - , frailty_within_defined_window.exclusion_date - , frailty_within_defined_window.exclusion_reason - , 'measure specific exclusion for defined window' as exclusion_type - from frailty_within_defined_window - -) - -, exclusions as ( - - select * from valid_advanced_illness_exclusions - - union all - - select * from valid_dementia_exclusions - - union all - - select * from valid_institutional_snp - - union all - - select * from valid_hospice_palliative - - union all - - select * from exclusion_procedure_and_medication - - union all - - select * from frailty_patients_within_defined_window - -) - -select - * - , '{{ var('tuva_last_run')}}' as tuva_last_run -from exclusions diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_long.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_long.sql deleted file mode 100644 index 95da7a80a..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_long.sql +++ /dev/null @@ -1,152 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_nqf0053_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_nqf0053_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf0053_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_numerator.sql b/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_numerator.sql deleted file mode 100644 index c3dbe8863..000000000 --- a/models/quality_measures/intermediate/nqf0053_osteoporosis_management_in_women_who_had_a_fracture/quality_measures__int_nqf0053_numerator.sql +++ /dev/null @@ -1,282 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , recorded_date - , measure_id - , measure_name - , measure_version - from {{ref('quality_measures__int_nqf0053_denominator')}} - -) - -, value_sets as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - -) - -, osteo_procedure_codes as ( - - select - code - , code_system - , concept_name - from value_sets - where lower(concept_name) in ( - 'bone mineral density test' - , 'bone mineral density tests cpt' - , 'bone mineral density tests icd10pcs' - , 'bone mineral density tests hcpcs' - , 'dexa dual energy xray absorptiometry, bone density' - , 'central dual energy x-ray absorptiometry (dxa)' - , 'spinal densitometry x-ray' - , 'ultrasonography for densitometry' - , 'ct bone density axial' - , 'peripheral dual-energy x-ray absorptiometry (dxa)' - , 'osteoporosis medication' - ) - -) - -, procedures_osteo_related as ( - - select - patient_id - , procedure_date - from {{ref('quality_measures__stg_core__procedure')}} as procs - inner join osteo_procedure_codes - on coalesce(procs.normalized_code, procs.source_code) = osteo_procedure_codes.code - and coalesce(procs.normalized_code_type, procs.source_code_type) = osteo_procedure_codes.code_system - -) - -, qualifying_procedures as ( - - select - procedures_osteo_related.patient_id - , procedures_osteo_related.procedure_date - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.recorded_date - , denominator.performance_period_begin - , denominator.performance_period_end - from procedures_osteo_related - inner join denominator - on procedures_osteo_related.patient_id = denominator.patient_id - and - procedures_osteo_related.procedure_date between - denominator.recorded_date - and - {{dbt.dateadd ( - datepart = "month" - , interval = +6 - , from_date_or_timestamp = "denominator.recorded_date" - ) - }} - -) - -, denominator_patients_disqualified_from_procedure as ( - - select - denominator.patient_id - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , denominator.recorded_date - , denominator.performance_period_begin - , denominator.performance_period_end - from denominator - left join qualifying_procedures - on denominator.patient_id = qualifying_procedures.patient_id - where qualifying_procedures.patient_id is null - -) - --- pharmacy_claim begin - -, osteo_rx_codes as ( - - select - code - , code_system - , concept_name - from value_sets - where lower(concept_name) - in - ( - 'osteoporosis medications for urology care' - , 'osteoporosis medication' - , 'bisphosphonates' - ) - -) - -, pharmacy_claims_osteo_related as ( - - select - patient_id - , dispensing_date - , ndc_code - from {{ref('quality_measures__stg_pharmacy_claim')}} as pharmacy_claims - inner join osteo_rx_codes - on pharmacy_claims.ndc_code = osteo_rx_codes.code - and lower(osteo_rx_codes.code_system) = 'ndc' - -) - -, qualifying_pharmacy_claims as ( - - select - pharmacy_claims_osteo_related.patient_id - , pharmacy_claims_osteo_related.dispensing_date - , pharmacy_claims_osteo_related.ndc_code - , denominator_patients_disqualified_from_procedure.measure_id - , denominator_patients_disqualified_from_procedure.measure_name - , denominator_patients_disqualified_from_procedure.measure_version - , denominator_patients_disqualified_from_procedure.recorded_date - , denominator_patients_disqualified_from_procedure.performance_period_begin - , denominator_patients_disqualified_from_procedure.performance_period_end - from pharmacy_claims_osteo_related - inner join denominator_patients_disqualified_from_procedure - on pharmacy_claims_osteo_related.patient_id = denominator_patients_disqualified_from_procedure.patient_id - and pharmacy_claims_osteo_related.dispensing_date - between - denominator_patients_disqualified_from_procedure.recorded_date - and - {{ dbt.dateadd ( - datepart = "month" - , interval = +6 - , from_date_or_timestamp = "denominator_patients_disqualified_from_procedure.recorded_date" - ) - }} -) - --- medication begin - -, medication_osteo_related as ( - - select - patient_id - , encounter_id - , prescribing_date - , dispensing_date - , source_code - , source_code_type - , ndc_code - , rxnorm_code - from {{ref('quality_measures__stg_core__medication')}} as medications - inner join osteo_rx_codes - on medications.source_code = osteo_rx_codes.code - and medications.source_code_type = osteo_rx_codes.code_system - -) - -, qualifying_medications as ( - - select - medication_osteo_related.patient_id - , medication_osteo_related.encounter_id - , denominator_patients_disqualified_from_procedure.measure_id - , denominator_patients_disqualified_from_procedure.measure_name - , denominator_patients_disqualified_from_procedure.measure_version - , denominator_patients_disqualified_from_procedure.recorded_date - , denominator_patients_disqualified_from_procedure.performance_period_begin - , denominator_patients_disqualified_from_procedure.performance_period_end - from medication_osteo_related - inner join denominator_patients_disqualified_from_procedure - on medication_osteo_related.patient_id = denominator_patients_disqualified_from_procedure.patient_id - and coalesce(medication_osteo_related.prescribing_date, medication_osteo_related.dispensing_date) between - denominator_patients_disqualified_from_procedure.recorded_date - and - {{ dbt.dateadd ( - datepart = "month" - , interval = +6 - , from_date_or_timestamp = "denominator_patients_disqualified_from_procedure.recorded_date" - ) - }} - -) - -, numerator as ( - - select - qualifying_procedures.patient_id - , qualifying_procedures.performance_period_begin - , qualifying_procedures.performance_period_end - , qualifying_procedures.measure_id - , qualifying_procedures.measure_name - , qualifying_procedures.measure_version - , recorded_date as evidence_date - , 1 as numerator_flag - from qualifying_procedures - - union all - - select - qualifying_pharmacy_claims.patient_id - , qualifying_pharmacy_claims.performance_period_begin - , qualifying_pharmacy_claims.performance_period_end - , qualifying_pharmacy_claims.measure_id - , qualifying_pharmacy_claims.measure_name - , qualifying_pharmacy_claims.measure_version - , recorded_date as evidence_date - , 1 as numerator_flag - from qualifying_pharmacy_claims - - union all - - select - qualifying_medications.patient_id - , qualifying_medications.performance_period_begin - , qualifying_medications.performance_period_end - , qualifying_medications.measure_id - , qualifying_medications.measure_name - , qualifying_medications.measure_version - , recorded_date as evidence_date - , 1 as numerator_flag - from qualifying_medications - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from numerator - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059__performance_period.sql b/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059__performance_period.sql deleted file mode 100644 index 89749b24e..000000000 --- a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059__performance_period.sql +++ /dev/null @@ -1,67 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF0059') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF0059') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF0059') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_denominator.sql b/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_denominator.sql deleted file mode 100644 index c91adadce..000000000 --- a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_denominator.sql +++ /dev/null @@ -1,191 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'office visit' - , 'home healthcare services' - , 'preventive care services established office visit, 18 and up' - , 'preventive care services initial office visit, 18 and up' - , 'annual wellness visit' - , 'telephone visits' - , 'nutrition services' - ) - -) - -, visits_encounters as ( - - select patient_id - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ref('quality_measures__stg_core__encounter')}} encounter - inner join {{ref('quality_measures__int_nqf0059__performance_period')}} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ref('quality_measures__stg_core__procedure')}} procs - inner join {{ref('quality_measures__int_nqf0059__performance_period')}} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join visit_codes - on coalesce(procs.normalized_code,procs.source_code) = visit_codes.code - -) - -, claims_encounters as ( - - select - patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_nqf0059__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join visit_codes - on medical_claim.hcpcs_code= visit_codes.code - -) - -, all_encounters as ( - select *, 'v' as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc, 'p' as proc_enc, cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - union all - select *, cast(null as {{ dbt.type_string() }}) as visit_enc,cast(null as {{ dbt.type_string() }}) as proc_enc, 'c' as claim_enc - from claims_encounters -) - -, encounters_by_patient as ( - select patient_id,min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id -) - -, diabetics_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'diabetes' - , 'hba1c laboratory test' - ) -) - -, conditions as ( - - select - patient_id - , recorded_date - , source_code - , source_code_type - , normalized_code - , normalized_code_type - from {{ ref('quality_measures__stg_core__condition') }} - -) - -, diabetic_conditions as ( - - select - conditions.patient_id - , conditions.recorded_date - from conditions - inner join diabetics_codes - on coalesce(conditions.normalized_code_type, conditions.source_code_type) = diabetics_codes.code_system - and coalesce(conditions.normalized_code, conditions.source_code) = diabetics_codes.code - -) - -, patients_with_age as ( - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8760.0) as min_age - , max_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - -, qualifying_patients as ( - - select - distinct - diabetic_conditions.patient_id - , patients_with_age.max_age as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , 1 as denominator_flag - from diabetic_conditions - left join patients_with_age - on diabetic_conditions.patient_id = patients_with_age.patient_id - cross join {{ref('quality_measures__int_nqf0059__performance_period')}} pp - where max_age >= 18 and min_age <= 75 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_exclusions.sql b/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_exclusions.sql deleted file mode 100644 index 0bf33f81d..000000000 --- a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_exclusions.sql +++ /dev/null @@ -1,218 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_nqf0059__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_nqf0059__performance_period') }} - -) -{%- endset -%} - -with frailty as ( - - select - * - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - - -) --- advanced illness end - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, exclusions as ( - - select * from valid_advanced_illness_exclusions - union all - select * from valid_dementia_exclusions - union all - select * from valid_hospice_palliative - union all - select * from valid_institutional_snp - -) - -, combined_exclusions as ( - - select - exclusions.* - , denominator.age - from exclusions - inner join {{ref('quality_measures__int_nqf0059_denominator')}} as denominator - on exclusions.patient_id = denominator.patient_id - -) - -, valid_exclusions as ( - - select - * - from combined_exclusions - where exclusion_type != 'hospice_palliative' - and age >= 66 - - union all - - select - * - from combined_exclusions - where exclusion_type = 'hospice_palliative' - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_long.sql b/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_long.sql deleted file mode 100644 index 090871aa7..000000000 --- a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_long.sql +++ /dev/null @@ -1,153 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_nqf0059_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_nqf0059_numerator') }} - where numerator_flag = 1 - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf0059_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_numerator.sql b/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_numerator.sql deleted file mode 100644 index 112a21d77..000000000 --- a/models/quality_measures/intermediate/nqf0059_diabetes_hemoglobin_a1c/quality_measures__int_nqf0059_numerator.sql +++ /dev/null @@ -1,169 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_nqf0059_denominator') }} - -) - -, hba1c_test_code as ( - - select - code - , code_system - , concept_name - From {{ref('quality_measures__value_sets')}} - where lower(concept_name) in ( - 'hba1c laboratory test' - ) - -) - -, labs as ( - - select - patient_id - , result - , result_date - , collection_date - , source_code_type - , source_code - , normalized_code_type - , normalized_code - from {{ ref('quality_measures__stg_core__lab_result')}} - -) - -, qualifying_labs as ( - - select - labs.patient_id - , labs.result as evidence_value - , coalesce(collection_date,result_date) as evidence_date - , hba1c_test_code.concept_name - , row_number() over(partition by labs.patient_id order by coalesce(collection_date,result_date) desc) as rn - from labs - inner join hba1c_test_code - on coalesce(labs.normalized_code, labs.source_code) = hba1c_test_code.code - and coalesce(labs.normalized_code_type, labs.source_code_type) = hba1c_test_code.code_system - left join denominator - on labs.patient_id = denominator.patient_id - where coalesce(collection_date,result_date) <= denominator.performance_period_end - {% if target.type == 'fabric' %} - and result LIKE '%.%' OR result LIKE '%[0-9]%' - AND result NOT LIKE '%[^0-9.]%' - {% else %} - and {{ apply_regex('result', '^[+-]?([0-9]*[.])?[0-9]+$') }} - {% endif %} - -) - -, recent_readings as ( - - select - patient_id - , evidence_date - , evidence_value - from qualifying_labs - where rn = 1 - -) - -, qualifying_patients as ( - - select - denominator.* - , recent_readings.evidence_date - , recent_readings.evidence_value - from denominator - left join recent_readings - on denominator.patient_id = recent_readings.patient_id - -) - -, test_not_performed as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , 1 as numerator_flag - from qualifying_patients - where - (evidence_date not between performance_period_begin and performance_period_end) - or evidence_date is null - -) - -, valid_patients as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , case - when cast(evidence_value as {{ dbt.type_numeric() }}) > 9.0 then 1 - else 0 - end as numerator_flag - from qualifying_patients - where evidence_date between performance_period_begin and performance_period_end - -) - -, numerator as ( - - select * from valid_patients - - union all - - select * from test_not_performed - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from numerator - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag -from add_data_types diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372__performance_period.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372__performance_period.sql deleted file mode 100644 index 02c26ab60..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372__performance_period.sql +++ /dev/null @@ -1,86 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF2372') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF2372') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF2372') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -/* - set performance lookback period to 27 months prior to the end of the - performance period -*/ -, period_lookback as ( - - select - performance_period_end - , performance_period_begin - , {{ dbt.dateadd ( - datepart = "month" - , interval = -27 - , from_date_or_timestamp = "performance_period_end" - ) }} as performance_period_lookback - from period_begin - - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_end as date) as performance_period_end - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_lookback as date) as performance_period_lookback -from period_lookback \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_denominator.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_denominator.sql deleted file mode 100644 index f2172aff8..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_denominator.sql +++ /dev/null @@ -1,250 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with performance_period as ( - - select - measure_id - , measure_name - , measure_version - , performance_period_end - , performance_period_begin - , performance_period_lookback - from {{ ref('quality_measures__int_nqf2372__performance_period') }} - -) - -, patient as ( - - select - patient_id - , sex - , birth_date - , death_date - from {{ ref('quality_measures__stg_core__patient') }} - -) - -, encounters as ( - - select - patient_id - , encounter_type - , encounter_start_date - from {{ ref('quality_measures__stg_core__encounter') }} - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, visit_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where concept_name in ( - 'Office Visit' - , 'Home Healthcare Services' - , 'Preventive Care Services Established Office Visit, 18 and Up' - , 'Preventive Care Services Initial Office Visit, 18 and Up' - , 'Annual Wellness Visit' - , 'Telephone Visits' - , 'Online Assessments' - ) - -) - -, patient_with_age as ( - - select - patient.patient_id - , patient.sex - , patient.birth_date - , patient.death_date - , performance_period.measure_id - , performance_period.measure_name - , performance_period.measure_version - , performance_period.performance_period_begin - , performance_period.performance_period_end - , performance_period.performance_period_lookback - , floor({{ datediff('patient.birth_date', 'performance_period.performance_period_begin', 'hour') }} / 8760.0) as age -- 365*24 hours in a year - from patient - cross join performance_period - -) - -/* - Filter patient to living women 51 - 74 years of age - at the beginning of the measurement period -*/ -, patient_filtered as ( - - select - patient_id - , age - , measure_id - , measure_name - , measure_version - , performance_period_begin - , performance_period_end - , performance_period_lookback - , 1 as denominator_flag - from patient_with_age - where lower(sex) = 'female' - and age between 51 and 74 - and death_date is null - -) - -/* - Filter to qualifying visit types by claim procedures -*/ -, visit_claims as ( - - select - medical_claim.patient_id - , medical_claim.claim_start_date - , medical_claim.claim_end_date - , medical_claim.hcpcs_code - from medical_claim - inner join visit_codes - on medical_claim.hcpcs_code = visit_codes.code - where visit_codes.code_system = 'hcpcs' - -) - -/* - Filter encounters to qualifying visit type -*/ -, visit_encounters as ( - - select - patient_id - , encounter_start_date - from encounters - where lower(encounter_type) in ( - 'home health' - , 'office visit' - , 'outpatient' - , 'outpatient rehabilitation' - , 'telehealth' - ) - -) - -/* - Filter to qualifying visit types by procedure -*/ -, visit_procedures as ( - - select - procedures.patient_id - , procedures.procedure_date - from procedures - inner join visit_codes - on procedures.code = visit_codes.code - and procedures.code_type = visit_codes.code_system - -) - -/* - Filter to final eligible population/denominator before exclusions - with a qualifying visit during the measurement period -*/ -, eligible_population as ( - - select - patient_filtered.patient_id - , patient_filtered.age - , patient_filtered.measure_id - , patient_filtered.measure_name - , patient_filtered.measure_version - , patient_filtered.performance_period_begin - , patient_filtered.performance_period_end - , performance_period_lookback - , patient_filtered.denominator_flag - from patient_filtered - left join visit_claims - on patient_filtered.patient_id = visit_claims.patient_id - left join visit_procedures - on patient_filtered.patient_id = visit_procedures.patient_id - left join visit_encounters - on patient_filtered.patient_id = visit_encounters.patient_id - where ( - visit_claims.claim_start_date - between patient_filtered.performance_period_begin - and patient_filtered.performance_period_end - or visit_claims.claim_end_date - between patient_filtered.performance_period_begin - and patient_filtered.performance_period_end - or visit_procedures.procedure_date - between patient_filtered.performance_period_begin - and patient_filtered.performance_period_end - or visit_encounters.encounter_start_date - between patient_filtered.performance_period_begin - and patient_filtered.performance_period_end - ) - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(performance_period_lookback as date) as performance_period_lookback - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(denominator_flag as integer) as denominator_flag - from eligible_population - -) - - select distinct - patient_id - , age - , performance_period_begin - , performance_period_end - , performance_period_lookback - , measure_id - , measure_name - , measure_version - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclude_mastectomy.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclude_mastectomy.sql deleted file mode 100644 index bc08ad23d..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclude_mastectomy.sql +++ /dev/null @@ -1,272 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -/* - Women who had a bilateral mastectomy or who have a history of a bilateral - mastectomy or for whom there is evidence of a right and a left - unilateral mastectomy -*/ - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - from {{ ref('quality_measures__int_nqf2372_denominator') }} - -) - -, exclusion_codes as ( - - select - code - , code_system - , concept_name - from {{ ref('quality_measures__value_sets') }} - where concept_name in ( - 'Bilateral Mastectomy' - , 'History of bilateral mastectomy' - , 'Status Post Left Mastectomy' - , 'Status Post Right Mastectomy' - , 'Unilateral Mastectomy Left' - , 'Unilateral Mastectomy Right' - , 'Unilateral Mastectomy, Unspecified Laterality' - ) - -) - -, conditions as ( - - select - patient_id - , recorded_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__condition') }} - -) - -, observations as ( - - select - patient_id - , observation_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__observation') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, condition_exclusions as ( - - select - conditions.patient_id - , conditions.recorded_date - , exclusion_codes.concept_name - from conditions - inner join exclusion_codes - on conditions.code = exclusion_codes.code - and conditions.code_type = exclusion_codes.code_system - -) - -, observation_exclusions as ( - - select - observations.patient_id - , observations.observation_date - , exclusion_codes.concept_name - from observations - inner join exclusion_codes - on observations.code = exclusion_codes.code - and observations.code_type = exclusion_codes.code_system - -) - -, procedure_exclusions as ( - - select - procedures.patient_id - , procedures.procedure_date - , exclusion_codes.concept_name - from procedures - inner join exclusion_codes - on procedures.code = exclusion_codes.code - and procedures.code_type = exclusion_codes.code_system - -) - -, all_mastectomy as ( - - select - denominator.patient_id - , condition_exclusions.recorded_date as exclusion_date - , condition_exclusions.concept_name as exclusion_reason - from denominator - inner join condition_exclusions - on denominator.patient_id = condition_exclusions.patient_id - - union all - - select - denominator.patient_id - , observation_exclusions.observation_date as exclusion_date - , observation_exclusions.concept_name as exclusion_reason - from denominator - inner join observation_exclusions - on denominator.patient_id = observation_exclusions.patient_id - - union all - - select - denominator.patient_id - , procedure_exclusions.procedure_date as exclusion_date - , procedure_exclusions.concept_name as exclusion_reason - from denominator - inner join procedure_exclusions - on denominator.patient_id = procedure_exclusions.patient_id - -) - -/* - Women who had a bilateral mastectomy or who have a history of a bilateral - mastectomy -*/ -, bilateral_mastectomy as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from all_mastectomy - where exclusion_reason in ( - 'Bilateral Mastectomy' - , 'History of bilateral mastectomy' - ) - -) - -, right_mastectomy as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from all_mastectomy - where exclusion_reason in ( - 'Status Post Right Mastectomy' - , 'Unilateral Mastectomy Right' - ) - -) - -, left_mastectomy as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from all_mastectomy - where exclusion_reason in ( - 'Status Post Left Mastectomy' - , 'Unilateral Mastectomy Left' - ) - -) - -, unspecified_mastectomy as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from all_mastectomy - where exclusion_reason in ( - 'Unilateral Mastectomy, Unspecified Laterality' - ) - -) - -/* - Women for whom there is evidence of a right AND a left unilateral mastectomy - or unspecific mastectomies on different dates -*/ -, unilateral_mastectomy as ( - - select - right_mastectomy.patient_id - , right_mastectomy.exclusion_date - , right_mastectomy.exclusion_reason - from right_mastectomy - inner join left_mastectomy - on right_mastectomy.patient_id = left_mastectomy.patient_id - - union all - - select - unspecified_mastectomy.patient_id - , unspecified_mastectomy.exclusion_date - , unspecified_mastectomy.exclusion_reason - from unspecified_mastectomy - inner join unspecified_mastectomy as self_join - on unspecified_mastectomy.patient_id = self_join.patient_id - and unspecified_mastectomy.exclusion_date <> self_join.exclusion_date - -) - -, unioned as ( - - select * from bilateral_mastectomy - union all - select * from unilateral_mastectomy -) - -select - patient_id - , exclusion_date - , exclusion_reason - , '{{ var('tuva_last_run')}}' as tuva_last_run -from unioned \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclusions.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclusions.sql deleted file mode 100644 index 851f3074b..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_exclusions.sql +++ /dev/null @@ -1,269 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_nqf2372__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_nqf2372__performance_period') }} - -) -{%- endset -%} - -with frailty as ( - - select - * - from {{ ref('quality_measures__int_shared_exclusions_frailty') }} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_mastectomy_patients as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf2372_exclude_mastectomy') }} -) - -, valid_hospice_palliative as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where lower(exclusion_reason) in - ( - 'palliative care encounter' - , 'palliative care intervention' - , 'hospice care ambulatory' - , 'hospice encounter' - ) - and - exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_institutional_snp as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_institutional_snp')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - -) - -, valid_dementia_exclusions as ( - - select - source.patient_id - , source.exclusion_date - , source.exclusion_reason - , source.exclusion_type - from {{ref('quality_measures__int_shared_exclusions_dementia')}} source - inner join frailty - on source.patient_id = frailty.patient_id - where ( - source.dispensing_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - or source.paid_date - between {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp= performance_period_begin ) }} - and {{ performance_period_end }} - ) - -) - --- advanced illness start -, advanced_illness_exclusion as ( - - select - source.* - from {{ ref('quality_measures__int_shared_exclusions_advanced_illness') }} as source - inner join frailty - on source.patient_id = frailty.patient_id - where source.exclusion_date - between - {{ dbt.dateadd(datepart="year", interval=-1, from_date_or_timestamp=performance_period_begin) }} - and {{ performance_period_end }} - -) - -, acute_inpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'acute_inpatient' - -) - -, nonacute_outpatient_advanced_illness as ( - - select - * - from advanced_illness_exclusion - where patient_type = 'nonacute_outpatient' - -) - -, acute_inpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from acute_inpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, nonacute_outpatient_counts as ( - - select - patient_id - , exclusion_type - , count(distinct exclusion_date) as encounter_count - from nonacute_outpatient_advanced_illness - group by patient_id, exclusion_type - -) - -, valid_advanced_illness_exclusions as ( - - select - acute_inpatient_advanced_illness.patient_id - , acute_inpatient_advanced_illness.exclusion_date - , acute_inpatient_advanced_illness.exclusion_reason - , acute_inpatient_advanced_illness.exclusion_type - from acute_inpatient_advanced_illness - left join acute_inpatient_counts - on acute_inpatient_advanced_illness.patient_id = acute_inpatient_counts.patient_id - where acute_inpatient_counts.encounter_count >= 1 - - union all - - select - nonacute_outpatient_advanced_illness.patient_id - , nonacute_outpatient_advanced_illness.exclusion_date - , nonacute_outpatient_advanced_illness.exclusion_reason - , nonacute_outpatient_advanced_illness.exclusion_type - from nonacute_outpatient_advanced_illness - left join nonacute_outpatient_counts - on nonacute_outpatient_advanced_illness.patient_id = nonacute_outpatient_counts.patient_id - where nonacute_outpatient_counts.encounter_count >= 2 - -) --- advanced illness end - -, valid_mastectomy_patients_with_exclusion_type as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , 'mastectomy_performed' as exclusion_type - from valid_mastectomy_patients -) - -, exclusions as ( - - select * from valid_advanced_illness_exclusions - - union all - - select * from valid_dementia_exclusions - - union all - - select * from valid_institutional_snp - - union all - - select * from valid_hospice_palliative - -) - -, combined_exclusions as ( - - select - exclusions.* - , denominator.age - from exclusions - inner join {{ ref('quality_measures__int_nqf2372_denominator') }} denominator - on exclusions.patient_id = denominator.patient_id - -) - -, valid_exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from combined_exclusions - where exclusion_type != 'hospice_palliative' - and age >= 66 - - union all - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from combined_exclusions - where exclusion_type = 'hospice_palliative' - -) - -, valid_exclusions_with_mastectomy as ( - - select * - from valid_exclusions - - union all - - select * - from valid_mastectomy_patients_with_exclusion_type - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from valid_exclusions_with_mastectomy - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_long.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_long.sql deleted file mode 100644 index f3f201569..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_long.sql +++ /dev/null @@ -1,165 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_nqf2372_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , numerator_flag - from {{ ref('quality_measures__int_nqf2372_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - from {{ ref('quality_measures__int_nqf2372_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then denominator.denominator_flag - else null - end as denominator_flag - , case - when numerator.patient_id is not null - then numerator.numerator_flag - else null - end as numerator_flag - , case - when exclusions.patient_id is not null - then exclusions.exclusion_flag - else null - end as exclusion_flag - , numerator.evidence_date - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, add_rownum as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , row_number() over( - partition by - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - order by - case when evidence_date is null then 1 else 0 end, - evidence_date desc - , case when exclusion_date is null then 1 else 0 end, - exclusion_date desc - ) as row_num - from measure_flags - -) - -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from add_rownum - where row_num = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_numerator.sql b/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_numerator.sql deleted file mode 100644 index 9059b4329..000000000 --- a/models/quality_measures/intermediate/nqf2372_breast_cancer_screening/quality_measures__int_nqf2372_numerator.sql +++ /dev/null @@ -1,211 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -/* - Eligible population from the denominator model before exclusions -*/ -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , performance_period_lookback - , measure_id - , measure_name - , measure_version - from {{ ref('quality_measures__int_nqf2372_denominator') }} - -) - -, mammography_codes as ( - - select - code - , code_system - from {{ ref('quality_measures__value_sets') }} - where concept_name = 'Mammography' - -) - -, medical_claim as ( - - select - patient_id - , claim_start_date - , claim_end_date - , hcpcs_code - from {{ ref('quality_measures__stg_medical_claim') }} - -) - -, observations as ( - - select - patient_id - , observation_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce ( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__observation') }} - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, qualifying_claims as ( - - select - medical_claim.patient_id - , medical_claim.claim_start_date - , medical_claim.claim_end_date - from medical_claim - inner join mammography_codes - on medical_claim.hcpcs_code = mammography_codes.code - where mammography_codes.code_system = 'hcpcs' - -) - -, qualifying_observations as ( - - select - observations.patient_id - , observations.observation_date - from observations - inner join mammography_codes - on observations.code = mammography_codes.code - and observations.code_type = mammography_codes.code_system -) - -, qualifying_procedures as ( - - select - procedures.patient_id - , procedures.procedure_date - from procedures - inner join mammography_codes - on procedures.code = mammography_codes.code - and procedures.code_type = mammography_codes.code_system - -) - -/* - Check if patients in the eligible population have had a screening, - diagnostic, film, digital or digital breast tomosynthesis (3D) - mammography results documented and reviewed. -*/ - -, patients_with_mammograms as ( - - select - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.performance_period_lookback - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , case - when qualifying_claims.claim_start_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then qualifying_claims.claim_start_date - when qualifying_claims.claim_end_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then qualifying_claims.claim_end_date - when qualifying_observations.observation_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then qualifying_observations.observation_date - when qualifying_procedures.procedure_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then qualifying_procedures.procedure_date - else null - end as evidence_date - , case - when qualifying_claims.claim_start_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then 1 - when qualifying_claims.claim_end_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then 1 - when qualifying_observations.observation_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then 1 - when qualifying_procedures.procedure_date - between denominator.performance_period_lookback - and denominator.performance_period_end - then 1 - else 0 - end as numerator_flag - from denominator - left join qualifying_claims - on denominator.patient_id = qualifying_claims.patient_id - left join qualifying_observations - on denominator.patient_id = qualifying_observations.patient_id - left join qualifying_procedures - on denominator.patient_id = qualifying_procedures.patient_id - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(numerator_flag as integer) as numerator_flag - from patients_with_mammograms - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , numerator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types \ No newline at end of file diff --git a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097__performance_period.sql b/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097__performance_period.sql deleted file mode 100644 index 5963d05a1..000000000 --- a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097__performance_period.sql +++ /dev/null @@ -1,69 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) - | as_bool - ) -}} - -{%- set measure_id -%} -(select id -from {{ ref('quality_measures__measures') }} -where id = 'NQF0097') -{%- endset -%} - -{%- set measure_name -%} -(select name -from {{ ref('quality_measures__measures') }} -where id = 'NQF0097') -{%- endset -%} - -{%- set measure_version -%} -(select version -from {{ ref('quality_measures__measures') }} -where id = 'NQF0097') -{%- endset -%} - -/* - set performance period end to the end of the current calendar year - or use the quality_measures_period_end variable if provided -*/ -with period_end as ( - - select - {% if var('quality_measures_period_end',False) == False -%} - {{ last_day(dbt.current_timestamp(), 'year') }} - {% else -%} - cast('{{ var('quality_measures_period_end') }}' as date) - {%- endif %} - as performance_period_end - -) - -/* - set performance period begin to a year and a day prior - for a complete calendar year -*/ -, period_begin as ( - - select - performance_period_end - , {{ dbt.dateadd ( - datepart = "day" - , interval = +1 - , from_date_or_timestamp = - dbt.dateadd ( - datepart = "year" - , interval = -1 - , from_date_or_timestamp = "performance_period_end" - ) - ) }} as performance_period_begin - from period_end - -) - -select - cast({{ measure_id }} as {{ dbt.type_string() }}) as measure_id - , cast({{ measure_name }} as {{ dbt.type_string() }}) as measure_name - , cast({{ measure_version }} as {{ dbt.type_string() }}) as measure_version - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end -from period_begin diff --git a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_denominator.sql b/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_denominator.sql deleted file mode 100644 index ac0e4d235..000000000 --- a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_denominator.sql +++ /dev/null @@ -1,201 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with visit_codes as ( - - select - concept_name - , code - , code_system - from {{ ref('quality_measures__value_sets') }} - -) - -, valid_concepts as ( - - select - concept_name - from {{ ref('quality_measures__concepts') }} - where concept_name in ( - 'annual wellness visit' - , 'care services in long term residential facility' - , 'encounter to document medications' - , 'home healthcare services' - , 'office visit' - , 'outpatient' - , 'psychoanalysis' - ) - -) - -, valid_visit_codes as ( - - select - visit_codes.concept_name - , visit_codes.code - , visit_codes.code_system - from visit_codes - inner join valid_concepts - on visit_codes.concept_name = valid_concepts.concept_name - -) - -, visits_encounters as ( - - select patient_id - , length_of_stay - , encounter.encounter_end_date - , coalesce(encounter.encounter_start_date,encounter.encounter_end_date) as min_date - , coalesce(encounter.encounter_end_date,encounter.encounter_start_date) as max_date - from {{ref('quality_measures__stg_core__encounter')}} encounter - inner join {{ref('quality_measures__int_nqf0097__performance_period')}} as pp - on coalesce(encounter.encounter_end_date,encounter.encounter_start_date) >= pp.performance_period_begin - and coalesce(encounter.encounter_start_date,encounter.encounter_end_date) <= pp.performance_period_end - -- all encounter types considered; inpatient encounters are filtered by length of stay being more than 0 days - -) - -, procedure_encounters as ( - - select - patient_id - , procedure_date as min_date - , procedure_date as max_date - from {{ref('quality_measures__stg_core__procedure')}} procs - - inner join {{ref('quality_measures__int_nqf0097__performance_period')}} as pp - on procedure_date between pp.performance_period_begin and pp.performance_period_end - inner join valid_visit_codes - on coalesce(procs.normalized_code,procs.source_code) = valid_visit_codes.code - -) - -, claims_encounters as ( - - select patient_id - , coalesce(claim_start_date,claim_end_date) as min_date - , coalesce(claim_end_date,claim_start_date) as max_date - from {{ref('quality_measures__stg_medical_claim')}} medical_claim - inner join {{ref('quality_measures__int_nqf0097__performance_period')}} as pp on - coalesce(claim_end_date,claim_start_date) >= pp.performance_period_begin - and coalesce(claim_start_date,claim_end_date) <= pp.performance_period_end - inner join valid_visit_codes - on medical_claim.hcpcs_code= valid_visit_codes.code - -) - -, all_encounters as ( - - select - patient_id - , min_date - , max_date - , 'v' as visit_enc - , cast(null as {{ dbt.type_string() }}) as proc_enc - , cast(null as {{ dbt.type_string() }}) as claim_enc - from visits_encounters - - union all - - select - patient_id - , min_date - , max_date - , cast(null as {{ dbt.type_string() }}) as visit_enc - , 'p' as proc_enc - , cast(null as {{ dbt.type_string() }}) as claim_enc - from procedure_encounters - - union all - - select - patient_id - , min_date - , max_date - , cast(null as {{ dbt.type_string() }}) as visit_enc - , cast(null as {{ dbt.type_string() }}) as proc_enc - , 'c' as claim_enc - from claims_encounters - -) - -, encounters_by_patient as ( - - select patient_id,min(min_date) min_date, max(max_date) max_date, - concat(concat( - coalesce(min(visit_enc),'') - ,coalesce(min(proc_enc),'')) - ,coalesce(min(claim_enc),'') - ) as qualifying_types - from all_encounters - group by patient_id - -) - -, patients_with_age as ( - - select - p.patient_id - , min_date - , floor({{ datediff('birth_date', 'e.min_date', 'hour') }} / 8760.0) as min_age - , max_date - , floor({{ datediff('birth_date', 'e.max_date', 'hour') }} / 8760.0) as max_age - , qualifying_types - from {{ref('quality_measures__stg_core__patient')}} p - inner join encounters_by_patient e - on p.patient_id = e.patient_id - where p.death_date is null - -) - -, qualifying_patients as ( - - select - distinct - patients_with_age.patient_id - , patients_with_age.max_age as age - , pp.performance_period_begin - , pp.performance_period_end - , pp.measure_id - , pp.measure_name - , pp.measure_version - , visits_encounters.encounter_end_date as discharge_date - , 1 as denominator_flag - from patients_with_age - cross join {{ref('quality_measures__int_nqf0097__performance_period')}} pp - inner join visits_encounters - on patients_with_age.patient_id = visits_encounters.patient_id - where max_age >= 18 - and visits_encounters.length_of_stay > 0 --ensures inpatient -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(age as integer) as age - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(discharge_date as date) as discharge_date - , cast(denominator_flag as integer) as denominator_flag - from qualifying_patients - -) - -select - patient_id - , age - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , discharge_date - , denominator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_exclusions.sql b/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_exclusions.sql deleted file mode 100644 index 799fc2daf..000000000 --- a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_exclusions.sql +++ /dev/null @@ -1,70 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -{%- set performance_period_begin -%} -( - select - performance_period_begin - from {{ ref('quality_measures__int_nqf0097__performance_period') }} - -) -{%- endset -%} - -{%- set performance_period_end -%} -( - select - performance_period_end - from {{ ref('quality_measures__int_nqf0097__performance_period') }} - -) -{%- endset -%} - -with valid_hospice_exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_type - from {{ref('quality_measures__int_shared_exclusions_hospice_palliative')}} - where exclusion_date between {{ performance_period_begin }} and {{ performance_period_end }} - and lower(exclusion_reason) in ( - 'hospice encounter' - ) - -) - -, combined_exclusions as ( - - select - valid_hospice_exclusions.patient_id - , valid_hospice_exclusions.exclusion_date - , valid_hospice_exclusions.exclusion_reason - , valid_hospice_exclusions.exclusion_type - from valid_hospice_exclusions - inner join {{ref('quality_measures__int_nqf0097_denominator')}} as denominator - on valid_hospice_exclusions.patient_id = denominator.patient_id - -) - -, add_data_types as ( - - select - distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , 1 as exclusion_flag - from combined_exclusions - -) - -select - patient_id - , exclusion_date - , exclusion_reason - , exclusion_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_long.sql b/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_long.sql deleted file mode 100644 index 47fdf98c0..000000000 --- a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_long.sql +++ /dev/null @@ -1,153 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -/* selecting the full patient population as the grain of this table */ -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , denominator_flag - from {{ ref('quality_measures__int_nqf0097_denominator') }} - -) - -, numerator as ( - - select - patient_id - , evidence_date - , evidence_value - from {{ ref('quality_measures__int_nqf0097_numerator') }} - -) - -, exclusions as ( - - select - patient_id - , exclusion_date - , exclusion_reason - from {{ ref('quality_measures__int_nqf0097_exclusions') }} - -) - -, measure_flags as ( - - select - denominator.patient_id - , case - when denominator.patient_id is not null - then 1 - else null - end as denominator_flag - , case - when numerator.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as numerator_flag - , case - when exclusions.patient_id is not null and denominator.patient_id is not null - then 1 - when denominator.patient_id is not null - then 0 - else null - end as exclusion_flag - , numerator.evidence_date - , numerator.evidence_value - , exclusions.exclusion_date - , exclusions.exclusion_reason - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , (row_number() over( - partition by - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - order by - case when numerator.evidence_date is null then 1 else 0 end, - numerator.evidence_date desc - , case when exclusions.exclusion_date is null then 1 else 0 end, - exclusions.exclusion_date desc - )) as rn - from denominator - left join numerator - on denominator.patient_id = numerator.patient_id - left join exclusions - on denominator.patient_id = exclusions.patient_id - -) - -/* - Deduplicate measure rows by latest evidence date or exclusion date -*/ -, deduped as ( - - select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - from measure_flags - where rn = 1 - -) - -, add_data_types as ( - - select - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(denominator_flag as integer) as denominator_flag - , cast(numerator_flag as integer) as numerator_flag - , cast(exclusion_flag as integer) as exclusion_flag - , cast(evidence_date as date) as evidence_date - , cast(evidence_value as {{ dbt.type_string() }}) as evidence_value - , cast(exclusion_date as date) as exclusion_date - , cast(exclusion_reason as {{ dbt.type_string() }}) as exclusion_reason - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - from deduped - -) - -select - patient_id - , denominator_flag - , numerator_flag - , exclusion_flag - , evidence_date - , evidence_value - , exclusion_date - , exclusion_reason - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_numerator.sql b/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_numerator.sql deleted file mode 100644 index 146f31dfa..000000000 --- a/models/quality_measures/intermediate/nqf_0097_medication_reconciliation_post_discharge/quality_measures__int_nqf0097_numerator.sql +++ /dev/null @@ -1,111 +0,0 @@ -{{ config( - enabled = var('quality_measures_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool - ) -}} - -with denominator as ( - - select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , discharge_date - from {{ ref('quality_measures__int_nqf0097_denominator') }} - -) - -, reconciliation_codes as ( - - select - concept_name - , code - , code_system - from {{ ref('quality_measures__value_sets') }} - where lower(concept_name) in ( - 'medication reconciliation post discharge' - ) - -) - -, procedures as ( - - select - patient_id - , procedure_date - , coalesce ( - normalized_code_type - , case - when lower(source_code_type) = 'cpt' then 'hcpcs' - when lower(source_code_type) = 'snomed' then 'snomed-ct' - else lower(source_code_type) - end - ) as code_type - , coalesce( - normalized_code - , source_code - ) as code - from {{ ref('quality_measures__stg_core__procedure') }} - -) - -, reconciliation_procedures as ( - - select - procedures.patient_id - , procedures.procedure_date - from procedures - inner join reconciliation_codes - on procedures.code = reconciliation_codes.code - and procedures.code_type = reconciliation_codes.code_system - -) - -, qualifying_patients_with_denominator as ( - - select - denominator.patient_id - , denominator.performance_period_begin - , denominator.performance_period_end - , denominator.measure_id - , denominator.measure_name - , denominator.measure_version - , reconciliation_procedures.procedure_date as evidence_date - , 1 as numerator_flag - from denominator - inner join reconciliation_procedures - on denominator.patient_id = reconciliation_procedures.patient_id - where {{ datediff('denominator.discharge_date', 'reconciliation_procedures.procedure_date', 'day') }} between 0 and 30 - -) - -, add_data_types as ( - - select distinct - cast(patient_id as {{ dbt.type_string() }}) as patient_id - , cast(performance_period_begin as date) as performance_period_begin - , cast(performance_period_end as date) as performance_period_end - , cast(measure_id as {{ dbt.type_string() }}) as measure_id - , cast(measure_name as {{ dbt.type_string() }}) as measure_name - , cast(measure_version as {{ dbt.type_string() }}) as measure_version - , cast(evidence_date as date) as evidence_date - , cast(null as {{ dbt.type_string() }}) as evidence_value - , cast(numerator_flag as integer) as numerator_flag - from qualifying_patients_with_denominator - -) - -select - patient_id - , performance_period_begin - , performance_period_end - , measure_id - , measure_name - , measure_version - , evidence_date - , evidence_value - , numerator_flag - , '{{ var('tuva_last_run')}}' as tuva_last_run -from add_data_types diff --git a/models/quality_measures/quality_measures_models.yml b/models/quality_measures/quality_measures_models.yml index 31b24cad0..08cd1b488 100644 --- a/models/quality_measures/quality_measures_models.yml +++ b/models/quality_measures/quality_measures_models.yml @@ -127,53 +127,11 @@ models: columns: - name: patient_id description: Unique patient_id for each person. - - name: nqf_2372 - description: > - Performance flag for NQF2372, Breast Cancer Screening. A null - indicates that the measure was not applicable for the patient. - - name: nqf_0034 - description: > - Performance flag for NQF0034, Colorectal Cancer Screening. A null - indicates that the measure was not applicable for the patient. - - name: nqf_0059 - description: > - Performance flag for NQF0059, Diabetes: Hemoglobin A1c (HbA1c) Poor - Control (> 9%). A null indicates that the measure was not applicable - for the patient. - - name: cqm_236 - description: > - Performance flag for CQM236, Controlling High Blood Pressure. A null - indicates that the measure was not applicable for the patient. - - name: nqf_0053 - description: > - Performance flag for NQF0053, Osteoporosis Management in Women Who - Had a Fracture. A null indicates that the measure was not applicable - for the patient. - - name: cbe_0055 - description: > - Performance flag for CBE0055, Diabetes: Eye Exam. A null - indicates that the measure was not applicable for the patient. - - name: nqf_0097 - description: > - Performance flag for NQF0097, Medication Reconciliation Post-Discharge. A null - indicates that the measure was not applicable for the patient. - name: cqm_438 description: > Performance flag for CQM438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease. A null indicates that the measure was not applicable for the patient. - - name: nqf_0041 - description: > - Performance flag for NQF0041, Influenza Immunization. A null indicates that the - measure was not applicable for the patient. - - name: cbe_0101 - description: > - Performance flag for CBE0101, Falls: Plan of Care. A null indicates that the - measure was not applicable for the patient. - - name: cqm_48 - description: > - Performance flag for CQM48, Urinary Incontinence: Assessment of Presence or Absence of Urinary Incontinence in Women Aged 65 Years and Older. - A null indicates that the measure was not applicable for the patient. - name: cqm_130 description: > Performance flag for CQM130, Documentation of Current Medications in the Medical Record. @@ -253,142 +211,30 @@ models: Exclusion logic for patients staying in an institution for the reporting for entire patient population. ## Intermediate -### Breast Cancer Screening - - name: quality_measures__int_nqf2372__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Breast Cancer screening. - - - name: quality_measures__int_nqf2372_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of NQF 2372, Breast Cancer - Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age as of the performance_period_begin date. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: performance_period_lookback - description: Lookback period of NQF2372. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf2372_exclude_mastectomy - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372_exclude_mastectomy - tags: quality_measures - materialized: table - description: > - Exclusion logic for patients with a mastectomy for the reporting - version of NQF 2372, Breast Cancer Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf2372_exclusions +### Statin Therapy for the Prevention and Treatment of Cardiovascular Disease + - name: quality_measures__int_cqm438__performance_period config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372_exclusions + alias: _int_cqm438__performance_period tags: quality_measures - materialized: table + materialized: view description: > - Combined exclusion logic for the reporting version of NQF 2372, Breast Cancer - Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. + Performance Period definition for Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - - name: quality_measures__int_nqf2372_long + - name: quality_measures__int_cqm438_denominator_criteria1 config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372_long + alias: _int_cqm438_denominator_criteria1 tags: quality_measures materialized: table description: > - Final preparation of the reporting version of NQF 2372, Breast Cancer - Screening before combining with other measures. + Subset of denominator logic for submission of criteria 1 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - name: patient_id description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -402,16 +248,15 @@ models: - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf2372_numerator + - name: quality_measures__int_cqm438_denominator_criteria2 config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf2372_numerator + alias: _int_cqm438_denominator_criteria2 tags: quality_measures materialized: table description: > - Numerator logic for the reporting version of NQF 2372, Breast Cancer - Screening. + Subset of denominator logic for submission of criteria 2 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - name: patient_id description: Unique patient_id for each person. @@ -425,128 +270,21 @@ models: description: Name of the measure. - name: measure_version description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Colorectal Cancer Screening - - name: quality_measures__int_nqf0034_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of NQF 0034, Colorectal Cancer - Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: min_age - description: Patient's minumum age during encounter as of the performance_period. - - name: max_age - description: Patient's maximum age during encounter as of the performance_period. - - name: qualifying_types - description: Indicative letter of patient's type of encounter. - - - name: quality_measures__int_nqf0034_exclude_colectomy_cancer - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034_exclude_colectomy_cancer - tags: quality_measures - materialized: table - description: > - Exclusion logic for patients with frailty and advanced illness for - the reporting version of NQF 0034, Colorectal Cancer Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_type - description: Measure specific exclusion for historical record of colectomy cancer. - - name: tuva_last_run - desciption: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0034_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of NQF 0034, Colorectal Cancer Screening. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf0034_long + - name: quality_measures__int_cqm438_denominator_criteria3 config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034_long + alias: _int_cqm438_denominator_criteria3 tags: quality_measures materialized: table description: > - Final preparation of the reporting version of NQF 0034, Colorectal Cancer Screening - before combining with other measures. + Subset of denominator logic for submission of criteria 3 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - name: patient_id description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -560,61 +298,20 @@ models: - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf0034_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of NQF 0034, - Colorectal Cancer Screening - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence - description: Reason (usually the value set concept name) that includes patient - from the measure. - - - name: quality_measures__int_nqf0034__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0034__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for NQF 0034 Colorectal Cancer screening. - -### Diabetes Hemoglobin a1c - - name: quality_measures__int_nqf0059__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0059__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Diabetes Hemoglobin a1c. - - - name: quality_measures__int_nqf0059_denominator + - name: quality_measures__int_cqm438_denominator config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0059_denominator + alias: _int_cqm438_denominator tags: quality_measures materialized: table description: > - Denominator logic for the reporting version of NQF 0059, Diabetes Hemoglobin a1c. + Denominator logic for submission of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - name: patient_id description: Unique patient_id for each person. - name: age - description: Patient's age during encounter in the performance period. + description: Patient's age as of performance_period_begin date. - name: performance_period_begin description: Beginning date of the performance or measurement period. - name: performance_period_end @@ -632,15 +329,15 @@ models: - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf0059_exclusions + - name: quality_measures__int_cqm438_exclusions config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0059_exclusions + alias: _int_cqm438_exclusions tags: quality_measures materialized: table description: > - Combined exclusion logic for the reporting version of NQF 0059, Diabetes Hemoglobin a1c. + Combined exclusion logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease. columns: - name: patient_id description: Unique patient_id for each person. @@ -659,15 +356,15 @@ models: - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf0059_long + - name: quality_measures__int_cqm438_long config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0059_long + alias: _int_cqm438_long tags: quality_measures materialized: table description: > - Final preparation of the reporting version of NQF 0059,Diabetes Hemoglobin a1c before combining with other measures. + Final preparation of the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease before combining with other measures. columns: - name: patient_id description: Unique patient_id for each person. @@ -711,1411 +408,15 @@ models: - name: tuva_last_run description: The date and timestamp of the dbt run. - - name: quality_measures__int_nqf0059_numerator + - name: quality_measures__int_cqm438_numerator config: schema: | {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0059_numerator + alias: _int_cqm438_numerator tags: quality_measures materialized: table description: > - Numerator logic for the reporting version of NQF 0059, Diabetes Hemoglobin a1c. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Controlling Blood Pressure - - name: quality_measures__int_cqm236__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Controlling Blood Pressure. - - - name: quality_measures__int_cqm236_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of CQM 236, Controlling Blood Pressure - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm236_exclude_procedures_observations - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236_exclude_procedures_observations - tags: quality_measures - materialized: table - description: > - Exclusion logic for patients with certain observations and procedures for - the reporting version of CQM 236, Controlling Blood Pressure. - - - name: quality_measures__int_cqm236_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of CQM 236, Controlling Blood Pressure. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm236_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of CQM 236, Controlling Blood Pressure. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm236_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm236_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of CQM 236,Controlling Blood Pressure before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Osteoporosis Management in women who had a fracture - - name: quality_measures__int_nqf0053__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Osteoporosis Management in women who had a fracture - - - name: quality_measures__int_nqf0053_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: recorded_date - description: Date of incident/fracture recorded. - - name: age - description: Patient's age during encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0053_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0053_exclusions_stage_1 - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_exclusions_stage_1 - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture. - First stage of final exclusion logic. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_type - description: > - Type of exclusion from the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0053_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0053_exclude_procedures_medications - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_exclude_procedures_medications - tags: quality_measures - materialized: table - description: > - Exclusion logic for patients with certain procedures and medicatons for - the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_type - description: measure specific exclusion for procedure medication. - - name: tuva_last_run - desciption: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0053_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0053_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of NQF 0053, Osteoporosis Management in women who had a fracture before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Diabetes: Eye Exam - - name: quality_measures__int_cbe0055__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0055__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Diabetes: Eye Exam - - - name: quality_measures__int_cbe0055_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0055_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of Diabetes: Eye Exam - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0055_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0055_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of CBE 0055, Diabetes: Eye Exam - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0055_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0055_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of CBE 0055, Diabetes: Eye Exam. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0055_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0055_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of CBE 0055, Diabetes: Eye Exam before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Medication Reconciliation Post-Discharge - - name: quality_measures__int_nqf0097_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0097_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of Medication Reconciliation Post-Discharge - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: discharge_date - description: Inpatient discharged date. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0097_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0097_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of NQF 0097, Medication Reconciliation Post-Discharge. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0097_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0097_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of NQF 0097, Medication Reconciliation Post-Discharge before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0097_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0097_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of NQF 0097, Medication Reconciliation Post-Discharge. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0097__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0097__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Medication Reconciliation Post-Discharge - -### Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - - name: quality_measures__int_cqm438__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - - - name: quality_measures__int_cqm438_denominator_criteria1 - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_denominator_criteria1 - tags: quality_measures - materialized: table - description: > - Subset of denominator logic for submission of criteria 1 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_denominator_criteria2 - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_denominator_criteria2 - tags: quality_measures - materialized: table - description: > - Subset of denominator logic for submission of criteria 2 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_denominator_criteria3 - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_denominator_criteria3 - tags: quality_measures - materialized: table - description: > - Subset of denominator logic for submission of criteria 3 of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for submission of the reporting version of Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age as of performance_period_begin date. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm438_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm438_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Influenza Immunization - - name: quality_measures__int_nqf0041__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0041__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Influenza Immunization - - - name: quality_measures__int_nqf0041_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0041_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of Influenza Immunization - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0041_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0041_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of NQF 0041, Influenza Immunization. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0041_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0041_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of NQF 0041, Influenza Immunization before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_nqf0041_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_nqf0041_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of NQF 0041, Influenza Immunization - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Falls: Plan of Care - - name: quality_measures__int_cbe0101__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0101__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Falls: Plan of Care. - - - name: quality_measures__int_cbe0101_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0101_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of Falls: Plan of Care. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: encounter_date - description: Patient's date of encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0101_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0101_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of CBE 0101, Falls: Plan of Care. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0101_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0101_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of CBE 0101, Falls: Plan of Care before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cbe0101_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cbe0101_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of CBE 0101, Falls: Plan of Care. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - -### Urinary Incontinence: Assessment of Presence or Absence of Urinary Incontinence in Women Aged 65 Years and Older - - name: quality_measures__int_cqm48__performance_period - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm48__performance_period - tags: quality_measures - materialized: view - description: > - Performance Period definition for Urinary Incontinence. - - - name: quality_measures__int_cqm48_denominator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm48_denominator - tags: quality_measures - materialized: table - description: > - Denominator logic for the reporting version of Urinary Incontinence. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: age - description: Patient's age during encounter in the performance period. - - name: encounter_date - description: Patient's date of encounter in the performance period. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm48_exclusions - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm48_exclusions - tags: quality_measures - materialized: table - description: > - Combined exclusion logic for the reporting version of CQM 48, Urinary Incontinence. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm48_long - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm48_long - tags: quality_measures - materialized: table - description: > - Final preparation of the reporting version of CQM 48, Urinary Incontinence before combining with other measures. - columns: - - name: patient_id - description: Unique patient_id for each person. - - name: denominator_flag - description: > - The denominator is associated with a given patient population that - may be counted as eligible to meet a measure’s inclusion requirements. - - name: numerator_flag - description: > - The numerator reflects the subset of patients in the denominator - for whom a particular service has been provided or for whom a - particular outcome has been achieved. - - name: exclusion_flag - description: > - Specifications of those characteristics that would cause groups of - individuals to be removed from the numerator and/or denominator of - a measure although they experience the denominator index event. - - name: evidence_date - description: > - Date of event or service that places patient in the numerator. - - name: evidence_value - description: > - Observed evidence value for the patients in the numerator. - - name: exclusion_date - description: > - Date of event or service that excludes patient from the measure. - - name: exclusion_reason - description: > - Reason (usually the value set concept name) that excludes patient - from the measure. - - name: performance_period_begin - description: Beginning date of the performance or measurement period. - - name: performance_period_end - description: Ending date of the performance or measurement period. - - name: measure_id - description: Unique measure identification number. - - name: measure_name - description: Name of the measure. - - name: measure_version - description: Version of the measure. - - name: tuva_last_run - description: The date and timestamp of the dbt run. - - - name: quality_measures__int_cqm48_numerator - config: - schema: | - {%- if var('tuva_schema_prefix',None) != None -%}{{var('tuva_schema_prefix')}}_quality_measures{% else %}quality_measures{%- endif -%} - alias: _int_cqm48_numerator - tags: quality_measures - materialized: table - description: > - Numerator logic for the reporting version of CQM 48, Urinary Incontinence. + Numerator logic for the reporting version of CQM 438, Statin Therapy for the Prevention and Treatment of Cardiovascular Disease columns: - name: patient_id description: Unique patient_id for each person.