-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSC_SO_1.3_all_qtr.py
93 lines (70 loc) · 4.91 KB
/
BSC_SO_1.3_all_qtr.py
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
import pandas as pd
import path as PT
import data_prep as prep
import warnings
import datetime
import math
from dateutil.relativedelta import relativedelta
warnings.filterwarnings("ignore")
def obtain_new_patient(df_look_back, df_BSC_quarter):
list_look_back = set(df_look_back.Ext_Pat_ID.to_list())
list_BSC_quarter = set(df_BSC_quarter.Ext_Pat_ID.to_list())
BSC_final = list_BSC_quarter - list_look_back
return len(BSC_final)
for yr in range(2019, 2022):
for qtr in range(1, 5):
first_lastyear = datetime.datetime(yr - 1, 3 * qtr - 2, 1).replace(day=1).strftime("%m/%d/%Y")
start_of_quarter = datetime.datetime(yr, 3 * qtr - 2, 1)
end_of_quarter = start_of_quarter + relativedelta(months=3, seconds=-1)
quarter_start = start_of_quarter.strftime("%m/%d/%Y")
quarter_end = end_of_quarter.strftime("%m/%d/%Y")
# for Inpatient calculation
df_adm = pd.read_parquet(PT.path_wip_output + 'Combined_adm.parquet.gzip')
df_adm["Year"] = df_adm['Adm_Date'].dt.year
df_adm["Month"] = df_adm['Adm_Date'].dt.month
df_adm["Quarter"] = df_adm['Adm_Date'].dt.quarter
df_adm = df_adm.loc[df_adm['Adm_Type'].str.contains('EM|SD|DI|EL|SO|TA', regex=True)]
df_adm = df_adm.loc[df_adm['Adm_Status'] != 'P']
df_program = pd.read_excel(PT.path_lookup + 'Class.xlsx', sheet_name="Program")
df_program.rename(columns={'Dept_OU': 'Adm_Dept_OU'}, inplace=True)
df_adm = pd.merge(df_adm, df_program, how='left', on='Adm_Dept_OU')
df_adm['cnt'] = 1
df_adm_look_back = df_adm[df_adm['Adm_Date'] >= first_lastyear]
df_adm_look_back = df_adm_look_back[df_adm['Adm_Date'] < quarter_start]
df_adm_BSC_quarter = df_adm[df_adm['Adm_Date'] <= quarter_end]
df_adm_BSC_quarter = df_adm_BSC_quarter[df_adm['Adm_Date'] >= quarter_start]
df_adm_look_back_FAST = df_adm_look_back.loc[df_adm_look_back['Program'] == 'Alex Fast Program']
df_adm_BSC_quarter_FAST = df_adm_BSC_quarter.loc[df_adm_BSC_quarter['Program'] == 'Alex Fast Program']
df_adm_look_back_HA = df_adm_look_back.loc[df_adm_look_back['Program'] == 'Alex Healthy Aging Program']
df_adm_BSC_quarter_HA = df_adm_BSC_quarter.loc[df_adm_BSC_quarter['Program'] == 'Alex Healthy Aging Program']
df_adm_look_back_PAL = df_adm_look_back.loc[df_adm_look_back['Program'] == 'Alex Palliative Program']
df_adm_BSC_quarter_PAL = df_adm_BSC_quarter.loc[df_adm_BSC_quarter['Program'] == 'Alex Palliative Program']
print('Inpatient FAST BSC1.3 for', yr, 'Q', qtr, '(', quarter_start, 'to', quarter_end, '):',
obtain_new_patient(df_adm_look_back_FAST, df_adm_BSC_quarter_FAST))
print('Inpatient HA BSC1.3 for', yr, 'Q', qtr, '(', quarter_start, 'to', quarter_end, '):',
obtain_new_patient(df_adm_look_back_HA, df_adm_BSC_quarter_HA))
print('Inpatient PAL BSC1.3 for', yr, 'Q', qtr, '(', quarter_start, 'to', quarter_end, '):',
obtain_new_patient(df_adm_look_back_PAL, df_adm_BSC_quarter_PAL))
# for Outpatient calculation
df_SOC = pd.read_parquet(PT.path_wip_output + 'Combined_SOC.parquet.gzip')
df_SOC["Year"] = df_SOC['Visit_Date'].dt.year
df_SOC["Month"] = df_SOC['Visit_Date'].dt.month
df_SOC["Quarter"] = df_SOC['Visit_Date'].dt.quarter
df_SOC = df_SOC.loc[df_SOC['Visit_Type'].str.contains('FV|RV|FW|RW|DF|DR|FD|RD', regex=True)]
df_SOC = df_SOC.loc[df_SOC['Trt_Cat'] != 'NC']
df_SOC = df_SOC.loc[df_SOC['Status'] != 'P']
df_SOC_look_back = df_SOC[df_SOC['Visit_Date'] >= first_lastyear]
df_SOC_look_back = df_SOC_look_back[df_SOC['Visit_Date'] < quarter_start]
df_SOC_BSC_quarter = df_SOC[df_SOC['Visit_Date'] <= quarter_end]
df_SOC_BSC_quarter = df_SOC_BSC_quarter[df_SOC['Visit_Date'] >= quarter_start]
df_SOC_BSC_quarter = df_SOC_BSC_quarter.loc[df_SOC_BSC_quarter['Visit_Type'].str.contains('FV|FW', regex=True)]
df_SOC_look_back_Chronic = df_SOC_look_back.loc[df_SOC_look_back['Clinical_Dept'] == 'Alex Chronic Program']
df_SOC_BSC_quarter_Chronic = df_SOC_BSC_quarter.loc[
df_SOC_BSC_quarter['Clinical_Dept'] == 'Alex Chronic Program']
df_SOC_look_back_HA = df_SOC_look_back.loc[df_SOC_look_back['Clinical_Dept'] == 'Alex Healthy Aging Program']
df_SOC_BSC_quarter_HA = df_SOC_BSC_quarter.loc[
df_SOC_BSC_quarter['Clinical_Dept'] == 'Alex Healthy Aging Program']
print('Outpatient Chronic BSC1.3 for', yr, 'Q', qtr, '(', quarter_start, 'to', quarter_end, '):',
obtain_new_patient(df_SOC_look_back_Chronic, df_SOC_BSC_quarter_Chronic))
print('Outpatient HA BSC1.3 for', yr, 'Q', qtr, '(', quarter_start, 'to', quarter_end, '):',
obtain_new_patient(df_SOC_look_back_HA, df_SOC_BSC_quarter_HA))