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

Update withlogging.py

Browse files
Files changed (1) hide show
  1. withlogging.py +38 -25
withlogging.py CHANGED
@@ -12,37 +12,49 @@ def date_dict(df_list, pif_key):
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
@@ -52,4 +64,5 @@ def json_report_date_insertion(json_data, df_list):
52
 
53
  # json_data = {} # Load JSON data
54
 
55
- # json_report_date_insertion(json_data, [df2022, df2023, df2024])
 
 
12
  else:
13
  return ''
14
 
15
+ def report_date_check(dict_list, df_list, logging_df):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  pif_keys_with_report_date = set()
17
  pif_keys_without_report_date = set()
18
 
19
+ for col in dict_list:
20
+ pif_key = col.get('attribute_prediction', None)
21
+ if pif_key is not None:
22
+ if col['attribute_name'] == 'report_date':
23
+ pif_keys_with_report_date.add(pif_key)
24
+ else:
25
+ pif_keys_without_report_date.add(pif_key)
26
+ latest_date = date_dict(df_list, pif_key)
27
+ if latest_date:
28
+ logging_df = logging_df.append({'pif_key': pif_key,
29
+ 'report_date_exists': False,
30
+ 'report_date_missing': True,
31
+ 'encounter_dates': None,
32
+ 'latest_date': latest_date}, ignore_index=True)
33
+ else:
34
+ logging_df = logging_df.append({'pif_key': pif_key,
35
+ 'report_date_exists': False,
36
+ 'report_date_missing': True,
37
+ 'encounter_dates': None,
38
+ 'latest_date': ''}, ignore_index=True)
39
+
40
+ for pif_key in pif_keys_with_report_date:
41
+ logging_df = logging_df.append({'pif_key': pif_key,
42
+ 'report_date_exists': True,
43
+ 'report_date_missing': False,
44
+ 'encounter_dates': None,
45
+ 'latest_date': ''}, ignore_index=True)
46
+
47
+ return logging_df
48
+
49
+ def json_report_date_insertion(json_data, df_list):
50
+ logging_df = pd.DataFrame(columns=['pif_key', 'report_date_exists', 'report_date_missing', 'encounter_dates', 'latest_date'])
51
+
52
  for biomarker_detail in json_data['patient_level']['biomarkers']['details']:
53
  for attribute in biomarker_detail['attribute']:
54
  attribute_details = attribute['attribute_details']
55
+ logging_df = report_date_check(attribute_details, df_list, logging_df)
 
 
 
 
 
 
 
56
 
57
+ return logging_df
58
 
59
  # Usage
60
  # Load dataframes df2022, df2023, df2024
 
64
 
65
  # json_data = {} # Load JSON data
66
 
67
+ # logging_df = json_report_date_insertion(json_data, [df2022, df2023, df2024])
68
+ # print(logging_df)