Classify Diaphragmatic Hernias. Describe surgical management of post-traumatic diaphragmatic hernias. What is abdominal wall reconstruction? Describe component separation technique in ventral hernia repair. -from standard literature like sabiston/bailey , if possible in an easy memorable format/Table in a downloadable two/three page pdf/image.

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Reading File
Finding Sources
Reading File
Reading File
Reading File
Running Command

mkdir -p /tmp/workspace/hernia-notes && ls /tmp/workspace/hernia-notes/

Writing File

~/hernia-notes/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, KeepTogether
)
from reportlab.lib.enums import TA_CENTER, TA_LEFT, TA_JUSTIFY
from reportlab.platypus import PageBreak

OUTPUT = "/tmp/workspace/hernia-notes/Hernia_Surgery_Notes.pdf"

# ── colour palette ──────────────────────────────────────────────────────────
NAVY   = colors.HexColor("#1B3A5C")
TEAL   = colors.HexColor("#1A7A7E")
AMBER  = colors.HexColor("#E07B39")
LGREY  = colors.HexColor("#F2F5F9")
MGREY  = colors.HexColor("#D0D8E4")
WHITE  = colors.white
BLACK  = colors.black
GREEN  = colors.HexColor("#2E7D32")
RED    = colors.HexColor("#C62828")
PURPLE = colors.HexColor("#6A1B9A")

# ── styles ──────────────────────────────────────────────────────────────────
styles = getSampleStyleSheet()

def S(name, **kw):
    return ParagraphStyle(name, parent=styles["Normal"], **kw)

title_style    = S("Title2",   fontSize=18, textColor=WHITE,   alignment=TA_CENTER,
                   fontName="Helvetica-Bold", spaceAfter=2)
sub_style      = S("Sub",      fontSize=9,  textColor=MGREY,   alignment=TA_CENTER,
                   fontName="Helvetica", spaceAfter=6)
h1_style       = S("H1",       fontSize=13, textColor=WHITE,   fontName="Helvetica-Bold",
                   spaceAfter=4, spaceBefore=4, leftIndent=6)
h2_style       = S("H2",       fontSize=10.5, textColor=NAVY,  fontName="Helvetica-Bold",
                   spaceAfter=2, spaceBefore=6)
body_style     = S("Body",     fontSize=8.5, textColor=BLACK,  fontName="Helvetica",
                   spaceAfter=2, leading=12, alignment=TA_JUSTIFY)
small_bold     = S("SmBold",   fontSize=8,   textColor=NAVY,   fontName="Helvetica-Bold")
cell_hdr       = S("CellHdr",  fontSize=8.5, textColor=WHITE,  fontName="Helvetica-Bold",
                   alignment=TA_CENTER)
cell_body      = S("CellBody", fontSize=8,   textColor=BLACK,  fontName="Helvetica",
                   alignment=TA_LEFT, leading=11)
cell_body_c    = S("CellBodyC",fontSize=8,   textColor=BLACK,  fontName="Helvetica",
                   alignment=TA_CENTER, leading=11)
bullet_style   = S("Bullet",   fontSize=8.5, textColor=BLACK,  fontName="Helvetica",
                   leftIndent=12, firstLineIndent=-10, spaceAfter=1, leading=12,
                   bulletIndent=4)
note_style     = S("Note",     fontSize=7.5, textColor=PURPLE, fontName="Helvetica-Oblique",
                   spaceAfter=2)
mnemonic_style = S("Mnemo",    fontSize=9,   textColor=GREEN,  fontName="Helvetica-Bold",
                   spaceAfter=2, leading=13)

def colored_heading(text, bg=NAVY, style=h1_style):
    tbl = Table([[Paragraph(text, style)]], colWidths=[17.5*cm])
    tbl.setStyle(TableStyle([
        ("BACKGROUND", (0,0), (-1,-1), bg),
        ("ROUNDEDCORNERS", [4]),
        ("TOPPADDING",    (0,0), (-1,-1), 4),
        ("BOTTOMPADDING", (0,0), (-1,-1), 4),
        ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ]))
    return tbl

def section_header(text, bg=TEAL):
    return colored_heading(text, bg=bg)

def bullet(txt):
    return Paragraph(f"• {txt}", bullet_style)

def b(txt):
    return f"<b>{txt}</b>"

def bi(txt):
    return f"<b><i>{txt}</i></b>"

def red(txt):
    return f'<font color="#C62828">{txt}</font>'

def grn(txt):
    return f'<font color="#2E7D32">{txt}</font>'

def amb(txt):
    return f'<font color="#E07B39">{txt}</font>'

# ── document ─────────────────────────────────────────────────────────────────
doc = SimpleDocTemplate(
    OUTPUT, pagesize=A4,
    leftMargin=1.5*cm, rightMargin=1.5*cm,
    topMargin=1.5*cm, bottomMargin=1.5*cm
)
story = []

# ============================================================
#  TITLE BANNER
# ============================================================
title_tbl = Table([[Paragraph("HERNIA SURGERY — QUICK REFERENCE", title_style)],
                   [Paragraph("Diaphragmatic Hernias • Abdominal Wall Reconstruction • Component Separation", sub_style)]],
                  colWidths=[17.5*cm])
title_tbl.setStyle(TableStyle([
    ("BACKGROUND", (0,0), (-1,-1), NAVY),
    ("TOPPADDING",    (0,0), (-1,-1), 10),
    ("BOTTOMPADDING", (0,0), (-1,-1), 8),
    ("LEFTPADDING",   (0,0), (-1,-1), 10),
    ("ROUNDEDCORNERS", [6]),
]))
story += [title_tbl, Spacer(1, 8)]

source_note = Paragraph(
    f"<i>Based on {b('Sabiston Textbook of Surgery 21e')}, {b('Bailey & Love 28e')}, "
    f"{b('Current Surgical Therapy 14e')}, {b('Schwartz Principles of Surgery 11e')}</i>",
    S("SrcNote", fontSize=7.5, textColor=colors.grey, alignment=TA_CENTER))
story += [source_note, Spacer(1, 6)]

# ============================================================
#  PAGE 1 — DIAPHRAGMATIC HERNIA CLASSIFICATION
# ============================================================
story.append(section_header("1. CLASSIFICATION OF DIAPHRAGMATIC HERNIAS"))
story.append(Spacer(1, 4))

# Classification table
cls_data = [
    [Paragraph(b("Type"), cell_hdr),
     Paragraph(b("Name"), cell_hdr),
     Paragraph(b("Location"), cell_hdr),
     Paragraph(b("Sac?"), cell_hdr),
     Paragraph(b("Key Features"), cell_hdr)],

    [Paragraph("I", cell_body_c),
     Paragraph("Sliding hiatus hernia", cell_body),
     Paragraph("Gastro-oesophageal junction + part of stomach slide into chest", cell_body),
     Paragraph(grn("Yes (lax)"), cell_body_c),
     Paragraph("Most common (95%). GOR, heartburn. Rarely requires surgery.", cell_body)],

    [Paragraph("II", cell_body_c),
     Paragraph("Para-oesophageal (rolling) hernia", cell_body),
     Paragraph("Fundus herniates beside fixed GOJ", cell_body),
     Paragraph(grn("Yes"), cell_body_c),
     Paragraph("5%. Obstruction/strangulation risk. Elective repair advised.", cell_body)],

    [Paragraph("III", cell_body_c),
     Paragraph("Mixed (sliding + rolling)", cell_body),
     Paragraph("Both GOJ and fundus herniate", cell_body),
     Paragraph(grn("Yes"), cell_body_c),
     Paragraph("Most common para-oesophageal type in practice.", cell_body)],

    [Paragraph("IV", cell_body_c),
     Paragraph("Intrathoracic stomach / large defect", cell_body),
     Paragraph("Large hiatus; colon, spleen may also herniate", cell_body),
     Paragraph(grn("Yes"), cell_body_c),
     Paragraph("Organoaxial volvulus risk. Urgent/emergent repair.", cell_body)],

    [Paragraph("CDH\n(Bochdalek)", cell_body_c),
     Paragraph("Posterolateral (Bochdalek) hernia", cell_body),
     Paragraph("Left posterolateral (pleuroperitoneal canal defect)", cell_body),
     Paragraph(red("No"), cell_body_c),
     Paragraph("Most common CDH (75–90%). Neonatal respiratory distress. Bowel in chest.", cell_body)],

    [Paragraph("CDH\n(Morgagni)", cell_body_c),
     Paragraph("Anterior (Morgagni) hernia", cell_body),
     Paragraph("Right parasternal (foramen of Morgagni)", cell_body),
     Paragraph(grn("Yes"), cell_body_c),
     Paragraph("2–3% of CDH. Often diagnosed late/incidentally in adults.", cell_body)],

    [Paragraph("Traumatic", cell_body_c),
     Paragraph("Post-traumatic diaphragmatic hernia", cell_body),
     Paragraph("Any site; left-sided more common (70%)", cell_body),
     Paragraph(red("No"), cell_body_c),
     Paragraph("Blunt/penetrating trauma. May present acutely or years later (latent phase).", cell_body)],
]

cls_tbl = Table(cls_data, colWidths=[1.3*cm, 3.2*cm, 4.0*cm, 1.4*cm, 6.6*cm])
cls_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,0), NAVY),
    ("ROWBACKGROUNDS",(0,1), (-1,-1), [LGREY, WHITE]),
    ("GRID",          (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",        (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",    (0,0), (-1,-1), 4),
    ("BOTTOMPADDING", (0,0), (-1,-1), 4),
    ("LEFTPADDING",   (0,0), (-1,-1), 4),
    ("ROUNDEDCORNERS",[3]),
]))
story += [cls_tbl, Spacer(1, 6)]

# Mnemonic box
mn_data = [[Paragraph(
    f'{b("MNEMONIC — Types")} &nbsp;&nbsp; '
    f'{grn(b("\"Slides, Rolls, Mixes, Huge\""))} = Type I, II, III, IV hiatus hernias<br/>'
    f'{grn(b("\"Big, Anterior, Trauma\""))} = Bochdalek / Anterior (Morgagni) / Traumatic (non-hiatus)<br/>'
    f'{amb(b("Left > Right"))} for both Bochdalek CDH and traumatic diaphragmatic hernia (liver protects right side)',
    mnemonic_style)]]
mn_tbl = Table(mn_data, colWidths=[17.5*cm])
mn_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), colors.HexColor("#F0FFF0")),
    ("BOX",           (0,0), (-1,-1), 1, GREEN),
    ("TOPPADDING",    (0,0), (-1,-1), 6),
    ("BOTTOMPADDING", (0,0), (-1,-1), 6),
    ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ("ROUNDEDCORNERS",[4]),
]))
story += [mn_tbl, Spacer(1, 8)]

# ============================================================
#  POST-TRAUMATIC DIAPHRAGMATIC HERNIA — Surgical management
# ============================================================
story.append(section_header("2. POST-TRAUMATIC DIAPHRAGMATIC HERNIA — Surgical Management"))
story.append(Spacer(1, 4))

story.append(Paragraph(
    f"{b('Background:')} Traumatic diaphragmatic rupture occurs in ~3–5% of major blunt abdominal trauma "
    f"and ~10–15% of penetrating wounds. Left-sided in 70% (liver protects right). "
    f"Three phases: {b('Acute')} (at injury), {b('Latent')} (silent, months–years), {b('Obstructive')} (visceral strangulation).",
    body_style))
story.append(Spacer(1, 4))

# Phase table
phase_data = [
    [Paragraph(b("Phase"), cell_hdr),
     Paragraph(b("Timing"), cell_hdr),
     Paragraph(b("Presentation"), cell_hdr),
     Paragraph(b("Approach"), cell_hdr)],
    [Paragraph(b("Acute"), cell_body_c),
     Paragraph("Hours–days post trauma", cell_body),
     Paragraph("Haemothorax, respiratory distress, bowel sounds in chest, NG tube in chest on CXR, CT diagnosis", cell_body),
     Paragraph("Transabdominal (laparotomy) — control associated injuries first; diaphragm repair done concurrently", cell_body)],
    [Paragraph(b("Latent"), cell_body_c),
     Paragraph("Weeks to years", cell_body),
     Paragraph("Vague chest/abdominal pain, incidental CXR finding, GI symptoms, dyspnoea", cell_body),
     Paragraph("Elective repair; laparoscopic preferred if no dense adhesions", cell_body)],
    [Paragraph(b("Obstructive"), cell_body_c),
     Paragraph("Variable", cell_body),
     Paragraph("Acute bowel obstruction/strangulation, ischaemia, sepsis", cell_body),
     Paragraph("Emergency laparotomy; bowel resection if non-viable; thoracotomy if adhesions prevent abdominal access", cell_body)],
]
phase_tbl = Table(phase_data, colWidths=[2.2*cm, 2.8*cm, 5.5*cm, 7.0*cm])
phase_tbl.setStyle(TableStyle([
    ("BACKGROUND",     (0,0), (-1,0), TEAL),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [LGREY, WHITE, colors.HexColor("#FFF3E0")]),
    ("GRID",           (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",         (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",     (0,0), (-1,-1), 4),
    ("BOTTOMPADDING",  (0,0), (-1,-1), 4),
    ("LEFTPADDING",    (0,0), (-1,-1), 4),
    ("ROUNDEDCORNERS", [3]),
]))
story += [phase_tbl, Spacer(1, 5)]

# Operative steps
story.append(Paragraph(b("Operative Steps — Transabdominal (Laparotomy) Approach"), h2_style))
steps = [
    f"{b('Position:')} Supine; GA with double-lumen tube if thoracic extension anticipated.",
    f"{b('Incision:')} Midline laparotomy (or left subcostal for isolated left-sided injury).",
    f"{b('Explore abdomen:')} Identify associated injuries — spleen, liver, bowel, major vessels; control haemorrhage first.",
    f"{b('Reduce herniated contents:')} Gently reduce stomach/colon/spleen from chest; assess viability.",
    f"{b('Decompress chest:')} Clear haemothorax/haemopneumothorax; place chest drain if needed.",
    f"{b('Trim defect edges:')} Debride any devitalised diaphragmatic tissue.",
    f"{b('Primary repair (preferred):')} Interrupted non-absorbable sutures (Prolene 0/1-0) in figure-of-8 or horizontal mattress fashion; tension-free closure.",
    f"{b('Mesh reinforcement:')} If defect is large, chronic/fibrotic, or tension-free closure not possible — use synthetic (Prolene/PTFE) or biological mesh for patch repair.",
    f"{b('Drain:')} Intercostal tube to drain residual haemothorax/pneumothorax.",
    f"{b('Thoracoabdominal approach:')} Used when abdominal exposure alone is inadequate (right-sided injuries, dense thoracic adhesions in delayed cases).",
]
for s in steps:
    story.append(bullet(s))

story.append(Spacer(1, 4))

# Laparoscopic approach
story.append(Paragraph(b("Laparoscopic Approach (Elective/Latent Phase)"), h2_style))
lap = [
    "Ports: 10 mm umbilical camera + two 5 mm working ports (left or right side).",
    "CO₂ insufflation aids visualization; may need low pressure (8–10 mmHg) to avoid tension pneumothorax.",
    "Careful lysis of adhesions between herniated viscera and thoracic structures.",
    "Reduce all herniated contents; assess viability.",
    "Primary intracorporeal suture repair (non-absorbable) — possible for defects < 5 cm.",
    "Mesh patch for large or chronic defects; tack/sutured in place.",
    "Convert to open if dense adhesions, non-reducible viscera, or haemodynamic instability.",
]
for l in lap:
    story.append(bullet(l))

story.append(Spacer(1, 4))
story.append(Paragraph(
    f'{red(b("KEY POINT:"))} In the acute trauma setting, diaphragm repair is always '
    f'secondary to damage control — {b("control haemorrhage first")}. '
    f'Bilateral injuries occur in 2%; always inspect both domes.',
    note_style))

# ── PAGE BREAK ──────────────────────────────────────────────────────────────
story.append(PageBreak())

# ============================================================
#  PAGE 2 — ABDOMINAL WALL RECONSTRUCTION
# ============================================================
story.append(title_tbl)
story.append(Spacer(1, 8))
story.append(section_header("3. ABDOMINAL WALL RECONSTRUCTION (AWR)"))
story.append(Spacer(1, 4))

story.append(Paragraph(
    f"{b('Definition:')} AWR refers to the restoration of structural and functional continuity of the "
    f"musculofascial complex of the abdominal wall in patients with complex ventral/incisional hernias, "
    f"enterocutaneous fistulae, loss of domain, or open abdomens (Sabiston 21e, Ch. 37).",
    body_style))
story.append(Spacer(1, 4))

# Indications
story.append(Paragraph(b("Indications for AWR"), h2_style))
indic = [
    "Complex/recurrent incisional hernias with loss of abdominal domain",
    "Contaminated fields (enterocutaneous fistula, infected mesh, stoma reversal)",
    "Open abdomen after damage control surgery (OA/VAC-treated patients)",
    "Giant ventral hernias where primary closure is impossible",
    "Failed prior hernia repairs",
]
for i in indic:
    story.append(bullet(i))
story.append(Spacer(1, 4))

# Preoperative optimisation
story.append(Paragraph(b("Preoperative Optimisation (MANDATORY before elective AWR)"), h2_style))
opt_data = [
    [Paragraph(b("Factor"), cell_hdr), Paragraph(b("Target / Action"), cell_hdr)],
    [Paragraph("Smoking", cell_body), Paragraph("Cessation ≥ 4–6 weeks; urine cotinine screening", cell_body)],
    [Paragraph("Diabetes", cell_body), Paragraph("HbA1c < 7%; tight perioperative glucose control", cell_body)],
    [Paragraph("Obesity", cell_body), Paragraph("BMI < 35 preferred; bariatric surgery if severe", cell_body)],
    [Paragraph("Nutrition", cell_body), Paragraph("Prealbumin > 20 mg/dL; protein-calorie optimisation", cell_body)],
    [Paragraph("Infection", cell_body), Paragraph("Clear all active infection/fistula before elective repair", cell_body)],
    [Paragraph("MRSA", cell_body), Paragraph("Decolonise carriers; use vancomycin prophylaxis periop", cell_body)],
    [Paragraph("CT scan", cell_body), Paragraph("Essential preoperative mapping of defect, residual muscle, vessels", cell_body)],
]
opt_tbl = Table(opt_data, colWidths=[3.5*cm, 14*cm])
opt_tbl.setStyle(TableStyle([
    ("BACKGROUND",     (0,0), (-1,0), NAVY),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [LGREY, WHITE]),
    ("GRID",           (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",         (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",     (0,0), (-1,-1), 3),
    ("BOTTOMPADDING",  (0,0), (-1,-1), 3),
    ("LEFTPADDING",    (0,0), (-1,-1), 5),
    ("ROUNDEDCORNERS", [3]),
]))
story += [opt_tbl, Spacer(1, 5)]

# Mesh position table
story.append(Paragraph(b("Mesh Position Options in AWR"), h2_style))
mesh_data = [
    [Paragraph(b("Position"), cell_hdr),
     Paragraph(b("Location"), cell_hdr),
     Paragraph(b("Advantages"), cell_hdr),
     Paragraph(b("Disadvantages"), cell_hdr)],
    [Paragraph("Onlay", cell_body_c),
     Paragraph("Anterior to anterior rectus sheath", cell_body),
     Paragraph("Easy access; no bowel contact", cell_body),
     Paragraph("High SSO, wound complications, recurrence", cell_body)],
    [Paragraph("Inlay\n(Bridge)", cell_body_c),
     Paragraph("Defect edge to edge — no fascial closure", cell_body),
     Paragraph("Used when fascia cannot be approximated", cell_body),
     Paragraph(red("Highest recurrence; worst functional results"), cell_body)],
    [Paragraph("Sublay\n(Retrorectus)", cell_body_c),
     Paragraph("Posterior to rectus, anterior to posterior sheath (Rives-Stoppa)", cell_body),
     Paragraph("Protected by posterior sheath; large overlap; preferred", cell_body),
     Paragraph("More dissection; longer OR time", cell_body)],
    [Paragraph("IPOM\n(intraperitoneal)", cell_body_c),
     Paragraph("Inside peritoneal cavity", cell_body),
     Paragraph("Simple laparoscopic access", cell_body),
     Paragraph("Bowel adhesion/erosion; anti-adhesive coating needed", cell_body)],
    [Paragraph("Preperitoneal", cell_body_c),
     Paragraph("Between peritoneum and posterior sheath", cell_body),
     Paragraph("Good overlap, away from bowel", cell_body),
     Paragraph("Difficult access in scarred fields", cell_body)],
]
mesh_tbl = Table(mesh_data, colWidths=[2.3*cm, 4.0*cm, 5.2*cm, 6.0*cm])
mesh_tbl.setStyle(TableStyle([
    ("BACKGROUND",     (0,0), (-1,0), AMBER),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [LGREY, WHITE]),
    ("GRID",           (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",         (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",     (0,0), (-1,-1), 3),
    ("BOTTOMPADDING",  (0,0), (-1,-1), 3),
    ("LEFTPADDING",    (0,0), (-1,-1), 4),
    ("ROUNDEDCORNERS", [3]),
]))
story += [mesh_tbl, Spacer(1, 5)]

story.append(Paragraph(
    f'{b("Rives-Stoppa-Wantz repair")} (retrorectus sublay) and {b("TAR")} (transversus abdominis release) '
    f'are the preferred techniques in AWR — both restore a {b("dynamic abdominal wall")} with mesh in the '
    f'retromuscular plane, outside the peritoneal cavity. (Sabiston 21e, Ch. 37)',
    note_style))

# ── PAGE BREAK ──────────────────────────────────────────────────────────────
story.append(PageBreak())

# ============================================================
#  PAGE 3 — COMPONENT SEPARATION TECHNIQUE
# ============================================================
story.append(title_tbl)
story.append(Spacer(1, 8))
story.append(section_header("4. COMPONENT SEPARATION TECHNIQUE IN VENTRAL HERNIA REPAIR"))
story.append(Spacer(1, 4))

story.append(Paragraph(
    f"{b('Definition:')} Component separation = creation of myofascial advancement flaps to allow "
    f"medialization of the rectus muscles and tension-free midline fascial closure in large ventral hernias. "
    f"Originally described by {b('Ramirez et al. in 1990')} (anterior technique).",
    body_style))
story.append(Spacer(1, 4))

# Overview comparison table
story.append(Paragraph(b("Anterior vs Posterior Component Separation — At-a-Glance"), h2_style))
comp_data = [
    [Paragraph(b("Feature"), cell_hdr),
     Paragraph(b("Anterior (EOR/ACS)"), cell_hdr),
     Paragraph(b("Posterior (TAR)"), cell_hdr)],
    [Paragraph("Layer released", cell_body_c),
     Paragraph("External oblique muscle/aponeurosis", cell_body),
     Paragraph("Transversus abdominis muscle", cell_body)],
    [Paragraph("First described", cell_body_c),
     Paragraph("Ramirez, 1990", cell_body),
     Paragraph("Novitsky, 2012", cell_body)],
    [Paragraph("Advancement per side", cell_body_c),
     Paragraph("~3–10 cm (debated)", cell_body),
     Paragraph("~5–8 cm additional (retromuscular space)", cell_body)],
    [Paragraph("Mesh position", cell_body_c),
     Paragraph("Onlay / sublay", cell_body),
     Paragraph("Retromuscular (retrorectus/pre-peritoneal)", cell_body)],
    [Paragraph("Wound morbidity", cell_body_c),
     Paragraph(red("High (large skin flaps → devascularisation)"), cell_body),
     Paragraph(grn("Lower (no large skin flaps)"), cell_body)],
    [Paragraph("Perforator preservation", cell_body_c),
     Paragraph("Standard: disrupted. Endoscopic: preserved", cell_body),
     Paragraph(grn("Preserved"), cell_body)],
    [Paragraph("Best for", cell_body_c),
     Paragraph("Moderate defects; limited mesh experience", cell_body),
     Paragraph("Large/giant/recurrent; contaminated fields", cell_body)],
]
comp_tbl = Table(comp_data, colWidths=[3.5*cm, 7.0*cm, 7.0*cm])
comp_tbl.setStyle(TableStyle([
    ("BACKGROUND",     (0,0), (-1,0), PURPLE),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [LGREY, WHITE]),
    ("GRID",           (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",         (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",     (0,0), (-1,-1), 4),
    ("BOTTOMPADDING",  (0,0), (-1,-1), 4),
    ("LEFTPADDING",    (0,0), (-1,-1), 4),
    ("ROUNDEDCORNERS", [3]),
]))
story += [comp_tbl, Spacer(1, 5)]

# ANTERIOR - step by step
story.append(Paragraph(b("A. Anterior Component Separation (Ramirez Technique) — Step by Step"), h2_style))
ant_steps = [
    f"{b('Incision:')} Midline laparotomy; reduce hernia sac; lyse adhesions to anterior abdominal wall.",
    f"{b('Skin flaps:')} Develop subcutaneous flaps between anterior rectus fascia and subcutaneous fat, "
    f"extending laterally to the {b('linea semilunaris')} bilaterally.",
    f"{b('External oblique release:')} Incise the external oblique aponeurosis {b('2 cm lateral to the linea semilunaris')}. "
    f"Extend superiorly over the rib cage and inferiorly to the inguinal ligament.",
    f"{b('Develop plane:')} Open the avascular plane between external oblique and internal oblique muscles.",
    f"{b('Posterior sheath:')} Optionally incise posterior rectus sheath at linea alba edge for additional release.",
    f"{b('Fascial closure:')} Reapproximate the linea alba with running slow-absorbable (PDS) or permanent suture; "
    f"defects up to 10–20 cm can be closed.",
    f"{b('Mesh reinforcement:')} Place mesh (typically onlay or sublay) over the repair with ≥ 5 cm overlap.",
    f"{b('Drains:')} Subcutaneous drains in the large skin flap spaces (high seroma/SSO risk!).",
    f"{b('Endoscopic modification (eMST):')} Avoids large skin flaps; tunnels under the subcutaneous fat to "
    f"release external oblique — preserves periumbilical perforators, reduces wound morbidity.",
]
for s in ant_steps:
    story.append(bullet(s))
story.append(Spacer(1, 5))

# POSTERIOR — step by step
story.append(Paragraph(b("B. Posterior Component Separation with TAR (Novitsky/Rives-Stoppa) — Step by Step"), h2_style))
post_steps = [
    f"{b('Incision:')} Midline laparotomy; reduce hernia; enter and develop the retrorectus space bilaterally.",
    f"{b('Retrorectus dissection:')} Develop the plane between posterior rectus sheath and rectus muscle from "
    f"xiphoid to pubis and laterally to the linea semilunaris.",
    f"{b('TAR (Transversus Abdominis Release):')} At the lateral edge of the rectus, the {b('posterior rectus sheath')} "
    f"(composed partly by TAM) is incised. The transversus abdominis muscle is divided, opening the "
    f"{b('preperitoneal/retroperitoneal space')} — a continuous avascular plane extending far laterally.",
    f"{b('Lateral dissection:')} This plane is developed lateral to the epigastric vessels, beneath the "
    f"neurovascular bundles (T7–L1); preserving these maintains the innervation of the rectus muscle.",
    f"{b('Posterior closure:')} Posterior rectus sheath + peritoneum is closed as one layer with running absorbable suture, "
    f"creating a large retromuscular pocket for mesh.",
    f"{b('Mesh placement:')} A {b('large lightweight synthetic mesh')} (e.g. 30×30 cm) is placed in the retromuscular "
    f"space; {b('no fixation sutures needed')} — intraabdominal pressure holds it.",
    f"{b('Anterior closure:')} The linea alba is re-approximated with continuous slowly-absorbable suture.",
    f"{b('No large skin flaps:')} SSO rates significantly lower than anterior component separation.",
]
for s in post_steps:
    story.append(bullet(s))
story.append(Spacer(1, 5))

# Advancement amounts (key table)
story.append(Paragraph(b("Expected Fascial Advancement per Side (Sabiston 21e / Novitsky data)"), h2_style))
adv_data = [
    [Paragraph(b("Manoeuvre"), cell_hdr),
     Paragraph(b("Advancement (cm/side)"), cell_hdr),
     Paragraph(b("Total potential closure"), cell_hdr)],
    [Paragraph("Posterior rectus sheath release alone", cell_body),
     Paragraph("1–2 cm", cell_body_c),
     Paragraph("~2–4 cm", cell_body_c)],
    [Paragraph("Anterior CS (external oblique release)", cell_body),
     Paragraph("3–10 cm", cell_body_c),
     Paragraph("~6–20 cm", cell_body_c)],
    [Paragraph("TAR (posterior CS)", cell_body),
     Paragraph("Additional 3–5 cm on top of retrorectus", cell_body_c),
     Paragraph("~10–20+ cm total", cell_body_c)],
]
adv_tbl = Table(adv_data, colWidths=[7.5*cm, 4.5*cm, 5.5*cm])
adv_tbl.setStyle(TableStyle([
    ("BACKGROUND",     (0,0), (-1,0), TEAL),
    ("ROWBACKGROUNDS", (0,1), (-1,-1), [LGREY, WHITE]),
    ("GRID",           (0,0), (-1,-1), 0.4, MGREY),
    ("VALIGN",         (0,0), (-1,-1), "MIDDLE"),
    ("TOPPADDING",     (0,0), (-1,-1), 4),
    ("BOTTOMPADDING",  (0,0), (-1,-1), 4),
    ("LEFTPADDING",    (0,0), (-1,-1), 5),
    ("ROUNDEDCORNERS", [3]),
]))
story += [adv_tbl, Spacer(1, 5)]

# Final mnemonic
mn2_data = [[Paragraph(
    f'{b("MNEMONIC — Component Separation Steps")} ({grn(b("\"SEEDS-M\""))})<br/>'
    f'{grn("S")}kin flaps / {grn("E")}xternal oblique incised 2 cm lateral to semilunar line / '
    f'{grn("E")}xtend from rib to inguinal ligament / {grn("D")}evelop EO-IO plane / '
    f'{grn("S")}uture fascia / {grn("M")}esh reinforcement<br/>'
    f'<br/>'
    f'{b("TAR mnemonic")} ({grn(b("\"RTTPCM\""))}): '
    f'{grn("R")}etrorectus → {grn("T")}AR (transversus divided) → {grn("T")}unnel laterally → '
    f'{grn("P")}osterior sheath closed → {grn("C")}olossal mesh placed → {grn("M")}idline closed',
    mnemonic_style)]]
mn2_tbl = Table(mn2_data, colWidths=[17.5*cm])
mn2_tbl.setStyle(TableStyle([
    ("BACKGROUND",    (0,0), (-1,-1), colors.HexColor("#F0FFF0")),
    ("BOX",           (0,0), (-1,-1), 1, GREEN),
    ("TOPPADDING",    (0,0), (-1,-1), 6),
    ("BOTTOMPADDING", (0,0), (-1,-1), 6),
    ("LEFTPADDING",   (0,0), (-1,-1), 8),
    ("ROUNDEDCORNERS",[4]),
]))
story += [mn2_tbl, Spacer(1, 5)]

# Complications
story.append(Paragraph(b("Complications of Component Separation"), h2_style))
comp_c = [
    f"{b('Wound complications:')} Seroma (30–50%), wound infection, skin flap necrosis — especially with anterior CS",
    f"{b('Hernia recurrence:')} Lower with posterior/TAR + mesh vs anterior CS alone",
    f"{b('Denervation:')} TAR risks lateral cutaneous nerve injury if dissection goes too far; anterior CS risks flap ischaemia",
    f"{b('Mesh infection:')} Synthetic mesh in contaminated field — consider biological mesh (acellular dermal matrix)",
    f"{b('Enterotomy:')} Adhesiolysis risk; bowel resection may be needed",
]
for c in comp_c:
    story.append(bullet(c))

story.append(Spacer(1, 6))
story.append(Paragraph(
    f"Sources: Sabiston Textbook of Surgery 21e (Ch. 37 Abdominal Wall, Ch. 56 Thorax/Diaphragm) • "
    f"Bailey & Love's Short Practice of Surgery 28e • Current Surgical Therapy 14e (Novitsky et al.) • "
    f"Schwartz Principles of Surgery 11e • Fischer's Mastery of Surgery 8e",
    S("Footer", fontSize=7, textColor=colors.grey, alignment=TA_CENTER)))

# ── BUILD ────────────────────────────────────────────────────────────────────
doc.build(story)
print("PDF generated:", OUTPUT)
Running Command

cd /tmp/workspace/hernia-notes && python generate_pdf.py 2>&1

Running Command

ls -lh /tmp/workspace/hernia-notes/Hernia_Surgery_Notes.pdf

Your 3-page quick-reference PDF is ready:

Hernia Surgery Notes

PDF Document · PDF


Here is a full summary of what's covered inside:

PAGE 1 — Classification of Diaphragmatic Hernias

TypeNameSac?Key Point
ISliding hiatus herniaYes95%; GOJ slides up; GOR symptoms
IIPara-oesophageal (rolling)Yes5%; GOJ fixed; fundus rolls beside it; strangulation risk
IIIMixed (sliding + rolling)YesMost common PEH type seen in practice
IVIntrathoracic stomachYesLarge defect; volvulus risk; urgent repair
CDH — BochdalekPosterolateralNo75–90% CDH; left-sided; neonatal respiratory distress
CDH — MorgagniAnterior/parasternalYes2–3%; right-sided; often diagnosed incidentally in adults
TraumaticPost-traumaticNoBlunt/penetrating; left >right; three phases: Acute/Latent/Obstructive
Mnemonic: "Slides, Rolls, Mixes, Huge" = Types I–IV; "Big, Anterior, Trauma" = Bochdalek / Morgagni / Traumatic; Left > Right for both Bochdalek and traumatic (liver protects right).

PAGE 1–2 — Post-Traumatic Diaphragmatic Hernia: Surgical Management

Three clinical phases:
  • Acute - at time of injury; transabdominal approach; control hemorrhage first
  • Latent - weeks to years; elective; laparoscopic preferred
  • Obstructive - strangulated viscera; emergency laparotomy
Key operative steps (transabdominal):
  1. Midline laparotomy / left subcostal
  2. Explore and control associated injuries first (damage control priority)
  3. Reduce herniated contents from chest; assess viability
  4. Intercostal drain for haemothorax
  5. Trim defect edges
  6. Primary repair - interrupted non-absorbable sutures (Prolene 0/1-0), figure-of-8 or horizontal mattress
  7. Mesh patch - if large, chronic, or fibrotic defect
  8. Thoracoabdominal approach for right-sided or densely adherent injuries

PAGE 2 — Abdominal Wall Reconstruction (AWR)

AWR = restoration of musculofascial continuity with medialization of rectus muscles. Goals: (1) restore dynamic wall, (2) tension-free fascial closure, (3) adequate mesh reinforcement, (4) soft-tissue coverage.
Mesh positions ranked:
  • Inlay/bridge = highest recurrence (avoid if possible)
  • Onlay = easy but high wound morbidity
  • Retrorectus (sublay) = preferred - Rives-Stoppa-Wantz technique
  • IPOM = laparoscopic but bowel contact risk
  • TAR = best for large/complex/contaminated cases
Preop optimisation targets: Smoking stopped ≥6 weeks; HbA1c <7; BMI <35; prealbumin >20; active infection cleared; CT scan mandatory.

PAGE 3 — Component Separation Technique

FeatureAnterior CS (Ramirez 1990)Posterior CS / TAR (Novitsky 2012)
Layer releasedExternal oblique aponeurosisTransversus abdominis muscle
Advancement/side~3–10 cm~5–8 cm additional
Wound morbidityHigh (large skin flaps)Lower (no large flaps)
Mesh positionOnlay/sublayRetromuscular - preferred
Anterior CS steps (mnemonic "SEEDS-M"): Skin flaps → External oblique incised 2 cm lateral to semilunar line → Extend rib-to-inguinal ligament → Develop EO-IO plane → Suture fascia midline → Mesh reinforcement.
TAR steps (mnemonic "RTTPCM"): Retrorectus dissection → TAR (transversus divided at lateral rectus edge) → Tunnel laterally in preperitoneal plane → Posterior sheath closed → Colossal lightweight mesh placed retromuscularly → Midline (anterior) closed.

Sources: Sabiston 21e, Bailey & Love 28e, Current Surgical Therapy 14e (Novitsky et al.), Schwartz 11e, Fischer's Mastery 8e
This is a shared conversation. Sign in to Orris to start your own chat.