jkushwaha commited on
Commit
fba9ff3
·
verified ·
1 Parent(s): a71b937

Update rwd_code_for_opt.py

Browse files
Files changed (1) hide show
  1. rwd_code_for_opt.py +23 -23
rwd_code_for_opt.py CHANGED
@@ -1,29 +1,29 @@
1
  def date_dict(df, pif_key):
2
- date = df.loc[df['pif_key'].astype(str)==str(pif_key), 'encounter_date'].values[0]
3
- date_insert_dict = {'attribute_name': 'report_date',
4
- 'attribute_method': 'cv',
5
- 'attribute_normalized_prediction': '',
6
- 'attribute_prediction': f'{date}',
7
- 'attribute_version': 'v2_090523',
8
- 'attribute_vocab': '',
9
- 'attribute_code': '',
10
- 'date_of_service': ''}
 
 
11
  return date_insert_dict
12
 
13
  def report_date_check(dict_list, df):
14
- cols = []
15
- for col_idx, col in enumerate(dict_list):
16
- if col['attribute_name'] == 'pif_key':
17
- pif_key = col['attribute_prediction']
18
- cols.append(col['attribute_name'])
19
- if 'report_date' not in cols:
20
- date_insert_dict = date_dict(df, pif_key)
21
- dict_list = dict_list + [date_insert_dict]
22
- # dict_list = dict_list.insert(1, date_insert_dict)
23
  return dict_list
 
24
  def json_report_date_insertion(json_data, df):
25
- for i, temp1 in enumerate(json_data['patient_level']['biomarkers']['details']):
26
- for j, temp2 in enumerate(json_data['patient_level']['biomarkers']['details'][i]['attribute']):
27
- dict_list = json_data['patient_level']['biomarkers']['details'][i]['attribute'][j]['attribute_details']
28
- json_data['patient_level']['biomarkers']['details'][i]['attribute'][j]['attribute_details'] = report_date_check(dict_list, df)
29
- return json_data
 
1
  def date_dict(df, pif_key):
2
+ date = df.loc[df['pif_key'].astype(str) == str(pif_key), 'encounter_date'].values[0]
3
+ date_insert_dict = {
4
+ 'attribute_name': 'report_date',
5
+ 'attribute_method': 'cv',
6
+ 'attribute_normalized_prediction': '',
7
+ 'attribute_prediction': str(date),
8
+ 'attribute_version': 'v2_090523',
9
+ 'attribute_vocab': '',
10
+ 'attribute_code': '',
11
+ 'date_of_service': ''
12
+ }
13
  return date_insert_dict
14
 
15
  def report_date_check(dict_list, df):
16
+ col_names = {col['attribute_name'] for col in dict_list}
17
+ if 'report_date' not in col_names:
18
+ pif_key = next((col['attribute_prediction'] for col in dict_list if col['attribute_name'] == 'pif_key'), None)
19
+ if pif_key is not None:
20
+ date_insert_dict = date_dict(df, pif_key)
21
+ dict_list.append(date_insert_dict)
 
 
 
22
  return dict_list
23
+
24
  def json_report_date_insertion(json_data, df):
25
+ for biomarker_detail in json_data['patient_level']['biomarkers']['details']:
26
+ for attribute in biomarker_detail['attribute']:
27
+ attribute_details = attribute['attribute_details']
28
+ attribute['attribute_details'] = report_date_check(attribute_details, df)
29
+ return json_data