thbndi commited on
Commit
5410da5
1 Parent(s): a027be0

Update Mimic4Dataset.py

Browse files
Files changed (1) hide show
  1. Mimic4Dataset.py +17 -18
Mimic4Dataset.py CHANGED
@@ -523,24 +523,23 @@ class Mimic4Dataset(datasets.GeneratorBasedBuilder):
523
  )
524
 
525
  def _generate_examples_text(self, filepath):
526
- df = pd.read_csv('icd10.txt',sep=';', header=0)
527
- with open(filepath, 'rb') as fp:
528
- dico = pickle.load(fp)
529
- for key, data in dico.items():
530
- conds = data['Cond']['fids']
531
- text=[]
532
- for code in conds:
533
- desc = df.where((df['icd10'].apply(lambda x: code >= x[:3]) & df['icd10'].apply(lambda x: code <= x[4:]))).dropna()
534
- if not desc.empty:
535
- desc = desc['description'].to_string(index=False)
536
- text.append(desc)
537
- template = 'The patient is diagnosed with {}.'
538
- text = template.format('; '.join(text))
539
-
540
- yield int(key),{
541
- 'label' : data['label'],
542
- 'COND': text,
543
- }
544
  #############################################################################################################################
545
  def _info(self):
546
  self.path = self.init_cohort()
 
523
  )
524
 
525
  def _generate_examples_text(self, filepath):
526
+ icd = pd.read_csv('icd10.txt',names=['code','description'],sep='\t')
527
+ with open(filepath, 'rb') as fp:
528
+ dico = pickle.load(fp)
529
+ for key, data in dico.items():
530
+ conds = data['Cond']['fids']
531
+ text=[]
532
+ for code in conds:
533
+ desc = icd[icd['code']==code]
534
+ if not desc.empty:
535
+ text.append(desc['description'].to_string(index=False))
536
+ template = 'The patient is diagnosed with {}.'
537
+ text = template.format('; '.join(text))
538
+
539
+ yield int(key),{
540
+ 'label' : data['label'],
541
+ 'COND': text,
542
+ }
 
543
  #############################################################################################################################
544
  def _info(self):
545
  self.path = self.init_cohort()