首页 > 解决方案 > 如何从临床笔记中进行部分分割?

问题描述

我有几个临床笔记对应一个病人。每个注释由几个部分组成,如过敏、药物、既往病史等。所有这些都是非结构化的,即,部分出现的顺序没有特定的顺序。

这是样本医生说明:-

Chief Complaint:  cough
   HPI:
   Mr. [**Known lastname **] is 64-year-old man with liver cirrhosis [**1-19**] NASH, DM, HTN,
   CHF EF 40%, CAD, Seizure disorder who p/w cough. Per report from his
   nursing home, he has had cough, low grade fever x 3 days. Today, he had
   an episode of likely aspiration while using mouth wash, had a coughing
   fit and during this episode desat'ed to 80's. His family reports that
   he has been on small amounts of oxygen at the nursing home, which he
   has been on chronically since [**Hospital 258**] Rehab for unclear reasons. They
   state that he has had a ratteling cough for several days but has not
   appeared unwell. They also note that he has normally waxing and [**Doctor Last Name 42**]
   mental status, that he is not "chatty" normally and that his mental
   status appears to be at baseline. Per the patient, he feels relatively
   well and denies SOB. He was BIBA from his NH, enroute EMS had a
   difficult time obtaining a good pleth/sats and reported variable O2
   sats in high 80's.
   .
   In the ED: The patient was thought to be ill appearing and "dry". His
   vital signs were temp 100.0, HR 107, BP 120/80's, RR 22-26, Sa 96%
   2LNC. EKG unchanged, trop 0.06.CXR was noted to have hazy RLL and LLL.
   He received Vanc and CTX as well as normal saline.
   Patient admitted from: [**Hospital1 54**] ER
   History obtained from Patient, Family / [**Hospital 56**] Medical records
   Allergies:
   No Known Drug Allergies
   Last dose of Antibiotics:
   Ceftriaxone - [**2199-10-20**] 01:00 PM
   Infusions:
   Other ICU medications:
   Other medications:
   Topiramate 100 mg PO BID
   Metoprolol 25 mg PO BID
   Levetiracetam PO BID
   Zonisamide 500 mg DAILY
   Levothyroxine PO DAILY
   Fluocinolone 0.025 % Cream
   Lactulose 10 gram/15 mL Syrup
   Rifaximin PO TID
   Lorazepam 0.5 mg PO DAILY
   Furosemide 40 mg PO DAILY
   Heparin (Porcine) 5,000 unit/mL
   Multivitamin  PO DAILY
   Folic Acid 1 mg PO DAILY
   Lansoprazole 30 mg
   Thiamine HCl 100 mg PO DAILY
   Polyvinyl Alcohol 1.4 % Drops
   Lantus- dose?
   SSI
   Past medical history:
   Family history:
   Social History:
   1.  Seizure disorder with history of status epilepticus with
   recent admission for recurrent seizures & 2 prior admission in
   [**2197**] & [**2199-1-18**] for status requiring intubation. He has been on
   multiple antiepileptic drugs
   2.  NASH, cirrhosis, hepatocellular carcinoma, recently removed from
   transplant list [**1-19**] chronic illness
   3.  Diabetes.
   4.  Hypothyroidism.
   5.  Hypertension.
   6.  CHF with ejection fraction of 40% on an echo in [**2198-7-18**].
   7.  Coronary artery disease status post cardiac catheterization
   in [**2187**] w/o stenting.
   8.  History of upper GI bleed status post tips in [**2197**].
   9.  Stage IV sacral decubitus ulcer.
   n/c
   Occupation:
   Drugs: none
   Tobacco: past
   Alcohol: none
   Other: Prior to his illness, he was living with wife; remote tobacco,
   no EtOH or drug use. He now resides at [**Hospital 6307**] Nursing Home.
   Review of systems:
   Constitutional: Fatigue, Fever
   Eyes:  Blurry vision
   Ear, Nose, Throat: Dry mouth
   Nutritional Support: NPO, Tube feeds
   Respiratory: Cough, Dyspnea
   Endocrine: hypoglycemia
   Neurologic: Seizure
   Flowsheet Data as of [**2199-10-20**] 03:10 PM
   Vital Signs
   Hemodynamic monitoring
   Fluid Balance
                                                                  24 hours
                                                               Since 12 AM
   Tmax: 38.1
C (100.6
   Tcurrent: 38.1
C (100.6
   HR: 103 (103 - 105) bpm
   BP: 141/64(80) {130/51(72) - 141/64(80)} mmHg
   RR: 23 (23 - 25) insp/min
   SpO2: 96%
   Heart rhythm: ST (Sinus Tachycardia)
             Total In:
             71 mL
   PO:
             TF:
   IVF:
   71 mL
   Blood products:
   Total out:
                                                                      0 mL
                                                                    100 mL
   Urine:
   100 mL
   NG:
   Stool:
   Drains:
   Balance:
                                                                      0 mL
                                                                    -29 mL
   Respiratory
   O2 Delivery Device: Nasal cannula
   SpO2: 96%
   Physical Examination
   General Appearance: Thin, debilated appearing
   Eyes / Conjunctiva: PERRL
   Head, Ears, Nose, Throat: Normocephalic, Poor dentition, dry mucus
   membranes with yellowish caking, no thrush
   Lymphatic: NAD
   Cardiovascular: (S1: Normal), (S2: Normal)
   Peripheral Vascular: (Right radial pulse: Not assessed), (Left radial
   pulse: Not assessed), (Right DP pulse: Not assessed), (Left DP pulse:
   Not assessed)
   Respiratory / Chest: (Expansion: Symmetric), (Breath Sounds:
   Rhonchorous: )
   Abdominal: Soft, Non-tender, Bowel sounds present, PEG in place w/o
   erythema or drainage, no ascities
   Extremities: Right: Absent, Left: Absent, 4 beats clonus b/l
   Musculoskeletal: Muscle wasting, muscle wasting in hands c/l with
   intention tremor, unable to assess for asterixis
   Skin:  Warm, no stimata of liver dz- no aplmar erythema, no superifical
   venous engorgement
   Neurologic: Attentive, Follows simple commands, Responds to: Not
   assessed, Movement: Not assessed, Tone: Not assessed
   Labs / Radiology
   65
   178
   1.1
   50
   34
   110
   4.1
   150
   37
   5.2
        [image002.jpg]
   PT: 13.8
   PTT: 23.7
   INR: 1.2
   Ammonia 73
   BNP 667
   Trop 0.09
   Lactate 1.1
   ALT: 27
   AP: 124
   Tbili: 0.3
   Alb: 3.6
   AST: 23
   LDH:
   Dbili:
   TProt:
   [**Doctor First Name 429**]:
   Lip: 49
   UA : neg leuk, neg nitrite, WBC 0-3, many bacteria
   Imaging: CXR [**10-20**]: elevated right hemidiaphragm, opacity over right mid
   lung, there may also be streaky atelectasis in retrocardiac space; no
   PTX, no edema, no effusion, TIPS in RUQ; impression: right perihilar
   lung opacity which could represent atelectasis, aspiration or PNA.
   ECG: frequent PVC's, no ischemic changes
   Assessment and Plan
   Assessment and Plan: 64-year-old man with liver cirrhosis [**1-19**] NASH, DM,
   HTN, CHF EF 40%, CAD, Seizure disorder who p/w cough, fevers and CXR
   findings c/w PNA.
   .
   # PNA: CXR with new RML haziness, cough and low grade fever c/w PNA.
   Patient is not hypoxic. Patient resides in NH making him at risk for
   hospital acquired PNA. In addition, he has an aspiration risk.
   - Vanc, Azithro and Unasyn
   .
   # Hypernatremia: Patient appears dry on exam, hypernatremia is likely
   [**1-19**] vol depletion [**1-19**] poor free water intake and daily lasix. Pt
   received NS in the ED
   - obtain urine lytes
   - stop NS
   - reassess chem 7 and consider free water in tube feeds
   .
   # Limited mental status: Per family, pt is at baseline. Ammonia level
   not particularly elevated although the patient does have clonus on
   exam. PNA, fever and multiple anticonvulsants may be contributing. He
   does not appear encephalopathic
   .
   # Hx Cirrhosis: s/p TIPS, not transplant candidate. LFT's are
   unremarkable. MELD score 5.
   - cont rifamixin and lactulose
   .
   # Hx CHF: systolic dysfunction with EF 40%, BNP equivocal but pt not
   volume overloaded on exam. No acute exacerbation. As pt is currently
   vol depleted and hypernatremic will hold lasix for time being
   - hold lasix
   - cont Metoprolol
   .
   # hx Seizures:
   - cont keppra, topomax and zonisamide
   .
   # Hx  DM: NH records are diffucult to read re lantus dosing but wife
   reports that his lantus dose has been recently reduced since last
   discharge
   - will prescribe lantus 20 qhs
   - SSI
   .
   # Hx hypothyroidism
   - cont levothyroxine 400mg daily
   - check TSH, FT4
   .
   #) Prophylaxis: PPI, sc heparin, bowel regimen
   .
   #) FEN: TF and NPO for now given ? of aspiration
   .
   #) Access: PIVs
   .
   #) Code Status: Full
   .
   #) Dispo: pending further work-up and treatment
   ICU Care
   Nutrition:
   Glycemic Control: Regular insulin sliding scale
   Lines:
   18 Gauge - [**2199-10-20**] 01:48 PM
   Prophylaxis:
   DVT: SQ UF Heparin
   Stress ulcer: PPI
   VAP:
   Comments:
   Communication: Family meeting held , ICU consent signed Comments:
   Code status: Full code
   Disposition: ICU

从这个注释中,我需要在出院摘要中放置的重要部分是: 1. 主诉 2. HPI 3. 在急诊室 4. 过敏 5. 其他药物 6. 社会史 7. 药物 8. 烟草 9.酒精 10. 体格检查 11. 实验室/放射科 12. 评估和计划 13. ICU 护理

我尝试为每个部分获取内容,例如,对于“HPI”部分,我应该从 HPI: 部分开始到下一部分开始之前获取内容。但我无法进入某些部分,例如“评估和计划”、“实验室/放射学”等。谁能帮我解决这个问题。

section_names = ['Chief Complaint', 'HPI', 'Allergies', 'Last dose of Antibiotics', 'Other ICU medications', 'Other medications', 'Past medical history', 'Family history', 'Social History', 'Occupation', 'Review of systems', 'Physical Examination', 'Labs / Radiology', 'Assessment and Plan', 'ICU Care', 'Comments', 'Disposition']

section_dict = {     
     'Chief Complaint': ['chief', 'complaint'],
     'HPI': ['hpi'],
     'Allergies': ['allergy'],
     'Last dose of Antibiotics': ['last', 'dose', 'of', 'antibiotics'],
     'Other ICU medications': ['other', 'icu', 'medications'],
     'Other medications': ['other', 'medications'],
     'Past medical history': ['past', 'medical', 'history'],
     'Family History': ['family', 'history'],
     'Social History': ['social', 'history'],
     'Occupation': ['occupation'],
     'Review of systems': ['review', 'of', 'systems'],
     'Physical Examination': ['physical', 'examination'],
     'Labs / Radiology': ['labs', '/', 'radiology'],
     'Assessment and Plan': ['assessment', 'and', 'plan'],
     'ICU Care': ['icu', 'care'],
     'Comments': ['comments'],
     'Disposition': ['disposition']}

all_section_dict = {}
all_section_dict.update(section_dict)

sections = {}
sections['None'] = []
with open("/home/lekha/Documents/physician.txt", 'r') as f:
    lines_buffer = []
    previous_section_name = 'None'
    for line in f:
        line = line.strip()
        if line:
            lines_buffer.append(line)   

        if lines_buffer:
            lines_buffer_head = lines_buffer[0]
            if ':' in lines_buffer_head:
                section_name = lines_buffer_head.split(':')[0]

                for key, value in all_section_dict.items():
                    if key == section_name:
                        matched_section_name = section_name
                        break
                    else:
                        sub_section_name = section_name

                if matched_section_name != 'None':
                    previous_section_name = matched_section_name
                    afterColon = lines_buffer_head.split(':')[1:]
                    length_afterColon = len(afterColon[0].strip())

                    if length_afterColon > 1:
                        sections[matched_section_name] = [' '.join(lines_buffer_head.split(':')[1:])] + lines_buffer[1:]
                    else:
                        sections[matched_section_name] = lines_buffer[1:]
                    previous_section_name = matched_section_name

                    lines_buffer = []
                    continue

            sections[previous_section_name] = sections.get(previous_section_name, None) + lines_buffer 
            lines_buffer = []

对实现我的目标的任何帮助都是值得赞赏的。先感谢您。

标签: python-3.xextract

解决方案


我做了一个重写。

添加功能check_section以检查新部分的开始。如果它不是另一个部分,则可以将行添加到当前部分。

section_names = ['Chief Complaint', 'HPI', 'Allergies', 'Last dose of Antibiotics', 'Other ICU medications', 'Other medications', 'Past medical history', 'Family history', 'Social History', 'Occupation', 'Review of systems', 'Physical Examination', 'Labs / Radiology', 'Assessment and Plan', 'ICU Care', 'Comments', 'Disposition']

section_dict = {     
     'Chief Complaint': ['chief', 'complaint'],
     'HPI': ['hpi'],
     'Allergies': ['allergy'],
     'Last dose of Antibiotics': ['last', 'dose', 'of', 'antibiotics'],
     'Other ICU medications': ['other', 'icu', 'medications'],
     'Other medications': ['other', 'medications'],
     'Past medical history': ['past', 'medical', 'history'],
     'Family History': ['family', 'history'],
     'Social History': ['social', 'history'],
     'Occupation': ['occupation'],
     'Review of systems': ['review', 'of', 'systems'],
     'Physical Examination': ['physical', 'examination'],
     'Labs / Radiology': ['labs', '/', 'radiology'],
     'Assessment and Plan': ['assessment', 'and', 'plan'],
     'ICU Care': ['icu', 'care'],
     'Comments': ['comments'],
     'Disposition': ['disposition']}

all_section_dict = {}
all_section_dict.update(section_dict)

def check_section(x):
    s = ""
    match = ""
    if ':' in x:
        s = x.split(':')[0]
        if s not in all_section_dict:
             s = ""
    return(s)

sections = {}
sections['None'] = []
with open("physician.txt", 'r') as f:
    lines_buffer = []
    section = 'None'
    for line in f:
        line = line.strip()
        next_section = check_section(line)
        if next_section != "":
            section = next_section
            sections[section] = line.split(':')[1]
        else:
            sections[section] = sections[section] + " " + line



for i in sections:
   print(i, ": ", sections[i])

推荐阅读