Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions taf/MCP/MCP.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ def screen_runid(self, intbl, runtbl, runvars, outtbl, runtyp="C"):
T.submitting_state = R.submitting_state and
upper(T.state_plan_id_num) = R.state_plan_id_num"""

# retain tmsis table column names used in subsequent merge and in TAF_Metadata.py
renames = [
'tmsis_run_id as tms_run_id',
'submtg_state_cd as submitting_state',
]

# diststyle key distkey(state_plan_id_num)
# compound sortkey (&&&runvars) as
z = f"""
create or replace temporary view {outtbl} as
select
T.*
from
{intbl} T
from (
select
*,
{ ','.join(renames) }
from
{intbl}
) T
inner join {runtbl} R
{ on.format(runvars) }
order by
Expand Down Expand Up @@ -78,7 +89,7 @@ def copy_activerows(self, intbl, collist, whr, outtbl):
from
{ intbl }
where
tms_is_active=1
tmsis_actv_ind=1
{ whr }
order by
tms_run_id,
Expand All @@ -90,21 +101,24 @@ def copy_activerows(self, intbl, collist, whr, outtbl):
def copy_activerows_nts(self, intbl, collist, outtbl):

# diststyle even compound sortkey(tms_run_id, submitting_state)
# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
z = f"""
create or replace temporary view {outtbl} as
select
{ ', '.join(collist) }
from (
select
*,
submitting_state as submtg_state_cd
tmsis_run_id as tms_run_id,
submtg_state_cd as submitting_state
from
{intbl}
where
tms_is_active = 1 and
tms_reporting_period is not null and
tmsis_actv_ind = 1 and
tmsis_rptg_prd is not null and
tot_rec_cnt > 0 and
trim(submitting_state) not in ('94','96'))
trim(submtg_state_cd) not in ('94','96'))
where
1=1 { self.mcp.ST_FILTER() }
order by
Expand Down
2 changes: 1 addition & 1 deletion taf/MCP/MCP01.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def process_01_header(self, outtbl):

# copy managed care header table
self.copy_activerows_nts(
"tmsis.file_header_record_managed_care", cols01, "MC01_Header_Copy"
"tmsis.tmsis_fhdr_rec_mc", cols01, "MC01_Header_Copy"
)

# self.mcp.countrows('MC01_Header_Copy', 'cnt_active', 'MC01_Active')
Expand Down
38 changes: 20 additions & 18 deletions taf/MCP/MCP02.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,33 @@ def process_02_mcmain(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state"]

self.screen_runid(
"tmsis.Managed_Care_Main", runtbl, runlist, "MC02_Main_Latest1", "M"
"tmsis.Tmsis_Mc_Mn_Data", runtbl, runlist, "MC02_Main_Latest1", "M"
)

# row count
self.count_rows("MC02_Main_Latest1", "cnt_latest", "MC02_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols02 = [
"tms_run_id",
"tms_reporting_period",
"submitting_state",
"submitting_state as submtg_state_cd",
"record_number",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
"rec_num as record_number",
"%upper_case(state_plan_id_num) as state_plan_id_num",
"managed_care_main_rec_eff_date",
"managed_care_main_rec_end_date",
"%fix_old_dates(managed_care_contract_eff_date)",
"case when managed_care_contract_eff_date is not null and managed_care_contract_end_date is null then to_date('9999-12-31') when to_date('1600-01-01') > managed_care_contract_end_date then to_date('1599-12-31') else managed_care_contract_end_date end as MC_CNTRCT_END_DT",
"managed_care_name",
"managed_care_program",
"managed_care_plan_type",
"reimbursement_arrangement",
"managed_care_profit_status",
"core_based_statistical_area_code",
"percent_business",
"managed_care_service_area",
"mc_mn_rec_efctv_dt as managed_care_main_rec_eff_date",
"mc_mn_rec_end_dt as managed_care_main_rec_end_date",
"%fix_old_dates_rename(mc_cntrct_efctv_dt, managed_care_contract_eff_date)",
"case when mc_cntrct_efctv_dt is not null and mc_cntrct_end_dt is null then to_date('9999-12-31') when to_date('1600-01-01') > mc_cntrct_end_dt then to_date('1599-12-31') else mc_cntrct_end_dt end as MC_CNTRCT_END_DT",
"mc_name as managed_care_name",
"mc_pgm_cd as managed_care_program",
"mc_plan_type_cd as managed_care_plan_type",
"reimbrsmt_arngmt_cd as reimbursement_arrangement",
"mc_prft_stus_cd as managed_care_profit_status",
"cbsa_cd as core_based_statistical_area_code",
"busns_pct as percent_business",
"mc_sarea_cd as managed_care_service_area",
]

whr02 = "upper(state_plan_id_num) is not null"
Expand Down
38 changes: 20 additions & 18 deletions taf/MCP/MCP03.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process_03_location(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state", "state_plan_id_num"]

self.screen_runid(
"tmsis.Managed_care_location_and_contact_info",
"tmsis.Tmsis_Mc_Lctn_Cntct",
runtbl,
runlist,
"MC03_Location_Latest1",
Expand All @@ -29,27 +29,29 @@ def process_03_location(self, runtbl, outtbl):
# row count
self.count_rows("MC03_Location_Latest1", "cnt_latest", "MC03_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols03 = [
"tms_run_id",
"tms_reporting_period",
"record_number",
"submitting_state",
"submitting_state as submtg_state_cd",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"rec_num as record_number",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
"%upper_case(state_plan_id_num) as state_plan_id_num",
"%upper_case(managed_care_location_id) as managed_care_location_id",
"%fix_old_dates(managed_care_location_and_contact_info_eff_date)",
"%set_end_dt(managed_care_location_and_contact_info_end_date) as managed_care_location_and_contact_info_end_date",
"%upper_case(managed_care_addr_ln1) as managed_care_addr_ln1",
"managed_care_addr_ln2",
"managed_care_addr_ln3",
"managed_care_addr_type",
"managed_care_city",
"managed_care_county",
"%upper_case(managed_care_state) as managed_care_state",
"managed_care_zip_code",
"%upper_case(mc_lctn_id) as managed_care_location_id",
"%fix_old_dates_rename(mc_lctn_cntct_efctv_dt, managed_care_location_and_contact_info_eff_date)",
"%set_end_dt(mc_lctn_cntct_end_dt) as managed_care_location_and_contact_info_end_date",
"%upper_case(mc_line_1_adr) as managed_care_addr_ln1",
"mc_line_2_adr as managed_care_addr_ln2",
"mc_line_3_adr as managed_care_addr_ln3",
"mc_adr_type_cd as managed_care_addr_type",
"mc_city_name as managed_care_city",
"mc_cnty_cd as managed_care_county",
"%upper_case(mc_state_cd) as managed_care_state",
"mc_zip_cd as managed_care_zip_code",
]

whr03 = "managed_care_addr_type=3"
whr03 = "mc_adr_type_cd=3"

self.copy_activerows(
"MC03_Location_Latest1", cols03, whr03, "MC03_Location_Copy"
Expand Down
22 changes: 12 additions & 10 deletions taf/MCP/MCP04.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process_04_service_area(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state", "state_plan_id_num"]

self.screen_runid(
"tmsis.Managed_care_service_area",
"tmsis.Tmsis_Mc_Sarea",
runtbl,
runlist,
"MC04_Service_Area_Latest1",
Expand All @@ -28,19 +28,21 @@ def process_04_service_area(self, runtbl, outtbl):
# row count
self.count_rows("MC04_Service_Area_Latest1", "cnt_latest", "MC04_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols04 = [
"tms_run_id",
"tms_reporting_period",
"record_number",
"submitting_state",
"submitting_state as submtg_state_cd",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"rec_num as record_number",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
f"""{ TAF_Closure.upper_case('state_plan_id_num')} as state_plan_id_num""",
f"""{ TAF_Closure.upper_case('managed_care_service_area_name')} as managed_care_service_area_name""",
f"""{ TAF_Closure.fix_old_dates('managed_care_service_area_eff_date')}""",
f"""{ TAF_Closure.set_end_dt('managed_care_service_area_end_date')} as managed_care_service_area_end_date"""
f"""{ TAF_Closure.upper_case('mc_sarea_name')} as managed_care_service_area_name""",
f"""{ TAF_Closure.fix_old_dates_rename('mc_sarea_efctv_dt','managed_care_service_area_eff_date')}""",
f"""{ TAF_Closure.set_end_dt('mc_sarea_end_dt')} as managed_care_service_area_end_date"""
]

whr04 = "upper(managed_care_service_area_name) is not null"
whr04 = "upper(mc_sarea_name) is not null"

self.copy_activerows(
"MC04_Service_Area_Latest1", cols04, whr04, "MC04_Service_Area_Copy"
Expand Down
32 changes: 17 additions & 15 deletions taf/MCP/MCP05.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def process_05_operating_authority(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state", "state_plan_id_num"]

self.screen_runid(
"tmsis.Managed_care_operating_authority",
"tmsis.Tmsis_Mc_Oprtg_Authrty",
runtbl,
runlist,
"MC05_Operating_Authority_Latest1",
Expand All @@ -28,27 +28,29 @@ def process_05_operating_authority(self, runtbl, outtbl):
# row count
self.count_rows("MC05_Operating_Authority_Latest1", "cnt_latest", "MC05_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols05 = [
"tms_run_id",
"tms_reporting_period",
"record_number",
"submitting_state",
"submitting_state as submtg_state_cd",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"rec_num as record_number",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
"%upper_case(state_plan_id_num) as state_plan_id_num",
"""case
when length(trim(TRAILING FROM operating_authority))<2 and length(trim(TRAILING FROM operating_authority))>0 and operating_authority in ('1','2','3','4','5','6','7','8','9')
then lpad(trim(TRAILING FROM operating_authority),2,'0')
when trim(TRAILING FROM operating_authority) in ('01','02','03','04','05','06','07','08','09') or
trim(TRAILING FROM operating_authority) in ('10','11','12','13','14','15','16','17','18','19','20','21','22','23')
then trim(TRAILING FROM operating_authority)
when length(trim(TRAILING FROM oprtg_authrty_cd))<2 and length(trim(TRAILING FROM oprtg_authrty_cd))>0 and oprtg_authrty_cd in ('1','2','3','4','5','6','7','8','9')
then lpad(trim(TRAILING FROM oprtg_authrty_cd),2,'0')
when trim(TRAILING FROM oprtg_authrty_cd) in ('01','02','03','04','05','06','07','08','09') or
trim(TRAILING FROM oprtg_authrty_cd) in ('10','11','12','13','14','15','16','17','18','19','20','21','22','23')
then trim(TRAILING FROM oprtg_authrty_cd)
else null
end as operating_authority""",
"%upper_case(waiver_id) as waiver_id",
"managed_care_op_authority_eff_date",
"managed_care_op_authority_end_date",
"%upper_case(wvr_id) as waiver_id",
"mc_op_authrty_efctv_dt as managed_care_op_authority_eff_date",
"mc_op_authrty_end_dt as managed_care_op_authority_end_date",
]

whr05 = "(trim(TRAILING FROM operating_authority) in ('1','2','3','4','5','6','7','8','9') or trim(TRAILING FROM operating_authority) in ('01','02','03','04','05','06','07','08','09') or trim(TRAILING FROM operating_authority) in ('10','11','12','13','14','15','16','17','18','19','20','21','22','23')) or (upper(waiver_id) is not null)"
whr05 = "(trim(TRAILING FROM oprtg_authrty_cd) in ('1','2','3','4','5','6','7','8','9') or trim(TRAILING FROM oprtg_authrty_cd) in ('01','02','03','04','05','06','07','08','09') or trim(TRAILING FROM oprtg_authrty_cd) in ('10','11','12','13','14','15','16','17','18','19','20','21','22','23')) or (upper(wvr_id) is not null)"

self.copy_activerows(
"MC05_Operating_Authority_Latest1",
Expand Down
22 changes: 12 additions & 10 deletions taf/MCP/MCP06.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def process_06_population(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state", "state_plan_id_num"]

self.screen_runid(
"tmsis.Managed_care_plan_population_enrolled",
"tmsis.Tmsis_Mc_Plan_Pop_Enrld",
runtbl,
runlist,
"MC06_Population_Latest1",
Expand All @@ -29,19 +29,21 @@ def process_06_population(self, runtbl, outtbl):
# row count
self.count_rows("MC06_Population_Latest1", "cnt_latest", "MC06_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols06 = [
"tms_run_id",
"tms_reporting_period",
"record_number",
"submitting_state",
"submitting_state as submtg_state_cd",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"rec_num as record_number",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
"%upper_case(state_plan_id_num) as state_plan_id_num",
"%zero_pad(managed_care_plan_pop, 2)",
"%fix_old_dates(managed_care_plan_pop_eff_date)",
"%set_end_dt(managed_care_plan_pop_end_date) as managed_care_plan_pop_end_date",
"%zero_pad_rename(mc_plan_pop_cnt, 2, managed_care_plan_pop)",
"%fix_old_dates_rename(mc_plan_pop_efctv_dt, managed_care_plan_pop_eff_date)",
"%set_end_dt(mc_plan_pop_end_dt) as managed_care_plan_pop_end_date",
]

whr06 = "managed_care_plan_pop is not null"
whr06 = "mc_plan_pop_cnt is not null"

self.copy_activerows(
"MC06_Population_Latest1", cols06, whr06, "MC06_Population_Copy"
Expand Down
22 changes: 12 additions & 10 deletions taf/MCP/MCP07.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def process_07_accreditation(self, runtbl, outtbl):
runlist = ["tms_run_id", "submitting_state", "state_plan_id_num"]

self.screen_runid(
"tmsis.Managed_care_accreditation_organization",
"tmsis.Tmsis_Mc_Acrdtn_Org",
runtbl,
runlist,
"MC07_Accreditation_Latest1",
Expand All @@ -30,19 +30,21 @@ def process_07_accreditation(self, runtbl, outtbl):
# row count
self.count_rows("MC07_Accreditation_Latest1", "cnt_latest", "MC07_Latest")

# upon conversion from using TMSIS tables to using TMSIS views
# retain TMSIS table column names to preserve downstream processing
cols07 = [
"tms_run_id",
"tms_reporting_period",
"record_number",
"submitting_state",
"submitting_state as submtg_state_cd",
"tmsis_run_id as tms_run_id",
"tmsis_rptg_prd as tms_reporting_period",
"rec_num as record_number",
"submtg_state_cd as submitting_state",
"submtg_state_cd",
"%upper_case(state_plan_id_num) as state_plan_id_num",
"%zero_pad(accreditation_organization, 2)",
"%fix_old_dates(date_accreditation_achieved)",
"%set_end_dt(date_accreditation_end) as date_accreditation_end",
"%zero_pad_rename(acrdtn_org_cd, 2, accreditation_organization)",
"%fix_old_dates_rename(acrdtn_achvmt_dt, date_accreditation_achieved)",
"%set_end_dt(acrdtn_end_dt) as date_accreditation_end",
]

whr07 = "accreditation_organization is not null"
whr07 = "acrdtn_org_cd is not null"

self.copy_activerows(
"MC07_Accreditation_Latest1", cols07, whr07, "MC07_Accreditation_Copy"
Expand Down
Loading