Commit 252fec63 authored by Venkat Malladi's avatar Venkat Malladi
Browse files

Update data to not be frequency.

parent 08ae4031
Pipeline #5184 failed with stage
in 11 seconds
......@@ -64,29 +64,24 @@ def filter_supplemental(epic, sup, meds_map):
return supmeds_named, meds_named, missing_meds
def calculate_supp_frequency(supp_meds):
'''Calculate supportive meds frequency'''
def filter_supp(supp_meds):
'''Filter supportive meds'''
# Filter Adminstered drugs
meds_admin = supp_meds[supp_meds['MODIFIER_CD'].isin(['RX|ADMIN', 'RX|FILLED'])]
# Make date
meds_admin['START_DATE'] = pd.to_datetime(meds_admin['START_DATE'])
# Calculate Frequency
meds_frequency = pd.crosstab(meds_admin.MRN,meds_admin.Meds).\
replace(0,np.nan).stack().reset_index()
# Filter for Meds taken
meds_taken = meds_admin[meds_admin['TVAL_CHAR'].isin(['Given', 'New Bag', 'IV Started', 'IV Stopped'])]
meds_non_taken = meds_admin[~meds_admin['TVAL_CHAR'].isin(['Given', 'New Bag', 'IV Started', 'IV Stopped'])]
# Add Earliest date of Adminstration
meds_date = meds_admin.groupby(['MRN', 'Meds']).\
agg({'START_DATE' : np.min}).reset_index()
# Merge dataframes and output
meds_merge = meds_frequency.merge(meds_date)
# Make date
meds_taken['START_DATE'] = pd.to_datetime(meds_taken['START_DATE'])
meds_merge.columns = ['mrn', 'name', 'frequency', 'Start_date']
#Filter columns
supp_meds_reformated = meds_taken[['MRN', 'Meds', 'START_DATE']]
supp_meds_reformated.columns = ['mrn', 'name', 'Start_date']
return meds_merge
return supp_meds_reformated, meds_non_taken
def parse_blob(meds):
......@@ -233,6 +228,7 @@ def main():
meds_table = os.path.join(out_path + 'med_table.csv')
unmapped_table = os.path.join(out_path + 'unmapped_med_table.csv')
suppmeds_table = os.path.join(out_path + 'suppmed_table.csv')
not_given_suppmeds_table = os.path.join(out_path + 'not_given_suppmed_table.csv')
# Read in files
epic_df = pd.read_csv(epic)
......@@ -244,20 +240,21 @@ def main():
supp_meds, onco_meds, missing_meds = filter_supplemental(epic_df, supmedsmap_df, medsmap_df)
# Find Supplemental Meds Frequency
meds_freq = calculate_supp_frequency(supp_meds)
supp_meds_regime, filtered_supp_meds = filter_supp(supp_meds)
# Calculate start and end dates
# Need to include Follow-up Date
onco_meds_regime = calculate_regime(onco_meds)
# Calculate Date Shift
supmeds_freq_shifted_df = calculate_shift(meds_freq, date_shift)
supp_meds_regime_shifted_df = calculate_shift(supp_meds_regime, date_shift)
onco_meds_shifted_df = calculate_shift(onco_meds_regime, date_shift)
# Write out meds tables
supmeds_freq_shifted_df.to_csv(suppmeds_table, index=False)
supp_meds_regime_shifted_df.to_csv(suppmeds_table, index=False)
onco_meds_shifted_df.to_csv(meds_table, index=False)
missing_meds.to_csv(unmapped_table, index=False)
filtered_supp_meds.to_csv(not_given_suppmeds_table, index=False)
if __name__ == '__main__':
......
MRN,NAME,GENERIC_NAME,CONCEPT_CD,START_DATE,END_DATE,MODIFIER_CD,TVAL_CHAR,UNITS_CD,OBSERVATION_BLOB,Meds,ID
903,Zolderonic Acid,ZOLEDRONIC ACID INFUSION 730414,MED:730414,7/14/15 10:56,,RX|ADMIN,Stopped,@,,Zoledronic Acid,MED:730414
903,Zolderonic Acid,ZOLEDRONIC ACID INFUSION 730414,MED:730414,9/17/15 15:30,,RX|ADMIN,Due,@,,Zoledronic Acid,MED:730414
mrn,name,frequency,Start_date,MRN
313,Denosumab,2.0,1855-01-10 15:20:00,313
903,Zoledronic Acid,3.0,1822-07-06 10:45:00,903
mrn,name,Start_date,MRN
313,Denosumab,1855-01-10 15:20:00,313
313,Denosumab,1855-05-30 15:20:00,313
903,Zoledronic Acid,1822-07-06 10:45:00,903
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment