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

Create rwd_code_for_opt.py

Browse files
Files changed (1) hide show
  1. rwd_code_for_opt.py +29 -0
rwd_code_for_opt.py ADDED
@@ -0,0 +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