Commit 2ac0370a authored by Venkat Malladi's avatar Venkat Malladi
Browse files

Update labs transformation.

parent d455ebe4
......@@ -163,6 +163,9 @@ def calculate_shift(labs, date_shift):
date_shift['Shift'] = pd.to_timedelta(date_shift['Shift'], unit='s')
labs['date'] = pd.to_datetime(labs['date'])
# Get labs with more than 1 value on the same datetime
multiple_labs = labs.groupby(['mrn', 'date', 'lab']).filter(lambda x: len(x) > 1)
# Merge data
merged = labs.merge(date_shift, left_on='mrn', right_on='MRN', how='inner')
......@@ -177,7 +180,7 @@ def calculate_shift(labs, date_shift):
# Int MRN
merged.mrn = merged.mrn.astype(int)
return merged
return merged, multiple_labs
def calculate_maximum(labs):
......@@ -198,6 +201,8 @@ def main():
# Make output files
lab_table = os.path.join(out_path + 'lab_table.csv')
unmapped_table = os.path.join(out_path + 'unmapped_lab_table.csv')
multiple_labs_table = os.path.join(out_path + 'multiple_lab_table.csv')
# Read in files
labs_df = pd.read_csv(labs)
......@@ -215,7 +220,7 @@ def main():
labs_clean, unmapped_labs = convert_units(labs_range, unitmap_df, convert_df)
# Convert value flags
labs_flag = convert_flags(labs_clean)
labs_flag, multiple_labs = convert_flags(labs_clean)
# Calculate Date Shift
shifted_df = calculate_shift(labs_flag, date_shift)
......@@ -224,7 +229,7 @@ def main():
max_lab = calculate_maximum(shifted_df)
# Write out lab table
max_lab.to_csv(lab_table, index=False)
calculate_maximum.to_csv(lab_table, index=False)
# Write out unmapped sites if there are any
if unmapped_labs.shape[0] > 1:
......
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