jkushwaha commited on
Commit
9bde11f
·
verified ·
1 Parent(s): f0a794c

Create withlogging.py

Browse files
Files changed (1) hide show
  1. withlogging.py +55 -0
withlogging.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ def date_dict(df_list, pif_key):
4
+ encounter_dates = []
5
+ for df in df_list:
6
+ df_date = df.loc[df['pif_key'].astype(str) == str(pif_key), 'encounter_date'].values
7
+ if len(df_date) > 0:
8
+ encounter_dates.extend(df_date)
9
+ if encounter_dates:
10
+ latest_date = max(encounter_dates)
11
+ return str(latest_date)
12
+ else:
13
+ return ''
14
+
15
+ def report_date_check(dict_list, df_list, pif_keys_with_report_date, pif_keys_without_report_date):
16
+ col_names = {col['attribute_name'] for col in dict_list}
17
+ pif_key = next((col['attribute_prediction'] for col in dict_list if col['attribute_name'] == 'pif_key'), None)
18
+ if pif_key is not None:
19
+ if 'report_date' in col_names:
20
+ pif_keys_with_report_date.add(pif_key)
21
+ else:
22
+ pif_keys_without_report_date.add(pif_key)
23
+ date_insert_dict = date_dict(df_list, pif_key)
24
+ if date_insert_dict:
25
+ dict_list.append(date_insert_dict)
26
+ return dict_list, pif_keys_with_report_date, pif_keys_without_report_date
27
+
28
+ def json_report_date_insertion(json_data, df_list):
29
+ pif_keys = set()
30
+ pif_keys_with_report_date = set()
31
+ pif_keys_without_report_date = set()
32
+
33
+ for biomarker_detail in json_data['patient_level']['biomarkers']['details']:
34
+ for attribute in biomarker_detail['attribute']:
35
+ attribute_details = attribute['attribute_details']
36
+ attribute_details, pif_keys_with_report_date, pif_keys_without_report_date = report_date_check(
37
+ attribute_details, df_list, pif_keys_with_report_date, pif_keys_without_report_date)
38
+ pif_keys.add(attribute_details['pif_key'])
39
+
40
+ # Logging
41
+ print("1. No of unique pif_key present in a json:", len(pif_keys))
42
+ print("2. Pif_keys with report_date in json:", pif_keys_with_report_date)
43
+ print("3. Pif_keys without report_date in json:", pif_keys_without_report_date)
44
+
45
+ return json_data
46
+
47
+ # Usage
48
+ # Load dataframes df2022, df2023, df2024
49
+ # df2022 = pd.read_csv('df2022.csv')
50
+ # df2023 = pd.read_csv('df2023.csv')
51
+ # df2024 = pd.read_csv('df2024.csv')
52
+
53
+ # json_data = {} # Load JSON data
54
+
55
+ # json_report_date_insertion(json_data, [df2022, df2023, df2024])