File size: 1,217 Bytes
b171cab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from typing import List, Dict
COMMON_RED_FLAGS = ["Severe pain","Syncope","Heavy bleeding","Chest pain/SOB","Persistent fever"]
def compose_soap(narrative: str, retrieved: List[Dict]) -> Dict:
    text = (narrative or "").lower()
    assessment, plan = [], ["Safety-net advice.","Follow-up in 3–7 days."]
    if any(k in text for k in ["bleed","period","aub","spotting"]):
        assessment.append("Abnormal uterine bleeding β€” consider structural vs hormonal causes.")
        plan.append("Pregnancy test if indicated; CBC; consider pelvic ultrasound.")
    if any(k in text for k in ["pelvic pain","cramp","lower abdominal pain"]):
        assessment.append("Pelvic pain β€” consider dysmenorrhea, ovarian cyst, endometriosis, or infection.")
        plan.append("Trial NSAIDs; pelvic exam and ultrasound if persistent or severe.")
    if not assessment:
        assessment.append("Non-specific gynae symptoms β€” conservative management and targeted testing.")
    citations = [it.get("title","") for it in retrieved]
    return {"subjective": narrative,"objective":"Vitals stable","assessment":assessment,"plan":plan,"red_flags":COMMON_RED_FLAGS,"follow_up":"3–7 days","citations":citations}