-
Notifications
You must be signed in to change notification settings - Fork 35
/
hcc_suspecting__list.sql
123 lines (101 loc) · 2.84 KB
/
hcc_suspecting__list.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{{ config(
enabled = var('hcc_suspecting_enabled',var('claims_enabled',var('clinical_enabled',var('tuva_marts_enabled',False)))) | as_bool
)
}}
with hcc_history_suspects as (
select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
from {{ ref('hcc_suspecting__int_patient_hcc_history') }}
where (current_year_billed = false
or current_year_billed is null)
)
, comorbidity_suspects as (
select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
from {{ ref('hcc_suspecting__int_comorbidity_suspects') }}
where (current_year_billed = false
or current_year_billed is null)
)
, observation_suspects as (
select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
from {{ ref('hcc_suspecting__int_observation_suspects') }}
where (current_year_billed = false
or current_year_billed is null)
)
, lab_suspects as (
select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
from {{ ref('hcc_suspecting__int_lab_suspects') }}
where (current_year_billed = false
or current_year_billed is null)
)
, medication_suspects as (
select distinct
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
from {{ ref('hcc_suspecting__int_medication_suspects') }}
where (current_year_billed = false
or current_year_billed is null)
)
, unioned as (
select * from hcc_history_suspects
union all
select * from comorbidity_suspects
union all
select * from observation_suspects
union all
select * from lab_suspects
union all
select * from medication_suspects
)
, add_data_types as (
select
cast(patient_id as {{ dbt.type_string() }}) as patient_id
, cast(data_source as {{ dbt.type_string() }}) as data_source
, cast(hcc_code as {{ dbt.type_string() }}) as hcc_code
, cast(hcc_description as {{ dbt.type_string() }}) as hcc_description
, cast(reason as {{ dbt.type_string() }}) as reason
, cast(contributing_factor as {{ dbt.type_string() }}) as contributing_factor
, cast(suspect_date as date) as suspect_date
from unioned
)
select
patient_id
, data_source
, hcc_code
, hcc_description
, reason
, contributing_factor
, suspect_date
, '{{ var('tuva_last_run')}}' as tuva_last_run
from add_data_types