def concat_data(labelsfile, notes_file):
    '\n        INPUTS:\n            labelsfile: sorted by hadm id, contains one label per line\n            notes_file: sorted by hadm id, contains one note per line\n    '
    with open(labelsfile, 'r') as lf:
        print('CONCATENATING')
        with open(notes_file, 'r') as notesfile:
            outfilename = ('%s/notes_labeled.csv' % MIMIC_3_DIR)
            with open(outfilename, 'w') as outfile:
                w = csv.writer(outfile)
                w.writerow(['SUBJECT_ID', 'HADM_ID', 'TEXT', 'LABELS'])
                labels_gen = next_labels(lf)
                notes_gen = next_notes(notesfile)
                for (i, (subj_id, text, hadm_id)) in enumerate(notes_gen):
                    if ((i % 10000) == 0):
                        print((str(i) + ' done'))
                    (cur_subj, cur_labels, cur_hadm) = next(labels_gen)
                    if (cur_hadm == hadm_id):
                        w.writerow([subj_id, str(hadm_id), text, ';'.join(cur_labels)])
                    else:
                        print("couldn't find matching hadm_id. data is probably not sorted correctly")
                        break
    return outfilename
INPUTS:
    labelsfile: sorted by hadm id, contains one label per line
    notes_file: sorted by hadm id, contains one note per line
def concat_data(labelsfile, notes_file):
    '\n        INPUTS:\n            labelsfile: sorted by hadm id, contains one label per line\n            notes_file: sorted by hadm id, contains one note per line\n    '
    with open(labelsfile, 'r') as lf:
        print('CONCATENATING')
        with open(notes_file, 'r') as notesfile:
            outfilename = ('%s/notes_labeled.csv' % MIMIC_3_DIR)
            with open(outfilename, 'w') as outfile:
                w = csv.writer(outfile)
                w.writerow(['SUBJECT_ID', 'HADM_ID', 'TEXT', 'LABELS'])
                labels_gen = next_labels(lf)
                notes_gen = next_notes(notesfile)
                for (i, (subj_id, text, hadm_id)) in enumerate(notes_gen):
                    if ((i % 10000) == 0):
                        print((str(i) + ' done'))
                    (cur_subj, cur_labels, cur_hadm) = next(labels_gen)
                    if (cur_hadm == hadm_id):
                        w.writerow([subj_id, str(hadm_id), text, ';'.join(cur_labels)])
                    else:
                        print("couldn't find matching hadm_id. data is probably not sorted correctly")
                        break
    return outfilename