Give that appendicitis pdf

Reading File
Finding Sources
Finding Sources
Asking for Preferences

Create a PDF quick reference card (two-pager) of this content , like definition, pathophysiology,investigation, clinical features, diagnosis, treatment, homeopathic remedies

Reading File
Finding Sources
Reading File
Reading File
Searching the Web

homeopathic remedies appendicitis treatment

Finding Sources
Reading Web Page

https://www.doctorbhatia.com/treatment/appendicitis-homeopat…

Finding Sources
Finding Sources
Running Command

mkdir -p /home/daytona/workspace/appendicitis-ref && ls /home/daytona/workspace/…

Writing File

~/appendicitis-ref/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm, mm
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, HRFlowable
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_JUSTIFY
from reportlab.platypus import KeepTogether

OUTPUT = "/home/daytona/workspace/appendicitis-ref/Appendicitis_Quick_Reference.pdf"

doc = SimpleDocTemplate(
    OUTPUT,
    pagesize=A4,
    leftMargin=1.5*cm,
    rightMargin=1.5*cm,
    topMargin=1.5*cm,
    bottomMargin=1.5*cm,
)

# ── Color palette ──────────────────────────────────────────────────────────────
C_HEADER   = colors.HexColor("#1a3a5c")   # deep navy
C_SECTION  = colors.HexColor("#2e86c1")   # cobalt blue
C_ACCENT   = colors.HexColor("#e74c3c")   # red alert
C_HOMEO    = colors.HexColor("#27ae60")   # green for homeopathy
C_LIGHT    = colors.HexColor("#eaf4fb")   # pale blue fill
C_LIGHTYEL = colors.HexColor("#fef9e7")   # pale yellow fill
C_LIGHTGRN = colors.HexColor("#eafaf1")   # pale green fill
C_WHITE    = colors.white
C_DARK     = colors.HexColor("#1c1c1c")

# ── Styles ─────────────────────────────────────────────────────────────────────
base = getSampleStyleSheet()

def make_style(name, parent="Normal", **kw):
    s = ParagraphStyle(name, parent=base[parent])
    for k, v in kw.items():
        setattr(s, k, v)
    return s

s_title   = make_style("Title",   fontSize=22, textColor=C_WHITE,    alignment=TA_CENTER, fontName="Helvetica-Bold", leading=28)
s_subtitle= make_style("Sub",     fontSize=10, textColor=C_LIGHT,    alignment=TA_CENTER, fontName="Helvetica",      leading=14)
s_sec     = make_style("Sec",     fontSize=9,  textColor=C_WHITE,    fontName="Helvetica-Bold", leading=13, spaceAfter=0)
s_body    = make_style("Body",    fontSize=7.5,textColor=C_DARK,     fontName="Helvetica",      leading=11, spaceAfter=2)
s_bullet  = make_style("Bullet",  fontSize=7.5,textColor=C_DARK,     fontName="Helvetica",      leading=11, leftIndent=8, bulletIndent=0, spaceAfter=1)
s_bold    = make_style("Bold",    fontSize=7.5,textColor=C_DARK,     fontName="Helvetica-Bold", leading=11, spaceAfter=1)
s_note    = make_style("Note",    fontSize=6.5,textColor=colors.HexColor("#555555"), fontName="Helvetica-Oblique", leading=10)
s_homeo_h = make_style("HomeoH",  fontSize=7.5,textColor=C_HOMEO,    fontName="Helvetica-Bold", leading=11, spaceAfter=1)

def section_header(title, color=C_SECTION):
    data = [[Paragraph(f"■ {title}", s_sec)]]
    t = Table(data, colWidths=["100%"])
    t.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), color),
        ("TOPPADDING",    (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ]))
    return t

def two_col_table(left_data, right_data, left_title, right_title, bg=C_LIGHT):
    """Build a two-column section table."""
    left_cells  = [Paragraph(left_title,  s_bold)] + [Paragraph(r, s_bullet) for r in left_data]
    right_cells = [Paragraph(right_title, s_bold)] + [Paragraph(r, s_bullet) for r in right_data]
    rows = []
    max_r = max(len(left_cells), len(right_cells))
    for i in range(max_r):
        l = left_cells[i]  if i < len(left_cells)  else Paragraph("", s_body)
        r = right_cells[i] if i < len(right_cells) else Paragraph("", s_body)
        rows.append([l, r])
    t = Table(rows, colWidths=["50%", "50%"])
    t.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), bg),
        ("TOPPADDING",    (0,0), (-1,-1), 3),
        ("BOTTOMPADDING", (0,0), (-1,-1), 3),
        ("LEFTPADDING",   (0,0), (-1,-1), 5),
        ("RIGHTPADDING",  (0,0), (-1,-1), 5),
        ("LINEAFTER",     (0,0), (0,-1), 0.4, colors.HexColor("#aaaaaa")),
        ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ]))
    return t

def info_box(rows_data, bg=C_LIGHT):
    table_rows = [[Paragraph(item, s_bullet)] for item in rows_data]
    t = Table(table_rows, colWidths=["100%"])
    t.setStyle(TableStyle([
        ("BACKGROUND",    (0,0), (-1,-1), bg),
        ("TOPPADDING",    (0,0), (-1,-1), 2),
        ("BOTTOMPADDING", (0,0), (-1,-1), 2),
        ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ]))
    return t

# ══════════════════════════════════════════════════════════════════════════════
# CONTENT
# ══════════════════════════════════════════════════════════════════════════════

story = []

# ── TITLE BANNER ──────────────────────────────────────────────────────────────
title_data = [[
    Paragraph("APPENDICITIS", s_title),
    Paragraph("Quick Reference Card", s_subtitle),
]]
title_table = Table([[
    Paragraph("APPENDICITIS", s_title),
]], colWidths=["100%"])
title_table.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), C_HEADER),
    ("TOPPADDING",    (0,0), (-1,-1), 10),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
]))
story.append(title_table)

subtitle_table = Table([[
    Paragraph("Quick Reference Card  |  Clinical Overview &amp; Homeopathic Approach", s_subtitle),
]], colWidths=["100%"])
subtitle_table.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), C_SECTION),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
]))
story.append(subtitle_table)
story.append(Spacer(1, 4*mm))

# ── TWO-COLUMN LAYOUT using a master table ─────────────────────────────────

# We'll build the page as a master 2-col table
left_col = []
right_col = []

# ── LEFT COL: Definition + Pathophysiology ────────────────────────────────────
left_col.append(section_header("DEFINITION"))
left_col.append(info_box([
    "&#8226; Inflammation of the vermiform appendix (a blind-ended pouch at the caecum).",
    "&#8226; Most common acute surgical emergency worldwide; lifetime risk 7-10%.",
    "&#8226; Incidence: 100-150 per 100,000 persons/year; ~400,000 US cases/year.",
    "&#8226; Peak incidence: 10-30 years; slight male predominance.",
    "&#8226; Can affect any age including pregnant patients (same incidence as non-pregnant).",
], bg=C_LIGHT))
left_col.append(Spacer(1, 3*mm))

left_col.append(section_header("PATHOPHYSIOLOGY"))
left_col.append(info_box([
    "&#8226; <b>Obstruction</b> of appendiceal lumen (most common cause) by:",
    "   - Faecolith / appendicolith (calcified faecal mass)",
    "   - Lymphoid hyperplasia (common in children)",
    "   - Tumour, foreign body, parasites (rare)",
    "&#8226; Obstruction &#8594; mucosal secretions accumulate &#8594; intraluminal pressure rises.",
    "&#8226; Raised pressure &#8594; lymphatic obstruction &#8594; mucosal oedema + bacterial overgrowth.",
    "&#8226; Progressive ischaemia &#8594; transmural inflammation &#8594; necrosis &#8594; perforation.",
    "&#8226; Perforation rate 16-40%; higher in children &lt;5 yrs and elderly.",
    "&#8226; Perforation &#8594; localised abscess or generalised peritonitis.",
], bg=C_LIGHT))
left_col.append(Spacer(1, 3*mm))

left_col.append(section_header("CLINICAL FEATURES"))
left_col.append(info_box([
    "<b>Classic Triad:</b>  Periumbilical pain &#8594; RIF pain  |  Nausea/vomiting  |  Low-grade fever",
    "",
    "<b>Symptoms:</b>",
    "&#8226; Pain: starts periumbilical (visceral), migrates to RIF (McBurney's point) within 12-24 h",
    "&#8226; Anorexia (almost universal), nausea, vomiting",
    "&#8226; Low-grade fever 37.5-38.5 °C (high fever suggests perforation)",
    "&#8226; Constipation; occasionally diarrhoea (pelvic appendix)",
    "&#8226; Dysuria / frequency (if appendix near bladder)",
    "",
    "<b>Signs:</b>",
    "&#8226; McBurney's point tenderness (1/3 way from ASIS to umbilicus)",
    "&#8226; Rovsing's sign: palpation of LIF causes RIF pain",
    "&#8226; Psoas sign: extension of right hip causes RIF pain (retrocaecal appendix)",
    "&#8226; Obturator sign: internal rotation of flexed right hip causes RIF pain (pelvic appendix)",
    "&#8226; Rebound tenderness / guarding (peritoneal irritation)",
    "&#8226; Dunphy's sign: increased pain on coughing",
    "",
    "<b>Atypical Presentations:</b>",
    "&#8226; Retrocaecal: back/flank pain, psoas sign positive",
    "&#8226; Pelvic: suprapubic pain, urinary/GI symptoms",
    "&#8226; Pregnancy: RUQ/RIF pain (displaced appendix in 2nd/3rd trimester)",
], bg=C_LIGHT))

# ── RIGHT COL: Investigations + Diagnosis + Treatment ─────────────────────────
right_col.append(section_header("INVESTIGATIONS"))
right_col.append(info_box([
    "<b>Laboratory Tests:</b>",
    "&#8226; FBC: leukocytosis (WBC &gt;10,000) with left shift - present in 70-90%",
    "&#8226; CRP: elevated (&gt;10 mg/L); rises later than WBC, more specific for perforation",
    "&#8226; Urinalysis: mild pyuria/haematuria if appendix near ureter/bladder",
    "&#8226; Pregnancy test (urine/serum beta-hCG) - mandatory in women of childbearing age",
    "&#8226; Electrolytes, renal function - pre-operative assessment",
    "",
    "<b>Imaging:</b>",
    "&#8226; <b>Ultrasound (USS)</b> - 1st line (especially children &amp; pregnancy); appendix &gt;6mm non-compressible",
    "&#8226; <b>CT Abdomen/Pelvis</b> - gold standard; sensitivity 94-98%, specificity 95-99%",
    "   - Findings: dilated appendix &gt;6mm, periappendiceal fat stranding, appendicolith",
    "&#8226; <b>MRI</b> - preferred in pregnancy (no radiation); comparable accuracy to CT",
    "&#8226; Plain AXR: limited use; may show faecolith, gas in RIF",
    "",
    "<b>Scoring Systems:</b>",
    "&#8226; Alvarado Score (MANTRELS): 0-10; &#8805;7 = high probability",
    "&#8226; Appendicitis Inflammatory Response (AIR) Score",
    "&#8226; Paediatric Appendicitis Score (PAS)",
], bg=C_LIGHTYEL))
right_col.append(Spacer(1, 3*mm))

right_col.append(section_header("DIAGNOSIS", color=colors.HexColor("#8e44ad")))
right_col.append(info_box([
    "<b>Alvarado Score (MANTRELS):</b>",
    "&#8226; Migration of pain to RIF         +1",
    "&#8226; Anorexia                          +1",
    "&#8226; Nausea / Vomiting                 +1",
    "&#8226; RIF Tenderness                    +2",
    "&#8226; Rebound Tenderness                +1",
    "&#8226; Elevated Temperature (&gt;37.3°C) +1",
    "&#8226; Leukocytosis (WBC &gt;10K)        +2",
    "&#8226; Left shift                        +1",
    "Score: 1-4 = Low | 5-6 = Equivocal | 7-10 = High (operate)",
    "",
    "<b>Differential Diagnosis:</b>",
    "&#8226; Mesenteric adenitis, Meckel's diverticulitis",
    "&#8226; Ovarian cyst/torsion, ectopic pregnancy (females)",
    "&#8226; Crohn's disease, caecal carcinoma",
    "&#8226; Urolithiasis (ureteric colic), UTI, pyelonephritis",
    "&#8226; Psoas abscess, hernia",
], bg=colors.HexColor("#f5eef8")))
right_col.append(Spacer(1, 3*mm))

right_col.append(section_header("TREATMENT", color=colors.HexColor("#c0392b")))
right_col.append(info_box([
    "<b>Surgical (Standard of Care):</b>",
    "&#8226; <b>Laparoscopic appendectomy</b> - gold standard; same-day discharge in many cases",
    "&#8226; Open appendectomy - if laparoscopy unavailable or conversion required",
    "&#8226; Timing: within 12-24 h of diagnosis (acceptable delay up to 24 h)",
    "&#8226; Pre-op IV antibiotics: 2nd/3rd generation cephalosporin + metronidazole",
    "",
    "<b>Non-Operative (Antibiotics-First) - Uncomplicated:</b>",
    "&#8226; IV Amoxicillin-clavulanate or Piperacillin-tazobactam; then oral antibiotics",
    "&#8226; Success rate 80-90% at 24-48 h; recurrence rate up to 40% at 5 years",
    "&#8226; NOT suitable if: faecolith present, perforation, peritonitis, abscess",
    "",
    "<b>Perforated Appendicitis:</b>",
    "&#8226; Broad-spectrum IV antibiotics + urgent appendectomy",
    "&#8226; If abscess with &#8805;5 days symptoms: IR drainage + interval appendectomy (6-8 wks)",
    "",
    "<b>Special Populations:</b>",
    "&#8226; Pregnancy: early surgical intervention recommended (fetal loss risk with perforation)",
    "&#8226; Children: prefer USS/MRI; laparoscopic appendectomy standard; same management",
    "&#8226; Elderly: lower threshold for CT; higher perforation rate at presentation",
], bg=colors.HexColor("#fdedec")))

# Assemble master 2-column layout
master_content = [[left_col, right_col]]

# Build the two columns as nested lists
left_content = []
for item in left_col:
    left_content.append(item)

right_content = []
for item in right_col:
    right_content.append(item)

from reportlab.platypus import TopPadder
from io import BytesIO

# Use a Table to do two-column layout
main_table = Table(
    [[left_content, right_content]],
    colWidths=["50%", "50%"],
)
main_table.setStyle(TableStyle([
    ("VALIGN", (0,0), (-1,-1), "TOP"),
    ("LEFTPADDING",  (0,0), (-1,-1), 2),
    ("RIGHTPADDING", (0,0), (-1,-1), 2),
    ("TOPPADDING",   (0,0), (-1,-1), 0),
    ("BOTTOMPADDING",(0,0), (-1,-1), 0),
]))
story.append(main_table)

# ── PAGE 2: HOMEOPATHIC REMEDIES ──────────────────────────────────────────────
from reportlab.platypus import PageBreak
story.append(PageBreak())

# Banner
banner2 = Table([[
    Paragraph("APPENDICITIS - HOMEOPATHIC REMEDIES", s_title),
]], colWidths=["100%"])
banner2.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), C_HOMEO),
    ("TOPPADDING",    (0,0), (-1,-1), 10),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
]))
story.append(banner2)

subban2 = Table([[
    Paragraph("Homeopathic Quick Reference  |  For Practitioner Guidance Only  |  Not a Substitute for Emergency Surgery", s_subtitle),
]], colWidths=["100%"])
subban2.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), colors.HexColor("#1e8449")),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
]))
story.append(subban2)
story.append(Spacer(1, 4*mm))

# Warning box
warn_data = [[Paragraph(
    "<b>&#9888; IMPORTANT:</b>  Acute appendicitis is a surgical emergency. Homeopathic remedies below are used adjunctively or in sub-acute/recurrent cases under professional supervision. Perforation risk demands prompt surgical evaluation. <b>Do not delay surgery based on homeopathic treatment.</b>",
    make_style("Warn", fontSize=7.5, textColor=colors.HexColor("#7b241c"), fontName="Helvetica", leading=11)
)]]
warn_table = Table(warn_data, colWidths=["100%"])
warn_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), colors.HexColor("#fadbd8")),
    ("TOPPADDING",    (0,0), (-1,-1), 6),
    ("BOTTOMPADDING", (0,0), (-1,-1), 6),
    ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ("RIGHTPADDING",  (0,0), (-1,-1), 8),
    ("BOX",           (0,0), (-1,-1), 1, colors.HexColor("#e74c3c")),
]))
story.append(warn_table)
story.append(Spacer(1, 4*mm))

# Homeopathic remedies table
remedies = [
    ("Iris Tenax", "The specific remedy for appendicitis.", [
        "Cutting pain in RIF; sensation of something tearing",
        "Pain extending to groin/thigh; stool may be mucoid",
        "Constriction and cramping; better lying still",
    ]),
    ("Belladonna", "Early stage; sudden violent onset with fever.", [
        "Throbbing, burning RIF pain; worse from jarring/touch",
        "High fever, flushed face, dilated pupils",
        "Right-sided predominance; aggravation from slightest movement",
        "Tongue strawberry-red; dry mouth",
    ]),
    ("Bryonia Alba", "Pain severely aggravated by any movement.", [
        "Stitching, tearing RIF pain; patient lies perfectly still",
        "Dry mucous membranes; great thirst for large amounts",
        "Peritoneally irritated picture; constipation",
        "Irritable, wants to be left alone; worse any motion",
    ]),
    ("Mercurius Corrosivus", "Severe inflammation; approaching peritonitis.", [
        "Violent, burning RIF pain with great tenderness",
        "Offensive diarrhoea with tenesmus; profuse sweat",
        "Fever with chills; marked prostration",
        "Trembling; worse at night",
    ]),
    ("Colocynthis", "Colicky, cramping pain relieved by bending double.", [
        "Severe cutting/cramping pain; better hard pressure, bending double",
        "Restlessness and anxiety with pain",
        "Pain may radiate to thigh/hip",
        "After anger or indignation",
    ]),
    ("Lachesis", "Left-to-right tendency; worse after sleep; septic state.", [
        "Cannot bear tight clothing over abdomen",
        "High fever; worse after sleep; loquacious",
        "Dark, purplish discolouration; haemorrhagic tendency",
        "Useful if peritonitis threatens",
    ]),
    ("Lycopodium", "Sub-acute or chronic appendicitis; right-sided affinity.", [
        "Bloating; worse 4-8 PM; craves sweets",
        "Fulness and heaviness in RIF; rumbling flatulence",
        "Timid, anxious; fear of being alone",
    ]),
    ("Arnica Montana", "Post-operative/trauma phase; bruised soreness.", [
        "Soreness and bruised feeling of abdomen",
        "Refuses help; says 'I'm alright'",
        "Bed feels too hard; used pre/post-operatively",
    ]),
    ("Nux Vomica", "When constipation, irritability, and toxic state predominate.", [
        "Spasmodic abdominal pain with urging to stool",
        "Oversensitive to noise, light, odours",
        "History of overindulgence; sedentary; chilly",
        "Better after warm drinks",
    ]),
    ("Rhus Toxicodendron", "Restlessness; worse at rest, better motion.", [
        "Restless; cannot stay still due to pain",
        "Better with warmth and gentle motion",
        "Stiffness; worse initial motion then better",
    ]),
]

s_rem_name  = make_style("RemName", fontSize=8.5, textColor=C_HOMEO,  fontName="Helvetica-Bold", leading=12)
s_rem_ind   = make_style("RemInd",  fontSize=7.2, textColor=colors.HexColor("#1e8449"), fontName="Helvetica-Oblique", leading=10)
s_rem_sym   = make_style("RemSym",  fontSize=7.2, textColor=C_DARK,   fontName="Helvetica", leading=10)

# 3-column grid for remedies
col_w = ["33.3%", "33.3%", "33.4%"]
rem_rows = []
row = []
for i, (name, indication, symptoms) in enumerate(remedies):
    cell = [
        Paragraph(name, s_rem_name),
        Paragraph(indication, s_rem_ind),
    ] + [Paragraph(f"&#8226; {s}", s_rem_sym) for s in symptoms]
    row.append(cell)
    if len(row) == 3:
        rem_rows.append(row)
        row = []
if row:
    while len(row) < 3:
        row.append([Paragraph("", s_body)])
    rem_rows.append(row)

rem_table = Table(rem_rows, colWidths=col_w)
rem_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), C_LIGHTGRN),
    ("TOPPADDING",    (0,0), (-1,-1), 5),
    ("BOTTOMPADDING", (0,0), (-1,-1), 5),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("RIGHTPADDING",  (0,0), (-1,-1), 6),
    ("VALIGN",        (0,0), (-1,-1), "TOP"),
    ("GRID",          (0,0), (-1,-1), 0.4, colors.HexColor("#aed6c4")),
    ("ROWBACKGROUNDS",(0,0), (-1,-1), [C_LIGHTGRN, colors.HexColor("#d5f5e3")]),
]))
story.append(rem_table)
story.append(Spacer(1, 5*mm))

# Potency guidance
pot_header = Table([[Paragraph("&#9632; POTENCY &amp; DOSAGE GUIDELINES", s_sec)]], colWidths=["100%"])
pot_header.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), colors.HexColor("#1e8449")),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
]))
story.append(pot_header)

pot_data = [
    ["Stage", "Recommended Potency", "Frequency", "Notes"],
    ["Acute / Emergency", "30C or 200C", "Every 15-30 min until relief, then reduce", "Use single dose; watch for aggravation"],
    ["Sub-acute", "30C", "3x daily for 3-5 days", "Re-assess every 48 h"],
    ["Chronic / Recurrent", "200C or 1M", "Weekly or as directed by practitioner", "Constitutional prescribing recommended"],
    ["Post-operative support", "30C Arnica", "3x daily for 3-5 days", "Reduces bruising, swelling, pain"],
]
pot_table = Table(pot_data, colWidths=["18%", "22%", "30%", "30%"])
pot_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0), colors.HexColor("#1abc9c")),
    ("TEXTCOLOR",     (0,0), (-1,0), C_WHITE),
    ("FONTNAME",      (0,0), (-1,0), "Helvetica-Bold"),
    ("FONTSIZE",      (0,0), (-1,-1), 7),
    ("BACKGROUND",    (0,1), (-1,-1), colors.HexColor("#eafaf1")),
    ("ROWBACKGROUNDS",(0,1), (-1,-1), [colors.HexColor("#eafaf1"), colors.HexColor("#d5f5e3")]),
    ("GRID",          (0,0), (-1,-1), 0.5, colors.HexColor("#aed6c4")),
    ("TOPPADDING",    (0,0), (-1,-1), 3),
    ("BOTTOMPADDING", (0,0), (-1,-1), 3),
    ("LEFTPADDING",   (0,0), (-1,-1), 5),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
]))
story.append(pot_table)
story.append(Spacer(1, 5*mm))

# Footer
footer_data = [[Paragraph(
    "Sources: Current Surgical Therapy 14e | ROSEN's Emergency Medicine | Goldman-Cecil Medicine | Gray's Anatomy for Students | Homeopathy360 | AskDrShah | DoctorBhatia  |  Compiled: 2026",
    s_note
)]]
footer_t = Table(footer_data, colWidths=["100%"])
footer_t.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), colors.HexColor("#f2f3f4")),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 6),
    ("LINEABOVE",     (0,0), (-1,0), 0.5, colors.HexColor("#aaaaaa")),
]))
story.append(footer_t)

# ── BUILD ──────────────────────────────────────────────────────────────────────
doc.build(story)
print(f"PDF created: {OUTPUT}")
Running Command

cd /home/daytona/workspace/appendicitis-ref && python generate_pdf.py 2>&1

Writing File

~/appendicitis-ref/generate_pdf.py

from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm, mm
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak
from reportlab.lib.enums import TA_LEFT, TA_CENTER

OUTPUT = "/home/daytona/workspace/appendicitis-ref/Appendicitis_Quick_Reference.pdf"

doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=1.2*cm, rightMargin=1.2*cm,
    topMargin=1.2*cm, bottomMargin=1.2*cm,
)

# ── Colors ──────────────────────────────────────────────────────────────────
C_NAVY    = colors.HexColor("#1a3a5c")
C_BLUE    = colors.HexColor("#2e86c1")
C_RED     = colors.HexColor("#c0392b")
C_PURPLE  = colors.HexColor("#8e44ad")
C_GREEN   = colors.HexColor("#1e8449")
C_TEAL    = colors.HexColor("#1abc9c")
C_LBLUE   = colors.HexColor("#eaf4fb")
C_LYELL   = colors.HexColor("#fef9e7")
C_LRED    = colors.HexColor("#fdedec")
C_LPURP   = colors.HexColor("#f5eef8")
C_LGREEN  = colors.HexColor("#eafaf1")
C_LGREEN2 = colors.HexColor("#d5f5e3")
C_LGREY   = colors.HexColor("#f2f3f4")
C_WHITE   = colors.white
C_DARK    = colors.HexColor("#1c1c1c")
C_WARN_BG = colors.HexColor("#fadbd8")
C_WARN_BD = colors.HexColor("#e74c3c")
C_WARN_TX = colors.HexColor("#7b241c")

# ── Styles ───────────────────────────────────────────────────────────────────
base = getSampleStyleSheet()
def S(name, **kw):
    s = ParagraphStyle(name, parent=base["Normal"])
    for k,v in kw.items(): setattr(s,k,v)
    return s

s_pg_title = S("PGT", fontSize=20, textColor=C_WHITE, fontName="Helvetica-Bold",
                alignment=TA_CENTER, leading=26)
s_pg_sub   = S("PGS", fontSize=9,  textColor=colors.HexColor("#d6eaf8"),
                fontName="Helvetica", alignment=TA_CENTER, leading=13)
s_sec_hdr  = S("SH",  fontSize=8.5,textColor=C_WHITE, fontName="Helvetica-Bold", leading=12)
s_body     = S("B",   fontSize=7.5,textColor=C_DARK,  fontName="Helvetica", leading=11, spaceAfter=1)
s_bold     = S("Bo",  fontSize=7.5,textColor=C_DARK,  fontName="Helvetica-Bold", leading=11, spaceAfter=1)
s_note     = S("N",   fontSize=6.3,textColor=colors.HexColor("#555"), fontName="Helvetica-Oblique", leading=9)
s_rem_name = S("RN",  fontSize=8.5,textColor=C_GREEN, fontName="Helvetica-Bold", leading=12)
s_rem_ind  = S("RI",  fontSize=7.2,textColor=colors.HexColor("#1a5e35"), fontName="Helvetica-Oblique", leading=10)
s_rem_sym  = S("RS",  fontSize=7.2,textColor=C_DARK,  fontName="Helvetica", leading=10)
s_warn     = S("W",   fontSize=7.5,textColor=C_WARN_TX,fontName="Helvetica", leading=11)
s_pot_hdr  = S("PH",  fontSize=7.5,textColor=C_WHITE, fontName="Helvetica-Bold", leading=11)
s_pot_cell = S("PC",  fontSize=7.2,textColor=C_DARK,  fontName="Helvetica", leading=10)

story = []

# ════════════════════════════════ PAGE 1 ═════════════════════════════════════

def title_banner(text, sub, bg_main, bg_sub):
    t1 = Table([[Paragraph(text, s_pg_title)]], colWidths=["100%"])
    t1.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg_main),
                             ("TOPPADDING",(0,0),(-1,-1),8),("BOTTOMPADDING",(0,0),(-1,-1),3),
                             ("LEFTPADDING",(0,0),(-1,-1),8)]))
    t2 = Table([[Paragraph(sub, s_pg_sub)]], colWidths=["100%"])
    t2.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg_sub),
                             ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                             ("LEFTPADDING",(0,0),(-1,-1),8)]))
    return t1, t2

t1, t2 = title_banner("APPENDICITIS", "Quick Reference Card  |  Clinical Overview",
                        C_NAVY, C_BLUE)
story += [t1, t2, Spacer(1, 3*mm)]

# Helper: section header cell (single row, full width inside a column)
def sh(text, color):
    return Table([[Paragraph(f"&#9632; {text}", s_sec_hdr)]], colWidths=["100%"],
                 style=TableStyle([("BACKGROUND",(0,0),(-1,-1),color),
                                   ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                                   ("LEFTPADDING",(0,0),(-1,-1),5)]))

# Helper: bullet paragraph
def b(txt): return Paragraph(f"&#8226; {txt}", s_body)
def bb(txt): return Paragraph(txt, s_bold)
def plain(txt): return Paragraph(txt, s_body)

# ─── Build each section as a list of flowables ───────────────────────────────

def box(items, bg):
    rows = [[Paragraph(x, s_body)] for x in items]
    t = Table(rows, colWidths=["100%"])
    t.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg),
                            ("TOPPADDING",(0,0),(-1,-1),2),("BOTTOMPADDING",(0,0),(-1,-1),2),
                            ("LEFTPADDING",(0,0),(-1,-1),6),("RIGHTPADDING",(0,0),(-1,-1),4)]))
    return t

# LEFT column items
L = []
L.append(sh("DEFINITION", C_BLUE))
L.append(box([
    "&#8226; Inflammation of the vermiform appendix.",
    "&#8226; Most common acute surgical emergency; lifetime risk 7-10%.",
    "&#8226; Incidence: 100-150 per 100,000/year; ~400,000 US cases/year.",
    "&#8226; Peak age: 10-30 years; slight male predominance.",
], C_LBLUE))
L.append(Spacer(1,2*mm))

L.append(sh("PATHOPHYSIOLOGY", C_BLUE))
L.append(box([
    "&#8226; <b>Obstruction</b> of appendiceal lumen:",
    "  - Faecolith / appendicolith (calcified faecal mass)",
    "  - Lymphoid hyperplasia (common in children &lt;10 yr)",
    "  - Tumour, foreign body, parasites (rare)",
    "&#8226; Obstruction &#8594; secretions accumulate &#8594; intraluminal pressure rises",
    "&#8226; Lymphatic obstruction &#8594; mucosal oedema + bacterial overgrowth",
    "&#8226; Progressive ischaemia &#8594; transmural inflammation &#8594; necrosis",
    "&#8226; <b>Perforation</b> rate: 16-40%; higher in children &lt;5 yrs and elderly",
    "&#8226; Perforation &#8594; localised abscess or generalised peritonitis",
], C_LBLUE))
L.append(Spacer(1,2*mm))

L.append(sh("CLINICAL FEATURES", C_BLUE))
L.append(box([
    "<b>Classic Triad:</b>  RIF pain  |  Nausea/vomiting  |  Low-grade fever",
    "<b>Symptoms:</b>",
    "&#8226; Pain: periumbilical &#8594; migrates to RIF (McBurney's pt) in 12-24 h",
    "&#8226; Anorexia (almost universal); nausea; vomiting",
    "&#8226; Low-grade fever 37.5-38.5 °C (high fever = perforation risk)",
    "&#8226; Constipation; occasionally diarrhoea (pelvic appendix)",
    "&#8226; Dysuria / frequency (appendix near bladder)",
    "<b>Signs:</b>",
    "&#8226; McBurney's point tenderness",
    "&#8226; Rovsing's sign: LIF palpation causes RIF pain",
    "&#8226; Psoas sign: right hip extension &#8594; RIF pain (retrocaecal)",
    "&#8226; Obturator sign: right hip internal rotation &#8594; RIF pain (pelvic)",
    "&#8226; Rebound tenderness / guarding; Dunphy's sign (cough pain)",
    "<b>Atypical Presentations:</b>",
    "&#8226; Retrocaecal: back/flank pain; Pelvic: suprapubic/urinary Sx",
    "&#8226; Pregnancy: RIF or RUQ (displaced appendix in 2nd/3rd trimester)",
], C_LBLUE))

# RIGHT column items
R = []
R.append(sh("INVESTIGATIONS", C_BLUE))
R.append(box([
    "<b>Laboratory:</b>",
    "&#8226; FBC: Leukocytosis WBC &gt;10,000 + left shift (70-90% sensitive)",
    "&#8226; CRP &gt;10 mg/L: rises later; more specific for perforation",
    "&#8226; Urinalysis: mild pyuria/haematuria if appendix near ureter",
    "&#8226; Beta-hCG: mandatory in females of childbearing age",
    "&#8226; Electrolytes &amp; renal function: pre-op assessment",
    "<b>Imaging:</b>",
    "&#8226; <b>Ultrasound</b>: 1st line in children &amp; pregnancy; appendix &gt;6mm non-compressible",
    "&#8226; <b>CT Abdomen/Pelvis</b>: gold standard; sensitivity 94-98%, specificity 95-99%",
    "   Findings: dilated appendix &gt;6mm, periappendiceal fat stranding, appendicolith",
    "&#8226; <b>MRI</b>: preferred in pregnancy (no radiation); comparable accuracy to CT",
    "&#8226; Plain AXR: limited; may show faecolith or gas in RIF",
    "<b>Scoring:</b>",
    "&#8226; Alvarado Score (MANTRELS) 0-10: &#8805;7 = high probability",
    "&#8226; Appendicitis Inflammatory Response (AIR) Score",
    "&#8226; Paediatric Appendicitis Score (PAS)",
], C_LYELL))
R.append(Spacer(1,2*mm))

R.append(sh("DIAGNOSIS / ALVARADO SCORE", C_PURPLE))
R.append(box([
    "&#8226; Migration of pain to RIF       +1",
    "&#8226; Anorexia                        +1",
    "&#8226; Nausea / Vomiting               +1",
    "&#8226; RIF Tenderness                  +2",
    "&#8226; Rebound Tenderness              +1",
    "&#8226; Elevated Temp (&gt;37.3°C)      +1",
    "&#8226; Leukocytosis (WBC &gt;10K)      +2",
    "&#8226; Left shift                      +1",
    "<b>Score:  1-4 = Low | 5-6 = Equivocal | 7-10 = Operate</b>",
    "<b>Differential Diagnosis:</b>",
    "&#8226; Mesenteric adenitis, Meckel's diverticulitis, Crohn's disease",
    "&#8226; Ovarian cyst/torsion, ectopic pregnancy (females)",
    "&#8226; Urolithiasis, UTI/pyelonephritis, psoas abscess",
], C_LPURP))
R.append(Spacer(1,2*mm))

R.append(sh("TREATMENT", C_RED))
R.append(box([
    "<b>Surgical (Standard of Care):</b>",
    "&#8226; Laparoscopic appendectomy: gold standard; same-day discharge possible",
    "&#8226; Pre-op antibiotics: cephalosporin + metronidazole",
    "&#8226; Timing: within 12-24 h of diagnosis",
    "<b>Non-Operative (Antibiotics-First) - Uncomplicated only:</b>",
    "&#8226; IV amoxicillin-clavulanate or pip-tazo then oral antibiotics",
    "&#8226; Success 80-90% at 24-48 h; recurrence up to 40% at 5 years",
    "&#8226; NOT if: faecolith, perforation, peritonitis, abscess",
    "<b>Perforated Appendicitis:</b>",
    "&#8226; Broad-spectrum IV antibiotics + urgent appendectomy",
    "&#8226; Abscess with &#8805;5 days Sx: IR drainage + interval appendectomy 6-8 wks",
    "<b>Special Groups:</b>",
    "&#8226; Pregnancy: early surgery (fetal loss risk with perforation)",
    "&#8226; Children: USS/MRI first; laparoscopic appendectomy standard",
    "&#8226; Elderly: lower CT threshold; higher perforation rate at presentation",
], C_LRED))

# Pair rows together
max_rows = max(len(L), len(R))
while len(L) < max_rows: L.append(Spacer(1,1))
while len(R) < max_rows: R.append(Spacer(1,1))

master_rows = [[l, r] for l, r in zip(L, R)]
master = Table(master_rows, colWidths=["50%","50%"])
master.setStyle(TableStyle([
    ("VALIGN",(0,0),(-1,-1),"TOP"),
    ("LEFTPADDING",(0,0),(-1,-1),2),
    ("RIGHTPADDING",(0,0),(-1,-1),2),
    ("TOPPADDING",(0,0),(-1,-1),0),
    ("BOTTOMPADDING",(0,0),(-1,-1),0),
]))
story.append(master)

# Footer p1
story.append(Spacer(1,3*mm))
story.append(Table([[Paragraph(
    "Sources: Current Surgical Therapy 14e | ROSEN's Emergency Medicine | Goldman-Cecil Medicine | Gray's Anatomy for Students",
    s_note)]], colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_LGREY),
                      ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                      ("LEFTPADDING",(0,0),(-1,-1),6),
                      ("LINEABOVE",(0,0),(-1,0),0.5,colors.HexColor("#aaaaaa"))])))

# ════════════════════════════════ PAGE 2 ═════════════════════════════════════
story.append(PageBreak())

t1, t2 = title_banner(
    "APPENDICITIS - HOMEOPATHIC REMEDIES",
    "Quick Reference  |  For Practitioner Guidance Only  |  Not a Substitute for Emergency Surgery",
    C_GREEN, colors.HexColor("#1a6e3a")
)
story += [t1, t2, Spacer(1,3*mm)]

# Warning
story.append(Table([[Paragraph(
    "<b>&#9888; IMPORTANT:</b> Acute appendicitis is a surgical emergency. "
    "These remedies are used adjunctively or in sub-acute/recurrent cases under professional supervision. "
    "<b>Do not delay surgery based on homeopathic treatment.</b>",
    s_warn)]], colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_WARN_BG),
                      ("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5),
                      ("LEFTPADDING",(0,0),(-1,-1),7),("RIGHTPADDING",(0,0),(-1,-1),7),
                      ("BOX",(0,0),(-1,-1),1,C_WARN_BD)])))
story.append(Spacer(1,3*mm))

# Remedies section header
story.append(Table([[Paragraph("&#9632; KEY HOMEOPATHIC REMEDIES", s_sec_hdr)]],
    colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_GREEN),
                      ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                      ("LEFTPADDING",(0,0),(-1,-1),5)])))
story.append(Spacer(1,1*mm))

remedies = [
    ("1. Iris Tenax", "Specific remedy for appendicitis.",
     ["Cutting/tearing pain in RIF; sensation of constriction",
      "Pain extending to groin/thigh; mucoid stools",
      "Better lying still; colicky character"]),
    ("2. Belladonna", "Early stage; sudden violent onset.",
     ["Throbbing, burning RIF pain; worse from jarring/touch",
      "High fever, flushed face, dilated pupils",
      "Worse slightest movement; tongue strawberry-red"]),
    ("3. Bryonia Alba", "Pain aggravated by any movement.",
     ["Stitching, tearing pain; patient lies perfectly still",
      "Dry mucous membranes; great thirst for large amounts",
      "Irritable; constipation; worse any motion"]),
    ("4. Mercurius Corrosivus", "Severe inflammation; near peritonitis.",
     ["Violent burning RIF pain with great tenderness",
      "Offensive diarrhoea with tenesmus; profuse sweat",
      "Fever with chills; worse at night"]),
    ("5. Colocynthis", "Cramping pain relieved by pressure/bending.",
     ["Severe cutting pain; better hard pressure, bending double",
      "Restlessness and anxiety; pain radiates to hip/thigh",
      "Often after anger or indignation"]),
    ("6. Lachesis", "Left-to-right; worse after sleep; septic.",
     ["Cannot bear tight clothing over abdomen",
      "High fever; worse after sleep; loquacious",
      "Dark/purplish discolouration; haemorrhagic tendency"]),
    ("7. Lycopodium", "Sub-acute/chronic; right-sided affinity.",
     ["Bloating; worse 4-8 PM; craves sweets",
      "Fulness and heaviness in RIF; rumbling flatulence",
      "Timid, anxious; fear of being alone"]),
    ("8. Arnica Montana", "Post-operative/trauma phase.",
     ["Bruised soreness of abdomen; refuses help",
      "Bed feels too hard; says 'I am alright'",
      "Pre/post-operative support"]),
    ("9. Nux Vomica", "Constipation, irritability, toxic state.",
     ["Spasmodic abdominal pain with urging to stool",
      "Oversensitive to noise, light, odours",
      "History of overindulgence; chilly; better warmth"]),
    ("10. Rhus Toxicodendron", "Restlessness; worse at rest.",
     ["Cannot stay still; better warmth and gentle motion",
      "Stiffness worse on initial motion then improves",
      "Anxiety and restlessness at night"]),
]

# 3-column grid for remedies (row by row)
def rem_cell(name, indication, symptoms):
    items = [Paragraph(name, s_rem_name), Paragraph(indication, s_rem_ind)]
    for s in symptoms:
        items.append(Paragraph(f"&#8226; {s}", s_rem_sym))
    return items

# Build grid rows - 2 remedies per row (5 rows of 2)
COLS = 2
grid_rows = []
for i in range(0, len(remedies), COLS):
    row = []
    for j in range(COLS):
        idx = i + j
        if idx < len(remedies):
            row.append(rem_cell(*remedies[idx]))
        else:
            row.append([Paragraph("", s_body)])
    grid_rows.append(row)

col_w = ["50%", "50%"]
rem_table = Table(grid_rows, colWidths=col_w)
rem_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,-1), C_LGREEN),
    ("ROWBACKGROUNDS",(0,0),(-1,-1), [C_LGREEN, C_LGREEN2]),
    ("TOPPADDING",    (0,0),(-1,-1), 5),
    ("BOTTOMPADDING", (0,0),(-1,-1), 5),
    ("LEFTPADDING",   (0,0),(-1,-1), 7),
    ("RIGHTPADDING",  (0,0),(-1,-1), 7),
    ("VALIGN",        (0,0),(-1,-1), "TOP"),
    ("GRID",          (0,0),(-1,-1), 0.4, colors.HexColor("#aed6c4")),
]))
story.append(rem_table)
story.append(Spacer(1,4*mm))

# Potency table
story.append(Table([[Paragraph("&#9632; POTENCY &amp; DOSAGE GUIDELINES", s_sec_hdr)]],
    colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_GREEN),
                      ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                      ("LEFTPADDING",(0,0),(-1,-1),5)])))

pot_data = [
    [Paragraph("Stage",s_pot_hdr), Paragraph("Potency",s_pot_hdr),
     Paragraph("Frequency",s_pot_hdr), Paragraph("Notes",s_pot_hdr)],
    [Paragraph("Acute / Emergency",s_pot_cell), Paragraph("30C or 200C",s_pot_cell),
     Paragraph("Every 15-30 min until relief, then reduce",s_pot_cell),
     Paragraph("Single dose; watch for aggravation",s_pot_cell)],
    [Paragraph("Sub-acute",s_pot_cell), Paragraph("30C",s_pot_cell),
     Paragraph("3x daily for 3-5 days",s_pot_cell),
     Paragraph("Re-assess every 48 h",s_pot_cell)],
    [Paragraph("Chronic / Recurrent",s_pot_cell), Paragraph("200C or 1M",s_pot_cell),
     Paragraph("Weekly or as directed",s_pot_cell),
     Paragraph("Constitutional prescribing recommended",s_pot_cell)],
    [Paragraph("Post-operative (Arnica)",s_pot_cell), Paragraph("30C",s_pot_cell),
     Paragraph("3x daily for 3-5 days",s_pot_cell),
     Paragraph("Reduces bruising, swelling, pain",s_pot_cell)],
]
pot_table = Table(pot_data, colWidths=["20%","15%","35%","30%"])
pot_table.setStyle(TableStyle([
    ("BACKGROUND",    (0,0),(-1,0), C_TEAL),
    ("TEXTCOLOR",     (0,0),(-1,0), C_WHITE),
    ("FONTNAME",      (0,0),(-1,0), "Helvetica-Bold"),
    ("BACKGROUND",    (0,1),(-1,-1), C_LGREEN),
    ("ROWBACKGROUNDS",(0,1),(-1,-1), [C_LGREEN, C_LGREEN2]),
    ("FONTSIZE",      (0,0),(-1,-1), 7.2),
    ("GRID",          (0,0),(-1,-1), 0.5, colors.HexColor("#aed6c4")),
    ("TOPPADDING",    (0,0),(-1,-1), 3),
    ("BOTTOMPADDING", (0,0),(-1,-1), 3),
    ("LEFTPADDING",   (0,0),(-1,-1), 5),
    ("VALIGN",        (0,0),(-1,-1), "MIDDLE"),
]))
story.append(pot_table)
story.append(Spacer(1,4*mm))

# Footer p2
story.append(Table([[Paragraph(
    "Sources: Homeopathy360 | AskDrShah | DoctorBhatia | Thieme Homeopathic Journal  |  Compiled: 2026  |  "
    "This card is for educational purposes. Consult a qualified homeopathic practitioner before prescribing.",
    s_note)]], colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_LGREY),
                      ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                      ("LEFTPADDING",(0,0),(-1,-1),6),
                      ("LINEABOVE",(0,0),(-1,0),0.5,colors.HexColor("#aaaaaa"))])))

doc.build(story)
print(f"PDF created: {OUTPUT}")
Editing File

~/appendicitis-ref/generate_pdf.py

Successfully replaced 1 instance(s) of the string in '/home/daytona/workspace/appendicitis-ref/generate_pdf.py'
Running Command

cp /home/daytona/workspace/appendicitis-ref/generate_pdf.py /home/daytona/worksp…

Writing File

~/appendicitis-ref/generate_pdf_v2.py

#!/usr/bin/env python3
"""Appendicitis Quick Reference PDF - Two Pager"""
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm, mm
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak
from reportlab.lib.enums import TA_LEFT, TA_CENTER

OUTPUT = "/home/daytona/workspace/appendicitis-ref/Appendicitis_Quick_Reference.pdf"

doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=1.2*cm, rightMargin=1.2*cm,
    topMargin=1.2*cm, bottomMargin=1.2*cm,
)

C_NAVY    = colors.HexColor("#1a3a5c")
C_BLUE    = colors.HexColor("#2e86c1")
C_RED     = colors.HexColor("#c0392b")
C_PURPLE  = colors.HexColor("#8e44ad")
C_GREEN   = colors.HexColor("#1e8449")
C_TEAL    = colors.HexColor("#1abc9c")
C_LBLUE   = colors.HexColor("#eaf4fb")
C_LYELL   = colors.HexColor("#fef9e7")
C_LRED    = colors.HexColor("#fdedec")
C_LPURP   = colors.HexColor("#f5eef8")
C_LGREEN  = colors.HexColor("#eafaf1")
C_LGREEN2 = colors.HexColor("#d5f5e3")
C_LGREY   = colors.HexColor("#f2f3f4")
C_WHITE   = colors.white
C_DARK    = colors.HexColor("#1c1c1c")
C_WARN_BG = colors.HexColor("#fadbd8")
C_WARN_BD = colors.HexColor("#e74c3c")
C_WARN_TX = colors.HexColor("#7b241c")

base = getSampleStyleSheet()
def S(name, **kw):
    s = ParagraphStyle(name, parent=base["Normal"])
    for k, v in kw.items(): setattr(s, k, v)
    return s

s_pg_title = S("PGT", fontSize=19, textColor=C_WHITE, fontName="Helvetica-Bold", alignment=TA_CENTER, leading=24)
s_pg_sub   = S("PGS", fontSize=8.5, textColor=colors.HexColor("#d6eaf8"), fontName="Helvetica", alignment=TA_CENTER, leading=12)
s_sec_hdr  = S("SH", fontSize=8.5, textColor=C_WHITE, fontName="Helvetica-Bold", leading=12)
s_body     = S("B", fontSize=7.3, textColor=C_DARK, fontName="Helvetica", leading=10.5, spaceAfter=0)
s_note     = S("N", fontSize=6.2, textColor=colors.HexColor("#555"), fontName="Helvetica-Oblique", leading=9)
s_rem_name = S("RN", fontSize=8.2, textColor=C_GREEN, fontName="Helvetica-Bold", leading=11)
s_rem_ind  = S("RI", fontSize=7.0, textColor=colors.HexColor("#1a5e35"), fontName="Helvetica-Oblique", leading=10)
s_rem_sym  = S("RS", fontSize=7.0, textColor=C_DARK, fontName="Helvetica", leading=10)
s_warn     = S("W", fontSize=7.3, textColor=C_WARN_TX, fontName="Helvetica", leading=11)
s_pot_hdr  = S("PH", fontSize=7.5, textColor=C_WHITE, fontName="Helvetica-Bold", leading=11)
s_pot_cell = S("PC", fontSize=7.0, textColor=C_DARK, fontName="Helvetica", leading=10)

story = []

# ─── Helpers ─────────────────────────────────────────────────────────────────
def title_row(text, sub, bg_main, bg_sub):
    t1 = Table([[Paragraph(text, s_pg_title)]], colWidths=["100%"])
    t1.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg_main),
                             ("TOPPADDING",(0,0),(-1,-1),7),("BOTTOMPADDING",(0,0),(-1,-1),3),
                             ("LEFTPADDING",(0,0),(-1,-1),8)]))
    t2 = Table([[Paragraph(sub, s_pg_sub)]], colWidths=["100%"])
    t2.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg_sub),
                             ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                             ("LEFTPADDING",(0,0),(-1,-1),8)]))
    return t1, t2

def sh(text, color):
    return Table([[Paragraph(f"&#9632; {text}", s_sec_hdr)]], colWidths=["100%"],
                 style=TableStyle([("BACKGROUND",(0,0),(-1,-1),color),
                                   ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
                                   ("LEFTPADDING",(0,0),(-1,-1),5)]))

def box(items, bg):
    rows = [[Paragraph(x, s_body)] for x in items]
    t = Table(rows, colWidths=["100%"])
    t.setStyle(TableStyle([("BACKGROUND",(0,0),(-1,-1),bg),
                            ("TOPPADDING",(0,0),(-1,-1),2),("BOTTOMPADDING",(0,0),(-1,-1),2),
                            ("LEFTPADDING",(0,0),(-1,-1),5),("RIGHTPADDING",(0,0),(-1,-1),4)]))
    return t

# ════════════════════════════════ PAGE 1 ═════════════════════════════════════
t1, t2 = title_row("APPENDICITIS", "Quick Reference Card  |  Clinical Overview",
                   C_NAVY, C_BLUE)
story += [t1, t2, Spacer(1, 3*mm)]

# Build columns as alternating header/box pairs
L = [
    sh("DEFINITION", C_BLUE),
    box(["&#8226; Inflammation of the vermiform appendix (blind-ended pouch at caecum).",
         "&#8226; Most common acute surgical emergency worldwide; lifetime risk 7-10%.",
         "&#8226; Incidence: 100-150/100,000/year; ~400,000 US cases/year.",
         "&#8226; Peak age: 10-30 years; slight male predominance."], C_LBLUE),
    Spacer(1,2*mm),
    sh("PATHOPHYSIOLOGY", C_BLUE),
    box(["&#8226; <b>Obstruction</b> of appendiceal lumen by:",
         "  - Faecolith/appendicolith (most common)",
         "  - Lymphoid hyperplasia (common in children)",
         "  - Tumour, foreign body, parasites (rare)",
         "&#8226; Obstruction &#8594; secretions accumulate &#8594; intraluminal pressure rises",
         "&#8226; Lymphatic obstruction &#8594; mucosal oedema + bacterial overgrowth",
         "&#8226; Progressive ischaemia &#8594; transmural inflammation &#8594; necrosis",
         "&#8226; <b>Perforation rate:</b> 16-40%; higher in children &lt;5 yrs &amp; elderly",
         "&#8226; Perforation &#8594; localised abscess or generalised peritonitis"], C_LBLUE),
    Spacer(1,2*mm),
    sh("CLINICAL FEATURES", C_BLUE),
    box(["<b>Classic Triad:</b> RIF pain | Nausea/vomiting | Low-grade fever",
         "<b>Symptoms:</b>",
         "&#8226; Pain: periumbilical &#8594; migrates to RIF (McBurney's pt) within 12-24 h",
         "&#8226; Anorexia (almost universal); nausea; vomiting",
         "&#8226; Low-grade fever 37.5-38.5 C (high fever = perforation risk)",
         "&#8226; Constipation; occasionally diarrhoea (pelvic appendix)",
         "&#8226; Dysuria/frequency (appendix near bladder)",
         "<b>Signs:</b>",
         "&#8226; McBurney's point tenderness (1/3 from ASIS to umbilicus)",
         "&#8226; Rovsing's sign: LIF palpation causes RIF pain",
         "&#8226; Psoas sign: right hip extension causes RIF pain (retrocaecal)",
         "&#8226; Obturator sign: right hip internal rotation causes RIF pain (pelvic)",
         "&#8226; Rebound tenderness / guarding; Dunphy's sign (cough pain)",
         "<b>Atypical Presentations:</b>",
         "&#8226; Retrocaecal: back/flank pain; Pelvic: suprapubic/urinary symptoms",
         "&#8226; Pregnancy: RIF or RUQ (appendix displaced in 2nd/3rd trimester)"], C_LBLUE),
]

R = [
    sh("INVESTIGATIONS", C_BLUE),
    box(["<b>Laboratory:</b>",
         "&#8226; FBC: Leukocytosis WBC &gt;10,000 + left shift (70-90% sensitive)",
         "&#8226; CRP &gt;10 mg/L: rises later; more specific for perforation",
         "&#8226; Urinalysis: mild pyuria/haematuria if near ureter/bladder",
         "&#8226; Beta-hCG: mandatory in women of childbearing age",
         "&#8226; U&amp;E, renal function: pre-operative baseline",
         "<b>Imaging:</b>",
         "&#8226; <b>USS</b>: 1st line in children &amp; pregnancy; appendix &gt;6mm non-compressible",
         "&#8226; <b>CT Abdomen/Pelvis</b>: gold standard; sensitivity 94-98%, specificity 95-99%",
         "  Findings: dilated appendix &gt;6mm, periappendiceal fat stranding, appendicolith",
         "&#8226; <b>MRI</b>: preferred in pregnancy (no radiation); comparable accuracy to CT",
         "&#8226; Plain AXR: limited; may show faecolith or gas in RIF",
         "<b>Scoring:</b>",
         "&#8226; Alvarado Score (MANTRELS) 0-10: score &gt;=7 = high probability",
         "&#8226; Appendicitis Inflammatory Response (AIR) Score",
         "&#8226; Paediatric Appendicitis Score (PAS)"], C_LYELL),
    Spacer(1,2*mm),
    sh("DIAGNOSIS  /  ALVARADO SCORE", C_PURPLE),
    box(["&#8226; Migration of pain to RIF      +1",
         "&#8226; Anorexia                       +1",
         "&#8226; Nausea / Vomiting              +1",
         "&#8226; RIF Tenderness                 +2",
         "&#8226; Rebound Tenderness             +1",
         "&#8226; Elevated Temp (&gt;37.3 C)     +1",
         "&#8226; Leukocytosis (WBC &gt;10K)     +2",
         "&#8226; Left shift                     +1",
         "<b>Score:  1-4 = Low | 5-6 = Equivocal | 7-10 = Operate</b>",
         "<b>Differential Diagnosis:</b>",
         "&#8226; Mesenteric adenitis, Meckel's diverticulitis, Crohn's disease",
         "&#8226; Ovarian cyst/torsion, ectopic pregnancy (females)",
         "&#8226; Urolithiasis, UTI/pyelonephritis, psoas abscess"], C_LPURP),
    Spacer(1,2*mm),
    sh("TREATMENT", C_RED),
    box(["<b>Surgical (Standard of Care):</b>",
         "&#8226; Laparoscopic appendectomy: gold standard; same-day discharge possible",
         "&#8226; Pre-op antibiotics: 2nd/3rd gen cephalosporin + metronidazole",
         "&#8226; Timing: within 12-24 h of diagnosis",
         "<b>Non-Operative (Antibiotics-First) - Uncomplicated only:</b>",
         "&#8226; IV amoxicillin-clavulanate or piperacillin-tazobactam; then oral",
         "&#8226; Success 80-90% at 24-48 h; recurrence up to 40% at 5 years",
         "&#8226; NOT suitable if: faecolith, perforation, peritonitis, abscess",
         "<b>Perforated Appendicitis:</b>",
         "&#8226; Broad-spectrum IV antibiotics + urgent appendectomy",
         "&#8226; Abscess with &gt;=5 days Sx: IR drainage + interval appendectomy 6-8 wks",
         "<b>Special Groups:</b>",
         "&#8226; Pregnancy: early surgery (fetal loss risk with perforation)",
         "&#8226; Children: USS/MRI first; laparoscopic appendectomy standard",
         "&#8226; Elderly: lower CT threshold; higher perforation rate at presentation"], C_LRED),
]

# Pad to equal lengths
pad = Spacer(1,1)
while len(L) < len(R): L.append(pad)
while len(R) < len(L): R.append(pad)

master = Table([[l, r] for l, r in zip(L, R)], colWidths=["50%","50%"])
master.setStyle(TableStyle([
    ("VALIGN",(0,0),(-1,-1),"TOP"),
    ("LEFTPADDING",(0,0),(-1,-1),2),("RIGHTPADDING",(0,0),(-1,-1),2),
    ("TOPPADDING",(0,0),(-1,-1),0),("BOTTOMPADDING",(0,0),(-1,-1),0),
]))
story.append(master)
story.append(Spacer(1,2*mm))
story.append(Table([[Paragraph(
    "Sources: Current Surgical Therapy 14e | ROSEN's Emergency Medicine | Goldman-Cecil Medicine | Gray's Anatomy for Students", s_note)]],
    colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_LGREY),("TOPPADDING",(0,0),(-1,-1),3),
                      ("BOTTOMPADDING",(0,0),(-1,-1),3),("LEFTPADDING",(0,0),(-1,-1),6),
                      ("LINEABOVE",(0,0),(-1,0),0.5,colors.HexColor("#aaaaaa"))])))

# ════════════════════════════════ PAGE 2 ═════════════════════════════════════
story.append(PageBreak())

t1, t2 = title_row(
    "APPENDICITIS - HOMEOPATHIC REMEDIES",
    "Quick Reference  |  For Practitioner Guidance Only  |  Not a Substitute for Emergency Surgery",
    C_GREEN, colors.HexColor("#1a6e3a"))
story += [t1, t2, Spacer(1,3*mm)]

story.append(Table([[Paragraph(
    "<b>&#9888; IMPORTANT:</b> Acute appendicitis is a surgical emergency. "
    "Homeopathic remedies are used adjunctively or in sub-acute/recurrent cases under professional supervision. "
    "<b>Do not delay surgery based on homeopathic treatment.</b>",
    s_warn)]], colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_WARN_BG),("TOPPADDING",(0,0),(-1,-1),5),
                      ("BOTTOMPADDING",(0,0),(-1,-1),5),("LEFTPADDING",(0,0),(-1,-1),7),
                      ("RIGHTPADDING",(0,0),(-1,-1),7),("BOX",(0,0),(-1,-1),1,C_WARN_BD)])))
story.append(Spacer(1,3*mm))

story.append(Table([[Paragraph("&#9632; KEY HOMEOPATHIC REMEDIES", s_sec_hdr)]],
    colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_GREEN),("TOPPADDING",(0,0),(-1,-1),3),
                      ("BOTTOMPADDING",(0,0),(-1,-1),3),("LEFTPADDING",(0,0),(-1,-1),5)])))
story.append(Spacer(1,1*mm))

remedies = [
    ("1. Iris Tenax",          "Specific remedy for appendicitis.",
     ["Cutting/tearing pain in RIF; sensation of constriction and cramping",
      "Pain extending to groin/thigh; may have mucoid stools",
      "Better lying still; colicky character"]),
    ("2. Belladonna",          "Early stage; sudden violent onset with high fever.",
     ["Throbbing, burning RIF pain; worse from jarring/touch",
      "High fever, flushed face, dilated pupils; tongue strawberry-red",
      "Worse slightest movement; sudden onset"]),
    ("3. Bryonia Alba",        "Pain severely aggravated by any movement.",
     ["Stitching, tearing pain; patient lies perfectly still",
      "Dry mucous membranes; great thirst for large amounts",
      "Irritable; wants to be left alone; constipation"]),
    ("4. Mercurius Corrosivus","Severe inflammation; approaching peritonitis.",
     ["Violent burning RIF pain with great tenderness and prostration",
      "Offensive diarrhoea with tenesmus; profuse sweating",
      "Fever with chills; trembling; worse at night"]),
    ("5. Colocynthis",         "Cramping pain relieved by pressure/bending double.",
     ["Severe cutting pain; better hard pressure, bending double",
      "Restlessness and anxiety with pain; radiates to hip/thigh",
      "Often triggered by anger or indignation"]),
    ("6. Lachesis",            "Left-to-right affinity; worse after sleep; septic state.",
     ["Cannot bear tight clothing over abdomen; loquacious",
      "High fever; worse after sleep; dark/purplish discolouration",
      "Haemorrhagic tendency; useful when peritonitis threatens"]),
    ("7. Lycopodium",          "Sub-acute or chronic appendicitis; right-sided affinity.",
     ["Bloating worse 4-8 PM; craves sweets; rumbling flatulence",
      "Fulness and heaviness in RIF",
      "Timid, anxious; fear of being alone"]),
    ("8. Arnica Montana",      "Post-operative/trauma phase; bruised soreness.",
     ["Bruised soreness of abdomen; bed feels too hard",
      "Refuses help; insists 'I am alright'",
      "Used pre/post-operatively to reduce bruising and swelling"]),
    ("9. Nux Vomica",          "Constipation, irritability, and toxic state predominate.",
     ["Spasmodic abdominal pain with urging to stool",
      "Oversensitive to noise, light, odours; chilly",
      "History of overindulgence; better warmth"]),
    ("10. Rhus Toxicodendron", "Restlessness; worse at rest, better gentle motion.",
     ["Cannot stay still due to pain; anxious and restless at night",
      "Better with warmth and gentle continued motion",
      "Stiffness worse on initial motion then improves"]),
]

def rem_cell(name, indication, symptoms):
    items = [Paragraph(name, s_rem_name), Paragraph(indication, s_rem_ind)]
    for s in symptoms:
        items.append(Paragraph(f"&#8226; {s}", s_rem_sym))
    return items

grid_rows = []
for i in range(0, len(remedies), 2):
    row = []
    for j in range(2):
        idx = i + j
        if idx < len(remedies):
            row.append(rem_cell(*remedies[idx]))
        else:
            row.append([Paragraph("", s_body)])
    grid_rows.append(row)

rem_table = Table(grid_rows, colWidths=["50%","50%"])
rem_table.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,-1),C_LGREEN),
    ("ROWBACKGROUNDS",(0,0),(-1,-1),[C_LGREEN, C_LGREEN2]),
    ("TOPPADDING",(0,0),(-1,-1),5),("BOTTOMPADDING",(0,0),(-1,-1),5),
    ("LEFTPADDING",(0,0),(-1,-1),7),("RIGHTPADDING",(0,0),(-1,-1),7),
    ("VALIGN",(0,0),(-1,-1),"TOP"),
    ("GRID",(0,0),(-1,-1),0.4,colors.HexColor("#aed6c4")),
]))
story.append(rem_table)
story.append(Spacer(1,4*mm))

story.append(Table([[Paragraph("&#9632; POTENCY &amp; DOSAGE GUIDELINES", s_sec_hdr)]],
    colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_GREEN),("TOPPADDING",(0,0),(-1,-1),3),
                      ("BOTTOMPADDING",(0,0),(-1,-1),3),("LEFTPADDING",(0,0),(-1,-1),5)])))

pot_data = [
    [Paragraph(h, s_pot_hdr) for h in ["Stage","Potency","Frequency","Notes"]],
    [Paragraph(c, s_pot_cell) for c in ["Acute / Emergency","30C or 200C",
     "Every 15-30 min until relief, then reduce","Single dose; watch for aggravation"]],
    [Paragraph(c, s_pot_cell) for c in ["Sub-acute","30C",
     "3x daily for 3-5 days","Re-assess every 48 h"]],
    [Paragraph(c, s_pot_cell) for c in ["Chronic / Recurrent","200C or 1M",
     "Weekly or as directed by practitioner","Constitutional prescribing recommended"]],
    [Paragraph(c, s_pot_cell) for c in ["Post-operative (Arnica)","30C",
     "3x daily for 3-5 days","Reduces bruising, swelling, and pain"]],
]
pot_table = Table(pot_data, colWidths=["20%","15%","35%","30%"])
pot_table.setStyle(TableStyle([
    ("BACKGROUND",(0,0),(-1,0),C_TEAL),("TEXTCOLOR",(0,0),(-1,0),C_WHITE),
    ("FONTNAME",(0,0),(-1,0),"Helvetica-Bold"),
    ("BACKGROUND",(0,1),(-1,-1),C_LGREEN),
    ("ROWBACKGROUNDS",(0,1),(-1,-1),[C_LGREEN, C_LGREEN2]),
    ("FONTSIZE",(0,0),(-1,-1),7.2),
    ("GRID",(0,0),(-1,-1),0.5,colors.HexColor("#aed6c4")),
    ("TOPPADDING",(0,0),(-1,-1),3),("BOTTOMPADDING",(0,0),(-1,-1),3),
    ("LEFTPADDING",(0,0),(-1,-1),5),("VALIGN",(0,0),(-1,-1),"MIDDLE"),
]))
story.append(pot_table)
story.append(Spacer(1,3*mm))

story.append(Table([[Paragraph(
    "Sources: Homeopathy360 | AskDrShah | DoctorBhatia | Thieme Homeopathic Journal  |  "
    "Compiled: 2026  |  For educational purposes. Consult a qualified homeopathic practitioner before prescribing.",
    s_note)]], colWidths=["100%"],
    style=TableStyle([("BACKGROUND",(0,0),(-1,-1),C_LGREY),("TOPPADDING",(0,0),(-1,-1),3),
                      ("BOTTOMPADDING",(0,0),(-1,-1),3),("LEFTPADDING",(0,0),(-1,-1),6),
                      ("LINEABOVE",(0,0),(-1,0),0.5,colors.HexColor("#aaaaaa"))])))

doc.build(story)
print(f"PDF created: {OUTPUT}")
Running Command

cd /home/daytona/workspace/appendicitis-ref && python generate_pdf_v2.py 2>&1

Running Command

ls -lh /home/daytona/workspace/appendicitis-ref/Appendicitis_Quick_Reference.pdf

Your Appendicitis Quick Reference PDF is ready:

Appendicitis Quick Reference

PDF Document · PDF


What's inside the two-pager:
Page 1 - Clinical Reference (two-column layout)
  • Definition - incidence, lifetime risk, demographics
  • Pathophysiology - obstruction mechanism, faecolith, lymphoid hyperplasia, progression to perforation
  • Clinical Features - classic triad, McBurney's point, Rovsing/Psoas/Obturator signs, atypical presentations (retrocaecal, pelvic, pregnancy)
  • Investigations - FBC, CRP, beta-hCG, USS, CT, MRI, plain AXR, scoring systems
  • Diagnosis - full Alvarado/MANTRELS score breakdown + differential diagnosis
  • Treatment - laparoscopic appendectomy, antibiotics-first approach, perforated appendicitis management, special populations
Page 2 - Homeopathic Remedies
  • 10 key remedies with specific indications and keynote symptoms: Iris Tenax, Belladonna, Bryonia Alba, Mercurius Corrosivus, Colocynthis, Lachesis, Lycopodium, Arnica Montana, Nux Vomica, Rhus Toxicodendron
  • Potency and dosage table for acute, sub-acute, chronic, and post-operative stages
  • Safety warning that acute appendicitis remains a surgical emergency
This is a shared conversation. Sign in to Orris to start your own chat.