def medical_D(path_to_alarms_time): alarms = ['Yellow Alarm', 'Red Alarm'] total_alarms = [] sheets = [] yellow_dataframe = pd.read_excel(path_to_alarms_time + 'Alarm_Time.xlsx', sheet_name=alarms[0]) red_dataframe = pd.read_excel(path_to_alarms_time + 'Alarm_Time.xlsx', sheet_name=alarms[1]) dataframe = pd.concat([yellow_dataframe, red_dataframe], axis=0).sort_values(by='Row') dataframe = dataframe.reset_index(drop=True) unique_beds = dataframe['Bed Label'].unique().tolist() med_dataframe = md.AlarmDataFrame() med_dataframe.set_dataframe(dataframe) med_dataframe.analize(action_type=unique_beds, by_label=['Bed Label']) beds_dataframe = med_dataframe.get_dataframe()[1] unique_alarm_trigger = md.get_unique_alarms(dataframe, flag='P') for j in range(len(unique_alarm_trigger)): alarm_trigger_dataframe = [] for k in range(0, len(beds_dataframe)): alarm_trigger_dataframe.append( md.alarm_deep_analysis(beds_dataframe[k], unique_alarm_trigger[j], bed_info=True, unique=True)) if alarm_trigger_dataframe[len(alarm_trigger_dataframe) - 1] is None: alarm_trigger_dataframe.pop() if alarm_trigger_dataframe: total_alarms.append( pd.concat(alarm_trigger_dataframe, axis=0, sort=True)) colon = re.search(r':', unique_alarm_trigger[j]) slash = re.search(r'/', unique_alarm_trigger[j]) if not colon is None: sheets.append(unique_alarm_trigger[j].replace(':', '|')) elif not slash is None: sheets.append(unique_alarm_trigger[j].replace('/', '|')) else: sheets.append(unique_alarm_trigger[j]) total_alarms[len(total_alarms) - 1] = total_alarms[len(total_alarms) - 1].fillna(value=0) total_alarms = pd.concat(total_alarms, axis=0) total_alarms = total_alarms.fillna(value=0) md.save_excel(total_alarms, name='AlarmTriggers', sheet_name='Sheet1')
def medical_C(path_to_alarms_time): alarms = ['Yellow Alarm', 'Red Alarm'] physiological_dataframe = [] sheets = [] for alarm in alarms: dataframe = pd.read_excel(path_to_alarms_time + 'Alarm_Time.xlsx', sheet_name=alarm) sheets.append(alarm) physiological_dataframe.append(md.threshold_feature_include(dataframe)) if alarm == 'Yellow Alarm': symbol = '✱' single = [] double = [] for j in range(len(dataframe)): f = re.search(r'^' + symbol * 2, dataframe['Action'][j]) if not f is None: double.append(j) else: single.append(j) if len(single) == 0 or len(double) == 0: continue else: if len(single) > 0: physiological_dataframe.append( physiological_dataframe[len(physiological_dataframe) - 1].iloc[single]) sheets.append('Single ' + symbol) if len(double) > 0: physiological_dataframe.append(physiological_dataframe[ len(physiological_dataframe) - 2].iloc[double]) #changed 2 to 1 sheets.append('Double ' + symbol) unique_alarms = md.get_unique_alarms(dataframe, flag='P') physiological_dataframe.append( md.get_threshold_dataframe(dataframe, unique_alarms)) sheets.append(alarm + ' Activity') else: unique_alarms = md.get_unique_alarms(dataframe, flag='P') physiological_dataframe.append( md.get_threshold_dataframe(dataframe, unique_alarms)) sheets.append(alarm + ' Activity') md.save_excel(physiological_dataframe, name='PhyAlarms_Threshold', sheet_name=sheets)
def medical_E(name, sheet_name='Sheet1'): med_dataframe = md.AlarmDataFrame(name + '.xlsx', sheet_name) unique_actions = med_dataframe.get_dataframe()[0]['Action_Type'].unique( ).tolist() med_dataframe.analize(action_type=unique_actions, by_label=['Action_Type']) dataframe = med_dataframe.get_others()[0] unique_alarms = md.get_unique_alarms(dataframe, flag='N') alarm_list_counter = [0 for i in unique_alarms] dummy = '' for row in dataframe['Action']: i = 0 found = False search = re.search(r'^.*?(?=\s*\d{1,4}/)|^.*?(?<=User Request)' \ + '|^.*?(?<=Limit)|^.*?(?=:)|^.*?(?=\s+set)|^.*?(?=\s+to)|^.*?(?=\s+from)|^.*', row) if not search is None: if search.group() == "12 Lead": dummy = search.group() + " printed" else: remove = re.search( r'^.*?(?=Order)|(?:\s+[A-Z]{1,3}\d*\.{1}[A-Z]*\d+)', search.group()) if not remove is None: dummy = search.group().replace(remove.group(), '') else: search = re.search( r'^.*?(?=\s+from)|^.*?(?=\s+for)|^.*?(?=\s+is)|^.*', search.group()) dummy = search.group() for alarm in unique_alarms: if alarm == dummy: found = True break i += 1 if found: alarm_list_counter[i] += 1 alarm_dataframe = pd.concat([ pd.DataFrame(unique_alarms, columns=['Alarms']), pd.DataFrame(alarm_list_counter, columns=['# of Ocurrences']) ], axis=1) md.save_excel(alarm_dataframe, name='OtherAlarms', sheet_name='Other Activity')
def medical_B(name, sheet_name='Sheet1'): alarm_type = [ 'Logged Inop', 'Yellow Inop', 'Red Inop', 'Yellow Alarm', 'Red Alarm' ] sheets = alarm_type[:] med_dataframe = md.AlarmDataFrame(data_path=name + '.xlsx', sheet_name=sheet_name) med_dataframe.analize(action_type=alarm_type, by_label=['Action_Type']) dataframes = med_dataframe.get_dataframe()[1] for i in range(len(dataframes) - 1, -1, -1): if dataframes[i].empty: del dataframes[i] else: unique_devices = dataframes[i]['Device Name'].unique().tolist() med_dataframe.set_dataframe(dataframes[i]) med_dataframe.analize(action_type=unique_devices, by_label=['Device Name']) dataframes[i] = md.time_feature_include( med_dataframe.get_dataframe()[1]) med_dataframe.set_dataframe(pd.concat([i for i in dataframes], axis=0)) med_dataframe.analize(action_type=alarm_type, by_label=['Action_Type']) single, double = med_dataframe.get_alarm_priority() if len(single) > 1: sheets.append('Single ✱') sheets.append('Single !') else: symbol = re.search(r'\!', single[0]['Action'][0]) if not symbol is None: sheets.append('Single !') else: sheets.append('Single ✱') if len(double) > 1: sheets.append('Double ✱') sheets.append('Double !') else: symbol = re.search(r'\!', double[0]['Action'][0]) if not symbol is None: sheets.append('Double !') else: sheets.append('Double ✱') i = 0 dataframes = [] for frame in med_dataframe.get_dataframe()[1] + single + double: if not frame.empty: dataframes.append(frame) else: del sheets[i] i += 1 md.save_excel(dataframe=dataframes, name='Alarm_Time', sheet_name=sheets) #----------------------------------------------------------------------------------- # Part B: InopAlarms_Time.xlsx inop = [] physiological = [] for frame in med_dataframe.get_dataframe()[1]: if not frame.empty: if 'Inop' in frame['Action_Type'][0]: inop.append(frame) else: physiological.append(frame) dataframes = [] sheets = [] for frame in inop: unique_devices = frame['Device Name'].unique().tolist() sheets.append(frame['Action_Type'][0]) if 'Yellow' in frame['Action_Type'][0]: P = True else: P = False dataframes.append( md.get_alarms_per_device(frame, list_of_devices=unique_devices, priority_dataframe=P, priority_symbol='!')) sheets.append(sheets[len(sheets) - 1] + 'Activity') unique_alarms = md.get_unique_alarms(frame, flag='I') dataframes.append(md.get_timing_dataframe(frame, unique_alarms)) md.save_excel(dataframe=dataframes, name='Inop_Alarms_Time', sheet_name=sheets) #------------------------------------------------------------------------------------ # Part B: PhyAlarms_Time.xlsx dataframes = [] sheets = [] for frame in physiological: unique_devices = frame['Device Name'].unique().tolist() sheets.append(frame['Action_Type'][0]) if 'Yellow' in frame['Action_Type'][0]: P = True else: P = False dataframes.append( md.get_alarms_per_device(frame, list_of_devices=unique_devices, priority_dataframe=P, priority_symbol='✱')) sheets.append(sheets[len(sheets) - 1] + 'Activity') unique_alarms = md.get_unique_alarms(frame, flag='P') dataframes.append(md.get_timing_dataframe(frame, unique_alarms)) md.save_excel(dataframe=dataframes, name='Phy_Alarms_Time', sheet_name=sheets)
def medical_A(name, sheet_name='Sheet1'): alarm_type = [ 'Logged Inop', 'Yellow Inop', 'Red Inop', 'Yellow Alarm', 'Red Alarm' ] sheets = alarm_type[:] med_dataframe = md.AlarmDataFrame(data_path=name + '.xlsx', sheet_name=sheet_name) med_dataframe.analize(action_type=alarm_type, by_label=['Action_Type']) single, double = med_dataframe.get_alarm_priority() if len(single) > 1: sheets.append('Single ✱') sheets.append('Single !') else: symbol = re.search(r'\!', single[0]['Action'][0]) if not symbol is None: sheets.append('Single !') else: sheets.append('Single ✱') if len(double) > 1: sheets.append('Double ✱') sheets.append('Double !') else: symbol = re.search(r'\!', double[0]['Action'][0]) if not symbol is None: sheets.append('Double !') else: sheets.append('Double ✱') i = 0 dataframes = [] for frame in med_dataframe.get_dataframe()[1] + single + double: if not frame.empty: dataframes.append(frame) else: del sheets[i] i += 1 md.save_excel(dataframe=dataframes, name='Alarm_Types', sheet_name=sheets) #----------------------------------------------------------------------------------- # Part A: InopAlarms.xlsx inop = [] physiological = [] for frame in med_dataframe.get_dataframe()[1]: if not frame.empty: if 'Inop' in frame['Action_Type'][0]: inop.append(frame) else: physiological.append(frame) dataframes = [] sheets = [] for frame in inop: unique_devices = frame['Device Name'].unique().tolist() sheets.append(frame['Action_Type'][0]) if 'Yellow' in frame['Action_Type'][0]: P = True else: P = False dataframes.append( md.get_alarms_per_device(frame, list_of_devices=unique_devices, priority_dataframe=P, priority_symbol='!')) md.save_excel(dataframe=dataframes, name='Inop_Alarms', sheet_name=sheets) #------------------------------------------------------------------------------------ # Part A: PhyAlarms.xlsx dataframes = [] sheets = [] for frame in physiological: unique_devices = frame['Device Name'].unique().tolist() sheets.append(frame['Action_Type'][0]) if 'Yellow' in frame['Action_Type'][0]: P = True else: P = False dataframes.append( md.get_alarms_per_device(frame, list_of_devices=unique_devices, priority_dataframe=P, priority_symbol='✱')) md.save_excel(dataframe=dataframes, name='Phy_Alarms', sheet_name=sheets)