Skip to content

Commit a3c29c3

Browse files
committed
Refactor eligibility_unpivot, and remove possible bug with using regex_extract on what could be a decimal type field
1 parent 00b5a2d commit a3c29c3

11 files changed

Lines changed: 259 additions & 152 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ package-lock.yml
1010
.env
1111
.envrc
1212
requirements.txt
13+
.data/

dbt_project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: 'cms_synthetic_connector'
22
version: '0.1'
33
config-version: 2
44

5-
profile: default
5+
profile: cms_synthetic
66

77
vars:
88
## Demo Data Only variable, if true, seeds are used, if false, source data is expected (see models/_sourecs.yml for details)
9-
demo_data_only: true
9+
# demo_data_only: true
1010

1111
claims_enabled: true
1212
clinical_enabled: false

models/_models.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ models:
4949
schema: |
5050
{%- if var('tuva_schema_prefix',None) != None -%}_{{var('tuva_schema_prefix')}}_input_layer{% else %}input_layer{%- endif -%}
5151
tags: connector
52+
materialized: table
5253
#
5354
- name: home_health_claim
5455
description: Claim line details of home health claims

models/final/eligibility.sql

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ medicare_state_fips as (
2222
add_row_num as (
2323

2424
select
25-
desy_sort_key
25+
bene_id
2626
, enrollment_date
2727
, row_number() over (
28-
partition by desy_sort_key
28+
partition by bene_id
2929
order by enrollment_date
3030
) as row_num
3131
, case
32-
when medicare_status in (null, '00') and dual_status in (null, '00', '99', 'NA') then 1
32+
when mdcr_status_code in (null, '00') and dual_stus_cd in (null, '00', '99', 'NA') then 1
3333
--when hmo_status <> '0' then 1 -- MA coverage
3434
--when entitlement not in ('3','C') then 1 --Doesn't have both Part A and B
3535
else 0
@@ -45,7 +45,7 @@ add_row_num as (
4545
remove_disenrolled_months as (
4646

4747
select
48-
desy_sort_key
48+
bene_id
4949
, enrollment_date
5050
, row_num
5151
, disenrolled_flag
@@ -57,11 +57,11 @@ remove_disenrolled_months as (
5757
add_lag_enrollment as (
5858

5959
select
60-
desy_sort_key
60+
bene_id
6161
, enrollment_date
6262
, row_num
6363
, lag(enrollment_date) over (
64-
partition by desy_sort_key
64+
partition by bene_id
6565
order by row_num
6666
) as lag_enrollment
6767
from remove_disenrolled_months
@@ -71,7 +71,7 @@ add_lag_enrollment as (
7171
calculate_lag_diff as (
7272

7373
select
74-
desy_sort_key
74+
bene_id
7575
, enrollment_date
7676
, row_num
7777
, lag_enrollment
@@ -83,7 +83,7 @@ calculate_lag_diff as (
8383
calculate_gaps as (
8484

8585
select
86-
desy_sort_key
86+
bene_id
8787
, enrollment_date
8888
, row_num
8989
, lag_enrollment
@@ -99,12 +99,12 @@ calculate_gaps as (
9999
calculate_groups as (
100100

101101
select
102-
desy_sort_key
102+
bene_id
103103
, enrollment_date
104104
, row_num
105105
, gap_flag
106106
, sum(gap_flag) over (
107-
partition by desy_sort_key
107+
partition by bene_id
108108
order by row_num
109109
rows between unbounded preceding and current row
110110
) as row_group
@@ -115,22 +115,22 @@ calculate_groups as (
115115
enrollment_span as (
116116

117117
select
118-
desy_sort_key
118+
bene_id
119119
, row_group
120120
, min(enrollment_date) as enrollment_start_date
121121
, max(enrollment_date) as enrollment_end_date_max
122122
, last_day(max(enrollment_date)) as enrollment_end_date_last
123123
from calculate_groups
124-
group by desy_sort_key, row_group
124+
group by bene_id, row_group
125125

126126
),
127127

128128
joined as (
129129

130130
select
131-
cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as patient_id
132-
, cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as member_id
133-
, cast(enrollment_span.desy_sort_key as {{ dbt.type_string() }} ) as subscriber_id
131+
cast(enrollment_span.bene_id as {{ dbt.type_string() }} ) as patient_id
132+
, cast(enrollment_span.bene_id as {{ dbt.type_string() }} ) as member_id
133+
, cast(enrollment_span.bene_id as {{ dbt.type_string() }} ) as subscriber_id
134134
, case eligibility_unpivot.sex_code
135135
when '0' then 'unknown'
136136
when '1' then 'male'
@@ -157,8 +157,8 @@ joined as (
157157
, 'medicare' as payer_type
158158
, 'medicare' as plan
159159
, cast(eligibility_unpivot.orig_reason_for_entitlement as {{ dbt.type_string() }} ) as original_reason_entitlement_code
160-
, cast(eligibility_unpivot.dual_status as {{ dbt.type_string() }} ) as dual_status_code
161-
, cast(eligibility_unpivot.medicare_status as {{ dbt.type_string() }} ) as medicare_status_code
160+
, cast(eligibility_unpivot.dual_stus_cd as {{ dbt.type_string() }} ) as dual_status_code
161+
, cast(eligibility_unpivot.mdcr_status_code as {{ dbt.type_string() }} ) as medicare_status_code
162162
, cast(NULL as {{ dbt.type_string() }} ) as enrollment_status
163163
, cast(NULL as {{ dbt.type_string() }} ) as hospice_flag
164164
, cast(NULL as {{ dbt.type_string() }} ) as institutional_snp_flag
@@ -186,7 +186,7 @@ joined as (
186186

187187
from enrollment_span
188188
left join eligibility_unpivot
189-
on enrollment_span.desy_sort_key = eligibility_unpivot.desy_sort_key
189+
on enrollment_span.bene_id = eligibility_unpivot.bene_id
190190
and enrollment_span.enrollment_end_date_max = eligibility_unpivot.enrollment_date
191191
left join medicare_state_fips
192192
on eligibility_unpivot.state_code = medicare_state_fips.ssa_fips_state_code

models/intermediate/carrier_claim.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ select
4747
, cast(NULL as {{ dbt.type_string() }} ) as ms_drg_code
4848
, cast(NULL as {{ dbt.type_string() }} ) as apr_drg_code
4949
, cast(NULL as {{ dbt.type_string() }} ) as revenue_center_code
50-
, cast({{ regexp_substr("line_srvc_cnt","'.'") }} as integer) as service_unit_quantity
50+
, cast({{ regexp_substr("cast(line_srvc_cnt as " ~ dbt.type_string() ~ ")", "'.'") }} as integer) as service_unit_quantity
5151
, cast(hcpcs_cd as {{ dbt.type_string() }} ) as hcpcs_code
5252
, cast(null as {{ dbt.type_string() }} ) as hcpcs_modifier_1
5353
, cast(hcpcs_2nd_mdfr_cd as {{ dbt.type_string() }} ) as hcpcs_modifier_2

models/intermediate/dme_claim.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ select
4747
, cast(NULL as {{ dbt.type_string() }} ) as drg_code_type
4848
, cast(NULL as {{ dbt.type_string() }} ) as drg_code
4949
, cast(NULL as {{ dbt.type_string() }} ) as revenue_center_code
50-
, cast({{ regexp_substr('line_srvc_cnt',"'.'") }} as integer) as service_unit_quantity
50+
, cast({{ regexp_substr("cast(line_srvc_cnt as " ~ dbt.type_string() ~ ")", "'.'") }} as integer) as service_unit_quantity
5151
, cast(hcpcs_cd as {{ dbt.type_string() }} ) as hcpcs_code
5252
, cast(hcpcs_1st_mdfr_cd as {{ dbt.type_string() }} ) as hcpcs_modifier_1
5353
, cast(hcpcs_2nd_mdfr_cd as {{ dbt.type_string() }} ) as hcpcs_modifier_2

0 commit comments

Comments
 (0)