/generatehandwritten notes on uterine fibroid based on gynecological view
ls /tmp/workspace/ 2>/dev/null || mkdir -p /tmp/workspace/uterine-fibroid-notes
mkdir -p /tmp/workspace/uterine-fibroid-notes && python3 << 'PYEOF' from PIL import Image, ImageDraw, ImageFont import textwrap, os, math # ββ page geometry ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ W, H = 2480, 3508 # A4 at 300 dpi MARGIN_LEFT = 220 MARGIN_TOP = 180 MARGIN_RIGHT = W - 180 LINE_HEIGHT = 62 INDENT = 40 DOUBLE_INDENT = 90 # ββ colour palette βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ BG = (255, 252, 230) # warm cream paper RULE_COL = (180, 200, 230) # faint blue rule lines RED_MARGIN = (210, 60, 60) # red margin line INK = (20, 20, 80) # dark-blue ink TITLE_COL = (170, 0, 30) # deep red for titles HEAD1_COL = (0, 80, 150) # section heading blue HEAD2_COL = (0, 130, 100) # sub-heading teal BULLET_COL = (180, 60, 0) # orange-red for bullets BOX_FILL = (255, 240, 200, 180) # translucent highlight STAR_COL = (200, 30, 30) UNDER_COL = (220, 160, 0) # underline emphasis # ββ font loading βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ def load(path, size): try: return ImageFont.truetype(path, size) except: return ImageFont.load_default() FONT_PATHS = [ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf", "/usr/share/fonts/truetype/freefont/FreeSans.ttf", ] BOLD_PATHS = [ "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", "/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf", ] ITALIC_PATHS = [ "/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf", "/usr/share/fonts/truetype/liberation/LiberationSans-Italic.ttf", ] def first_valid(paths, size): for p in paths: if os.path.exists(p): return load(p, size) return ImageFont.load_default() f_body = first_valid(FONT_PATHS, 38) f_bold = first_valid(BOLD_PATHS, 38) f_h1 = first_valid(BOLD_PATHS, 52) f_h2 = first_valid(BOLD_PATHS, 44) f_title = first_valid(BOLD_PATHS, 68) f_small = first_valid(FONT_PATHS, 32) f_italic = first_valid(ITALIC_PATHS, 36) # ββ content (page-by-page) βββββββββββββββββββββββββββββββββββββββββββββββββββ # Format codes: # T = page title (big red centred) # H1 = major section heading # H2 = sub-section heading # B = body line (normal ink) # BU = body line + underline emphasis # BL = bullet point (β’) # BL2= second-level bullet (β¦) # BOX= draw a coloured box around next N lines # SP = vertical spacer (pixels) # HR = horizontal rule # SRC= small italic source line PAGES = [ # βββββββββββββββββββ PAGE 1 βββββββββββββββββββ [ ("T", "UTERINE FIBROIDS (LEIOMYOMATA)"), ("SP", 20), ("SRC","Source: Berek & Novak's Gynecology (Gynecological View)"), ("HR", None), ("H1", "DEFINITION & OVERVIEW"), ("B", "β’ Benign, monoclonal tumours of smooth muscle cells of myometrium"), ("B", "β’ Also called: Leiomyomas / Myomas / Fibroids"), ("B", "β’ Contain large aggregations of extracellular matrix:"), ("BL2","Collagen, Elastin, Fibronectin, Proteoglycan"), ("B", "β’ Most common indication for hysterectomy (~240,000/yr in USA)"), ("SP", 18), ("H1", "INCIDENCE & EPIDEMIOLOGY"), ("BL", "African-American women: 60% by age 35; >80% by age 50"), ("BL", "White women: 40% by age 35; ~70% by age 50"), ("BL", "Fine serial sectioning of hysterectomy specimens β fibroids in 77%"), ("BL", "Some fibroids as small as 2 mm on microscopy"), ("SP", 18), ("H1", "RISK FACTORS"), ("BL", "Race: African-American > Hispanic > White"), ("BL", "Obesity (adipose tissue β peripheral oestrogen conversion)"), ("BL", "Nulliparity"), ("BL", "Early menarche"), ("BL", "Family history"), ("BL", "Protective: multiparity, smoking (β oestrogen), OCP use"), ("SP", 18), ("H1", "PATHOGENESIS"), ("BL", "Oestrogen & progesterone both promote fibroid growth"), ("BL", "Fibroid cells have more oestrogen receptors than normal myometrium"), ("BL", "Progesterone stimulates growth factors (EGF, IGF-1)"), ("BL", "Regression occurs after menopause (β ovarian hormones)"), ("BL", "GnRH agonist β β oestrogen β tumour shrinkage by ~30β35%"), ], # βββββββββββββββββββ PAGE 2 βββββββββββββββββββ [ ("T", "CLASSIFICATION (FIGO System)"), ("SP", 10), ("H1", "LOCATION-BASED CLASSIFICATION"), ("B", "Type 0 β Intracavitary (pedunculated submucosal, entirely in cavity)"), ("B", "Type 1 β <50% fibroid diameter within myometrium (submucosal)"), ("B", "Type 2 β β₯50% fibroid diameter within myometrium (submucosal)"), ("B", "Type 3 β Abuts endometrium; no intracavitary component"), ("B", "Type 4 β Intramural; entirely within myometrium"), ("B", "Type 5 β Subserosal; β₯50% intramural"), ("B", "Type 6 β Subserosal; <50% intramural"), ("B", "Type 7 β Subserosal; attached to serosa by a stalk (pedunculated)"), ("B", "Type 8 β No myometrial involvement (cervical, broad ligament, parasitic)"), ("SP", 10), ("H2", "Transmural fibroids: categorised by both endometrial & serosal"), ("B", "relationship (endometrial noted first e.g. Types 2β5)"), ("SP", 20), ("H1", "FIBROID VARIANTS"), ("BL", "Cellular leiomyoma β hypercellular, mitoses <5/10 HPF"), ("BL", "Mitotically active leiomyoma β mitoses β₯5/10 HPF, no atypia"), ("BL", "Atypical (bizarre) leiomyoma β nuclear atypia without malignant behaviour"), ("BL", "Lipoleiomyoma β fat cells within tumour"), ("BL", "Cotyledonoid dissecting leiomyoma β rare, grape-like protrusions"), ("SP", 20), ("H1", "TYPES OF DEGENERATION"), ("BL", "Hyaline degeneration (most common)"), ("BL", "Calcification (womb stone) β post-menopausal women"), ("BL", "Cystic degeneration β liquefaction of hyaline areas"), ("BL", "Haemorrhagic (red / carneous) degeneration β pregnancy"), ("BL", "Myxoid degeneration"), ("BL", "Necrosis (rare, usually ischaemic)"), ("B", " β Type of degeneration NOT related to clinical symptoms"), ], # βββββββββββββββββββ PAGE 3 βββββββββββββββββββ [ ("T", "CLINICAL FEATURES"), ("SP", 10), ("H1", "SYMPTOMS"), ("H2", "1. Abnormal Uterine Bleeding (most common)"), ("BL", "Heavy menstrual bleeding (HMB) β menorrhagia"), ("BL", "Mechanism: enlarged uterine cavity, impaired contractility,"), ("BL2","increased vascularity, altered prostaglandin synthesis"), ("BL", "Submucosal fibroids most likely to cause bleeding"), ("SP", 10), ("H2", "2. Pelvic Pain / Pressure"), ("BL", "Bulk symptoms: heaviness, bloating, pelvic pressure"), ("BL", "Dysmenorrhoea in some women"), ("BL", "Fibroid degeneration β acute/subacute pain"), ("BL", "Torsion of pedunculated subserosal fibroid β acute pain"), ("BL", "Note: fibroids only slightly β risk of dyspareunia / noncyclic pain"), ("SP", 10), ("H2", "3. Urinary Symptoms"), ("BL", "Frequency, urgency (anterior fibroids β bladder compression)"), ("BL", "After UAE (35% β uterine vol): 68% had marked urinary improvement"), ("BL", "Rarely: ureteral obstruction β hydronephrosis"), ("SP", 10), ("H2", "4. Reproductive Effects"), ("BL", "Implantation failure / early pregnancy loss"), ("BL", "Submucosal fibroids most strongly associated with infertility"), ("BL", "Premature labour, placenta praevia, malpresentation"), ("BL", "Haemorrhagic degeneration in pregnancy β pain, fever"), ("SP", 15), ("H1", "SIGNS (Physical Examination)"), ("BL", "Enlarged, irregularly shaped, firm, nontender uterus"), ("BL", "Uterine size by bimanual exam correlates well with pathological weight"), ("BL", "Definite diagnosis of submucosal fibroids needs SIS / hysteroscopy / MRI"), ], # βββββββββββββββββββ PAGE 4 βββββββββββββββββββ [ ("T", "DIAGNOSIS"), ("SP", 10), ("H1", "INVESTIGATIONS"), ("H2", "1. Ultrasound (first-line)"), ("BL", "Transvaginal sonography (TVS) β most accessible"), ("BL", "Well-defined hypoechoic / heterogeneous mass within myometrium"), ("BL", "Maps location, number, size"), ("H2", "2. Saline Infusion Sonohysterography (SIS)"), ("BL", "Best for submucosal fibroids (Types 0, 1, 2)"), ("BL", "Distends cavity with saline for clear visualisation"), ("H2", "3. MRI (Gold Standard for mapping)"), ("BL", "Best for characterising fibroid location, size, number"), ("BL", "Distinguishes leiomyoma from adenomyosis or sarcoma"), ("BL", "Low signal T2 = benign; heterogeneous high T2 = sarcoma?"), ("H2", "4. Hysteroscopy"), ("BL", "Direct visualisation of submucosal fibroids"), ("BL", "Both diagnostic & therapeutic (resection)"), ("H2", "5. Other"), ("BL", "FBC β detect anaemia"), ("BL", "TFTs β exclude thyroid disease causing HMB"), ("BL", "Endometrial biopsy if >45 yrs or irregular bleeding"), ("SP", 20), ("H1", "RAPID GROWTH & SARCOMA RISK"), ("BL", "Rapid growth almost NEVER = uterine sarcoma in premenopausal women"), ("BL", "Only 0.26% of operations for rapid-growth fibroids found sarcoma"), ("BL", "Sarcoma concerns: postmenopausal + pain + bleeding"), ("BL", "Mean age uterine sarcoma: LMS ~55 yrs, Carcinosarcoma ~68 yrs"), ("BL", "Mean age myomectomy series: ~36 yrs"), ], # βββββββββββββββββββ PAGE 5 βββββββββββββββββββ [ ("T", "MANAGEMENT β CONSERVATIVE & MEDICAL"), ("SP", 10), ("H1", "EXPECTANT MANAGEMENT"), ("BL", "Asymptomatic fibroids β observe; routine US follow-up may detect"), ("BL2","clinically insignificant fibroids unnecessarily"), ("BL", "Most fibroids grow slowly (~9%/year); 7% regress spontaneously"), ("BL", "After menopause β regression expected"), ("SP", 15), ("H1", "MEDICAL MANAGEMENT"), ("H2", "1. NSAIDs"), ("BL", "Reduce prostaglandin synthesis β β dysmenorrhoea & blood loss"), ("H2", "2. Combined OCP / Progestins"), ("BL", "Reduce menstrual bleeding; do NOT shrink fibroids"), ("BL", "Norethisterone, medroxyprogesterone acetate"), ("H2", "3. Levonorgestrel IUS (Mirena)"), ("BL", "Reduces HMB by 74β97%; does not shrink fibroids"), ("BL", "Expulsion rate β if fibroids >3 cm (15.4%) vs <3 cm (6.3%)"), ("H2", "4. Tranexamic Acid"), ("BL", "1.3 g TDS Γ 3β5 days during menstruation"), ("BL", "Antifibrinolytic β significant β menstrual blood loss"), ("H2", "5. GnRH Agonist (e.g. Leuprolide, Goserelin)"), ("BL", "β fibroid volume by ~30%; total uterine vol by ~35%"), ("BL", "Most reduction in first 3 months; returns to baseline 4β6 months after stopping"), ("BL", "Used pre-operatively to reduce fibroid size & correct anaemia"), ("BL", "Side effects (95% women): hot flushes 78%, vaginal dryness 32%"), ("BL", "Bone loss after 6 months β limit to 6 months; add-back therapy"), ("H2", "6. GnRH Antagonist (Ganirelix)"), ("BL", "Immediate suppression; 29% β fibroid vol within 3 weeks"), ("H2", "7. Selective Progesterone Receptor Modulators (SPRMs)"), ("BL", "Ulipristal acetate (UPA) β 5 mg OD Γ 3 months"), ("BL", "β bleeding in 90%, shrinks fibroids; bridge to surgery"), ], # βββββββββββββββββββ PAGE 6 βββββββββββββββββββ [ ("T", "MANAGEMENT β SURGICAL & INTERVENTIONAL"), ("SP", 10), ("H1", "SURGICAL OPTIONS"), ("H2", "1. Hysteroscopic Myomectomy"), ("BL", "For submucosal fibroids (Types 0, 1, 2)"), ("BL", "Resection via hysteroscope; day-case procedure"), ("BL", "Relieves HMB & improves implantation in infertility"), ("SP", 8), ("H2", "2. Abdominal Myomectomy"), ("BL", "For large / multiple / intramural fibroids"), ("BL", "Conservative; preserves uterus for fertility"), ("BL", "80% symptom relief; recurrence 27% at 10 years"), ("BL", "Safe alternative to hysterectomy even for large fibroids"), ("SP", 8), ("H2", "3. Laparoscopic Myomectomy"), ("BL", "Minimally invasive; shorter recovery"), ("BL", "Suitable for limited number of fibroids (<4, <8 cm)"), ("BL", "Equivalent outcomes to open myomectomy when technically feasible"), ("SP", 8), ("H2", "4. Laparoscopic Radiofrequency Ablation"), ("BL", "Ultrasound-guided thermal ablation of fibroids"), ("BL", "Uterus preserved; outpatient/day surgery"), ("SP", 8), ("H2", "5. Endometrial Ablation"), ("BL", "For HMB when fertility not desired"), ("BL", "Destroys endometrium; reduces menstrual blood loss"), ("BL", "Contraindicated if future pregnancy desired"), ("SP", 8), ("H2", "6. Hysterectomy (Definitive)"), ("BL", "Abdominal / Vaginal / Laparoscopic"), ("BL", "Only definitive cure; eliminates recurrence"), ("BL", "Most common indication for hysterectomy in USA"), ("B", " β Ovarian conservation recommended in premenopausal women"), ("SP", 15), ("H1", "UTERINE ARTERY EMBOLISATION (UAE)"), ("BL", "Interventional radiology procedure"), ("BL", "Polyvinyl alcohol particles β occlusion of uterine arteries"), ("BL", "β uterine volume ~35%; significant symptom improvement"), ("BL", "68% marked urinary symptom improvement post-UAE"), ("BL", "75% significant β symptom scores at 6 months (vs myomectomy 75%)"), ("BL", "Concerns: premature ovarian failure, fertility, pregnancy outcomes unclear"), ("BL", "Post-embolisation syndrome: fever, pain, leucocytosis"), ], # βββββββββββββββββββ PAGE 7 βββββββββββββββββββ [ ("T", "FIBROIDS & SPECIAL SITUATIONS"), ("SP", 10), ("H1", "FIBROIDS IN PREGNANCY"), ("BL", "Usually asymptomatic during pregnancy"), ("BL", "Haemorrhagic (red/carneous) degeneration most common complication"), ("BL2","Pain + fever + localised tenderness β manage conservatively (analgesia, hydration)"), ("BL", "Risks: preterm labour, placenta praevia, malpresentation, PPH"), ("BL", "Myomectomy in pregnancy NOT recommended (high haemorrhage risk)"), ("BL", "Caesarean myomectomy: controversial; only for pedunculated/accessible fibroids"), ("SP", 18), ("H1", "FIBROIDS & INFERTILITY"), ("BL", "Submucosal fibroids (Types 0β2): strongest evidence for β fertility"), ("BL", "Hysteroscopic myomectomy β improves implantation & live-birth rates"), ("BL", "Intramural fibroids without cavity distortion: debated"), ("BL", "Subserosal fibroids: minimal effect on fertility"), ("SP", 18), ("H1", "NATURAL HISTORY & PROGNOSIS"), ("BL", "Median growth rate: 9%/12 months"), ("BL", "7% of fibroids regress spontaneously"), ("BL", "Growth rates decline after age 35 in White women (not African-American)"), ("BL", "Multiple fibroids in same uterus β highly variable individual growth rates"), ("BL", "Regression post-menopause (oestrogen withdrawal)"), ("BL", "Malignant transformation (to LMS) extremely rare (~0.1β0.2%)"), ("SP", 18), ("H1", "QUICK REVISION BOX"), ("B", "Most common benign uterine tumour"), ("B", "Oestrogen-dependent β regress post-menopause"), ("B", "Submucosal β worst bleeding & infertility effects"), ("B", "FIGO Types 0β8 (submucosal 0β2, intramural 3β4, subserosal 5β7)"), ("B", "Definitive Rx: Hysterectomy | Fertility-sparing: Myomectomy"), ("B", "Medical bridge: GnRH agonist (max 6 months), UPA, tranexamic acid"), ], ] # ββ drawing helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ def make_page(elements): img = Image.new("RGB", (W, H), BG) draw = ImageDraw.Draw(img, "RGBA") # ruled lines for y in range(MARGIN_TOP + LINE_HEIGHT, H - 100, LINE_HEIGHT): draw.line([(MARGIN_LEFT - 20, y), (MARGIN_RIGHT, y)], fill=RULE_COL, width=1) # red margin line draw.line([(MARGIN_LEFT - 30, MARGIN_TOP - 20), (MARGIN_LEFT - 30, H - 80)], fill=RED_MARGIN, width=3) cy = MARGIN_TOP # current y cursor x0 = MARGIN_LEFT def next_line(extra=0): nonlocal cy cy += LINE_HEIGHT + extra def wrap_and_draw(text, font, colour, x_start, max_width, extra_indent=0): nonlocal cy # estimate chars per line try: avg_w = font.getlength("m") except: avg_w = 20 chars = max(10, int(max_width / avg_w)) lines = textwrap.wrap(text, width=chars) or [""] for ln in lines: draw.text((x_start + extra_indent, cy), ln, font=font, fill=colour) next_line() for elem in elements: tag, content = elem if tag == "T": # big centred title with underline try: tw = f_title.getlength(content) except: tw = len(content) * 30 tx = (W - tw) / 2 draw.text((tx, cy), content, font=f_title, fill=TITLE_COL) cy += 75 draw.line([(MARGIN_LEFT - 30, cy), (MARGIN_RIGHT, cy)], fill=TITLE_COL, width=3) cy += 12 elif tag == "H1": draw.text((x0, cy), content, font=f_h1, fill=HEAD1_COL) cy += 58 draw.line([(x0, cy), (MARGIN_RIGHT, cy)], fill=HEAD1_COL, width=2) cy += 8 elif tag == "H2": draw.text((x0 + INDENT, cy), "βΊ " + content, font=f_h2, fill=HEAD2_COL) cy += 50 elif tag == "B": wrap_and_draw(content, f_body, INK, x0, MARGIN_RIGHT - x0, INDENT) elif tag == "BU": lx = x0 + INDENT draw.text((lx, cy), content, font=f_bold, fill=INK) try: tw = f_bold.getlength(content) except: tw = len(content) * 22 draw.line([(lx, cy + 42), (lx + tw, cy + 42)], fill=UNDER_COL, width=3) next_line() elif tag == "BL": draw.text((x0 + INDENT, cy), "β’ ", font=f_body, fill=BULLET_COL) wrap_and_draw(content, f_body, INK, x0 + INDENT + 30, MARGIN_RIGHT - x0 - 60) elif tag == "BL2": draw.text((x0 + DOUBLE_INDENT, cy), "β¦ ", font=f_body, fill=BULLET_COL) wrap_and_draw(content, f_body, INK, x0 + DOUBLE_INDENT + 30, MARGIN_RIGHT - x0 - 90) elif tag == "SP": cy += int(content) elif tag == "HR": draw.line([(x0, cy + 8), (MARGIN_RIGHT, cy + 8)], fill=(120, 120, 160), width=2) cy += 20 elif tag == "SRC": draw.text((x0, cy), content, font=f_italic, fill=(120, 100, 160)) cy += 42 # page border draw.rectangle([(40, 40), (W - 40, H - 40)], outline=(160, 160, 200), width=3) return img # ββ render all pages βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ out_dir = "/tmp/workspace/uterine-fibroid-notes" os.makedirs(out_dir, exist_ok=True) page_images = [make_page(p) for p in PAGES] # save individual pages for i, img in enumerate(page_images, 1): img.save(f"{out_dir}/page_{i:02d}.png", "PNG", dpi=(300, 300)) # combine into one multi-page PDF page_images[0].save( f"{out_dir}/Uterine_Fibroid_Notes.pdf", "PDF", resolution=300, save_all=True, append_images=page_images[1:] ) print(f"Done β {len(page_images)} pages saved to {out_dir}") PYEOF
Uterine Fibroid Notes
PDF Document Β· PDF
page 01
Image Β· PNG
page 02
Image Β· PNG
page 03
Image Β· PNG
page 04
Image Β· PNG
page 05
Image Β· PNG
page 06
Image Β· PNG
page 07
Image Β· PNG
| Page | Topic |
|---|---|
| 1 | Definition, incidence (race/age data), risk factors, pathogenesis |
| 2 | FIGO Types 0-8 classification, fibroid variants, degeneration types |
| 3 | Symptoms (HMB, pain, urinary, reproductive), signs on exam |
| 4 | Investigations (TVS, SIS, MRI, hysteroscopy), rapid growth & sarcoma risk |
| 5 | Medical management (NSAIDs, OCP, LNG-IUS, tranexamic acid, GnRH agonist/antagonist, UPA) |
| 6 | Surgical options (hysteroscopic/abdominal/laparoscopic myomectomy, hysterectomy) + UAE |
| 7 | Fibroids in pregnancy, fibroids & infertility, natural history, quick revision box |