else: lab_result_status = 'resulted' delta_hours = get_hours_between_datetimes( pcr_sample_times[str(patient_mrn)], str(lab_sample_time)) if delta_hours > -48 and delta_hours < 7 * 24: mapped_lab_name = map_lab_name(lab_name) mapped_lab_sample_site = map_lab_sample_site(lab_name, lab_sample_site) try: mapped_lab_value = map_lab_result_value(lab_result_string) except: print('Invalid lab value: ' + str(lab_result_string)) continue if mapped_lab_name == 'venous_o2_sat': print(mapped_lab_value) lab_data_rows.append([ patient_mrn, mapped_lab_name, mapped_lab_sample_site, map_time(lab_sample_time), map_time(lab_result_time), lab_result_status, lab_result_units, lab_result_string, mapped_lab_value ]) print('Total rows: %d' % len(lab_data_rows)) write_csv(TABLE_COLUMNS['lab_data'], lab_data_rows, os.path.join(CSV_DIRECTORY, 'lab_data.csv'))
patient_mrn = str(row[0]) patient_ramq = str(row[1]) patient_age = row[-1] patient_birth_sex = row[-2] try: patient_covid_status = map_patient_covid_status(row[-4]) except: print('Invalid COVID status: ' + str(row[-4])) continue pcr_result_time = row[-6] pcr_sample_time = row[-7] if map_time(pcr_sample_time) == '': print('Skipping row: invalid PCR time') continue if patient_mrn not in patient_covid_statuses: patient_covid_statuses[patient_mrn] = [patient_covid_status] else: patient_covid_statuses[patient_mrn].append(patient_covid_status) if patient_mrn not in patient_data: patient_data[patient_mrn] = [] patient_data[patient_mrn].append([ patient_mrn, map_patient_ramq(patient_ramq), map_time(pcr_sample_time), LOCAL_SITE_CODE, patient_covid_status,
if hours < -48: continue patients_with_imaging.append(row_patient_mrn) imaging_accession_numbers.append(row.accession_number) imaging_accession_uid = generate_accession_uid(row.accession_number) imaging_acquired_time = row.date_heure_debut_examen if 'rx' in lower_desc: modality = 'xr' elif 'scan' in lower_desc: modality = 'ct' imaging_data_rows.append([ row_patient_mrn, imaging_accession_uid, modality, 'chest', map_time(imaging_acquired_time) ]) patients_with_imaging = np.unique(patients_with_imaging) imaging_accession_numbers = np.unique(imaging_accession_numbers) print('Number of patients with imaging: %d' % \ len(patients_with_imaging)) write_csv(['accession_number'], \ [[x] for x in imaging_accession_numbers], \ IMAGING_LIST_FILENAME) write_csv(TABLE_COLUMNS['imaging_data'], imaging_data_rows, os.path.join(CSV_DIRECTORY, 'imaging_data.csv'))
pcr_sample_times[patient_mrn].append(pcr_time) # Get ER visit data from ADT df = sql_query( "SELECT dossier, noadm, dhreadm, dhredep, diagdesc FROM " + "dw_test.orcl_cichum_sejurg_live WHERE " + \ "dossier in ('" + "', '".join(patient_mrns) + "') " + \ "AND dhreadm > '2020-01-01'" ) episode_data_rows = [ [ map_string_lower(row.dossier), map_string_lower(int(row.noadm)), map_episode_unit_type('ER', None), map_time(row.dhreadm), map_time(row.dhredep), map_string_lower(row.diagdesc), get_hours_between_datetimes( \ row.dhreadm, row.dhredep, default_now=True), ] for i, row in df.iterrows() \ if row.dhreadm != '' and \ pcr_sample_times[str(row.dossier)][0] != '' and \ get_hours_between_datetimes( \ row.dhreadm, pcr_sample_times[str(row.dossier)][0] ) > 0 ] episode_ids = [ [map_string_lower(row.dossier)] for i, row in df.iterrows()
if 'annul' in str(pcr_result_value) or \ pcr_result_value is None or \ map_pcr_result_value(pcr_result_value) == '': continue if patient_mrn not in pcr_sample_times: pcr_sample_times[patient_mrn] = [] pcr_sample_times[patient_mrn].append(str(pcr_sample_time)) pcr_data_rows.append([ patient_mrn, map_pcr_name(pcr_name), map_pcr_sample_site(pcr_name, pcr_sample_site), map_time(pcr_sample_time), map_time(pcr_result_time), map_pcr_result_value(pcr_result_value), map_pcr_result_status(pcr_result_value) ]) live_sheet_rows = read_csv(LIVE_SHEET_FILENAME, remove_duplicates=True) for row in live_sheet_rows: is_external = (row[-3] == 'External') if is_external: continue patient_mrn = str(row[0]) if patient_mrn in patient_mrns:
#print(df.size) for index, row in df.iterrows(): patient_mrn = str(row.dossier) observation_name = row.servacro observation_value = row.rsltvalue observation_time = row.startdtm observation_unit = row.unitcd try: mapped_observation_name = map_observation_name(observation_name, observation_unit) except: continue mapped_observation_time = map_time(observation_time) mapped_observation_value = map_float_value(observation_value) delta_hours = get_hours_between_datetimes( pcr_sample_times[str(patient_mrn)], str(observation_time)) 9 if delta_hours < -48: continue observation_data_rows.append([ patient_mrn, mapped_observation_name, mapped_observation_time, mapped_observation_value ]) print('Done fetching observations from Oacis') df = sql_query(
for index, row in df.iterrows(): if row.longdesc.lower() in DRUG_SKIP_VALUES: continue patient_mrn = row.dossier drug_name = map_drug_name(row.longdesc) if 'ou placebo' in drug_name: continue drug_start_time = row.orderstartdtm drug_end_time = row.orderstopdtm delta_hours = get_hours_between_datetimes( pcr_sample_times[str(patient_mrn)], str(drug_start_time)) if delta_hours < -48: continue drug_data_rows.append([ patient_mrn, drug_name, map_time(drug_start_time), map_time(drug_end_time), map_drug_frequency(row.intervalsig), map_drug_route(row.routecd) ]) print('Total rows: %d' % len(drug_data_rows)) write_csv(TABLE_COLUMNS['drug_data'], drug_data_rows, os.path.join(CSV_DIRECTORY, 'drug_data.csv'))