def next_notes(notesfile):
    '\n        Generator for notes from the notes file\n        This will also concatenate discharge summaries and their addenda, which have the same subject and hadm id\n    '
    nr = csv.reader(notesfile)
    next(nr)
    first_note = next(nr)
    cur_subj = int(first_note[0])
    cur_hadm = int(first_note[1])
    cur_text = first_note[3]
    for row in nr:
        subj_id = int(row[0])
        hadm_id = int(row[1])
        text = row[3]
        if ((hadm_id != cur_hadm) or (subj_id != cur_subj)):
            (yield (cur_subj, cur_text, cur_hadm))
            cur_text = text
            cur_subj = subj_id
            cur_hadm = hadm_id
        else:
            cur_text += (' ' + text)
    (yield (cur_subj, cur_text, cur_hadm))
Generator for notes from the notes file
This will also concatenate discharge summaries and their addenda, which have the same subject and hadm id
def next_notes(notesfile):
    '\n        Generator for notes from the notes file\n        This will also concatenate discharge summaries and their addenda, which have the same subject and hadm id\n    '
    nr = csv.reader(notesfile)
    next(nr)
    first_note = next(nr)
    cur_subj = int(first_note[0])
    cur_hadm = int(first_note[1])
    cur_text = first_note[3]
    for row in nr:
        subj_id = int(row[0])
        hadm_id = int(row[1])
        text = row[3]
        if ((hadm_id != cur_hadm) or (subj_id != cur_subj)):
            (yield (cur_subj, cur_text, cur_hadm))
            cur_text = text
            cur_subj = subj_id
            cur_hadm = hadm_id
        else:
            cur_text += (' ' + text)
    (yield (cur_subj, cur_text, cur_hadm))