~/flashcards/make_flashcards.py
from reportlab.lib.pagesizes import A5
from reportlab.lib import colors
from reportlab.lib.units import mm
from reportlab.platypus import (
SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, HRFlowable
)
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.enums import TA_CENTER, TA_LEFT
from reportlab.platypus.flowables import KeepTogether
OUTPUT = "/home/daytona/workspace/flashcards/Surgery_Flashcards.pdf"
# ── Colour palette ──────────────────────────────────────────────────
C_DARK_BLUE = colors.HexColor("#1A3C6B")
C_MID_BLUE = colors.HexColor("#2E6DAD")
C_LIGHT_BLUE = colors.HexColor("#D6E8F7")
C_TEAL = colors.HexColor("#0D7377")
C_TEAL_LIGHT = colors.HexColor("#D0EEEE")
C_PURPLE = colors.HexColor("#5C2D91")
C_PURPLE_LIGHT= colors.HexColor("#EAD9F7")
C_ACCENT = colors.HexColor("#E8A020")
C_WHITE = colors.white
C_BG = colors.HexColor("#F5F8FC")
C_TEXT = colors.HexColor("#1C1C1C")
C_GREY = colors.HexColor("#555555")
W, H = A5 # 148 x 210 mm (portrait)
# ── Styles ──────────────────────────────────────────────────────────
styles = getSampleStyleSheet()
def S(name, **kw):
return ParagraphStyle(name, **kw)
ST_TOPIC = S("topic",
fontSize=7, textColor=C_WHITE, fontName="Helvetica-Bold",
alignment=TA_CENTER, spaceAfter=0)
ST_Q = S("q",
fontSize=10.5, textColor=C_WHITE, fontName="Helvetica-Bold",
alignment=TA_LEFT, leading=14, spaceAfter=2)
ST_A = S("a",
fontSize=9.5, textColor=C_TEXT, fontName="Helvetica",
alignment=TA_LEFT, leading=13, spaceAfter=3)
ST_AB = S("ab",
fontSize=9.5, textColor=C_TEXT, fontName="Helvetica-Bold",
alignment=TA_LEFT, leading=13, spaceAfter=3)
ST_BULLET = S("bullet",
fontSize=9, textColor=C_TEXT, fontName="Helvetica",
leftIndent=10, leading=13, spaceAfter=1)
ST_SECTION = S("section",
fontSize=8.5, textColor=C_MID_BLUE, fontName="Helvetica-Bold",
alignment=TA_LEFT, spaceAfter=3, spaceBefore=4)
ST_TITLE = S("title",
fontSize=18, textColor=C_DARK_BLUE, fontName="Helvetica-Bold",
alignment=TA_CENTER, spaceAfter=6)
ST_SUBTITLE = S("subtitle",
fontSize=10, textColor=C_GREY, fontName="Helvetica",
alignment=TA_CENTER, spaceAfter=4)
# ── Helper: make a header bar ────────────────────────────────────────
def header_bar(topic, q_text, hdr_color):
"""Returns a Table that looks like a coloured card header."""
topic_p = Paragraph(topic.upper(), ST_TOPIC)
q_p = Paragraph(q_text, ST_Q)
data = [[topic_p], [q_p]]
t = Table(data, colWidths=[W - 24*mm])
t.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), hdr_color),
("TOPPADDING", (0,0), (-1, 0), 4),
("BOTTOMPADDING",(0,0),(-1, 0), 2),
("TOPPADDING", (0,1), (-1, 1), 4),
("BOTTOMPADDING",(0,1),(-1,-1), 6),
("LEFTPADDING", (0,0), (-1,-1), 8),
("RIGHTPADDING",(0,0), (-1,-1), 8),
("ROUNDEDCORNERS", [4,4,0,0]),
]))
return t
def answer_box(content_rows, bg_color):
"""content_rows: list of Paragraph objects. Returns a styled Table."""
data = [[r] for r in content_rows]
t = Table(data, colWidths=[W - 24*mm])
t.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), bg_color),
("TOPPADDING", (0,0), (-1,-1), 2),
("BOTTOMPADDING",(0,0),(-1,-1), 2),
("LEFTPADDING", (0,0), (-1,-1), 10),
("RIGHTPADDING",(0,0), (-1,-1), 10),
("ROUNDEDCORNERS", [0,0,4,4]),
]))
return t
def sep():
return Spacer(1, 4*mm)
def make_card(story, topic, q, answer_items, hdr_color=C_DARK_BLUE, ans_bg=C_LIGHT_BLUE):
"""
answer_items: list of (style, text) tuples.
"""
paras = [Paragraph(txt, st) for st, txt in answer_items]
card = KeepTogether([
header_bar(topic, q, hdr_color),
answer_box(paras, ans_bg),
sep(),
])
story.append(card)
# ══════════════════════════════════════════════════════════════════════
# FLASHCARD DATA
# Format: (topic_label, question, [(style, answer_line), ...], hdr_col, ans_bg)
# ══════════════════════════════════════════════════════════════════════
APH = ("Antepartum Hemorrhage", C_DARK_BLUE, C_LIGHT_BLUE)
PERI = ("Peritonitis", C_TEAL, C_TEAL_LIGHT)
PERF = ("Hollow Viscus Perforation", C_PURPLE, C_PURPLE_LIGHT)
CARDS = [
# ─── COVER ──── (handled separately)
# ══ APH ══════════════════════════════════════════════════════
(APH[0], APH[1], APH[2],
"Define Antepartum Hemorrhage (APH)",
[(ST_A, "Bleeding from the genital tract at or <b>after 24 weeks</b> of gestation and <b>before delivery</b>."),
(ST_A, "Complicates <b>3–5%</b> of pregnancies. Leading cause of maternal and perinatal mortality worldwide.")]),
(APH[0], APH[1], APH[2],
"Causes / Classification of APH",
[(ST_SECTION, "Major Causes:"),
(ST_BULLET, "• <b>Placenta Previa</b> – painless, bright red bleeding (~20%)"),
(ST_BULLET, "• <b>Placental Abruption</b> – painful, dark, clotted blood (~30%)"),
(ST_BULLET, "• <b>Vasa Previa</b> – fetal blood loss, rare but catastrophic"),
(ST_BULLET, "• <b>Local causes</b> – cervical polyp, ectropion, cancer"),
(ST_BULLET, "• <b>Unclassified</b> – ~50% of all APH")]),
(APH[0], APH[1], APH[2],
"Placenta Previa – Risk Factors",
[(ST_BULLET, "• Prior caesarean section / uterine surgery (dose-dependent ↑ with each CS)"),
(ST_BULLET, "• Advanced maternal age (AMA)"),
(ST_BULLET, "• Multiparity"),
(ST_BULLET, "• Smoking and cocaine use"),
(ST_BULLET, "• Multiple gestation"),
(ST_BULLET, "• Assisted reproductive technology (ART)"),
(ST_BULLET, "• Prior miscarriage / induced abortions")]),
(APH[0], APH[1], APH[2],
"Placenta Previa – Subtypes",
[(ST_BULLET, "• <b>Marginal</b> – reaches internal os, does not cover it"),
(ST_BULLET, "• <b>Partial</b> – partially covers internal os"),
(ST_BULLET, "• <b>Complete</b> – completely covers internal os (~20% of previas; highest risk)")]),
(APH[0], APH[1], APH[2],
"Placenta Previa – Classic Presentation",
[(ST_AB, "Painless, bright red vaginal bleeding"),
(ST_A, "Usually after the <b>7th month</b> of pregnancy."),
(ST_A, "Uterine irritability present in ~<b>20%</b> of cases."),
(ST_A, "<b>NEVER</b> perform digital or speculum vaginal examination until placenta previa excluded by ultrasound – risk of catastrophic haemorrhage.")]),
(APH[0], APH[1], APH[2],
"Placenta Previa – Diagnosis",
[(ST_AB, "Ultrasound – investigation of choice"),
(ST_BULLET, "• Transvaginal US: safer, more accurate for internal os"),
(ST_BULLET, "• Empty bladder before scan (prevents overdiagnosis)"),
(ST_A, "Normal fibrinogen in pregnancy: <b>400–450 mg/dL</b>"),
(ST_A, "Fibrinogen <b><300 mg/dL</b> = significant coagulation factor consumption")]),
(APH[0], APH[1], APH[2],
"Placenta Previa – Management",
[(ST_SECTION, "All patients:"),
(ST_BULLET, "• 2 large-bore IVs + fluid resuscitation"),
(ST_BULLET, "• CBC, coagulation screen, type and crossmatch"),
(ST_BULLET, "• Continuous fetal monitoring; RhoGAM if Rh-negative"),
(ST_SECTION, "Definitive:"),
(ST_BULLET, "• Immature fetus + minimal bleeding → expectant management"),
(ST_BULLET, "• Severe bleeding / mature fetus → <b>caesarean delivery</b>"),
(ST_BULLET, "• Vaginal delivery is <b>CONTRAINDICATED</b>"),
(ST_BULLET, "• Neuraxial anaesthesia preferred (less blood loss than GA)")]),
(APH[0], APH[1], APH[2],
"Placenta Accreta – Risk with Placenta Previa",
[(ST_A, "Risk of placenta accreta <b>increases with each prior caesarean</b>:"),
(ST_BULLET, "• Primary CS: <b>3%</b>"),
(ST_BULLET, "• 3 prior caesareans: <b>61%</b>")]),
(APH[0], APH[1], APH[2],
"Placental Abruption – Definition & Incidence",
[(ST_A, "Premature separation of a <b>normally implanted placenta</b> before delivery."),
(ST_A, "Complicates <b>~1%</b> of deliveries, usually in the <b>final 10 weeks</b>."),
(ST_A, "Maternal mortality: <b><1%</b>; Perinatal mortality: <b>9–12%</b> in developed countries.")]),
(APH[0], APH[1], APH[2],
"Placental Abruption – Risk Factors (MNEMONIC: CAMP-TP)",
[(ST_BULLET, "C – <b>Cocaine</b> use"),
(ST_BULLET, "A – <b>Advanced maternal age</b>"),
(ST_BULLET, "M – <b>Multiple gestation</b>"),
(ST_BULLET, "P – <b>PPROM</b> (preterm premature rupture of membranes)"),
(ST_BULLET, "T – <b>Tobacco</b>, <b>Trauma</b>"),
(ST_BULLET, "P – <b>Preeclampsia/Hypertension</b>")]),
(APH[0], APH[1], APH[2],
"Placental Abruption – Clinical Features",
[(ST_AB, "Painful, dark, clotted vaginal bleeding"),
(ST_BULLET, "• Uterine tenderness and <b>hypertonus</b>"),
(ST_BULLET, "• Rigid, board-like uterus"),
(ST_BULLET, "• Bleeding may be <b>concealed</b> if placental margins remain attached"),
(ST_BULLET, "• Fetal distress → if separation >50%: <b>stillbirth</b> most likely"),
(ST_BULLET, "• Maternal shock if blood loss severe")]),
(APH[0], APH[1], APH[2],
"Placental Abruption – Diagnosis & Management",
[(ST_AB, "Diagnosis is CLINICAL"),
(ST_BULLET, "• CTG: 100% NPV when reassuring"),
(ST_BULLET, "• Ultrasound: specific but NOT sensitive – cannot exclude abruption"),
(ST_SECTION, "Management:"),
(ST_BULLET, "• 2 IVs, blood tests, type & crossmatch, RhoGAM if Rh-ve"),
(ST_BULLET, "• Mild → expectant; ARM + oxytocin augmentation if needed"),
(ST_BULLET, "• Severe / non-reassuring CTG → emergency <b>caesarean section</b>"),
(ST_BULLET, "• Watch for <b>DIC</b> – replace coagulation factors")]),
(APH[0], APH[1], APH[2],
"Vasa Previa",
[(ST_A, "Fetal vessels traverse fetal membranes <b>over the cervical os</b>, unsupported by cord/placenta."),
(ST_A, "Membrane rupture → vessel rupture → <b>fetal exsanguination</b>."),
(ST_SECTION, "Risk factors:"),
(ST_BULLET, "• Placenta previa, IVF, velamentous cord insertion, bilobed placenta"),
(ST_SECTION, "Treatment:"),
(ST_BULLET, "• <b>Immediate operative (caesarean) delivery</b>")]),
(APH[0], APH[1], APH[2],
"Previa vs. Abruption – Key Differences",
[(ST_BULLET, "• Pain: <b>Painless</b> (previa) vs. <b>Painful</b> (abruption)"),
(ST_BULLET, "• Blood: <b>Bright red</b> vs. <b>Dark, clotted</b>"),
(ST_BULLET, "• Uterus: <b>Soft</b> vs. <b>Rigid, hypertonic</b>"),
(ST_BULLET, "• Coagulopathy: <b>Rare</b> vs. <b>Common (DIC)</b>"),
(ST_BULLET, "• Ultrasound: <b>Confirms</b> previa vs. <b>Does NOT exclude</b> abruption"),
(ST_BULLET, "• Vaginal delivery: <b>Contraindicated</b> in previa; may be possible in abruption")]),
# ══ PERITONITIS ══════════════════════════════════════════════
(PERI[0], PERI[1], PERI[2],
"Define Peritonitis",
[(ST_A, "Inflammation of the <b>peritoneum</b> (serous membrane lining abdominal cavity and viscera)."),
(ST_A, "Can be <b>localised</b> or <b>diffuse/generalised</b>. Generalised peritonitis is a <b>life-threatening emergency</b>.")]),
(PERI[0], PERI[1], PERI[2],
"Classification of Peritonitis",
[(ST_SECTION, "By Extent:"),
(ST_BULLET, "• Localised – confined to one region"),
(ST_BULLET, "• Diffuse/Generalised – entire peritoneal cavity"),
(ST_SECTION, "By Cause:"),
(ST_BULLET, "• <b>Primary (SBP)</b> – no perforation; ascites + cirrhosis"),
(ST_BULLET, "• <b>Secondary</b> – GI perforation, ischaemia, anastomotic leak"),
(ST_BULLET, "• <b>Tertiary</b> – recurrent after adequate treatment; resistant organisms")]),
(PERI[0], PERI[1], PERI[2],
"Causes of Peritoneal Inflammation",
[(ST_BULLET, "• <b>Bacterial</b> – GI/non-GI perforation, PID"),
(ST_BULLET, "• <b>Chemical</b> – bile, gastric acid, barium"),
(ST_BULLET, "• <b>Ischaemic</b> – strangulated bowel, vascular occlusion"),
(ST_BULLET, "• <b>Traumatic</b> – operative handling, abdominal trauma"),
(ST_BULLET, "• <b>Allergic</b> – starch peritonitis"),
(ST_BULLET, "• <b>Miscellaneous</b> – Familial Mediterranean fever")]),
(PERI[0], PERI[1], PERI[2],
"Primary Bacterial Peritonitis (SBP) – Key Points",
[(ST_A, "Occurs without identifiable perforation. Almost exclusively with <b>pre-existing ascites</b> (cirrhosis)."),
(ST_A, "Mechanism: haematogenous spread + bacterial translocation."),
(ST_A, "Organism: <b>single organism</b> (E. coli, streptococci, pneumococci)."),
(ST_AB, "Diagnostic criterion: >250 PMNs/µL in peritoneal fluid.")]),
(PERI[0], PERI[1], PERI[2],
"Clinical Features of Peritonitis",
[(ST_BULLET, "• <b>Abdominal pain</b> – worse on movement, coughing, deep breathing"),
(ST_BULLET, "• Patient lies <b>still with knees drawn up</b>"),
(ST_BULLET, "• <b>Involuntary guarding</b> and <b>rebound tenderness</b>"),
(ST_BULLET, "• <b>Board-like rigidity</b> (diffuse peritonitis)"),
(ST_BULLET, "• Pyrexia, tachycardia"),
(ST_BULLET, "• <b>Absent bowel sounds</b> (paralytic ileus)"),
(ST_BULLET, "• Shoulder tip pain (sub-diaphragmatic irritation – C5 referral)"),
(ST_BULLET, "• <b>Hippocratic facies</b> in advanced cases")]),
(PERI[0], PERI[1], PERI[2],
"Investigations in Peritonitis",
[(ST_SECTION, "Blood:"),
(ST_BULLET, "• FBC (leukocytosis, left shift), CRP, procalcitonin"),
(ST_BULLET, "• U&E, LFTs, serum lactate, ABG, coagulation, blood cultures"),
(ST_SECTION, "Imaging:"),
(ST_BULLET, "• <b>Erect CXR</b> – free gas under diaphragm (pneumoperitoneum)"),
(ST_BULLET, "• <b>CT abdomen/pelvis</b> – investigation of choice; identifies cause"),
(ST_BULLET, "• US – limited; useful for tubo-ovarian pathology"),
(ST_BULLET, "• Diagnostic laparoscopy – if imaging inconclusive")]),
(PERI[0], PERI[1], PERI[2],
"Non-operative Management of Peritonitis",
[(ST_BULLET, "• 2 large-bore IVs – fluid resuscitation"),
(ST_BULLET, "• NGT decompression + urinary catheter"),
(ST_BULLET, "• IV analgesia (do NOT withhold)"),
(ST_BULLET, "• Broad-spectrum IV antibiotics (cover gram-neg + anaerobes)"),
(ST_BULLET, "• Correction of fluid, electrolyte, and coagulation abnormalities"),
(ST_BULLET, "• ICU/HDU support for septic shock")]),
(PERI[0], PERI[1], PERI[2],
"Antibiotic Regimens in Secondary Peritonitis",
[(ST_SECTION, "Community-acquired (mild–moderate):"),
(ST_BULLET, "• Piperacillin-tazobactam 3.375 g q6h IV, OR"),
(ST_BULLET, "• Ceftriaxone 2 g q24h IV + Metronidazole 500 mg q8h IV"),
(ST_SECTION, "Healthcare-associated / ICU:"),
(ST_BULLET, "• Meropenem 1 g q8h IV, OR"),
(ST_BULLET, "• Imipenem 500 mg q6h IV")]),
(PERI[0], PERI[1], PERI[2],
"Surgical Management of Peritonitis",
[(ST_SECTION, "Principles:"),
(ST_BULLET, "1. <b>Source control</b> – remove/exclude the cause"),
(ST_BULLET, "2. <b>Peritoneal lavage</b> – copious warm saline irrigation"),
(ST_BULLET, "3. <b>Drainage</b> – placed in dependent areas (pelvis, subphrenic)"),
(ST_BULLET, "4. <b>Damage control surgery</b> – abbreviated surgery + ICU resuscitation + re-look in critically ill"),
(ST_A, "At surgery: peritoneum is reddened, thickened, velvety; fibrin plaques; turbid/purulent fluid")]),
(PERI[0], PERI[1], PERI[2],
"Complications of Peritonitis",
[(ST_SECTION, "Early:"),
(ST_BULLET, "• Septic shock, MODS (renal failure, ARDS, hepatic failure), DIC"),
(ST_SECTION, "Late:"),
(ST_BULLET, "• Residual abscess (pelvic, subphrenic, paracolic)"),
(ST_BULLET, "• Adhesive small bowel obstruction"),
(ST_BULLET, "• Enterocutaneous fistula"),
(ST_BULLET, "• Incisional hernia"),
(ST_BULLET, "• Tertiary peritonitis")]),
# ══ HOLLOW VISCUS PERFORATION ═══════════════════════════════
(PERF[0], PERF[1], PERF[2],
"Common Causes of Hollow Viscus Perforation",
[(ST_BULLET, "• <b>Duodenum</b> – perforated duodenal ulcer (most common cause of pneumoperitoneum)"),
(ST_BULLET, "• <b>Stomach</b> – perforated gastric ulcer"),
(ST_BULLET, "• <b>Appendix</b> – perforated appendicitis"),
(ST_BULLET, "• <b>Colon</b> – diverticulitis, obstructing cancer, volvulus"),
(ST_BULLET, "• <b>Small bowel</b> – strangulation, typhoid, Crohn's"),
(ST_BULLET, "• <b>Gallbladder</b> – gangrenous/perforated cholecystitis")]),
(PERF[0], PERF[1], PERF[2],
"Perforated Peptic Ulcer – Classic Presentation",
[(ST_AB, "Sudden-onset severe generalised abdominal pain"),
(ST_A, "History of dyspepsia, NSAID use, H. pylori."),
(ST_A, "Initially shocked (tachycardia) but <b>pyrexia usually absent</b> in first few hours."),
(ST_A, "<b>Board-like rigidity</b>; abdomen does not move with respiration."),
(ST_A, "Gastric contents (low bacterial load initially) → bacterial peritonitis over hours.")]),
(PERF[0], PERF[1], PERF[2],
"Investigations for Suspected Perforation",
[(ST_SECTION, "Must perform:"),
(ST_BULLET, "• <b>Erect CXR</b> – free gas under diaphragm in >50% of PU perforation"),
(ST_BULLET, "• <b>Serum amylase</b> – distinguish perforation from pancreatitis (mildly elevated in perforation, very high in pancreatitis)"),
(ST_BULLET, "• <b>CT abdomen/pelvis</b> – investigation of choice; most accurate"),
(ST_SECTION, "If can't sit upright:"),
(ST_BULLET, "• Left lateral decubitus X-ray (gas rises between liver and wall)")]),
(PERF[0], PERF[1], PERF[2],
"Pre-operative Resuscitation (All Perforations)",
[(ST_BULLET, "• 2 large-bore IVs – aggressive fluid resuscitation"),
(ST_BULLET, "• Urinary catheter (target UO >0.5 mL/kg/hr)"),
(ST_BULLET, "• NGT – stomach decompression, nil by mouth"),
(ST_BULLET, "• IV opioid analgesia – <b>do NOT withhold</b> (aids examination)"),
(ST_BULLET, "• Early broad-spectrum IV antibiotics"),
(ST_BULLET, "• Blood: FBC, U&E, amylase, coagulation, G&S/crossmatch"),
(ST_BULLET, "• Unstable → <b>theatre directly without imaging</b>")]),
(PERF[0], PERF[1], PERF[2],
"Surgical Repair – Perforated Duodenal Ulcer",
[(ST_AB, "Graham (Omental) Patch Repair – most common operation"),
(ST_BULLET, "• Close perforation with sutures (transverse direction, as pyloroplasty)"),
(ST_BULLET, "• Place omental patch over repair – sutures not too tight"),
(ST_BULLET, "• If perforation too large → distal gastrectomy + Roux-en-Y"),
(ST_BULLET, "• Laparoscopic repair acceptable if expertise available"),
(ST_SECTION, "Post-op:"),
(ST_BULLET, "• NGT suction, PPI therapy, <b>H. pylori eradication mandatory</b>")]),
(PERF[0], PERF[1], PERF[2],
"Surgical Repair – Perforated Gastric Ulcer",
[(ST_AB, "Excise and close – to exclude malignancy"),
(ST_A, "<b>All perforated gastric ulcers must be biopsied</b> if not resected."),
(ST_BULLET, "• Stable patient → distal gastric resection"),
(ST_BULLET, "• Unstable patient → patch closure with biopsy only"),
(ST_BULLET, "• Imbrication using Lembert sutures if body of stomach closed primarily")]),
(PERF[0], PERF[1], PERF[2],
"Surgical Repair – Perforated Colon",
[(ST_AB, "Primary anastomosis is CONTRAINDICATED in gross peritonitis / haemodynamic instability"),
(ST_SECTION, "Right-sided perforation:"),
(ST_BULLET, "• Right hemicolectomy + end ileostomy"),
(ST_SECTION, "Left-sided perforation:"),
(ST_BULLET, "• <b>Hartmann's Procedure</b>: resect segment, end colostomy, close rectal stump"),
(ST_BULLET, "• Reversal at 6–12 months (only 44% actually reversed, mean 7.5 months)")]),
(PERF[0], PERF[1], PERF[2],
"Hartmann's Procedure",
[(ST_A, "Introduced 1923 by Henri Hartmann for large bowel obstruction/perforation."),
(ST_SECTION, "Steps:"),
(ST_BULLET, "1. Resection of perforated/obstructing left-sided segment"),
(ST_BULLET, "2. Formation of <b>end colostomy</b> proximally"),
(ST_BULLET, "3. Closure of <b>rectal stump</b> (Hartmann's pouch) left in pelvis"),
(ST_A, "Reversal rate: only ~44%; mean time to reversal: 7.5 months."),
(ST_A, "Morbidity: 3–50%; Mortality: 0–7.1%")]),
(PERF[0], PERF[1], PERF[2],
"Damage Control Surgery in Peritonitis",
[(ST_A, "Used in gross peritonitis + haemodynamic instability + pressor requirements."),
(ST_SECTION, "Steps:"),
(ST_BULLET, "1. Abbreviated initial surgery – eliminate source only"),
(ST_BULLET, "2. Temporary abdominal closure (VAC / Bogota bag)"),
(ST_BULLET, "3. ICU resuscitation"),
(ST_BULLET, "4. Re-look laparotomy at 48–72 hrs for definitive repair"),
(ST_A, "<i>Truism: \"The anastomosis never created will never leak.\"</i>")]),
(PERF[0], PERF[1], PERF[2],
"Peritoneal Lavage – Key Points",
[(ST_A, "Most important part of the operation after source control."),
(ST_SECTION, "Areas to irrigate:"),
(ST_BULLET, "• Subphrenic spaces (right and left)"),
(ST_BULLET, "• Paracolic gutters (right and left)"),
(ST_BULLET, "• Pelvis (most dependent – collects most fluid)"),
(ST_BULLET, "• Morrison's pouch (posterosuperior subhepatic space)"),
(ST_BULLET, "• Drains placed in dependent areas")]),
(PERF[0], PERF[1], PERF[2],
"Wound Closure & Post-operative Care",
[(ST_SECTION, "Closure:"),
(ST_BULLET, "• Mass closure with <b>looped PDS</b> – suture:wound length ratio ≥4:1 (Jenkins rule)"),
(ST_BULLET, "• Contaminated wounds: <b>leave skin open</b> → delayed primary closure (day 3–5)"),
(ST_SECTION, "Post-op:"),
(ST_BULLET, "• ICU/HDU monitoring, IV antibiotics 3–5 days (culture-guided)"),
(ST_BULLET, "• Early enteral nutrition within 24–48 hrs"),
(ST_BULLET, "• VTE prophylaxis (LMWH + TED stockings)")]),
(PERF[0], PERF[1], PERF[2],
"Complications of Hollow Viscus Perforation",
[(ST_SECTION, "Early:"),
(ST_BULLET, "• Septic shock, MODS, DIC, ongoing haemorrhage"),
(ST_BULLET, "• Anastomotic leak"),
(ST_SECTION, "Late:"),
(ST_BULLET, "• Residual intra-abdominal abscess"),
(ST_BULLET, "• Adhesive small bowel obstruction"),
(ST_BULLET, "• Enterocutaneous fistula"),
(ST_BULLET, "• Incisional hernia"),
(ST_BULLET, "• Stoma complications (parastomal hernia, prolapse)")]),
(PERF[0], PERF[1], PERF[2],
"Prognosis – Mortality Rates",
[(ST_BULLET, "• Perforated peptic ulcer: <b>10–40%</b>"),
(ST_BULLET, "• Faecal peritonitis (colonic perforation): <b>30–50%</b>"),
(ST_SECTION, "Determinants of outcome:"),
(ST_BULLET, "• Time to surgery (most important)"),
(ST_BULLET, "• Patient age and comorbidities"),
(ST_BULLET, "• Number of organ failures (Mannheim Peritonitis Index / APACHE II)"),
(ST_BULLET, "• Degree of peritoneal contamination")]),
]
# ══════════════════════════════════════════════════════════════════════
# BUILD PDF
# ══════════════════════════════════════════════════════════════════════
doc = SimpleDocTemplate(
OUTPUT,
pagesize=A5,
leftMargin=12*mm, rightMargin=12*mm,
topMargin=12*mm, bottomMargin=12*mm,
)
story = []
# ── Cover page ────────────────────────────────────────────────────────
cover_data = [
[Paragraph("Surgery Flashcards", ST_TITLE)],
[Paragraph("Antepartum Hemorrhage • Peritonitis • Hollow Viscus Perforation", ST_SUBTITLE)],
[Spacer(1, 6*mm)],
[HRFlowable(width="100%", thickness=2, color=C_MID_BLUE)],
[Spacer(1, 6*mm)],
[Paragraph(f"<b>Total Cards:</b> {len(CARDS)}", ST_A)],
[Paragraph("<b>Topics:</b> 3", ST_A)],
[Spacer(1, 4*mm)],
[Paragraph("Sources: Bailey & Love's Surgery 28e • Schwartz's Surgery 11e<br/>"
"Harrison's Medicine 22e • Tintinalli's EM • Barash Clinical Anaesthesia 9e", ST_SUBTITLE)],
]
cover_table = Table(cover_data, colWidths=[W - 24*mm])
cover_table.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), C_BG),
("BOX", (0,0), (-1,-1), 1.5, C_MID_BLUE),
("TOPPADDING", (0,0), (-1,-1), 6),
("BOTTOMPADDING",(0,0), (-1,-1), 6),
("LEFTPADDING", (0,0), (-1,-1), 12),
("RIGHTPADDING", (0,0), (-1,-1), 12),
("ROUNDEDCORNERS", [8,8,8,8]),
]))
story.append(Spacer(1, 20*mm))
story.append(cover_table)
story.append(Spacer(1, 8*mm))
# topic legend
legend_items = [
(C_DARK_BLUE, "Antepartum Hemorrhage"),
(C_TEAL, "Peritonitis"),
(C_PURPLE, "Hollow Viscus Perforation"),
]
for col, label in legend_items:
dot = Table([[Paragraph(f"<font color='white'><b> {label} </b></font>",
ParagraphStyle("lbl", fontSize=8, textColor=colors.white,
fontName="Helvetica-Bold"))]],
colWidths=[W - 24*mm])
dot.setStyle(TableStyle([
("BACKGROUND", (0,0), (-1,-1), col),
("TOPPADDING", (0,0), (-1,-1), 3),
("BOTTOMPADDING",(0,0), (-1,-1), 3),
("LEFTPADDING", (0,0), (-1,-1), 8),
("ROUNDEDCORNERS", [4,4,4,4]),
]))
story.append(dot)
story.append(Spacer(1, 2*mm))
# ── Flashcards ────────────────────────────────────────────────────────
story.append(Spacer(1, 6*mm))
for topic_label, hdr_color, ans_bg, question, answers in CARDS:
make_card(story, topic_label, question, answers, hdr_color, ans_bg)
doc.build(story)
print("PDF created:", OUTPUT)