Update dataset_utils.py
Browse files- dataset_utils.py +74 -1
dataset_utils.py
CHANGED
@@ -308,4 +308,77 @@ def generate_ml(dyn,stat,demo,concat_cols,concat):
|
|
308 |
|
309 |
X_df=pd.concat([dyn_df,stat],axis=1)
|
310 |
X_df=pd.concat([X_df,demo],axis=1)
|
311 |
-
return X_df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
X_df=pd.concat([dyn_df,stat],axis=1)
|
310 |
X_df=pd.concat([X_df,demo],axis=1)
|
311 |
+
return X_df
|
312 |
+
|
313 |
+
|
314 |
+
def generate_text(data,icd,items,feat_cond,feat_chart,feat_meds, feat_proc, feat_out):
|
315 |
+
#Diagnosis
|
316 |
+
if feat_cond:
|
317 |
+
conds = data['Cond']['fids']
|
318 |
+
cond_text=[]
|
319 |
+
for code in conds:
|
320 |
+
desc = icd[icd['code']==code]
|
321 |
+
if not desc.empty:
|
322 |
+
cond_text.append(desc['description'].to_string(index=False))
|
323 |
+
template = 'The patient is diagnosed with {}.'
|
324 |
+
cond_text = template.format(';'.join(cond_text))
|
325 |
+
else :
|
326 |
+
cond_text=''
|
327 |
+
|
328 |
+
#chart
|
329 |
+
if feat_chart:
|
330 |
+
chart = data['Chart']
|
331 |
+
if chart:
|
332 |
+
charts=chart['val']
|
333 |
+
feat=charts.keys()
|
334 |
+
chart_val=[charts[key] for key in feat]
|
335 |
+
chart_mean = [round(np.mean(c),3) for c in chart_val]
|
336 |
+
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
337 |
+
template='{} for {}'
|
338 |
+
chart_text = []
|
339 |
+
for mean_val, feat_label in zip(chart_mean, feat_text):
|
340 |
+
text = template.format(mean_val,feat_label)
|
341 |
+
chart_text.append(text)
|
342 |
+
chart_text='The chart events mesured are :{}.' + ';'.join(chart_text)
|
343 |
+
else:
|
344 |
+
chart_text=''
|
345 |
+
|
346 |
+
|
347 |
+
#meds
|
348 |
+
if feat_meds:
|
349 |
+
meds = data['Med']
|
350 |
+
if meds:
|
351 |
+
feat=meds['signal'].keys()
|
352 |
+
meds_val=[meds['amount'][key] for key in feat]
|
353 |
+
meds_mean = [round(np.mean(c),3) for c in meds_val]
|
354 |
+
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
355 |
+
template='{} of {}'
|
356 |
+
meds_text = []
|
357 |
+
for mean_val, feat_label in zip(meds_mean, feat_text):
|
358 |
+
text = template.format(mean_val,feat_label)
|
359 |
+
meds_text.append(text)
|
360 |
+
meds_text='The mean amounts of medications administered during the episode are :{}.' + ';'.join(meds_text)
|
361 |
+
else:
|
362 |
+
meds_text=''
|
363 |
+
|
364 |
+
#proc
|
365 |
+
if feat_proc:
|
366 |
+
proc = data['Proc']
|
367 |
+
if proc:
|
368 |
+
feat=proc.keys()
|
369 |
+
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
370 |
+
proc_text='The procedures performed are :{}.' + ';'.join(feat_text)
|
371 |
+
else:
|
372 |
+
proc_text=''
|
373 |
+
|
374 |
+
#out
|
375 |
+
if feat_out:
|
376 |
+
out = data['Out']
|
377 |
+
if out:
|
378 |
+
feat=out.keys()
|
379 |
+
feat_text = [(items[items['itemid']==f]['label']).to_string(index=False) for f in feat]
|
380 |
+
out_text='The outputs collected are :{}.' + ';'.join(feat_text)
|
381 |
+
else:
|
382 |
+
out_text=''
|
383 |
+
|
384 |
+
return cond_text,chart_text,meds_text,proc_text,out_text
|