| def date_dict(df, pif_key): |
| date = df.loc[df['pif_key'].astype(str) == str(pif_key), 'encounter_date'].values[0] |
| date_insert_dict = { |
| 'attribute_name': 'report_date', |
| 'attribute_method': 'cv', |
| 'attribute_normalized_prediction': '', |
| 'attribute_prediction': str(date), |
| 'attribute_version': 'v2_090523', |
| 'attribute_vocab': '', |
| 'attribute_code': '', |
| 'date_of_service': '' |
| } |
| return date_insert_dict |
|
|
| def report_date_check(dict_list, df): |
| col_names = {col['attribute_name'] for col in dict_list} |
| if 'report_date' not in col_names: |
| pif_key = next((col['attribute_prediction'] for col in dict_list if col['attribute_name'] == 'pif_key'), None) |
| if pif_key is not None: |
| date_insert_dict = date_dict(df, pif_key) |
| dict_list.append(date_insert_dict) |
| return dict_list |
|
|
| def json_report_date_insertion(json_data, df): |
| for biomarker_detail in json_data['patient_level']['biomarkers']['details']: |
| for attribute in biomarker_detail['attribute']: |
| attribute_details = attribute['attribute_details'] |
| attribute['attribute_details'] = report_date_check(attribute_details, df) |
| return json_data |
|
|
| def dicts_to_dataframe(list_of_dicts): |
| |
| df = pd.DataFrame() |
|
|
| |
| for d in list_of_dicts: |
| |
| temp_df = pd.DataFrame([d]) |
|
|
| |
| df = pd.concat([df, temp_df], ignore_index=True) |
|
|
| |
| df = df.fillna('') |
|
|
| return df |