Generate a photo for me a 15 marks answer on detailed answer on effect on cpb on respiratory system make sure you add content from Glen P gravlee book or Christina t mora or mohammed book I want the answer to look like the uploaded photo format n to fill two a3 sheet sides Add diagrams if necessary go in detail on the topic I want to get full marks when I present this in my exam make sure to add everyyy single thing that my invigilator would want. remove the reference n points to remember n give actual important content Add important diagrams if necessary .i have uploaded an example for u r references
ls -la /tmp/workspace/ 2>/dev/null || mkdir -p /tmp/workspace/cpb-respiratory && echo "workspace ready"
mkdir -p /tmp/workspace/cpb-respiratory && python3 << 'PYEOF' from PIL import Image, ImageDraw, ImageFont import os # A3 at 150 DPI = 1754 x 2480 px (portrait) # We want 2 A3 pages side by side as landscape = 3508 x 2480 px W, H = 3508, 2480 img = Image.new('RGB', (W, H), color='#F9F8F2') draw = ImageDraw.Draw(img) # Test that PIL works draw.rectangle([10,10,100,100], outline='#C02F2F', width=3) img.save('/tmp/workspace/cpb-respiratory/test.png') print("PIL test OK, image size:", img.size) PYEOF
python3 << 'PYEOF' from PIL import Image, ImageDraw, ImageFont import textwrap, os # ─── Canvas ─────────────────────────────────────────────────────────────────── W, H = 3508, 2480 # 2 × A3 landscape at 150 DPI MARGIN = 28 GAP = 10 BG = '#F9F8F2' RED = '#C02F2F' DARK = '#1E1E1E' BLUE = '#3A6EA5' LIGHT_BLUE = '#EAF0F8' LIGHT_RED = '#FDF0EF' img = Image.new('RGB', (W, H), BG) draw = ImageDraw.Draw(img) # ─── Fonts ──────────────────────────────────────────────────────────────────── def load_font(size, bold=False): paths = [ f'/usr/share/fonts/truetype/dejavu/DejaVuSans{"Bold" if bold else ""}.ttf', f'/usr/share/fonts/truetype/liberation/LiberationSans-{"Bold" if bold else "Regular"}.ttf', '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', ] for p in paths: if os.path.exists(p): return ImageFont.truetype(p, size) return ImageFont.load_default() F_TITLE = load_font(52, bold=True) F_HEAD = load_font(26, bold=True) F_SUB = load_font(21, bold=True) F_BODY = load_font(18) F_TINY = load_font(15) F_LABEL = load_font(16, bold=True) # ─── Helpers ────────────────────────────────────────────────────────────────── def box(x, y, w, h, fill=BG, outline=DARK, lw=2): draw.rectangle([x, y, x+w, y+h], fill=fill, outline=outline, width=lw) def red_header(x, y, w, text, font=F_HEAD): draw.rectangle([x, y, x+w, y+28], fill=RED) draw.text((x + w//2, y+14), text, font=font, fill='white', anchor='mm') def section_title(x, y, w, num, title): """Draws Roman-numeral section header inside box""" full = f'{num}. {title}' draw.text((x + w//2, y+13), full, font=F_HEAD, fill=RED, anchor='mm') draw.line([x+8, y+26, x+w-8, y+26], fill=RED, width=1) def wrap_text(draw, text, x, y, max_w, font=F_BODY, fill=DARK, line_h=22): """Word-wrap and draw text. Returns final y.""" # rough char width sample = draw.textlength('A', font=font) chars_per_line = max(1, int(max_w / max(1, sample))) lines = [] for para in text.split('\n'): if para.strip() == '': lines.append('') else: wrapped = textwrap.wrap(para, width=chars_per_line) lines.extend(wrapped if wrapped else ['']) cy = y for line in lines: draw.text((x, cy), line, font=font, fill=fill) cy += line_h return cy def bullet_list(draw, items, x, y, max_w, font=F_BODY, fill=DARK, lh=22, bullet='•'): cy = y sample = draw.textlength('A', font=font) chars = max(1, int((max_w - 16) / max(1, sample))) for item in items: lines = textwrap.wrap(item, width=chars) for i, line in enumerate(lines): prefix = f'{bullet} ' if i == 0 else ' ' draw.text((x, cy), prefix + line, font=font, fill=fill) cy += lh return cy def draw_arrow(x1, y1, x2, y2, color=DARK, width=2): draw.line([x1, y1, x2, y2], fill=color, width=width) # arrowhead import math angle = math.atan2(y2-y1, x2-x1) size = 10 for a in [angle + 2.5, angle - 2.5]: draw.line([x2, y2, int(x2 - size*math.cos(a)), int(y2 - size*math.sin(a))], fill=color, width=width) # ════════════════════════════════════════════════════════════════════════════ # MAIN TITLE # ════════════════════════════════════════════════════════════════════════════ title_text = '✦ EFFECTS OF CARDIOPULMONARY BYPASS (CPB) ON THE RESPIRATORY SYSTEM ✦' draw.text((W//2, 38), title_text, font=F_TITLE, fill=RED, anchor='mm') draw.line([MARGIN, 62, W-MARGIN, 62], fill=RED, width=2) # ════════════════════════════════════════════════════════════════════════════ # PAGE 1 (left half) x: 0 → 1754 # ════════════════════════════════════════════════════════════════════════════ P1_X = MARGIN P1_W = W//2 - MARGIN*2 - GAP//2 TOP_Y = 72 # Column widths for page 1: 3 columns C1W = (P1_W - 2*GAP) // 3 C2W = C1W C3W = P1_W - C1W - C2W - 2*GAP # ── SECTION I: DEFINITION ────────────────────────────────────────────────── bx, by, bw, bh = P1_X, TOP_Y, C1W, 290 box(bx, by, bw, bh) section_title(bx, by+4, bw, 'I', 'DEFINITION OF CPB') cy = by + 34 content = ( "Cardiopulmonary bypass (CPB) is a technique that temporarily assumes\n" "the function of the heart and lungs during cardiac surgery.\n" "A heart-lung machine:\n" "• Oxygenates blood\n" "• Removes CO₂\n" "• Maintains systemic circulation\n" "This allows the surgeon to operate on a still, bloodless heart.\n" "The lungs are bypassed — NO pulmonary blood flow occurs during CPB.\n" "Duration: typically 60–120 min (longer → more lung injury)" ) wrap_text(draw, content, bx+8, cy, bw-16, font=F_BODY, lh=21) # ── SECTION II: WHY LUNGS ARE VULNERABLE ────────────────────────────────── bx2, by2, bw2, bh2 = P1_X + C1W + GAP, TOP_Y, C2W, 290 box(bx2, by2, bw2, bh2) section_title(bx2, by2+4, bw2, 'II', 'WHY LUNGS VULNERABLE') cy2 = by2 + 34 items2 = [ "No bronchial artery flow during CPB", "Lungs are atelectatic & deflated", "Pulmonary circulation excluded from bypass", "No cardioplegia equivalent for lungs", "Lung is a metabolic organ — cannot clear stress hormones", "Ischemia-reperfusion injury on weaning", "Non-endothelialised pump surfaces activate blood", "Inflammatory mediators accumulate", ] bullet_list(draw, items2, bx2+8, cy2, bw2-16, font=F_BODY, lh=20) # ── SECTION III: OVERVIEW DIAGRAM (Mechanisms) ─────────────────────────── bx3, by3, bw3, bh3 = P1_X + C1W + C2W + 2*GAP, TOP_Y, C3W, 290 box(bx3, by3, bw3, bh3) section_title(bx3, by3+4, bw3, 'III', 'PATHWAYS OF INJURY') # simple flow diagram cy3 = by3 + 36 items3 = [ "CPB Circuit", "↓", "Blood-surface contact", "↓", "Complement activation", "(C3a, C5a)", "↓", "Neutrophil activation", "& degranulation", "↓", "Release of: ROS, proteases,", "cytokines (IL-1β, IL-6, TNF-α)", "↓", "Endothelial damage", "Capillary leak", "↓", "LUNG INJURY", ] fy = cy3 for line in items3: col = RED if line in ('CPB Circuit', 'LUNG INJURY') else (BLUE if line.startswith('↓') else DARK) fw = F_SUB if line in ('CPB Circuit', 'LUNG INJURY') else F_BODY draw.text((bx3 + bw3//2, fy), line, font=fw, fill=col, anchor='mm') fy += 14 # ── SECTION IV: INFLAMMATORY RESPONSE ──────────────────────────────────── row2_y = TOP_Y + 290 + GAP bx4, by4 = P1_X, row2_y bw4, bh4 = C1W + C2W + GAP, 310 box(bx4, by4, bw4, bh4) section_title(bx4, by4+4, bw4, 'IV', 'INFLAMMATORY RESPONSE (SIRS)') cy4 = by4 + 34 # 2-column layout inside this box col_w = (bw4 - 24) // 2 # Left sub-column draw.text((bx4+8, cy4), 'Triggers:', font=F_SUB, fill=RED) cy4a = cy4 + 22 items4a = [ "Blood-foreign surface contact", "Hypothermia → complement", "Endotoxin release (gut ischaemia)", "Ischaemia-reperfusion on weaning", "Surgical trauma & pericardial blood", "Non-pulsatile flow", "Hemodilution", ] bullet_list(draw, items4a, bx4+8, cy4a, col_w-8, font=F_BODY, lh=20) # Right sub-column rx4 = bx4 + col_w + 14 draw.text((rx4, cy4), 'Key Mediators:', font=F_SUB, fill=RED) cy4b = cy4 + 22 items4b = [ "C3a, C5a — anaphylatoxins", "IL-1β, IL-6, IL-8, TNF-α", "Neutrophil elastase", "Myeloperoxidase (MPO)", "Reactive oxygen species (ROS)", "Thromboxane A₂ → ↑PVR", "Platelet activating factor (PAF)", "Bradykinin → capillary leak", ] bullet_list(draw, items4b, rx4, cy4b, col_w-4, font=F_BODY, lh=20) # ── SECTION V: MECHANICAL EFFECTS ───────────────────────────────────────── bx5, by5 = P1_X + C1W + C2W + 2*GAP, row2_y bw5, bh5 = C3W, 310 box(bx5, by5, bw5, bh5) section_title(bx5, by5+4, bw5, 'V', 'MECHANICAL EFFECTS') cy5 = by5 + 34 items5 = [ "Lungs collapse (atelectasis) — ventilation stopped", "Loss of surfactant activity", "FRC ↓ → small airway closure", "V/Q mismatch → hypoxaemia", "Phrenic nerve palsy (cold cardioplegia)", "Diaphragm dysfunction post-op", "Pleural effusion (esp. left)", "Haemothorax / pneumothorax", "Chest wall compliance ↓ (sternotomy)", "Internal mammary harvest → more dysfunction", ] bullet_list(draw, items5, bx5+8, cy5, bw5-16, font=F_BODY, lh=20) # ── SECTION VI: ATELECTASIS (detailed) ───────────────────────────────────── row3_y = row2_y + 310 + GAP bx6, by6 = P1_X, row3_y bw6, bh6 = C1W + C2W + GAP, 310 box(bx6, by6, bw6, bh6) section_title(bx6, by6+4, bw6, 'VI', 'ATELECTASIS') cy6 = by6 + 34 # Draw simple lung diagram lx, ly = bx6 + 10, cy6 + 10 # Left lung outline draw.ellipse([lx, ly, lx+100, ly+160], outline=DARK, width=2) draw.ellipse([lx+8, ly+8, lx+92, ly+152], fill=LIGHT_RED, outline=None) draw.text((lx+50, ly+80), "ATEL-\nECTA-\nSIS", font=F_TINY, fill=RED, anchor='mm') # Right lung outline rx6 = lx + 115 draw.ellipse([rx6, ly, rx6+100, ly+160], outline=DARK, width=2) draw.ellipse([rx6+8, ly+8, rx6+92, ly+152], fill='#EAF8EA', outline=None) draw.text((rx6+50, ly+80), "NORMAL", font=F_TINY, fill='#2A6A2A', anchor='mm') draw.text((lx+50, ly+170), "Left", font=F_TINY, fill=DARK, anchor='mm') draw.text((rx6+50, ly+170), "Right", font=F_TINY, fill=DARK, anchor='mm') # Text alongside tx6 = lx + 240 draw.text((tx6, cy6+4), "Atelectasis post-CPB:", font=F_SUB, fill=RED) items6 = [ "Up to 50% of lung volume atelectatic", "Predominantly left lower lobe", "Causes: collapse during bypass, loss of surfactant, diaphragm paralysis", "Post-CABG: PaO₂ falls from ~75 to ~55 mmHg (nadir day 2)", "Shunt fraction: 3% pre-op → 19% post-op", "Lung volumes ↓ 30% post-CABG", "Takes weeks–months to return to baseline", "Detected by CXR: basal opacities, elevated hemidiaphragm", ] bullet_list(draw, items6, tx6, cy6+26, bw6 - (tx6 - bx6) - 8, font=F_BODY, lh=20) # ── SECTION VII: SURFACTANT CHANGES ──────────────────────────────────────── bx7, by7 = P1_X + C1W + C2W + 2*GAP, row3_y bw7, bh7 = C3W, 310 box(bx7, by7, bw7, bh7) section_title(bx7, by7+4, bw7, 'VII', 'SURFACTANT CHANGES') cy7 = by7 + 34 items7 = [ "CPB significantly reduces surfactant activity", "Type II pneumocyte dysfunction", "Hypothermia impairs surfactant recycling", "Pulmonary ischaemia → ↓ phospholipid synthesis", "Loss of surfactant → ↑ surface tension", "Alveolar instability → collapse", "FRC ↓ → airways close at end-expiration", "Treatment: PEEP, recruitment manoeuvres, early surfactant replacement in neonates", ] bullet_list(draw, items7, bx7+8, cy7, bw7-16, font=F_BODY, lh=20) # ── SECTION VIII: PULMONARY OEDEMA & CAPILLARY LEAK ───────────────────── row4_y = row3_y + 310 + GAP bx8, by8 = P1_X, row4_y bw8 = P1_W bh8 = H - row4_y - MARGIN box(bx8, by8, bw8, bh8) section_title(bx8, by8+4, bw8, 'VIII', 'PULMONARY OEDEMA & CAPILLARY LEAK') cy8 = by8 + 34 col8w = (bw8 - 24) // 3 # Col 1 draw.text((bx8+8, cy8), 'Mechanism:', font=F_SUB, fill=RED) items8a = [ "Haemodilution → ↓ oncotic pressure", "Capillary leak from inflammation", "↑ pulmonary vascular resistance (PVR)", "Hypothermic CPB → ↓ plasma proteins", "Water extravasation into extravascular space", "Re-perfusion on weaning → oedema", "Complement + neutrophils → alveolar membrane damage", ] bullet_list(draw, items8a, bx8+8, cy8+22, col8w-8, font=F_BODY, lh=20) # Col 2 cx8b = bx8 + col8w + 12 draw.text((cx8b, cy8), 'Clinical Features:', font=F_SUB, fill=RED) items8b = [ "Interstitial → alveolar oedema", "Reduced lung compliance", "↑ airway pressures on ventilator", "Hypoxaemia (↓ PaO₂ / ↑ FiO₂ req.)", "Crepitations on auscultation", "CXR: bilateral perihilar haziness", "Post-pump syndrome (severe form)", ] bullet_list(draw, items8b, cx8b, cy8+22, col8w-8, font=F_BODY, lh=20) # Col 3 cx8c = bx8 + 2*col8w + 20 draw.text((cx8c, cy8), 'Management:', font=F_SUB, fill=RED) items8c = [ "MUF (Modified Ultrafiltration) — most effective", "Conventional ultrafiltration during CPB", "Diuretics (furosemide) post-bypass", "PEEP (5–10 cmH₂O) on ventilator", "Prone positioning if severe", "Corticosteroids (methylprednisolone)", "Protease inhibitors (aprotinin)", ] bullet_list(draw, items8c, cx8c, cy8+22, col8w-8, font=F_BODY, lh=20) # ════════════════════════════════════════════════════════════════════════════ # PAGE 2 (right half) x: 1754 → 3508 # ════════════════════════════════════════════════════════════════════════════ P2_X = W//2 + MARGIN P2_W = W//2 - MARGIN*2 # 3 columns D1W = (P2_W - 2*GAP) // 3 D2W = D1W D3W = P2_W - D1W - D2W - 2*GAP # ── SECTION IX: V/Q MISMATCH ─────────────────────────────────────────────── bx9, by9 = P2_X, TOP_Y bw9, bh9 = D1W, 300 box(bx9, by9, bw9, bh9) section_title(bx9, by9+4, bw9, 'IX', 'V/Q MISMATCH') cy9 = by9 + 34 # mini V/Q diagram dia_x, dia_y = bx9+10, cy9+5 # Draw alveolus draw.ellipse([dia_x, dia_y, dia_x+80, dia_y+80], outline=DARK, width=2, fill='#E8F4FE') draw.text((dia_x+40, dia_y+40), "Alveolus", font=F_TINY, fill=DARK, anchor='mm') # Capillary draw.ellipse([dia_x+10, dia_y+90, dia_x+70, dia_y+130], outline=DARK, width=2, fill='#FEE8E8') draw.text((dia_x+40, dia_y+110), "Cap.", font=F_TINY, fill=DARK, anchor='mm') draw.line([dia_x+40, dia_y+80, dia_x+40, dia_y+90], fill=DARK, width=2) draw.text((dia_x+40, dia_y+145), "V/Q < 1 = SHUNT", font=F_TINY, fill=RED, anchor='mm') # Text tx9 = dia_x + 100 items9 = [ "Atelectatic units: perfused not ventilated (shunt)", "V/Q < 1 → hypoxaemia", "Shunt fraction rises from 3% → 19% post-CPB", "A-a gradient ↑ significantly", "Hypoxic pulmonary vasoconstriction (HPV) impaired by CPB", "Dead space ↑ if PVR elevated", "Corrected by: PEEP, lung recruitment, diuresis", ] bullet_list(draw, items9, tx9, cy9+5, bw9 - (tx9-bx9) - 8, font=F_BODY, lh=20) # ── SECTION X: GAS EXCHANGE CHANGES ────────────────────────────────────── bx10, by10 = P2_X + D1W + GAP, TOP_Y bw10, bh10 = D2W, 300 box(bx10, by10, bw10, bh10) section_title(bx10, by10+4, bw10, 'X', 'GAS EXCHANGE') cy10 = by10 + 34 items10 = [ "PaO₂ ↓: 75 mmHg pre-op → 55 mmHg day 2", "PaCO₂: may be ↓ (hyperventilation) or ↑ (if shunt severe)", "A-a gradient widens (normal: <15 mmHg)", "SaO₂ maintained by supplemental O₂ but FiO₂ req ↑", "DLCO (diffusion capacity) ↓ post-CABG", "Hypoxaemia worse with: longer CPB, hypothermia, IMA harvest", "PaO₂/FiO₂ ratio may fall <300 in pump lung", "CO₂ retention possible if weaning delayed", "Returns towards normal in 1–3 weeks", ] bullet_list(draw, items10, bx10+8, cy10, bw10-16, font=F_BODY, lh=20) # ── SECTION XI: PULMONARY MECHANICS ────────────────────────────────────── bx11, by11 = P2_X + D1W + D2W + 2*GAP, TOP_Y bw11, bh11 = D3W, 300 box(bx11, by11, bw11, bh11) section_title(bx11, by11+4, bw11, 'XI', 'PULMONARY MECHANICS') cy11 = by11 + 34 items11 = [ "Static compliance ↓", "Dynamic compliance ↓", "FRC ↓ — most important change", "TLC ↓ (all lung volumes reduced)", "FEV₁ ↓, FVC ↓ (restrictive pattern)", "Airway resistance ↑ (bronchospasm)", "Lung volumes return slowly — weeks", "Peak airway pressure ↑ on ventilator", "Work of breathing ↑", ] bullet_list(draw, items11, bx11+8, cy11, bw11-16, font=F_BODY, lh=20) # ── SECTION XII: PHRENIC NERVE & DIAPHRAGM ────────────────────────────── row2b_y = TOP_Y + 300 + GAP bx12, by12 = P2_X, row2b_y bw12, bh12 = D1W + D2W + GAP, 310 box(bx12, by12, bw12, bh12) section_title(bx12, by12+4, bw12, 'XII', 'PHRENIC NERVE PALSY & DIAPHRAGM DYSFUNCTION') cy12 = by12 + 34 # 2 columns col12 = (bw12 - 24) // 2 draw.text((bx12+8, cy12), 'Phrenic Nerve Palsy:', font=F_SUB, fill=RED) items12a = [ "Incidence: 20–70% after cardiac surgery", "Caused by cold cardioplegia (topical ice)", "Left phrenic more commonly affected", "Thermal injury from IMA harvesting", "Direct surgical trauma", "Results in unilateral diaphragm elevation", "Restrictive ventilatory defect", "Most recover in 6–12 months", ] bullet_list(draw, items12a, bx12+8, cy12+22, col12-8, font=F_BODY, lh=20) rx12 = bx12 + col12 + 14 draw.text((rx12, cy12), 'Diaphragm Dysfunction:', font=F_SUB, fill=RED) items12b = [ "Reduced transdiaphragmatic pressure", "Shift to rib-cage (paradoxical) breathing", "Inhibitory reflex via visceral sympathetic afferents", "Upper abdominal incision → ↓ phrenic drive", "FRC ↓ → postoperative hypoxaemia", "Aggravated by: pain, opioids, obesity, long CPB", "CPAP / incentive spirometry for recovery", ] bullet_list(draw, items12b, rx12, cy12+22, col12-8, font=F_BODY, lh=20) # ── SECTION XIII: PUMP LUNG (ALI/ARDS) ────────────────────────────────── bx13, by13 = P2_X + D1W + D2W + 2*GAP, row2b_y bw13, bh13 = D3W, 310 box(bx13, by13, bw13, bh13) section_title(bx13, by13+4, bw13, 'XIII', 'PUMP LUNG / ALI / ARDS') cy13 = by13 + 34 items13 = [ "Severe form of CPB lung injury", "Incidence ~2% after CPB", "PaO₂/FiO₂ < 300 (ALI) or <200 (ARDS)", "Bilateral infiltrates on CXR", "PCWP <18 mmHg (non-cardiogenic)", "Pathology: diffuse alveolar damage (DAD)", "Neutrophil sequestration in pulmonary vasculature", "High mortality: 50–80% in full ARDS", "Risk factors: long CPB, re-op, DHCA", "Treatment: protective ventilation (Vt 6 mL/kg), PEEP, prone", ] bullet_list(draw, items13, bx13+8, cy13, bw13-16, font=F_BODY, lh=20) # ── SECTION XIV: PULMONARY HYPERTENSION ────────────────────────────────── row3b_y = row2b_y + 310 + GAP bx14, by14 = P2_X, row3b_y bw14, bh14 = D1W, 310 box(bx14, by14, bw14, bh14) section_title(bx14, by14+4, bw14, 'XIV', 'PULMONARY HYPERTENSION POST-CPB') cy14 = by14 + 34 items14 = [ "PVR ↑ after CPB", "Thromboxane A₂ → vasoconstriction", "Endothelin-1 ↑ → sustained ↑PVR", "Serotonin release from platelets", "Complement activation (C5a)", "Loss of NO (endothelial dysfunction)", "Protamine administration → pulm. HTN", "RV afterload ↑ → RV failure risk", "Treatment: iNO (inhaled NO), sildenafil, milrinone", ] bullet_list(draw, items14, bx14+8, cy14, bw14-16, font=F_BODY, lh=20) # ── SECTION XV: BRONCHOSPASM ────────────────────────────────────────────── bx15, by15 = P2_X + D1W + GAP, row3b_y bw15, bh15 = D2W, 310 box(bx15, by15, bw15, bh15) section_title(bx15, by15+4, bw15, 'XV', 'BRONCHOSPASM & AIRWAY CHANGES') cy15 = by15 + 34 items15 = [ "Bronchoconstriction during/after CPB", "Complement-activated histamine release", "Protamine–heparin complexes → anaphylaxis", "Serotonin from platelet degranulation", "↑ airway reactivity in asthma/COPD", "Cold blood perfusing bronchial vasculature", "Humoral mediators (bradykinin, PGF₂α)", "Clinical: ↑ airway pressures, wheeze", "Treatment: bronchodilators (salbutamol, ipratropium)", "Deepened anaesthesia (volatile agents protective)", ] bullet_list(draw, items15, bx15+8, cy15, bw15-16, font=F_BODY, lh=20) # ── SECTION XVI: POSTOPERATIVE MANAGEMENT ──────────────────────────────── bx16, by16 = P2_X + D1W + D2W + 2*GAP, row3b_y bw16, bh16 = D3W, 310 box(bx16, by16, bw16, bh16) section_title(bx16, by16+4, bw16, 'XVI', 'POST-CPB RESPIRATORY MGT') cy16 = by16 + 34 items16 = [ "Ventilator: FiO₂ wean as tolerated", "PEEP: 5–8 cmH₂O routinely", "Tidal volume: 6–8 mL/kg IBW", "Early extubation protocols (fast-track)", "Incentive spirometry post-extubation", "Physiotherapy: postural drainage, cough", "Analgesia: ↓ splinting, ↑ effort", "Nebulised bronchodilators PRN", "MUF: reduces lung water in paediatrics", "Drain effusions if large", ] bullet_list(draw, items16, bx16+8, cy16, bw16-16, font=F_BODY, lh=20) # ── SECTION XVII: COMPARATIVE TABLE ───────────────────────────────────── row4b_y = row3b_y + 310 + GAP bx17, by17 = P2_X, row4b_y bw17 = P2_W bh17 = H - row4b_y - MARGIN box(bx17, by17, bw17, bh17) section_title(bx17, by17+4, bw17, 'XVII', 'SUMMARY TABLE: CPB RESPIRATORY EFFECTS') cy17 = by17 + 34 # Draw table cols = ['Parameter', 'Normal', 'After CPB', 'Clinical Significance'] col_widths = [bw17//5, bw17//6, bw17//6, bw17 - bw17//5 - bw17//6 - bw17//6 - 20] data = [ ['PaO₂ (room air)', '~90 mmHg', '~55 mmHg', 'Significant hypoxaemia — O₂ supplementation required'], ['A-a Gradient', '<15 mmHg', 'Markedly ↑', 'V/Q mismatch and shunting'], ['Lung Compliance', 'Normal', '↓ 30–50%', 'Stiffer lungs, ↑ ventilator pressures'], ['FRC', 'Normal', '↓ 15–30%', 'Small airway closure, atelectasis'], ['Shunt Fraction', '~3%', '~19%', 'Major contributor to hypoxaemia'], ['PVR', 'Normal', '↑', 'RV strain, potential RV failure'], ['Surfactant', 'Active', '↓ Activity', 'Alveolar instability, collapse'], ['Lung Volumes', 'Normal', '↓ 30%', 'Restrictive defect, prolonged recovery'], ] th = 24 tx17 = bx17 + 8 ty = cy17 # Header row cx_pos = tx17 for i, (col, cw) in enumerate(zip(cols, col_widths)): draw.rectangle([cx_pos, ty, cx_pos+cw, ty+th], fill=RED) draw.text((cx_pos + cw//2, ty+th//2), col, font=F_TINY, fill='white', anchor='mm') cx_pos += cw + 2 ty += th + 2 for ri, row in enumerate(data): fill_c = LIGHT_BLUE if ri % 2 == 0 else BG cx_pos = tx17 for i, (cell, cw) in enumerate(zip(row, col_widths)): draw.rectangle([cx_pos, ty, cx_pos+cw, ty+th], fill=fill_c, outline='#CCCCCC', width=1) wrapped = textwrap.wrap(cell, width=max(1, cw//9)) cell_text = wrapped[0] if wrapped else cell draw.text((cx_pos+4, ty+th//2), cell_text, font=F_TINY, fill=DARK, anchor='lm') cx_pos += cw + 2 ty += th + 2 # Save out_path = '/tmp/workspace/cpb-respiratory/CPB_Respiratory_A3x2.png' img.save(out_path, dpi=(150, 150)) print(f"Saved: {out_path} size={img.size}") PYEOF
python3 << 'PYEOF' from PIL import Image, ImageDraw, ImageFont import textwrap, os W, H = 3508, 2480 MARGIN = 28 GAP = 10 BG = '#F9F8F2' RED = '#C02F2F' DARK = '#1E1E1E' BLUE = '#3A6EA5' LIGHT_BLUE = '#EAF0F8' LIGHT_RED = '#FDF0EF' img = Image.new('RGB', (W, H), BG) draw = ImageDraw.Draw(img) def load_font(size, bold=False): paths = [ f'/usr/share/fonts/truetype/dejavu/DejaVuSans{"Bold" if bold else ""}.ttf', f'/usr/share/fonts/truetype/liberation/LiberationSans-{"Bold" if bold else "Regular"}.ttf', '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', ] for p in paths: if os.path.exists(p): return ImageFont.truetype(p, size) return ImageFont.load_default() F_TITLE = load_font(48, bold=True) F_HEAD = load_font(24, bold=True) F_SUB = load_font(19, bold=True) F_BODY = load_font(17) F_TINY = load_font(15) def box(x, y, w, h, fill=BG, outline=DARK, lw=2): draw.rectangle([x, y, x+w, y+h], fill=fill, outline=outline, width=lw) def section_title(x, y, w, num, title): draw.rectangle([x, y, x+w, y+26], fill=BG, outline=None) full = f'{num}. {title}' draw.text((x + w//2, y+13), full, font=F_HEAD, fill=RED, anchor='mm') draw.line([x+6, y+25, x+w-6, y+25], fill=RED, width=1) def wrap_text(draw, text, x, y, max_w, font=F_BODY, fill=DARK, line_h=21): sample = draw.textlength('A', font=font) chars_per_line = max(1, int(max_w / max(1, sample))) lines = [] for para in text.split('\n'): if para.strip() == '': lines.append('') else: wrapped = textwrap.wrap(para, width=chars_per_line) lines.extend(wrapped if wrapped else ['']) cy = y for line in lines: draw.text((x, cy), line, font=font, fill=fill) cy += line_h return cy def bullet_list(draw, items, x, y, max_w, font=F_BODY, fill=DARK, lh=21, bullet='•'): cy = y sample = draw.textlength('A', font=font) chars = max(1, int((max_w - 16) / max(1, sample))) for item in items: lines = textwrap.wrap(item, width=chars) for i, line in enumerate(lines): prefix = f'{bullet} ' if i == 0 else ' ' draw.text((x, cy), prefix + line, font=font, fill=fill) cy += lh return cy # MAIN TITLE draw.text((W//2, 36), '* EFFECTS OF CARDIOPULMONARY BYPASS (CPB) ON THE RESPIRATORY SYSTEM *', font=F_TITLE, fill=RED, anchor='mm') draw.line([MARGIN, 58, W-MARGIN, 58], fill=RED, width=2) TOP_Y = 66 # ─── PAGE 1 LAYOUT ─────────────────────────────────────────────────────────── P1_X = MARGIN P1_W = W//2 - MARGIN*2 - GAP//2 C1W = (P1_W - 2*GAP) // 3 C2W = C1W C3W = P1_W - C1W - C2W - 2*GAP # ROW 1 (height 280) R1H = 280 # S I: Definition x,y,w,h = P1_X, TOP_Y, C1W, R1H box(x,y,w,h) section_title(x,y,w,'I','DEFINITION OF CPB') cy=y+32 items=[ "Technique temporarily assuming heart & lung function during cardiac surgery", "Heart-lung machine: oxygenates blood, removes CO2, maintains circulation", "Lungs are BYPASSED — no pulmonary blood flow", "Ventilation is stopped during CPB", "Duration: typically 60–180 min", "Longer CPB = more severe lung injury", "3 phases: initiation, bypass, weaning", ] bullet_list(draw,items,x+8,cy,w-16,lh=20) # S II: Why lungs vulnerable x,y,w,h = P1_X+C1W+GAP, TOP_Y, C2W, R1H box(x,y,w,h) section_title(x,y,w,'II','WHY LUNGS VULNERABLE') cy=y+32 items=[ "No bronchial artery flow during CPB", "Pulmonary circulation excluded", "Deflated, atelectatic lungs", "No cardioplegia equivalent for lungs", "Lung cannot clear stress hormones", "Ischaemia–reperfusion injury on weaning", "Non-endothelialised pump surfaces activate blood", "Inflammatory cascade accumulates during bypass", ] bullet_list(draw,items,x+8,cy,w-16,lh=20) # S III: Mechanisms of injury x,y,w,h = P1_X+C1W+C2W+2*GAP, TOP_Y, C3W, R1H box(x,y,w,h) section_title(x,y,w,'III','2 MAIN PATHWAYS') cy=y+32 draw.text((x+w//2,cy), 'PATHWAY 1: INFLAMMATORY', font=F_SUB, fill=RED, anchor='mm') cy+=22 items_a=['Blood-surface contact', 'Complement activation (C3a, C5a)', 'Neutrophil activation & degranulation', 'Cytokine release (IL-1β, IL-6, TNF-α)', 'ROS, proteases → endothelial damage'] for it in items_a: draw.text((x+8,cy), '→ '+it, font=F_BODY, fill=DARK) cy+=19 cy+=4 draw.text((x+w//2,cy), 'PATHWAY 2: MECHANICAL', font=F_SUB, fill=BLUE, anchor='mm') cy+=22 items_b=['Surfactant loss', 'Atelectasis → V/Q mismatch', 'Loss of lung volumes, altered mechanics'] for it in items_b: draw.text((x+8,cy), '→ '+it, font=F_BODY, fill=DARK) cy+=19 # ROW 2 (height 300) R2_Y = TOP_Y + R1H + GAP R2H = 300 # S IV: Inflammatory mediators (wide, 2 cols) x,y,w,h = P1_X, R2_Y, C1W+C2W+GAP, R2H box(x,y,w,h) section_title(x,y,w,'IV','SYSTEMIC INFLAMMATORY RESPONSE (SIRS) TO CPB') cy=y+32 colw = (w-24)//2 draw.text((x+8,cy), 'Triggers:', font=F_SUB, fill=RED) items_t=['Blood contact with non-endothelialised surfaces (tubing, oxygenator)', 'Hypothermia → complement activation', 'Endotoxin release (gut ischaemia)', 'Ischaemia-reperfusion on weaning off bypass', 'Surgical trauma & pericardial blood re-infusion', 'Non-pulsatile flow → endothelial shear stress', 'Haemodilution → oncotic pressure'] bullet_list(draw,items_t,x+8,cy+22,colw-8,lh=20) rx=x+colw+14 draw.text((rx,cy), 'Key Mediators:', font=F_SUB, fill=RED) items_m=['C3a, C5a — anaphylatoxins, chemotaxis', 'IL-1β, IL-6, IL-8, TNF-α', 'Neutrophil elastase → alveolar damage', 'Myeloperoxidase (MPO)', 'Reactive oxygen species (ROS)', 'Thromboxane A₂ → ↑PVR, bronchoconstriction', 'Platelet activating factor (PAF)', 'Bradykinin → capillary leak'] bullet_list(draw,items_m,rx,cy+22,colw,lh=20) # S V: Mechanical effects x,y,w,h = P1_X+C1W+C2W+2*GAP, R2_Y, C3W, R2H box(x,y,w,h) section_title(x,y,w,'V','MECHANICAL EFFECTS') cy=y+32 items=['Lungs collapse — ventilation stopped', 'Loss of surfactant activity', 'FRC ↓ → small airway closure', 'V/Q mismatch → hypoxaemia', 'Phrenic nerve palsy (cold cardioplegia)', 'Diaphragm dysfunction post-op', 'Pleural effusion (esp. left side)', 'Chest wall compliance ↓ (sternotomy)', 'IMA harvest → more dysfunction', 'Haemothorax / pneumothorax (rare)'] bullet_list(draw,items,x+8,cy,w-16,lh=19) # ROW 3 (height 300) R3_Y = R2_Y + R2H + GAP R3H = 300 # S VI: Atelectasis with diagram x,y,w,h = P1_X, R3_Y, C1W+C2W+GAP, R3H box(x,y,w,h) section_title(x,y,w,'VI','ATELECTASIS POST-CPB') cy=y+32 # Draw left lung diagram (simple) lx,ly = x+8, cy+5 draw.ellipse([lx,ly,lx+85,ly+145], outline=DARK, width=2) draw.ellipse([lx+5,ly+5,lx+80,ly+140], fill=LIGHT_RED, outline=None) for ry in range(ly+10, ly+130, 12): draw.line([lx+10,ry,lx+75,ry], fill='#CCAAAA', width=1) draw.text((lx+42,ly+155), 'Atelectatic', font=F_TINY, fill=RED, anchor='mm') draw.text((lx+42,ly+168), '(Left lung CPB)', font=F_TINY, fill=RED, anchor='mm') rx6=lx+100 draw.ellipse([rx6,ly,rx6+85,ly+145], outline=DARK, width=2) draw.ellipse([rx6+5,ly+5,rx6+80,ly+140], fill='#E8F4E8', outline=None) for yy in range(ly+20,ly+130,25): draw.ellipse([rx6+15,yy,rx6+70,yy+18], outline='#77AA77', width=1) draw.text((rx6+42,ly+155), 'Normal', font=F_TINY, fill='#2A6A2A', anchor='mm') draw.text((rx6+42,ly+168), '(Aerated)', font=F_TINY, fill='#2A6A2A', anchor='mm') tx6=rx6+100 items6=['Up to 50% lung volume atelectatic', 'Predominantly left lower lobe', 'Post-CABG: PaO₂ falls ~75→55 mmHg (nadir day 2)', 'Shunt fraction: 3% pre-op → 19% post-op', 'Lung volumes ↓ by ~30%', 'Atelectasis persists for weeks', 'CXR: basal opacities, ↑ hemidiaphragm', 'Causes: no ventilation, surfactant loss, phrenic palsy'] bullet_list(draw,items6,tx6,cy+5,w-(tx6-x)-12,lh=19) # S VII: Surfactant x,y,w,h = P1_X+C1W+C2W+2*GAP, R3_Y, C3W, R3H box(x,y,w,h) section_title(x,y,w,'VII','SURFACTANT CHANGES') cy=y+32 # Draw alveolus with surfactant ax,ay = x+w//2, cy+55 draw.ellipse([ax-45,ay-40,ax+45,ay+40], outline=DARK, width=2, fill='#E8F4FE') draw.line([ax-45,ay,ax+45,ay], fill=BLUE, width=3) draw.text((ax,ay-20),'Air', font=F_TINY, fill=DARK, anchor='mm') draw.text((ax,ay+15),'Fluid', font=F_TINY, fill=BLUE, anchor='mm') draw.text((ax,ay), '— Surfactant Layer —', font=F_TINY, fill=BLUE, anchor='mm') cy2=ay+55 items7=['CPB significantly reduces surfactant activity', 'Type II pneumocyte dysfunction', 'Hypothermia → impaired phospholipid synthesis', 'Loss of surfactant → ↑ surface tension', 'Alveolar instability → collapse', 'FRC ↓ → airways close at expiration', 'Neonates: more severe, replacement needed'] bullet_list(draw,items7,x+8,cy2,w-16,lh=19) # ROW 4 (height — fill rest of page 1) R4_Y = R3_Y + R3H + GAP R4H = H - R4_Y - MARGIN # S VIII: Pulmonary oedema & capillary leak x,y,w,h = P1_X, R4_Y, P1_W, R4H box(x,y,w,h) section_title(x,y,w,'VIII','PULMONARY OEDEMA & CAPILLARY LEAK SYNDROME') cy=y+32 col8w = (w-24)//3 draw.text((x+8,cy), 'Mechanisms:', font=F_SUB, fill=RED) items8a=['Haemodilution → ↓ oncotic pressure', 'Capillary leak from complement/neutrophil activation', '↑ PVR → hydrostatic oedema', 'Hypothermic CPB → ↓ plasma proteins', 'Water extravasation into extravascular space', 'Reperfusion oedema on weaning', 'Alveolar-capillary membrane damage', 'Lung excluded — no lymphatic drainage during CPB'] bullet_list(draw,items8a,x+8,cy+22,col8w-8,lh=19) cx8b = x+col8w+12 draw.text((cx8b,cy), 'Clinical Features:', font=F_SUB, fill=RED) items8b=['Interstitial → alveolar oedema progression', 'Reduced lung compliance', '↑ Peak airway pressures', 'Hypoxaemia (↓PaO₂, ↑FiO₂ requirement)', 'Crepitations / crackles', 'CXR: bilateral perihilar haziness', 'Post-pump syndrome (severe form)', 'ARDS in 2% of cases (PaO₂/FiO₂ <200)'] bullet_list(draw,items8b,cx8b,cy+22,col8w-8,lh=19) cx8c = x+2*col8w+20 draw.text((cx8c,cy), 'Management:', font=F_SUB, fill=RED) items8c=['MUF (Modified Ultrafiltration) — MOST effective', 'Conventional ultrafiltration during CPB', 'Furosemide — post-bypass diuresis', 'PEEP 5–10 cmH₂O — alveolar recruitment', 'Prone positioning if severe ARDS', 'Corticosteroids (methylprednisolone)', 'Aprotinin / tranexamic acid pre-CPB', 'Minimise CPB duration'] bullet_list(draw,items8c,cx8c,cy+22,col8w-8,lh=19) # ─── PAGE 2 LAYOUT ─────────────────────────────────────────────────────────── P2_X = W//2 + MARGIN P2_W = W//2 - MARGIN*2 D1W = (P2_W - 2*GAP) // 3 D2W = D1W D3W = P2_W - D1W - D2W - 2*GAP # ROW A (height 290) RA_H = 290 # S IX: V/Q mismatch with diagram x,y,w,h = P2_X, TOP_Y, D1W, RA_H box(x,y,w,h) section_title(x,y,w,'IX','V/Q MISMATCH') cy=y+32 # V/Q diagram diax,diay=x+w//2, cy+65 draw.ellipse([diax-38,diay-55,diax+38,diay+5], outline=DARK, width=2, fill='#E8F4FE') draw.text((diax,diay-25),'Alveolus', font=F_TINY, fill=DARK, anchor='mm') draw.text((diax,diay-8),'(No Ventilation)', font=F_TINY, fill=RED, anchor='mm') draw.ellipse([diax-30,diay+10,diax+30,diay+48], outline=DARK, width=2, fill='#FEE8E8') draw.text((diax,diay+29),'Capillary', font=F_TINY, fill=DARK, anchor='mm') draw.line([diax,diay+5,diax,diay+10], fill=DARK, width=2) draw.text((diax,diay+58),'V=0, Q>0 → SHUNT', font=F_TINY, fill=RED, anchor='mm') cy2=diay+70 items9=['Atelectatic units: perfused not ventilated (shunt)', 'Shunt fraction 3%→19% post-CPB', 'A-a gradient markedly ↑', 'HPV impaired by CPB', 'Dead space ↑ if PVR elevated', 'Treated: PEEP, recruitment'] bullet_list(draw,items9,x+8,cy2,w-16,lh=18) # S X: Gas exchange x,y,w,h = P2_X+D1W+GAP, TOP_Y, D2W, RA_H box(x,y,w,h) section_title(x,y,w,'X','GAS EXCHANGE CHANGES') cy=y+32 items10=['PaO₂: ~90→55 mmHg (room air, nadir day 2)', 'A-a gradient: <15→markedly widened', 'SaO₂ maintained with ↑ FiO₂ requirement', 'DLCO (diffusion capacity) ↓ post-CABG', 'Shunt fraction ↑ (atelectasis/oedema)', 'PaO₂/FiO₂ ratio may fall <300 (ALI)', 'CO₂: normal or ↓ (hyperventilation)', 'Takes 1–3 weeks to approach baseline', 'Worse with: longer CPB, hypothermia, IMA harvest'] bullet_list(draw,items10,x+8,cy,w-16,lh=19) # S XI: Pulmonary mechanics x,y,w,h = P2_X+D1W+D2W+2*GAP, TOP_Y, D3W, RA_H box(x,y,w,h) section_title(x,y,w,'XI','PULMONARY MECHANICS') cy=y+32 items11=['Static compliance ↓ (30–50%)', 'Dynamic compliance ↓', 'FRC ↓ — most important change', 'TLC ↓, FEV₁ ↓, FVC ↓ (restrictive)', 'Airway resistance ↑ (bronchospasm)', 'Peak airway pressure ↑ on ventilator', 'Work of breathing ↑', 'Lung volumes return in weeks–months', 'CABG: ↓ 30% at 1 week post-op'] bullet_list(draw,items11,x+8,cy,w-16,lh=19) # ROW B (height 300) RB_Y = TOP_Y + RA_H + GAP RB_H = 300 # S XII: Phrenic nerve & diaphragm x,y,w,h = P2_X, RB_Y, D1W+D2W+GAP, RB_H box(x,y,w,h) section_title(x,y,w,'XII','PHRENIC NERVE PALSY & DIAPHRAGM DYSFUNCTION') cy=y+32 colw=(w-24)//2 draw.text((x+8,cy), 'Phrenic Nerve Palsy:', font=F_SUB, fill=RED) items12a=['Incidence: 20–70% after cardiac surgery', 'Caused by topical ice / cold cardioplegia', 'Left phrenic most commonly affected', 'Thermal injury from IMA harvesting', 'Direct surgical trauma to nerve', 'Unilateral diaphragm elevation on CXR', 'Restrictive ventilatory defect', 'Most recover in 6–12 months'] bullet_list(draw,items12a,x+8,cy+22,colw-8,lh=19) rx12=x+colw+14 draw.text((rx12,cy), 'Diaphragm Dysfunction:', font=F_SUB, fill=RED) items12b=['↓ Transdiaphragmatic pressure post-op', 'Shift to rib-cage breathing', 'Inhibitory reflex via visceral sympathetic afferents', 'Phrenic nerve output ↓ (not contractile failure)', 'FRC ↓ → postoperative hypoxaemia', 'Aggravated by: pain, opioids, obesity', 'Treatment: CPAP, incentive spirometry, epidural analgesia'] bullet_list(draw,items12b,rx12,cy+22,colw-8,lh=19) # S XIII: Pump lung / ARDS x,y,w,h = P2_X+D1W+D2W+2*GAP, RB_Y, D3W, RB_H box(x,y,w,h) section_title(x,y,w,'XIII','PUMP LUNG / ALI / ARDS') cy=y+32 items13=['Severe end of CPB-lung injury spectrum', 'Incidence ~2% after cardiac surgery', 'ALI: PaO₂/FiO₂ <300 mmHg', 'ARDS: PaO₂/FiO₂ <200 mmHg', 'Bilateral CXR infiltrates', 'PCWP <18 mmHg (non-cardiogenic)', 'Pathology: diffuse alveolar damage (DAD)', 'Neutrophil sequestration in pulm vasculature', 'Mortality: 50–80% in full ARDS', 'Rx: protective ventilation (Vt 6 mL/kg), PEEP, prone'] bullet_list(draw,items13,x+8,cy,w-16,lh=19) # ROW C (height 285) RC_Y = RB_Y + RB_H + GAP RC_H = 285 # S XIV: Pulmonary hypertension x,y,w,h = P2_X, RC_Y, D1W, RC_H box(x,y,w,h) section_title(x,y,w,'XIV','PULMONARY HTN POST-CPB') cy=y+32 items14=['PVR ↑ after bypass', 'Thromboxane A₂ → vasoconstriction', 'Endothelin-1 ↑ → sustained ↑PVR', 'C5a, serotonin from platelets', 'Loss of NO (endothelial dysfunction)', 'Protamine → anaphylaxis/pulm HTN', 'RV afterload ↑ → RV failure risk', 'Treatment: iNO, sildenafil, milrinone, PGI₂', 'Pre-existing PHT worsened by CPB'] bullet_list(draw,items14,x+8,cy,w-16,lh=19) # S XV: Bronchospasm x,y,w,h = P2_X+D1W+GAP, RC_Y, D2W, RC_H box(x,y,w,h) section_title(x,y,w,'XV','BRONCHOSPASM & AIRWAY') cy=y+32 items15=['Bronchoconstriction during/after CPB', 'Complement → histamine release', 'Protamine-heparin complexes → anaphylaxis', 'Serotonin from platelet degranulation', '↑ Airway reactivity in asthma/COPD patients', 'Bradykinin, PGF₂α → bronchoconstriction', 'Clinical: ↑ airway pressures, wheeze', 'Treatment: salbutamol nebuliser, ipratropium', 'Volatile agents (isoflurane) are bronchodilators', 'Deepened anaesthesia reduces reactivity'] bullet_list(draw,items15,x+8,cy,w-16,lh=18) # S XVI: Post-op management x,y,w,h = P2_X+D1W+D2W+2*GAP, RC_Y, D3W, RC_H box(x,y,w,h) section_title(x,y,w,'XVI','POST-CPB RESPIRATORY MGT') cy=y+32 items16=['FiO₂: wean as SpO₂/PaO₂ tolerate', 'PEEP: 5–8 cmH₂O routinely', 'Tidal volume: 6–8 mL/kg IBW', 'Early extubation (fast-track protocols)', 'Incentive spirometry post-extubation', 'Physiotherapy: cough assist, postural drainage', 'Adequate analgesia (↓ splinting)', 'MUF: reduces lung water in paediatrics', 'Nebulised bronchodilators PRN', 'Drain effusions if haemodynamically significant'] bullet_list(draw,items16,x+8,cy,w-16,lh=18) # ROW D (rest of page 2 — summary table) RD_Y = RC_Y + RC_H + GAP RD_H = H - RD_Y - MARGIN x,y,w,h = P2_X, RD_Y, P2_W, RD_H box(x,y,w,h) section_title(x,y,w,'XVII','SUMMARY TABLE: CPB EFFECTS ON RESPIRATORY SYSTEM') cy=y+32 TH = 26 cols = ['Parameter', 'Normal Value', 'Post-CPB', 'Mechanism', 'Clinical Significance'] col_ws = [w//7, w//8, w//8, w//4, w - w//7 - w//8 - w//8 - w//4 - 20] data = [ ['PaO₂ (room air)', '~90 mmHg', '~55 mmHg (day 2)', 'V/Q mismatch, shunt, oedema', 'Significant hypoxaemia — O₂ supplementation required'], ['A-a Gradient', '<15 mmHg', 'Markedly ↑', 'Shunting, diffusion impairment', 'Reflects severity of lung injury'], ['Static Compliance', '~100 mL/cmH₂O', '↓ 30–50%', 'Oedema, surfactant loss, atelectasis', 'Stiffer lungs, higher ventilator pressures'], ['FRC', 'Normal', '↓ 15–30%', 'Atelectasis, diaphragm dysfunction', 'Small airway closure, basal collapse'], ['Shunt Fraction', '~3%', '~19%', 'Atelectatic perfused units', 'Major cause of post-CPB hypoxaemia'], ['PVR', 'Normal', '↑', 'Thromboxane, endothelin, C5a', 'RV strain, potential RV failure'], ['Surfactant', 'Active', '↓ Activity', 'Type II pneumocyte dysfunction', 'Alveolar instability, progressive collapse'], ['Lung Volumes', 'Normal', '↓ ~30%', 'Atelectasis, pleural effusion', 'Restrictive defect — months to recover'], ] ty = cy cx0 = x+6 for i,col in enumerate(cols): cx1 = cx0 + sum(col_ws[:i]) + i*2 draw.rectangle([cx1,ty,cx1+col_ws[i],ty+TH], fill=RED) draw.text((cx1+col_ws[i]//2, ty+TH//2), col, font=F_TINY, fill='white', anchor='mm') ty+=TH+2 for ri,row in enumerate(data): fill_c = LIGHT_BLUE if ri%2==0 else BG cx0r = x+6 for i,(cell,cw) in enumerate(zip(row,col_ws)): cx1 = cx0r + sum(col_ws[:i]) + i*2 draw.rectangle([cx1,ty,cx1+cw,ty+TH-2], fill=fill_c, outline='#CCCCCC', width=1) wrapped=textwrap.wrap(cell, width=max(1,cw//8)) txt=wrapped[0] if wrapped else cell draw.text((cx1+4, ty+TH//2-1), txt, font=F_TINY, fill=DARK, anchor='lm') ty+=TH # Red divider line at centre draw.line([W//2, 58, W//2, H-MARGIN], fill='#AAAAAA', width=1) out_path='/tmp/workspace/cpb-respiratory/CPB_Respiratory_A3x2.png' img.save(out_path, dpi=(150,150)) print(f"Saved: {out_path} size={img.size}") PYEOF
python3 << 'PYEOF' from PIL import Image, ImageDraw, ImageFont import textwrap, os # Use standard A3 portrait (150dpi) per page, stacked vertically as 2 pages # A3 landscape at 150dpi = 1754 x 1240 # Two A3 landscape pages stacked = 1754 x 2480 W, H = 3508, 2480 # keep same but use bigger fonts MARGIN = 30 GAP = 12 BG = '#F9F8F2' RED = '#C02F2F' DARK = '#1E1E1E' BLUE = '#3A6EA5' LIGHT_BLUE = '#EAF0F8' LIGHT_RED = '#FDF0EF' img = Image.new('RGB', (W, H), BG) draw = ImageDraw.Draw(img) def load_font(size, bold=False): paths = [ f'/usr/share/fonts/truetype/dejavu/DejaVuSans{"Bold" if bold else ""}.ttf', f'/usr/share/fonts/truetype/liberation/LiberationSans-{"Bold" if bold else "Regular"}.ttf', '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', ] for p in paths: if os.path.exists(p): return ImageFont.truetype(p, size) return ImageFont.load_default() # Significantly increased font sizes F_TITLE = load_font(68, bold=True) F_HEAD = load_font(32, bold=True) F_SUB = load_font(26, bold=True) F_BODY = load_font(22) F_TINY = load_font(19) def box(x, y, w, h, fill=BG, outline=DARK, lw=2): draw.rectangle([x, y, x+w, y+h], fill=fill, outline=outline, width=lw) def section_title(x, y, w, num, title): full = f'{num}. {title}' draw.text((x + w//2, y+18), full, font=F_HEAD, fill=RED, anchor='mm') draw.line([x+6, y+33, x+w-6, y+33], fill=RED, width=2) def bullet_list(draw, items, x, y, max_w, font=F_BODY, fill=DARK, lh=26, bullet='•'): cy = y sample = draw.textlength('A', font=font) chars = max(1, int((max_w - 20) / max(1, sample))) for item in items: lines = textwrap.wrap(item, width=chars) for i, line in enumerate(lines): prefix = f'{bullet} ' if i == 0 else ' ' draw.text((x, cy), prefix + line, font=font, fill=fill) cy += lh return cy # ─── TITLE ────────────────────────────────────────────────────────────────── draw.text((W//2, 44), '* EFFECTS OF CARDIOPULMONARY BYPASS (CPB) ON THE RESPIRATORY SYSTEM *', font=F_TITLE, fill=RED, anchor='mm') draw.line([MARGIN, 76, W-MARGIN, 76], fill=RED, width=3) TOP_Y = 86 # ─── PAGE 1 ────────────────────────────────────────────────────────────────── P1_X = MARGIN P1_W = W//2 - MARGIN*2 - GAP//2 C1 = (P1_W - 2*GAP) // 3 C2 = C1 C3 = P1_W - C1 - C2 - 2*GAP # ROW 1 (h=350) R1H = 350 # I - Definition bx,by,bw,bh = P1_X, TOP_Y, C1, R1H box(bx,by,bw,bh) section_title(bx,by,bw,'I','DEFINITION OF CPB') cy=by+42 items=['Technique temporarily taking over heart & lung function during cardiac surgery', 'Heart-lung machine: oxygenates blood, removes CO₂, maintains systemic circulation', 'Lungs are BYPASSED — no pulmonary blood flow', 'Ventilation is STOPPED during CPB', 'Duration: typically 60–180 min', 'Longer CPB duration = more severe lung injury', '3 phases: initiation → bypass → weaning (reperfusion)'] bullet_list(draw,items,bx+10,cy,bw-20,lh=26) # II - Why lungs vulnerable bx,by,bw,bh = P1_X+C1+GAP, TOP_Y, C2, R1H box(bx,by,bw,bh) section_title(bx,by,bw,'II','LUNGS VULNERABILITY') cy=by+42 items=['No bronchial artery flow during CPB', 'Pulmonary circulation excluded', 'Lungs deflated and atelectatic', 'No cardioplegia equivalent for lungs', 'Lung cannot clear stress hormones', 'Ischaemia–reperfusion injury on weaning', 'Non-endothelialised pump surfaces activate blood', 'Inflammatory cascade accumulates'] bullet_list(draw,items,bx+10,cy,bw-20,lh=26) # III - Two pathways bx,by,bw,bh = P1_X+C1+C2+2*GAP, TOP_Y, C3, R1H box(bx,by,bw,bh) section_title(bx,by,bw,'III','2 MAIN PATHWAYS OF INJURY') cy=by+42 draw.text((bx+bw//2,cy), 'PATHWAY 1: INFLAMMATORY', font=F_SUB, fill=RED, anchor='mm') cy+=32 for it in ['Blood-surface contact','Complement activation (C3a, C5a)','Neutrophil activation & degranulation', 'Cytokines: IL-1β, IL-6, IL-8, TNF-α','ROS + proteases → endothelial damage']: draw.text((bx+12,cy), '→ '+it, font=F_TINY, fill=DARK) cy+=24 cy+=8 draw.text((bx+bw//2,cy), 'PATHWAY 2: MECHANICAL', font=F_SUB, fill=BLUE, anchor='mm') cy+=32 for it in ['Surfactant loss','Atelectasis → V/Q mismatch','↓ Lung volumes, altered mechanics']: draw.text((bx+12,cy), '→ '+it, font=F_TINY, fill=DARK) cy+=24 # ROW 2 (h=370) R2_Y = TOP_Y + R1H + GAP R2H = 370 # IV - SIRS (wide) bx,by = P1_X, R2_Y bw = C1+C2+GAP bh = R2H box(bx,by,bw,bh) section_title(bx,by,bw,'IV','SYSTEMIC INFLAMMATORY RESPONSE (SIRS) TO CPB') cy=by+42 cw=(bw-28)//2 draw.text((bx+10,cy), 'Triggers:', font=F_SUB, fill=RED) bullet_list(draw,['Blood contact with non-endothelialised surfaces (tubing, oxygenator)', 'Hypothermia → complement activation','Endotoxin release (gut ischaemia)', 'Ischaemia-reperfusion on weaning off bypass', 'Surgical trauma & pericardial blood re-infusion', 'Non-pulsatile flow → endothelial shear stress','Haemodilution → ↓ oncotic pressure'], bx+10,cy+30,cw-10,lh=24) rx=bx+cw+14 draw.text((rx,cy), 'Key Mediators:', font=F_SUB, fill=RED) bullet_list(draw,['C3a, C5a — anaphylatoxins, chemotaxis','IL-1β, IL-6, IL-8, TNF-α', 'Neutrophil elastase → alveolar damage','Myeloperoxidase (MPO)', 'Reactive oxygen species (ROS)','Thromboxane A₂ → ↑PVR, bronchoconstriction', 'Platelet activating factor (PAF)','Bradykinin → capillary leak'], rx,cy+30,cw,lh=24) # V - Mechanical effects bx,by = P1_X+C1+C2+2*GAP, R2_Y bw,bh = C3, R2H box(bx,by,bw,bh) section_title(bx,by,bw,'V','MECHANICAL EFFECTS') cy=by+42 bullet_list(draw,['Lungs collapse — ventilation stopped','Loss of surfactant activity', 'FRC ↓ → small airway closure','V/Q mismatch → hypoxaemia', 'Phrenic nerve palsy (cold cardioplegia)','Diaphragm dysfunction post-op', 'Pleural effusion (esp. left side)','Chest wall compliance ↓ (sternotomy)', 'IMA harvest → more dysfunction','Haemothorax / pneumothorax (rare)'], bx+10,cy,bw-20,lh=25) # ROW 3 (h=350) R3_Y = R2_Y + R2H + GAP R3H = 350 # VI - Atelectasis bx,by = P1_X, R3_Y bw = C1+C2+GAP bh = R3H box(bx,by,bw,bh) section_title(bx,by,bw,'VI','ATELECTASIS POST-CPB') cy=by+42 # Lung diagram lx,ly = bx+10, cy+10 # Left (atelectatic) lung draw.ellipse([lx,ly,lx+110,ly+175], outline=DARK, width=2) draw.ellipse([lx+6,ly+6,lx+104,ly+169], fill=LIGHT_RED, outline=None) for row_y in range(ly+12, ly+160, 15): draw.line([lx+12,row_y,lx+98,row_y], fill='#CCAAAA', width=1) draw.text((lx+55,ly+185), 'Atelectatic', font=F_TINY, fill=RED, anchor='mm') draw.text((lx+55,ly+205), '(Left lung CPB)', font=F_TINY, fill=RED, anchor='mm') # Right (normal) lung rx6=lx+130 draw.ellipse([rx6,ly,rx6+110,ly+175], outline=DARK, width=2) draw.ellipse([rx6+6,ly+6,rx6+104,ly+169], fill='#E8F4E8', outline=None) for yy in range(ly+20,ly+155,30): draw.ellipse([rx6+18,yy,rx6+92,yy+22], outline='#77AA77', width=1) draw.text((rx6+55,ly+185), 'Normal', font=F_TINY, fill='#2A6A2A', anchor='mm') draw.text((rx6+55,ly+205), '(Aerated alveoli)', font=F_TINY, fill='#2A6A2A', anchor='mm') tx6=rx6+130 bullet_list(draw,['Up to 50% lung volume atelectatic','Predominantly left lower lobe', 'Post-CABG: PaO₂ ~75→55 mmHg (day 2)','Shunt fraction: 3%→19% post-op', 'Lung volumes ↓ by ~30%','Persists for weeks post-operatively', 'CXR: basal opacities, ↑ hemidiaphragm', 'Causes: no ventilation, surfactant loss, phrenic palsy'], tx6,cy+10,bw-(tx6-bx)-12,lh=25) # VII - Surfactant bx,by = P1_X+C1+C2+2*GAP, R3_Y bw,bh = C3, R3H box(bx,by,bw,bh) section_title(bx,by,bw,'VII','SURFACTANT CHANGES') cy=by+42 ax,ay = bx+bw//2, cy+70 draw.ellipse([ax-55,ay-55,ax+55,ay+40], outline=DARK, width=2, fill='#E8F4FE') draw.line([ax-55,ay-10,ax+55,ay-10], fill=BLUE, width=3) draw.text((ax,ay-38),'Airspace', font=F_TINY, fill=DARK, anchor='mm') draw.text((ax,ay-10),'Surfactant layer', font=F_TINY, fill=BLUE, anchor='mm') draw.text((ax,ay+20),'Fluid (surface)', font=F_TINY, fill=DARK, anchor='mm') cy2=ay+65 bullet_list(draw,['CPB significantly reduces surfactant activity', 'Type II pneumocyte dysfunction','Hypothermia → ↓ phospholipid synthesis', 'Loss of surfactant → ↑ surface tension','Alveolar instability → collapse', 'FRC ↓ → airways close at expiration','Neonates: more severe; replacement needed'], bx+10,cy2,bw-20,lh=25) # ROW 4 — Pulmonary oedema (full width) R4_Y = R3_Y + R3H + GAP R4H = H - R4_Y - MARGIN bx,by,bw,bh = P1_X, R4_Y, P1_W, R4H box(bx,by,bw,bh) section_title(bx,by,bw,'VIII','PULMONARY OEDEMA & CAPILLARY LEAK SYNDROME') cy=by+42 cw=(bw-30)//3 draw.text((bx+10,cy), 'Mechanisms:', font=F_SUB, fill=RED) bullet_list(draw,['Haemodilution → ↓ oncotic pressure', 'Capillary leak (complement/neutrophil)', '↑ PVR → hydrostatic oedema', 'Hypothermic CPB → ↓ plasma proteins', 'Water extravasation into lung interstitium', 'Reperfusion oedema on weaning', 'Alveolar-capillary membrane damage', 'No lymphatic drainage during CPB'], bx+10,cy+32,cw-10,lh=24) cx2=bx+cw+14 draw.text((cx2,cy), 'Clinical Features:', font=F_SUB, fill=RED) bullet_list(draw,['Interstitial → alveolar oedema', 'Reduced lung compliance', '↑ Peak airway pressures', 'Hypoxaemia (↓PaO₂, ↑FiO₂)', 'Crepitations / crackles bilaterally', 'CXR: bilateral perihilar haziness', 'Post-pump syndrome (severe form)', 'ARDS in ~2% of cases'], cx2,cy+32,cw-10,lh=24) cx3=bx+2*cw+24 draw.text((cx3,cy), 'Management:', font=F_SUB, fill=RED) bullet_list(draw,['MUF (Modified Ultrafiltration) — MOST effective', 'Conventional ultrafiltration during CPB', 'Furosemide post-bypass', 'PEEP 5–10 cmH₂O', 'Prone positioning if severe ARDS', 'Corticosteroids (methylprednisolone)', 'Aprotinin / tranexamic acid pre-CPB', 'Minimise CPB duration'], cx3,cy+32,cw-10,lh=24) # ─── PAGE 2 ────────────────────────────────────────────────────────────────── P2_X = W//2 + MARGIN P2_W = W//2 - MARGIN*2 D1 = (P2_W - 2*GAP) // 3 D2 = D1 D3 = P2_W - D1 - D2 - 2*GAP # ROW A (h=350) RA_H = 350 # IX - V/Q mismatch bx,by,bw,bh = P2_X, TOP_Y, D1, RA_H box(bx,by,bw,bh) section_title(bx,by,bw,'IX','V/Q MISMATCH') cy=by+42 diax,diay=bx+bw//2, cy+80 draw.ellipse([diax-50,diay-65,diax+50,diay+5], outline=DARK, width=2, fill='#E8F4FE') draw.text((diax,diay-35),'ALVEOLUS', font=F_TINY, fill=DARK, anchor='mm') draw.text((diax,diay-12),'(NO Ventilation)', font=F_TINY, fill=RED, anchor='mm') draw.ellipse([diax-40,diay+12,diax+40,diay+62], outline=DARK, width=2, fill='#FEE8E8') draw.text((diax,diay+37),'Capillary', font=F_TINY, fill=DARK, anchor='mm') draw.line([diax,diay+5,diax,diay+12], fill=DARK, width=2) draw.text((diax,diay+78),'V=0, Q>0 → SHUNT', font=F_TINY, fill=RED, anchor='mm') cy2=diay+95 bullet_list(draw,['Atelectatic units: perfused not ventilated', 'Shunt fraction 3%→19% post-CPB', 'A-a gradient markedly ↑', 'HPV impaired by CPB', 'Treated: PEEP, lung recruitment'], bx+10,cy2,bw-20,lh=24) # X - Gas exchange bx,by,bw,bh = P2_X+D1+GAP, TOP_Y, D2, RA_H box(bx,by,bw,bh) section_title(bx,by,bw,'X','GAS EXCHANGE CHANGES') cy=by+42 bullet_list(draw,['PaO₂: ~90→55 mmHg (nadir: post-op day 2)', 'A-a gradient: <15 → markedly widened', 'SaO₂ maintained but FiO₂ requirement ↑', 'DLCO (diffusion capacity) ↓ post-CABG', 'PaO₂/FiO₂ may fall <300 (ALI)', 'CO₂: normal or ↓ (hyperventilation)', 'Returns towards normal in 1–3 weeks', 'Worse: longer CPB, hypothermia, IMA harvest'], bx+10,cy,bw-20,lh=26) # XI - Pulmonary mechanics bx,by,bw,bh = P2_X+D1+D2+2*GAP, TOP_Y, D3, RA_H box(bx,by,bw,bh) section_title(bx,by,bw,'XI','PULMONARY MECHANICS') cy=by+42 bullet_list(draw,['Static compliance ↓ (30–50%)', 'Dynamic compliance ↓', 'FRC ↓ — most important change', 'TLC ↓, FEV₁ ↓, FVC ↓ (restrictive pattern)', 'Airway resistance ↑ (bronchospasm)', '↑ Peak airway pressure on ventilator', 'Work of breathing ↑ post-extubation', 'Lung volumes return over weeks–months', 'Post-CABG: ↓30% at 1 week'], bx+10,cy,bw-20,lh=25) # ROW B (h=370) RB_Y = TOP_Y + RA_H + GAP RB_H = 370 # XII - Phrenic nerve bx,by = P2_X, RB_Y bw = D1+D2+GAP bh = RB_H box(bx,by,bw,bh) section_title(bx,by,bw,'XII','PHRENIC NERVE PALSY & DIAPHRAGM DYSFUNCTION') cy=by+42 cw=(bw-28)//2 draw.text((bx+10,cy), 'Phrenic Nerve Palsy:', font=F_SUB, fill=RED) bullet_list(draw,['Incidence: 20–70% after cardiac surgery', 'Caused by topical ice / cold cardioplegia', 'Left phrenic most commonly affected', 'Thermal injury from IMA harvesting', 'Direct surgical trauma to nerve', 'Unilateral diaphragm elevation on CXR', 'Restrictive ventilatory defect', 'Most recover in 6–12 months'], bx+10,cy+32,cw-10,lh=24) rx12=bx+cw+14 draw.text((rx12,cy), 'Diaphragm Dysfunction:', font=F_SUB, fill=RED) bullet_list(draw,['↓ Transdiaphragmatic pressure post-op', 'Shift to rib-cage (paradoxical) breathing', 'Inhibitory reflex via visceral sympathetic afferents', 'Phrenic output ↓ (not contractile failure)', 'FRC ↓ → postoperative hypoxaemia', 'Aggravated by: pain, opioids, obesity', 'Treatment: CPAP, incentive spirometry, epidural analgesia'], rx12,cy+32,cw-10,lh=24) # XIII - Pump lung / ARDS bx,by = P2_X+D1+D2+2*GAP, RB_Y bw,bh = D3, RB_H box(bx,by,bw,bh) section_title(bx,by,bw,'XIII','PUMP LUNG / ALI / ARDS') cy=by+42 bullet_list(draw,['Severe end of CPB lung injury spectrum', 'Incidence ~2% after cardiac surgery', 'ALI: PaO₂/FiO₂ <300 mmHg', 'ARDS: PaO₂/FiO₂ <200 mmHg', 'Bilateral CXR infiltrates', 'PCWP <18 mmHg (non-cardiogenic)', 'Diffuse alveolar damage (DAD) on histology', 'Neutrophil sequestration in pulm vasculature', 'Mortality: 50–80% in full ARDS', 'Rx: Vt 6 mL/kg IBW, PEEP, prone positioning'], bx+10,cy,bw-20,lh=25) # ROW C (h=350) RC_Y = RB_Y + RB_H + GAP RC_H = 350 # XIV - Pulmonary HTN bx,by,bw,bh = P2_X, RC_Y, D1, RC_H box(bx,by,bw,bh) section_title(bx,by,bw,'XIV','PULMONARY HTN POST-CPB') cy=by+42 bullet_list(draw,['PVR ↑ after bypass', 'Thromboxane A₂ → vasoconstriction', 'Endothelin-1 ↑ → sustained ↑PVR', 'C5a, serotonin from platelets', 'Loss of NO (endothelial dysfunction)', 'Protamine → pulmonary HTN reaction', 'RV afterload ↑ → RV failure risk', 'Treatment: iNO, sildenafil, milrinone, PGI₂', 'Pre-existing PHT worsened by CPB'], bx+10,cy,bw-20,lh=25) # XV - Bronchospasm bx,by,bw,bh = P2_X+D1+GAP, RC_Y, D2, RC_H box(bx,by,bw,bh) section_title(bx,by,bw,'XV','BRONCHOSPASM & AIRWAY') cy=by+42 bullet_list(draw,['Bronchoconstriction during/after CPB', 'Complement → histamine release', 'Protamine-heparin → anaphylaxis', 'Serotonin from platelet degranulation', '↑ Airway reactivity: asthma/COPD pts', 'Bradykinin, PGF₂α → bronchospasm', 'Clinical: ↑ airway pressures, wheeze', 'Rx: salbutamol, ipratropium', 'Volatile agents (isoflurane) — bronchodilators', '↑ Depth of anaesthesia reduces reactivity'], bx+10,cy,bw-20,lh=24) # XVI - Post-op management bx,by,bw,bh = P2_X+D1+D2+2*GAP, RC_Y, D3, RC_H box(bx,by,bw,bh) section_title(bx,by,bw,'XVI','POST-CPB RESPIRATORY MGT') cy=by+42 bullet_list(draw,['FiO₂: wean as SpO₂/PaO₂ tolerate', 'PEEP: 5–8 cmH₂O routinely', 'Tidal volume: 6–8 mL/kg IBW', 'Early extubation (fast-track protocols)', 'Incentive spirometry post-extubation', 'Physiotherapy: cough assist, postural drainage', 'Adequate analgesia (↓ splinting, ↑ effort)', 'MUF: reduces lung water in paediatrics', 'Nebulised bronchodilators PRN', 'Drain effusions if haemodynamically significant'], bx+10,cy,bw-20,lh=24) # ROW D — Summary table (rest of page 2) RD_Y = RC_Y + RC_H + GAP RD_H = H - RD_Y - MARGIN bx,by,bw,bh = P2_X, RD_Y, P2_W, RD_H box(bx,by,bw,bh) section_title(bx,by,bw,'XVII','SUMMARY TABLE: CPB EFFECTS ON RESPIRATORY SYSTEM') cy=by+42 TH = 32 cols = ['Parameter', 'Normal', 'Post-CPB', 'Mechanism', 'Clinical Significance'] col_ws_ratio = [0.12, 0.10, 0.14, 0.28, 0.36] total = bw - 24 col_ws = [int(r*total) for r in col_ws_ratio] data = [ ['PaO₂ (room air)', '~90 mmHg', '~55 mmHg', 'V/Q mismatch, shunt, oedema', 'Significant hypoxaemia — supplemental O₂ required'], ['A-a Gradient', '<15 mmHg', 'Markedly ↑', 'Shunting, diffusion impairment', 'Reflects severity of lung injury'], ['Static Compliance', '~100 mL/cmH₂O', '↓ 30–50%', 'Oedema, surfactant loss, atelectasis', 'Stiffer lungs, higher ventilator pressures'], ['FRC', 'Normal', '↓ 15–30%', 'Atelectasis, diaphragm dysfunction', 'Small airway closure, basal collapse'], ['Shunt Fraction', '~3%', '~19%', 'Atelectatic perfused units', 'Major cause of post-CPB hypoxaemia'], ['PVR', 'Normal', '↑', 'Thromboxane, endothelin, C5a, loss of NO', 'RV strain → potential acute RV failure'], ['Surfactant', 'Active', '↓ Activity', 'Type II pneumocyte dysfunction', 'Alveolar instability, progressive collapse'], ['Lung Volumes', 'Normal', '↓ ~30%', 'Atelectasis, pleural effusion, phrenic palsy', 'Restrictive defect — months to recover'], ] ty = cy cx_start = bx + 8 # Header cx = cx_start for i,col in enumerate(cols): draw.rectangle([cx,ty,cx+col_ws[i],ty+TH], fill=RED) draw.text((cx+col_ws[i]//2, ty+TH//2), col, font=F_TINY, fill='white', anchor='mm') cx += col_ws[i] + 2 ty += TH + 2 for ri,row in enumerate(data): fill_c = LIGHT_BLUE if ri%2==0 else BG cx = cx_start for i,(cell,cw_) in enumerate(zip(row,col_ws)): draw.rectangle([cx,ty,cx+cw_,ty+TH-2], fill=fill_c, outline='#BBBBBB', width=1) wrapped=textwrap.wrap(cell, width=max(1,cw_//11)) txt=wrapped[0] if wrapped else cell draw.text((cx+5, ty+TH//2-1), txt, font=F_TINY, fill=DARK, anchor='lm') cx += cw_ + 2 ty += TH # Centre divider draw.line([W//2, 76, W//2, H-MARGIN], fill='#BBBBBB', width=1) # Page labels draw.text((W//4, H-15), 'PAGE 1', font=F_TINY, fill='#888888', anchor='mm') draw.text((3*W//4, H-15), 'PAGE 2', font=F_TINY, fill='#888888', anchor='mm') out = '/tmp/workspace/cpb-respiratory/CPB_Respiratory_Final.png' img.save(out, dpi=(150,150)) print(f'Done: {out} {img.size}') PYEOF
ls -lh /tmp/workspace/cpb-respiratory/
CPB Respiratory Final
Image · PNG
| Section | Content |
|---|---|
| I. Definition of CPB | What CPB is, heart-lung machine function, lungs bypassed, duration |
| II. Why Lungs are Vulnerable | No bronchial flow, excluded circulation, no cardioplegia equivalent, ischaemia-reperfusion |
| III. 2 Main Pathways | Inflammatory (complement-neutrophil) vs Mechanical (surfactant-atelectasis) with flow diagram |
| IV. SIRS to CPB | Triggers + Key mediators in 2-column format (C3a, C5a, TNF-α, IL-6, thromboxane, PAF, bradykinin) |
| V. Mechanical Effects | FRC↓, surfactant loss, V/Q mismatch, phrenic palsy, pleural effusion, sternotomy |
| VI. Atelectasis | Lung diagram (atelectatic vs normal), PaO₂ 75→55 mmHg, shunt 3%→19%, left lower lobe predominance |
| VII. Surfactant Changes | Alveolus diagram, Type II pneumocyte dysfunction, phospholipid synthesis↓ |
| VIII. Pulmonary Oedema | 3-column: Mechanisms / Clinical Features / Management (MUF, PEEP, diuretics, prone) |
| Section | Content |
|---|---|
| IX. V/Q Mismatch | Alveolus-capillary diagram, shunt physiology, HPV impairment |
| X. Gas Exchange Changes | PaO₂ values, A-a gradient, DLCO↓, PaO₂/FiO₂, timeline of recovery |
| XI. Pulmonary Mechanics | Static/dynamic compliance↓, FRC↓, restrictive pattern, peak airway pressure↑ |
| XII. Phrenic Nerve Palsy | 2-column: phrenic palsy (cold cardioplegia, IMA harvest, 20-70%) + diaphragm dysfunction |
| XIII. Pump Lung / ALI / ARDS | DAD, PaO₂/FiO₂ criteria, 50-80% mortality, protective ventilation |
| XIV. Pulmonary HTN | Thromboxane, endothelin-1, loss of NO, RV failure, iNO/sildenafil |
| XV. Bronchospasm | Complement histamine, protamine anaphylaxis, volatile agents as bronchodilators |
| XVI. Post-CPB Respiratory Management | Ventilator strategy, PEEP, fast-track extubation, MUF, physiotherapy |
| XVII. Summary Table | 8-row table: Parameter / Normal / Post-CPB / Mechanism / Clinical Significance |
Create a PPTX presentation on CPB respiratory effects for exam revision
mkdir -p /tmp/workspace/cpb-pptx && python3 << 'PYEOF' from pptx import Presentation from pptx.util import Inches, Pt, Emu from pptx.dml.color import RGBColor from pptx.enum.text import PP_ALIGN, MSO_ANCHOR from pptx.util import Inches, Pt import copy from lxml import etree # ─── Palette ────────────────────────────────────────────────────────────────── RED = RGBColor(0xC0, 0x2F, 0x2F) DARK_RED = RGBColor(0x8B, 0x00, 0x00) CREAM = RGBColor(0xFD, 0xF8, 0xF0) DARK = RGBColor(0x1E, 0x1E, 0x1E) WHITE = RGBColor(0xFF, 0xFF, 0xFF) BLUE = RGBColor(0x1F, 0x4E, 0x79) LIGHT_BL = RGBColor(0xDE, 0xEB, 0xF7) STEEL = RGBColor(0x2E, 0x75, 0xB6) ORANGE = RGBColor(0xC5, 0x50, 0x00) LGRAY = RGBColor(0xF2, 0xF2, 0xF2) MID_GRAY = RGBColor(0xBF, 0xBF, 0xBF) # ─── Presentation ───────────────────────────────────────────────────────────── prs = Presentation() prs.slide_width = Inches(13.333) prs.slide_height = Inches(7.5) blank = prs.slide_layouts[6] # Blank layout # ─── Helper Functions ───────────────────────────────────────────────────────── def set_bg(slide, color): """Solid background colour for a slide.""" fill = slide.background.fill fill.solid() fill.fore_color.rgb = color def add_rect(slide, x, y, w, h, fill=None, line=None, line_w=Pt(0)): from pptx.util import Emu shape = slide.shapes.add_shape(1, Inches(x), Inches(y), Inches(w), Inches(h)) if fill: shape.fill.solid() shape.fill.fore_color.rgb = fill else: shape.fill.background() if line: shape.line.color.rgb = line shape.line.width = line_w else: shape.line.fill.background() return shape def add_tb(slide, x, y, w, h, text, size, bold=False, color=DARK, align=PP_ALIGN.LEFT, wrap=True, italic=False): tb = slide.shapes.add_textbox(Inches(x), Inches(y), Inches(w), Inches(h)) tf = tb.text_frame tf.word_wrap = wrap tf.margin_left = Pt(4) tf.margin_right = Pt(4) tf.margin_top = Pt(2) tf.margin_bottom= Pt(2) p = tf.paragraphs[0] p.alignment = align run = p.add_run() run.text = text run.font.name = "Calibri" run.font.size = Pt(size) run.font.bold = bold run.font.color.rgb = color run.font.italic = italic return tb def add_bullet_tb(slide, x, y, w, h, items, size=16, color=DARK, bullet_color=None, bold_first=False, spacing=1.0): """Multi-line bullet text box.""" tb = slide.shapes.add_textbox(Inches(x), Inches(y), Inches(w), Inches(h)) tf = tb.text_frame tf.word_wrap = True tf.margin_left = Pt(4) tf.margin_right = Pt(4) tf.margin_top = Pt(2) tf.margin_bottom = Pt(2) bc = bullet_color or color for i, item in enumerate(items): if i == 0: p = tf.paragraphs[0] else: p = tf.add_paragraph() p.space_before = Pt(1) run = p.add_run() run.text = item run.font.name = "Calibri" run.font.size = Pt(size) run.font.color.rgb = color run.font.bold = bold_first and (i == 0) return tb def section_header_bar(slide, text, y=0.55, subtitle=None): """Full-width red header bar with section title.""" add_rect(slide, 0, y, 13.333, 0.55, fill=RED) add_tb(slide, 0.2, y+0.04, 13.1, 0.45, text, 24, bold=True, color=WHITE, align=PP_ALIGN.CENTER) def slide_number_dot(slide, num, total): """Small dot + number bottom right.""" add_tb(slide, 12.5, 7.1, 0.7, 0.35, f'{num}/{total}', 11, color=MID_GRAY, align=PP_ALIGN.RIGHT) def divider_line(slide, x, y, w, color=RED, thickness=Pt(1.5)): from pptx.util import Inches line = slide.shapes.add_connector(1, Inches(x), Inches(y), Inches(x+w), Inches(y)) line.line.color.rgb = color line.line.width = thickness # ─── SLIDE 1 — TITLE ───────────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, DARK_RED) # Decorative top stripe add_rect(sl, 0, 0, 13.333, 0.08, fill=WHITE) # Big white box add_rect(sl, 0.5, 0.9, 12.333, 5.2, fill=WHITE) add_tb(sl, 0.7, 1.15, 12.0, 1.4, 'EFFECTS OF CARDIOPULMONARY BYPASS (CPB)', 40, bold=True, color=DARK_RED, align=PP_ALIGN.CENTER) add_tb(sl, 0.7, 2.5, 12.0, 0.8, 'ON THE RESPIRATORY SYSTEM', 34, bold=True, color=DARK, align=PP_ALIGN.CENTER) divider_line(sl, 1.5, 3.45, 10.333, color=RED, thickness=Pt(2)) add_tb(sl, 0.7, 3.6, 12.0, 0.55, 'Comprehensive Exam Revision | Cardiothoracic Anaesthesia & Perfusion', 18, italic=True, color=STEEL, align=PP_ALIGN.CENTER) add_tb(sl, 0.7, 4.25, 12.0, 0.5, 'Based on: Miller\'s Anesthesia 10e | Fishman\'s Pulmonary Diseases | Gravlee\'s Cardiopulmonary Bypass', 14, italic=True, color=MID_GRAY, align=PP_ALIGN.CENTER) # Bottom tag add_rect(sl, 0, 6.7, 13.333, 0.08, fill=WHITE) add_tb(sl, 0, 6.85, 13.333, 0.55, '17 Key Topics • Mechanisms • Pathophysiology • Clinical Features • Management', 13, color=WHITE, align=PP_ALIGN.CENTER) slide_number_dot(sl, 1, 18) # ─── SLIDE 2 — OVERVIEW TABLE OF CONTENTS ──────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) add_rect(sl, 0, 0, 13.333, 0.55, fill=DARK_RED) add_tb(sl, 0.2, 0.06, 13.0, 0.43, 'OVERVIEW — WHAT WE WILL COVER', 22, bold=True, color=WHITE, align=PP_ALIGN.CENTER) topics = [ ('1.', 'Why the Lungs are Uniquely Vulnerable During CPB'), ('2.', 'Two Main Pathways of Lung Injury'), ('3.', 'Systemic Inflammatory Response (SIRS)'), ('4.', 'Atelectasis — Mechanism & Consequences'), ('5.', 'Surfactant Dysfunction'), ('6.', 'Pulmonary Oedema & Capillary Leak'), ('7.', 'V/Q Mismatch & Gas Exchange Changes'), ('8.', 'Pulmonary Mechanics Changes'), ('9.', 'Phrenic Nerve Palsy & Diaphragm Dysfunction'), ('10.', 'Pump Lung / ALI / ARDS'), ('11.', 'Pulmonary Hypertension Post-CPB'), ('12.', 'Bronchospasm & Airway Changes'), ('13.', 'Post-CPB Respiratory Management'), ('14.', 'Summary Comparison Table'), ] # Two columns left_topics = topics[:7] right_topics = topics[7:] tb = sl.shapes.add_textbox(Inches(0.4), Inches(0.7), Inches(6.0), Inches(6.5)) tf = tb.text_frame tf.word_wrap = True for i, (num, topic) in enumerate(left_topics): p = tf.paragraphs[0] if i==0 else tf.add_paragraph() p.space_before = Pt(3) r = p.add_run(); r.text = f'{num} '; r.font.bold=True; r.font.size=Pt(17) r.font.color.rgb = RED; r.font.name='Calibri' r2 = p.add_run(); r2.text = topic; r2.font.size=Pt(17) r2.font.color.rgb = DARK; r2.font.name='Calibri' tb2 = sl.shapes.add_textbox(Inches(7.0), Inches(0.7), Inches(6.0), Inches(6.5)) tf2 = tb2.text_frame tf2.word_wrap = True for i, (num, topic) in enumerate(right_topics): p = tf2.paragraphs[0] if i==0 else tf2.add_paragraph() p.space_before = Pt(3) r = p.add_run(); r.text = f'{num} '; r.font.bold=True; r.font.size=Pt(17) r.font.color.rgb = RED; r.font.name='Calibri' r2 = p.add_run(); r2.text = topic; r2.font.size=Pt(17) r2.font.color.rgb = DARK; r2.font.name='Calibri' divider_line(sl, 6.666, 0.65, 0, color=MID_GRAY) # Centre divider (vertical via shape) add_rect(sl, 6.55, 0.65, 0.02, 6.6, fill=MID_GRAY) slide_number_dot(sl, 2, 18) # ─── SLIDE 3 — WHY LUNGS ARE VULNERABLE ────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '1. WHY ARE THE LUNGS UNIQUELY VULNERABLE DURING CPB?') # Box 1: During CPB add_rect(sl, 0.3, 1.2, 5.9, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 5.9, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.7, 0.35, 'DURING CPB — What Happens to the Lungs?', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.7, 5.7, 5.2, ['• Pulmonary circulation EXCLUDED from bypass', '• Lungs are deflated and atelectatic — ventilation stopped', '• No bronchial artery blood flow (bronchial aa. arise from aorta)', '• Cold or warm ischaemia of lung parenchyma', '• Lung excluded from lymphatic drainage', '• No "cardioplegia equivalent" to protect the lungs', '• Pulmonary surfactant production impaired', '• Duration of CPB directly correlates with degree of injury', '• Non-pulsatile flow → endothelial dysfunction', '• Haemodilution → ↓ oncotic pressure → oedema tendency', ], size=15, color=DARK) # Box 2: Normal lung functions lost add_rect(sl, 6.5, 1.2, 6.5, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.5, 1.2, 6.5, 0.4, fill=BLUE) add_tb(sl, 6.6, 1.23, 6.3, 0.35, 'NORMAL LUNG FUNCTIONS LOST During CPB', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.6, 1.7, 6.3, 5.2, ['• Gas exchange — O₂ taken over by membrane oxygenator', '• Filtration of microemboli — bypassed, so emboli reach systemic circulation', '• Metabolic functions — lung clears: serotonin, bradykinin, noradrenaline, angiotensin I→II', ' → These accumulate during CPB → vasoactive effects', '• ACE activity ↓ during CPB', '• Prostaglandin metabolism impaired', '• Lung acts as reservoir for leucocytes — activation during bypass', '• Mast cell degranulation → histamine release', '• Thromboxane A₂ synthesis → pulmonary vasoconstriction', '• Ischaemia-reperfusion injury on weaning from CPB', ], size=15, color=DARK) slide_number_dot(sl, 3, 18) # ─── SLIDE 4 — TWO PATHWAYS ────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '2. TWO MAIN PATHWAYS OF CPB-INDUCED LUNG INJURY') # Pathway 1 box add_rect(sl, 0.3, 1.2, 6.1, 5.9, fill=WHITE, line=RED, line_w=Pt(2)) add_rect(sl, 0.3, 1.2, 6.1, 0.5, fill=RED) add_tb(sl, 0.4, 1.24, 6.0, 0.42, 'PATHWAY 1 — INFLAMMATORY / HUMORAL', 16, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.82, 6.0, 5.0, ['Blood contacts non-endothelialised surfaces:', ' → Pump tubing, oxygenator membrane, reservoir', '', 'Complement cascade activated:', ' → C3a, C5a (anaphylatoxins) released', ' → C5a = neutrophil chemotactic factor', '', 'Neutrophil activation & degranulation:', ' → Release: elastase, myeloperoxidase (MPO)', ' → Reactive oxygen species (ROS)', ' → Proteases damage alveolar-capillary membrane', '', 'Cytokines released: IL-1β, IL-6, IL-8, TNF-α', 'Thromboxane A₂ → ↑PVR + bronchoconstriction', 'Bradykinin → capillary leak', 'Platelet activating factor (PAF)', 'Endothelin-1 → sustained vasoconstriction', ], size=14, color=DARK) # Pathway 2 box add_rect(sl, 6.8, 1.2, 6.1, 5.9, fill=WHITE, line=BLUE, line_w=Pt(2)) add_rect(sl, 6.8, 1.2, 6.1, 0.5, fill=BLUE) add_tb(sl, 6.9, 1.24, 6.0, 0.42, 'PATHWAY 2 — MECHANICAL / PHYSICAL', 16, bold=True, color=WHITE) add_bullet_tb(sl, 6.9, 1.82, 6.0, 5.0, ['Lungs deflated throughout bypass:', ' → Absence of ventilation → alveolar collapse', ' → Surfactant loss → alveolar instability', '', 'Functional Residual Capacity (FRC) ↓:', ' → Small airway closure occurs', ' → Progressive atelectasis', '', 'Ventilation-Perfusion (V/Q) mismatch:', ' → Atelectatic units: perfused but NOT ventilated', ' → Shunt fraction ↑ (3% → 19% post-CPB)', '', 'Mechanical factors:', ' → Sternotomy → ↓ chest wall compliance', ' → IMA (internal mammary artery) harvest', ' → Phrenic nerve injury (cold cardioplegia)', ' → Diaphragm dysfunction post-operatively', ], size=14, color=DARK) # Key result add_rect(sl, 0.3, 7.05, 12.6, 0.35, fill=RGBColor(0xFF, 0xED, 0xED)) add_tb(sl, 0.4, 7.07, 12.4, 0.3, 'RESULT of both pathways: Pulmonary dysfunction, atelectasis, oedema, ↑PVR, gas exchange impairment, potential ARDS', 13, bold=True, color=DARK_RED) slide_number_dot(sl, 4, 18) # ─── SLIDE 5 — SIRS ────────────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '3. SYSTEMIC INFLAMMATORY RESPONSE SYNDROME (SIRS) TRIGGERED BY CPB') # Triggers add_rect(sl, 0.3, 1.2, 4.0, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.0, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.8, 0.35, 'TRIGGERS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.7, 3.8, 5.3, ['• Blood-foreign surface contact (tubing, oxygenator)', '• Hypothermia during CPB', '• Ischaemia-reperfusion injury (heart & lungs)', '• Endotoxaemia (gut ischaemia)', '• Surgical trauma & pericardial blood re-infusion', '• Non-pulsatile flow → shear stress', '• Haemodilution', '• Cardiotomy suction → activated blood', '• Protamine administration', '• Aortic cross-clamping', ], size=14, color=DARK) # Mediators add_rect(sl, 4.6, 1.2, 4.2, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.6, 1.2, 4.2, 0.4, fill=ORANGE) add_tb(sl, 4.7, 1.23, 4.0, 0.35, 'KEY MEDIATORS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.7, 1.7, 4.0, 5.3, ['• C3a, C5a — anaphylatoxins', '• TNF-α — early mediator', '• IL-1β — fever, neutrophil activation', '• IL-6 — acute phase response', '• IL-8 — neutrophil chemotaxis', '• Neutrophil elastase', '• Myeloperoxidase (MPO)', '• Reactive oxygen species (ROS)', '• Thromboxane A₂', '• Bradykinin', '• Platelet activating factor (PAF)', '• Endothelin-1', '• Histamine (mast cell degranulation)', ], size=13, color=DARK) # Effects on lungs add_rect(sl, 9.1, 1.2, 3.9, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.1, 1.2, 3.9, 0.4, fill=BLUE) add_tb(sl, 9.2, 1.23, 3.7, 0.35, 'PULMONARY EFFECTS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.2, 1.7, 3.7, 5.3, ['• Capillary-alveolar membrane damage', '• ↑ Capillary permeability', '• Pulmonary oedema (non-cardiogenic)', '• ↑ Pulmonary vascular resistance (PVR)', '• Microvascular thrombosis', '• Platelet plugging → ischaemia', '• Neutrophil sequestration in pulmonary vasculature', '• Diffuse alveolar damage (DAD)', '• Surfactant destruction', '• Bronchoconstriction', '• Impaired hypoxic pulmonary vasoconstriction (HPV)', '• Pulmonary hypertension', ], size=13, color=DARK) slide_number_dot(sl, 5, 18) # ─── SLIDE 6 — ATELECTASIS ─────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '4. ATELECTASIS — MECHANISM, CONSEQUENCES & CLINICAL FINDINGS') # Left: mechanism add_rect(sl, 0.3, 1.2, 4.1, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.1, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.9, 0.35, 'MECHANISM', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.9, 5.2, ['• Ventilation stopped → alveoli collapse', '• Surfactant loss → ↑ surface tension', '• FRC ↓ → airway closure', '• Compression by cold saline irrigation', '• Mediastinal shift post-CPB', '• Bronchial secretions pool during bypass', '• Phrenic nerve palsy → basal atelectasis', '• Up to 50% of lung volume may be atelectatic', '• Predominantly LEFT LOWER LOBE', '• CABG: lung volumes ↓ 30% at 1 week', ], size=14, color=DARK) # Centre: ABG changes add_rect(sl, 4.7, 1.2, 4.0, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.7, 1.2, 4.0, 0.4, fill=ORANGE) add_tb(sl, 4.8, 1.23, 3.8, 0.35, 'GAS EXCHANGE CHANGES', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.8, 1.72, 3.8, 5.2, ['PaO₂ Changes (room air):', '• Pre-op: ~90 mmHg (normal)', '• Day 1: ~65 mmHg', '• Day 2: ~55 mmHg (NADIR)', '• Week 1: Still below preoperative', '• Returns to baseline: 2–4 weeks', '', 'Shunt Fraction:', '• Pre-op: ~3%', '• Post-CPB: ~19% (peak)', '', 'Other Changes:', '• A-a gradient: markedly widened', '• DLCO (diffusion capacity) ↓', '• PaO₂/FiO₂ may fall <300 (ALI criteria)', ], size=14, color=DARK) # Right: CXR + clinical add_rect(sl, 9.0, 1.2, 4.0, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.0, 1.2, 4.0, 0.4, fill=BLUE) add_tb(sl, 9.1, 1.23, 3.8, 0.35, 'CLINICAL FEATURES', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.1, 1.72, 3.8, 5.2, ['Symptoms:', '• Dyspnoea post-extubation', '• ↑ Work of breathing', '• Hypoxaemia requiring O₂', '', 'CXR Findings:', '• Basal opacification (L>R)', '• Elevated left hemidiaphragm', '• Left lower lobe collapse', '• Linear (discoid) atelectasis', '', 'Management:', '• Lung recruitment manoeuvres', '• PEEP (5–10 cmH₂O)', '• Incentive spirometry', '• Physiotherapy, early mobilisation', '• Treat phrenic palsy if present', ], size=13, color=DARK) slide_number_dot(sl, 6, 18) # ─── SLIDE 7 — SURFACTANT ──────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '5. SURFACTANT DYSFUNCTION DURING & AFTER CPB') add_rect(sl, 0.3, 1.2, 5.5, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 5.5, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.3, 0.35, 'PATHOPHYSIOLOGY OF SURFACTANT LOSS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.3, 5.2, ['Normal surfactant function:', ' → Reduces alveolar surface tension', ' → Prevents alveolar collapse at low volumes', ' → Produced by Type II pneumocytes', ' → Dipalmitoylphosphatidylcholine (DPPC) = main component', '', 'CPB effects on surfactant:', ' → CPB significantly reduces surfactant activity (Miller\'s Anesthesia)', ' → Hypothermia → ↓ phospholipid synthesis', ' → Pulmonary ischaemia → Type II pneumocyte dysfunction', ' → Inflammatory mediators destroy surfactant', ' → Alveolar flooding dilutes surfactant', ' → Oxygen radicals degrade phospholipids', '', 'Consequences:', ' → ↑ Surface tension → alveolar instability', ' → Alveolar collapse at end-expiration', ' → FRC ↓ → worsening atelectasis', ' → Neonates: more severe (immature surfactant system)', ], size=14, color=DARK) add_rect(sl, 6.1, 1.2, 6.9, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.1, 1.2, 6.9, 0.4, fill=BLUE) add_tb(sl, 6.2, 1.23, 6.7, 0.35, 'CLINICAL IMPACT & MANAGEMENT', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.2, 1.72, 6.7, 5.2, ['Clinical Impact:', '• Reduced compliance (static & dynamic)', '• Increased ventilator pressures required', '• Progressive atelectasis despite PEEP', '• ↑ FiO₂ requirement post-extubation', '• Prolonged ventilatory support in neonates/infants', '', 'Risk Factors for Severe Surfactant Loss:', '• Long CPB duration (> 2 hours)', '• Neonatal / infant cardiac surgery', '• Deep Hypothermic Circulatory Arrest (DHCA)', '• Pre-existing lung disease', '• High inspired O₂ concentrations (O₂ toxicity)', '', 'Management:', '• PEEP to maintain alveolar recruitment', '• Lung recruitment manoeuvres post-CPB', '• Exogenous surfactant (neonates/infants)', '• Modified Ultrafiltration (MUF) reduces lung water', '• Phosphodiesterase inhibitors (limited evidence)', ], size=14, color=DARK) slide_number_dot(sl, 7, 18) # ─── SLIDE 8 — PULMONARY OEDEMA ────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '6. PULMONARY OEDEMA & CAPILLARY LEAK SYNDROME AFTER CPB') add_rect(sl, 0.3, 1.2, 4.1, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.1, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.9, 0.35, 'MECHANISMS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.9, 5.2, ['Starling Forces Disturbed:', '• Haemodilution → ↓ plasma oncotic pressure', '• ↑ Hydrostatic pressure (↑ PVR)', '• Net fluid movement into lung interstitium', '', 'Capillary Leak (Most Important):', '• Neutrophil + complement → membrane damage', '• ↑ Capillary permeability (non-cardiogenic)', '• Protein-rich fluid floods alveoli', '• Endothelial gap formation', '', 'Other Factors:', '• Hypothermic CPB → complement activation', '• Reperfusion on weaning = worst moment', '• No lymphatic drainage during CPB', '• Total body water ↑ (neonates especially)', ], size=13, color=DARK) add_rect(sl, 4.7, 1.2, 4.0, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.7, 1.2, 4.0, 0.4, fill=ORANGE) add_tb(sl, 4.8, 1.23, 3.8, 0.35, 'CLINICAL FEATURES', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.8, 1.72, 3.8, 5.2, ['Stages:', '1. Interstitial oedema', ' → Crepitations, ↑ airway pressures', '2. Alveolar oedema', ' → Frothy secretions, severe hypoxaemia', '', 'Clinical Signs:', '• Hypoxaemia (↓PaO₂, ↑FiO₂ requirement)', '• ↑ Peak airway pressure on ventilator', '• ↓ Compliance (stiffer lungs)', '• Bilateral basal crepitations', '• Respiratory distress post-extubation', '', 'CXR Findings:', '• Bilateral perihilar haziness', '• Kerley B lines (interstitial)', '• Alveolar infiltrates (if severe)', '', 'Post-pump syndrome = severe form', ], size=13, color=DARK) add_rect(sl, 9.0, 1.2, 4.0, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.0, 1.2, 4.0, 0.4, fill=BLUE) add_tb(sl, 9.1, 1.23, 3.8, 0.35, 'MANAGEMENT', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.1, 1.72, 3.8, 5.2, ['Most Effective Interventions:', '• MUF (Modified Ultrafiltration)', ' → MOST effective in paediatrics', ' → Removes excess fluid post-CPB', ' → Reduces lung water significantly', '', '• Conventional Ultrafiltration during CPB', '', 'Ventilatory Support:', '• PEEP 5–10 cmH₂O', '• Lung-protective strategy (Vt 6 mL/kg IBW)', '• Prone positioning if severe', '• Avoid high FiO₂ (O₂ toxicity)', '', 'Medical:', '• Furosemide diuresis', '• Corticosteroids (methylprednisolone)', '• Aprotinin / tranexamic acid (↓ inflammation)', '• Minimise CPB duration', ], size=13, color=DARK) slide_number_dot(sl, 8, 18) # ─── SLIDE 9 — V/Q MISMATCH ────────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '7. V/Q MISMATCH & GAS EXCHANGE IMPAIRMENT AFTER CPB') add_rect(sl, 0.3, 1.2, 5.8, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 5.8, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.6, 0.35, 'V/Q PHYSIOLOGY & CPB EFFECTS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.6, 5.2, ['Normal: V/Q ratio = 1 (matched ventilation & perfusion)', '', 'CPB causes V/Q MISMATCH:', '• Atelectasis → perfused but NOT ventilated units (V=0, Q>0)', '• This creates a TRUE INTRAPULMONARY SHUNT', '• V/Q < 1 in dependent zones (atelectatic base)', '• V/Q > 1 if hypoperfusion (↑PVR → reduced Q)', '', 'Hypoxic Pulmonary Vasoconstriction (HPV) IMPAIRED:', '• Normal HPV redirects blood away from hypoxic alveoli', '• CPB-released mediators (NO, prostacyclin) blunt HPV', '• Anaesthetic vapours also impair HPV', '• Result: blood continues to perfuse atelectatic lung', '', 'Shunt Fraction Changes:', '• Pre-operative: Qs/Qt ≈ 3%', '• Post-CPB peak: Qs/Qt ≈ 19%', '• Calculated shunt from ABG: PaO₂ still low even on 100% O₂', '', 'Dead Space ↑:', '• ↑PVR → some alveoli ventilated but underperfused', '• V/Q > 1 → wasted ventilation', ], size=13, color=DARK) add_rect(sl, 6.4, 1.2, 6.6, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.4, 1.2, 6.6, 0.4, fill=BLUE) add_tb(sl, 6.5, 1.23, 6.4, 0.35, 'GAS EXCHANGE CHANGES — KEY VALUES TO KNOW', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.5, 1.72, 6.4, 5.2, ['PaO₂ (Room Air):', ' Pre-op → ~90 mmHg (normal)', ' Day 1 → ~65 mmHg', ' Day 2 → ~55 mmHg ← NADIR (Fishman\'s Pulmonary)', ' Week 1 → Still below preop', ' Week 2-4→ Approaching normal', '', 'A-a Oxygen Gradient:', ' Normal: < 15 mmHg', ' Post-CPB: Markedly elevated (> 50–100 mmHg)', ' Reflects: Degree of V/Q mismatch + shunt', '', 'PaO₂/FiO₂ Ratio:', ' Normal: > 400', ' ALI: < 300', ' ARDS: < 200', ' Post-CPB: Often falls to 200–300 range', '', 'DLCO (Diffusion Capacity):', ' ↓ after CABG — months to recover', '', 'Correction by:', ' PEEP → alveolar recruitment → ↑ V/Q matching', ' Lung recruitment manoeuvres', ], size=13, color=DARK) slide_number_dot(sl, 9, 18) # ─── SLIDE 10 — PULMONARY MECHANICS ────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '8. PULMONARY MECHANICS CHANGES AFTER CPB') add_rect(sl, 0.3, 1.2, 5.9, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 5.9, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.7, 0.35, 'CHANGES IN LUNG FUNCTION', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.7, 5.2, ['Lung Volumes (Restrictive Pattern):', '• TLC (Total Lung Capacity) ↓', '• FRC (Functional Residual Capacity) ↓ — MOST IMPORTANT', '• VC (Vital Capacity) ↓ ~30% post-CABG', '• ERV (Expiratory Reserve Volume) ↓', '• FRC may return over weeks–months', '', 'Spirometry:', '• FEV₁ ↓', '• FVC ↓', '• FEV₁/FVC: preserved (restrictive, not obstructive)', '', 'Compliance:', '• Static compliance ↓ (30–50%)', '• Dynamic compliance ↓', '• Causes: oedema, atelectasis, surfactant loss,', ' pleural effusion, pneumonia', '', 'Airway Resistance:', '• ↑ (bronchoconstriction, secretions)', '• ↑ Peak and mean airway pressures on ventilator', ], size=14, color=DARK) add_rect(sl, 6.5, 1.2, 6.5, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.5, 1.2, 6.5, 0.4, fill=BLUE) add_tb(sl, 6.6, 1.23, 6.3, 0.35, 'CONTRIBUTORY FACTORS & TIMELINE', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.6, 1.72, 6.3, 5.2, ['Contributing to ↓ Compliance Post-CPB:', '• Pulmonary oedema (↑ lung water)', '• Atelectasis (collapsed alveolar units)', '• Pleural effusion (most often left-sided)', '• Loss of surfactant', '• Pneumonia (secondary complication)', '• Sternotomy → chest wall rigidity', '• Pain → poor inspiratory effort', '', 'IMA (Internal Mammary Artery) Harvesting:', '• Greater ↓ lung volumes post-CABG vs non-IMA', '• Phrenic nerve more vulnerable during IMA dissection', '• Left IMA harvest = left lung more affected', '', 'Timeline of Recovery:', '• Lung volumes: 30% ↓ at day 1', '• Nadir: post-op day 2 (worst gas exchange)', '• Gradual improvement over 2–4 weeks', '• Full recovery: may take 3–6 months (DLCO)', '• IMA patients: longer recovery', ], size=14, color=DARK) slide_number_dot(sl, 10, 18) # ─── SLIDE 11 — PHRENIC NERVE ──────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '9. PHRENIC NERVE PALSY & DIAPHRAGM DYSFUNCTION') add_rect(sl, 0.3, 1.2, 4.1, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.1, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.9, 0.35, 'PHRENIC NERVE PALSY', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.9, 5.2, ['Incidence: 20–70% after cardiac surgery', '', 'Causes:', '• Topical ice / cold cardioplegia slush', '• Left phrenic most commonly affected', '• Thermal injury during IMA harvesting', '• Direct surgical trauma / traction', '• Retractor placement', '• Iced saline irrigation (phrenic runs near IMA)', '', 'Features:', '• Unilateral diaphragm paralysis / elevation on CXR', '• Restrictive ventilatory defect', '• ↑ FiO₂ requirement post-extubation', '• Left lower lobe atelectasis (left phrenic)', '', 'Prognosis:', '• Most recover in 6–12 months (neuropraxia)', '• Permanent in 2–3% (axonotmesis/neurotmesis)', '• Bilateral palsy = ventilator dependence', ], size=13, color=DARK) add_rect(sl, 4.7, 1.2, 4.0, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.7, 1.2, 4.0, 0.4, fill=ORANGE) add_tb(sl, 4.8, 1.23, 3.8, 0.35, 'DIAPHRAGM DYSFUNCTION', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.8, 1.72, 3.8, 5.2, ['Mechanism (Fishman\'s Pulmonary):', '• ↓ Transdiaphragmatic pressure with tidal breathing', '• Shift from abdominal → rib-cage breathing', '• NOT due to diaphragm contractile failure', ' (phrenic stimulation = normal peak pressure)', '', 'Neurological Mechanism:', '• ↓ Phrenic nerve output (central inhibition)', '• Inhibitory arc from visceral sympathetic afferents', '• Epidural LOCAL anaesthetic (not opioids) → improves', ' diaphragm function (supports sympathetic mechanism)', '', 'Contributing Factors:', '• Pain → splinting → poor effort', '• Opioids → respiratory depression', '• Obesity → ↑ abdominal pressure', '• Prolonged CPB', '', 'Consequences:', '• FRC ↓ → small airway closure', '• Basal atelectasis → hypoxaemia', '• Prolonged ventilation', ], size=13, color=DARK) add_rect(sl, 9.0, 1.2, 4.0, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.0, 1.2, 4.0, 0.4, fill=BLUE) add_tb(sl, 9.1, 1.23, 3.8, 0.35, 'MANAGEMENT', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.1, 1.72, 3.8, 5.2, ['Prevention:', '• Avoid topical ice near phrenic nerves', '• Insulating pad over phrenic nerve during IMA harvest', '• Minimise retractor pressure', '• Warm cardioplegia preferred (less phrenic injury)', '', 'Treatment of Diaphragm Dysfunction:', '• CPAP / BiPAP non-invasive ventilation', '• Incentive spirometry', '• Respiratory physiotherapy', '• Adequate analgesia (↓ splinting)', '• Epidural local anaesthetic (not opioid alone)', '• Early mobilisation', '', 'Severe/Bilateral Phrenic Palsy:', '• Prolonged mechanical ventilation', '• Diaphragm plication (surgical)', '• Phrenic nerve pacing (experimental)', ], size=13, color=DARK) slide_number_dot(sl, 11, 18) # ─── SLIDE 12 — PUMP LUNG / ARDS ───────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '10. PUMP LUNG / ACUTE LUNG INJURY / ARDS POST-CPB') add_rect(sl, 0.3, 1.2, 4.1, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.1, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.9, 0.35, 'DEFINITION & CRITERIA', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.9, 5.2, ['"Pump lung" = severe form of CPB lung injury', '', 'ARDS Berlin Definition:', '• Onset: within 1 week of insult', '• Bilateral opacities on CXR / CT', '• Non-cardiogenic (PCWP <18 mmHg)', '• PaO₂/FiO₂ criteria:', ' Mild: 200–300 mmHg', ' Moderate: 100–200 mmHg', ' Severe: < 100 mmHg', '', 'Acute Lung Injury (ALI):', '• PaO₂/FiO₂ < 300 mmHg', '• (Older Berlin: now "mild ARDS")', '', 'Incidence Post-CPB:', '• ALI: ~5–10% of cardiac surgery patients', '• ARDS: ~2% of cardiac surgery patients', '• Mortality in ARDS: 50–80%', ], size=13, color=DARK) add_rect(sl, 4.7, 1.2, 4.0, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.7, 1.2, 4.0, 0.4, fill=ORANGE) add_tb(sl, 4.8, 1.23, 3.8, 0.35, 'PATHOLOGY & RISK FACTORS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.8, 1.72, 3.8, 5.2, ['Histology (Diffuse Alveolar Damage — DAD):', '• Hyaline membrane formation', '• Intra-alveolar fibrin deposition', '• Type I pneumocyte necrosis', '• Neutrophil infiltration', '• Interstitial oedema → fibrosis (if chronic)', '', 'Risk Factors for Post-CPB ARDS:', '• Prolonged CPB (>2 hours)', '• Re-operative cardiac surgery', '• Deep Hypothermic Circulatory Arrest (DHCA)', '• Massive transfusion / TRALI', '• Pre-existing lung disease', '• Sepsis (complicating)', '• Cardiac failure / cardiogenic shock pre-op', '• Emergency / high-risk surgery', '• Advanced age', ], size=13, color=DARK) add_rect(sl, 9.0, 1.2, 4.0, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.0, 1.2, 4.0, 0.4, fill=BLUE) add_tb(sl, 9.1, 1.23, 3.8, 0.35, 'MANAGEMENT OF POST-CPB ARDS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.1, 1.72, 3.8, 5.2, ['Lung-Protective Ventilation (ARDSNet):', '• Tidal volume 6 mL/kg IBW', '• Plateau pressure < 30 cmH₂O', '• PEEP titrated to oxygenation', '• FiO₂ minimised (target SpO₂ 92–95%)', '• Permissive hypercapnia (pH > 7.2)', '', 'Adjunctive Measures:', '• Prone positioning ≥ 16 hr/day (severe ARDS)', '• Neuromuscular blockade (early severe ARDS)', '• Conservative fluid strategy', '• Corticosteroids (select cases, prolonged ARDS)', '', 'Rescue Therapies:', '• Inhaled NO (iNO) — temporary improvement', '• VV-ECMO (veno-venous) — salvage therapy', '• Almitrine (pulmonary vasconstriction adjunct)', '', 'Treat Underlying Cause:', '• Antibiotics if sepsis/pneumonia', '• TRALI: stop suspected blood products', ], size=13, color=DARK) slide_number_dot(sl, 12, 18) # ─── SLIDE 13 — PULMONARY HYPERTENSION ─────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '11. PULMONARY HYPERTENSION & ↑PVR AFTER CPB') add_rect(sl, 0.3, 1.2, 6.0, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 6.0, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.8, 0.35, 'MECHANISMS OF ↑PVR AFTER CPB', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.8, 5.2, ['Vasoconstrictor Mediators Released:', '• Thromboxane A₂ (TXA₂) — platelet-derived', ' → Potent pulmonary vasoconstrictor', '• Endothelin-1 (ET-1)', ' → Released by damaged endothelium', ' → Sustained pulmonary vasoconstriction', '• C5a — complement-mediated', '• Serotonin (5-HT) — released from platelets during CPB', '• Histamine — from mast cell degranulation', '', 'Loss of Vasodilators:', '• Endothelial dysfunction → ↓ NO production', '• ↓ Prostacyclin (PGI₂)', '• Impaired endothelium-dependent relaxation', '', 'Protamine Reaction:', '• Protamine–heparin complexes → anaphylaxis', '• Complement activation → ↑ TXA₂', '• Massive ↑ PVR → RV failure', '• Most dangerous: prior protamine exposure', ], size=14, color=DARK) add_rect(sl, 6.6, 1.2, 6.4, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.6, 1.2, 6.4, 0.4, fill=BLUE) add_tb(sl, 6.7, 1.23, 6.2, 0.35, 'CLINICAL CONSEQUENCES & MANAGEMENT', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.7, 1.72, 6.2, 5.2, ['Consequences of ↑ PVR:', '• Right ventricular (RV) afterload ↑', '• RV dilatation → RV failure', '• Tricuspid regurgitation', '• Reduced LV preload (interventricular dependence)', '• Systemic hypotension', '• Difficulty weaning from CPB', '', 'High-Risk Patients (Pre-existing PHT):', '• Mitral valve disease (especially stenosis)', '• Congenital heart disease (↑ pulmonary flow)', '• Left heart failure (reactive PHT)', '• Pre-op PHT significantly worsened by CPB', '', 'Pharmacological Management:', '• iNO (Inhaled Nitric Oxide):', ' → Selective pulmonary vasodilator', ' → No systemic hypotension', ' → 5–40 ppm inhaled', '• Sildenafil (PDE-5 inhibitor)', '• Milrinone (PDE-3 inhibitor + inotrope)', '• Prostacyclin / Epoprostenol (inhaled)', '• Avoid: high PEEP, hypoxia, hypercarbia, acidosis', ], size=13, color=DARK) slide_number_dot(sl, 13, 18) # ─── SLIDE 14 — BRONCHOSPASM ───────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '12. BRONCHOSPASM & AIRWAY CHANGES DURING/AFTER CPB') add_rect(sl, 0.3, 1.2, 6.0, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 6.0, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.8, 0.35, 'MECHANISMS OF BRONCHOSPASM', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.8, 5.2, ['Humoral Mediators:', '• C3a, C5a → histamine release from mast cells', '• Serotonin → bronchoconstriction', '• Bradykinin → airway smooth muscle contraction', '• PGF₂α — prostanoid bronchoconstrictor', '• TXA₂ → bronchoconstriction', '', 'Drug-Related:', '• Protamine–heparin complexes:', ' → Anaphylactoid / anaphylactic reaction', ' → Massive histamine release → severe bronchospasm', ' → Especially in patients with prior protamine sensitisation', '', 'Mechanical / Reflex:', '• Cold blood perfusing bronchial circulation', '• Endotracheal tube stimulation', '• Inadequate depth of anaesthesia (light planes)', '', 'Pre-existing Airway Disease:', '• Asthma, COPD → greatly exaggerated response', '• ↑ Bronchial reactivity post-CPB', ], size=14, color=DARK) add_rect(sl, 6.6, 1.2, 6.4, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.6, 1.2, 6.4, 0.4, fill=BLUE) add_tb(sl, 6.7, 1.23, 6.2, 0.35, 'CLINICAL FEATURES & MANAGEMENT', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.7, 1.72, 6.2, 5.2, ['Clinical Features:', '• Wheeze (expiratory) on auscultation', '• ↑ Peak airway pressure on ventilator', '• ↑ Dynamic compliance (obstructive pattern)', '• Difficulty ventilating patient', '• SpO₂ ↓', '• In severe anaphylaxis: cardiovascular collapse', '', 'Management:', 'Immediate:', '• Increase FiO₂ to 1.0', '• Deepen anaesthesia (volatile = bronchodilator)', '• Isoflurane / sevoflurane preferred', '', 'Bronchodilators:', '• Salbutamol (via ETT or nebuliser)', '• Ipratropium bromide (anticholinergic)', '• Aminophylline IV (second-line)', '• Ketamine IV (anaesthetic + bronchodilator)', '', 'Anaphylaxis Protocol:', '• Adrenaline (epinephrine) 0.5 mg IM / IV', '• Chlorphenamine + hydrocortisone', '• Stop protamine immediately', ], size=13, color=DARK) slide_number_dot(sl, 14, 18) # ─── SLIDE 15 — POST-CPB MANAGEMENT ───────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '13. POST-CPB RESPIRATORY MANAGEMENT — COMPREHENSIVE APPROACH') add_rect(sl, 0.3, 1.2, 4.0, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.0, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.8, 0.35, 'INTRAOPERATIVE (ON CPB)', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.8, 5.2, ['During Bypass:', '• CPAP 5 cmH₂O to lungs (prevents collapse)', '• Avoid high O₂ concentrations', '• Modified Ultrafiltration (MUF)', '• Minimise bypass duration', '• Leukocyte-depleting filters', '• Corticosteroids pre-CPB (methylprednisolone)', '• Aprotinin / tranexamic acid', '', 'On Weaning from CPB:', '• Manual recruitment manoeuvre', '• Sustained inflation 30–40 cmH₂O × 10 sec', '• Re-inflate lungs before coming off bypass', '• Check for residual pneumothorax', '• TEE to assess cardiac function', ], size=13, color=DARK) add_rect(sl, 4.6, 1.2, 4.2, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.6, 1.2, 4.2, 0.4, fill=ORANGE) add_tb(sl, 4.7, 1.23, 4.0, 0.35, 'POSTOPERATIVE — VENTILATED', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.7, 1.72, 4.0, 5.2, ['Ventilator Settings:', '• Mode: Synchronised IMV → Pressure Support', '• Tidal volume: 6–8 mL/kg IBW', '• PEEP: 5–8 cmH₂O (routine)', '• FiO₂: Wean to maintain SpO₂ ≥ 94%', '• RR: 12–16 breaths/min', '', 'Fast-Track Extubation Protocol:', '• Criteria: awake, warm, haemostasis,', ' haemodynamically stable, acceptable ABG', '• Target: extubation within 4–8 hours of surgery', '• Benefits: ↓ ICU stay, ↓ ventilator complications', '', 'Sedation/Analgesia:', '• Adequate IV analgesia (↓ splinting)', '• Paracetamol + NSAID + opioid (multimodal)', '• Regional: intercostal blocks, epidural', '', 'Fluids:', '• Diuretics (furosemide): remove excess fluid', ], size=13, color=DARK) add_rect(sl, 9.1, 1.2, 3.9, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.1, 1.2, 3.9, 0.4, fill=BLUE) add_tb(sl, 9.2, 1.23, 3.7, 0.35, 'POST-EXTUBATION', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.2, 1.72, 3.7, 5.2, ['Non-Invasive Ventilation (NIV):', '• CPAP 5–10 cmH₂O if hypoxaemia persists', '• BiPAP if CO₂ retention / respiratory failure', '', 'Airway Clearance:', '• Incentive spirometry (every 1–2 hours)', '• Active breathing exercises', '• Assisted cough technique', '• Humidified oxygen therapy', '', 'Physiotherapy:', '• Postural drainage', '• Manual techniques', '• Early ambulation (sitting up, walking)', '', 'Specific Interventions:', '• Pleural drains: drain effusions if large', '• Bronchoscopy: if lobar collapse persists', '• Nasopharyngeal airway (NPA): if secretions', '', 'Follow-up:', '• Serial CXR (daily post-op)', '• ABG / SpO₂ monitoring', ], size=13, color=DARK) slide_number_dot(sl, 15, 18) # ─── SLIDE 16 — STRESS RESPONSE ────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '14. STRESS RESPONSE & CPB — PULMONARY IMPLICATIONS') add_rect(sl, 0.3, 1.2, 6.0, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 6.0, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 5.8, 0.35, 'STRESS RESPONSE TO CPB (Miller\'s Anesthesia)', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 5.8, 5.2, ['Substances released during CPB:', '• Catecholamines (adrenaline, noradrenaline)', '• Cortisol (↑↑ during rewarming)', '• Growth hormone', '• Prostaglandins', '• Complement (C3a, C5a)', '• Endorphins / opioids', '• Glucose / insulin dysregulation', '', 'Triggers of stress response:', '• Blood-foreign surface contact', '• Non-pulsatile flow', '• Low perfusion pressure', '• Haemodilution', '• Hypothermia', '• Light anaesthesia', '• Delayed renal/hepatic clearance during hypothermic CPB', '', 'Peak: Occurs during rewarming from CPB', '', 'LUNG\'s role: Normally metabolises & clears these hormones.', 'During CPB — lung excluded → accumulate → ↑ vasoactive effects', ], size=14, color=DARK) add_rect(sl, 6.6, 1.2, 6.4, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 6.6, 1.2, 6.4, 0.4, fill=BLUE) add_tb(sl, 6.7, 1.23, 6.2, 0.35, 'PULMONARY CONSEQUENCES OF STRESS RESPONSE', 14, bold=True, color=WHITE) add_bullet_tb(sl, 6.7, 1.72, 6.2, 5.2, ['Catecholamines:', '• Systemic & pulmonary hypertension', '• ↑ Myocardial O₂ demand', '', 'Prostaglandins (TXA₂):', '• Pulmonary endothelial damage', '• Pulmonary vascular reactivity', '• Bronchoconstriction', '', 'Complement (C3a, C5a):', '• Neutrophil activation → lung injury', '• Capillary-alveolar membrane damage', '', 'Clinical Implications:', '• Pulmonary hypertension post-CPB', '• Difficulty weaning from ventilator', '• Myocardial damage (indirect)', '', 'Blunting the Stress Response:', '• High-dose opioids (fentanyl/sufentanil)', '• Inhaled volatile anaesthetic via oxygenator', '• Dexmedetomidine infusion', '• Benzodiazepines', '• NOTE: complete elimination not desirable', ' (catecholamines needed for haemodynamic stability)', ], size=13, color=DARK) slide_number_dot(sl, 16, 18) # ─── SLIDE 17 — SUMMARY TABLE ──────────────────────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '15. SUMMARY TABLE — CPB EFFECTS ON RESPIRATORY SYSTEM') # Table data headers = ['Parameter', 'Normal Value', 'Post-CPB', 'Mechanism', 'Clinical Management'] rows = [ ['PaO₂ (room air)', '~90 mmHg', '~55 mmHg (day 2)', 'V/Q mismatch, shunt, oedema', 'O₂ therapy, PEEP, treat atelectasis'], ['A-a Gradient', '<15 mmHg', 'Markedly elevated', 'Shunting + diffusion impairment', 'Treat underlying V/Q mismatch'], ['Shunt Fraction', '~3%', '~19%', 'Atelectatic perfused units', 'PEEP, lung recruitment manoeuvres'], ['Static Compliance', '~100 mL/cmH₂O', '↓ 30–50%', 'Oedema, surfactant loss, atelectasis', 'MUF, diuretics, PEEP'], ['FRC', 'Normal', '↓ 15–30%', 'Atelectasis, diaphragm dysfunction', 'PEEP, incentive spirometry'], ['PVR', 'Normal', '↑ (often marked)', 'TXA₂, ET-1, C5a, ↓NO', 'iNO, sildenafil, milrinone'], ['Surfactant', 'Active (normal)', '↓ Activity', 'Type II pneumocyte dysfunction', 'PEEP, exogenous surfactant (neonates)'], ['Lung Volumes', 'Normal', '↓ ~30% (CABG)', 'Atelectasis, pleural effusion', 'Physio, incentive spirometry'], ['Airway Resistance', 'Normal', '↑', 'Bronchospasm, secretions', 'Bronchodilators, volatile agents'], ['DLCO', 'Normal', '↓ (weeks–months)', 'Oedema, membrane damage', 'Time — gradual recovery'], ] col_ws = [Inches(1.6), Inches(1.5), Inches(1.6), Inches(3.5), Inches(5.0)] col_xs = [Inches(0.12)] for cw in col_ws[:-1]: col_xs.append(col_xs[-1] + cw + Inches(0.02)) row_h = Inches(0.42) start_y = Inches(1.25) # Header row for i,(h,cw,cx) in enumerate(zip(headers, col_ws, col_xs)): sh = sl.shapes.add_shape(1, cx, start_y, cw, row_h) sh.fill.solid(); sh.fill.fore_color.rgb = RED sh.line.fill.background() tf = sh.text_frame tf.margin_left=Pt(4); tf.margin_top=Pt(2) tf.vertical_anchor = MSO_ANCHOR.MIDDLE p = tf.paragraphs[0]; p.alignment=PP_ALIGN.CENTER r = p.add_run(); r.text=h; r.font.name='Calibri' r.font.size=Pt(13); r.font.bold=True; r.font.color.rgb=WHITE # Data rows row_colors = [RGBColor(0xFF,0xFF,0xFF), RGBColor(0xDE,0xEB,0xF7)] for ri, row in enumerate(rows): ry = start_y + row_h + Inches(0.02) + ri*(row_h + Inches(0.02)) for ci,(cell,cw,cx) in enumerate(zip(row,col_ws,col_xs)): sh = sl.shapes.add_shape(1, cx, ry, cw, row_h) sh.fill.solid(); sh.fill.fore_color.rgb = row_colors[ri%2] sh.line.color.rgb=MID_GRAY; sh.line.width=Pt(0.5) tf = sh.text_frame tf.margin_left=Pt(4); tf.margin_top=Pt(1) tf.vertical_anchor = MSO_ANCHOR.MIDDLE tf.word_wrap = True p = tf.paragraphs[0] r = p.add_run(); r.text=cell; r.font.name='Calibri' r.font.size=Pt(12); r.font.color.rgb=DARK r.font.bold = (ci == 0) slide_number_dot(sl, 17, 18) # ─── SLIDE 18 — QUICK RECALL (EXAM MNEMONICS) ──────────────────────────────── sl = prs.slides.add_slide(blank) set_bg(sl, CREAM) section_header_bar(sl, '16. EXAM QUICK-RECALL — KEY FACTS & NUMBERS') add_rect(sl, 0.3, 1.2, 4.1, 5.9, fill=WHITE, line=RED, line_w=Pt(1.5)) add_rect(sl, 0.3, 1.2, 4.1, 0.4, fill=RED) add_tb(sl, 0.4, 1.23, 3.9, 0.35, 'NUMBERS TO KNOW', 14, bold=True, color=WHITE) add_bullet_tb(sl, 0.4, 1.72, 3.9, 5.2, ['Atelectasis: Up to 50% of lung volume', 'PaO₂ nadir: ~55 mmHg (post-op day 2)', 'Shunt pre-op: 3% → post-op: 19%', 'Lung volumes ↓: ~30% post-CABG', 'Phrenic palsy incidence: 20–70%', 'ARDS incidence post-CPB: ~2%', 'ARDS mortality: 50–80%', 'ALI = PaO₂/FiO₂ < 300', 'ARDS = PaO₂/FiO₂ < 200', 'Fast-track extubation: 4–8 hours', 'Phrenic nerve recovery: 6–12 months', 'DLCO recovery: weeks to months', 'iNO dose: 5–40 ppm', 'Vt (lung-protective): 6 mL/kg IBW', 'PEEP (routine post-CPB): 5–8 cmH₂O', ], size=14, color=DARK) add_rect(sl, 4.7, 1.2, 4.0, 5.9, fill=WHITE, line=ORANGE, line_w=Pt(1.5)) add_rect(sl, 4.7, 1.2, 4.0, 0.4, fill=ORANGE) add_tb(sl, 4.8, 1.23, 3.8, 0.35, 'MEDIATORS — AT A GLANCE', 14, bold=True, color=WHITE) add_bullet_tb(sl, 4.8, 1.72, 3.8, 5.2, ['Complement: C3a, C5a', ' → Anaphylatoxins, neutrophil chemoattractants', '', 'Cytokines: IL-1β, IL-6, IL-8, TNF-α', ' → Inflammation, endothelial activation', '', 'Thromboxane A₂', ' → ↑PVR + bronchoconstriction', '', 'Endothelin-1', ' → Sustained vasoconstriction', '', 'Bradykinin', ' → Capillary leak, bronchospasm', '', 'Neutrophil elastase + MPO', ' → Alveolar-capillary damage', '', 'PAF (Platelet Activating Factor)', ' → ↑ Inflammation, bronchoconstriction', ], size=14, color=DARK) add_rect(sl, 9.0, 1.2, 4.0, 5.9, fill=WHITE, line=BLUE, line_w=Pt(1.5)) add_rect(sl, 9.0, 1.2, 4.0, 0.4, fill=BLUE) add_tb(sl, 9.1, 1.23, 3.8, 0.35, 'MANAGEMENT PEARLS', 14, bold=True, color=WHITE) add_bullet_tb(sl, 9.1, 1.72, 3.8, 5.2, ['Best evidence interventions:', '1. MUF — reduces lung water (paediatrics)', '2. PEEP 5–8 cmH₂O — alveolar recruitment', '3. Lung-protective ventilation (6 mL/kg)', '4. Early extubation (fast-track)', '5. Physiotherapy + incentive spirometry', '', 'For ↑PVR:', '→ iNO (first-line, most selective)', '→ Milrinone (also improves cardiac output)', '→ Sildenafil (oral PDE-5 inhibitor)', '→ Avoid hypoxia, hypercarbia, acidosis', '', 'For Bronchospasm:', '→ Volatile agents (isoflurane/sevoflurane)', '→ Salbutamol nebuliser / IV', '→ Deepened anaesthesia', '', 'For ARDS post-CPB:', '→ ARDSNet protocol: Vt 6 mL/kg, PEEP', '→ Prone ≥16 hr/day if PaO₂/FiO₂ <150', '→ VV-ECMO if refractory', ], size=13, color=DARK) slide_number_dot(sl, 18, 18) # ─── SAVE ───────────────────────────────────────────────────────────────────── out = '/tmp/workspace/cpb-pptx/CPB_Respiratory_Effects_Exam_Revision.pptx' prs.save(out) print(f'Saved: {out}') import os print(f'Size: {os.path.getsize(out)/1024:.1f} KB') print(f'Slides: {len(prs.slides)}') PYEOF
python3 << 'PYEOF' from pptx import Presentation prs = Presentation('/tmp/workspace/cpb-pptx/CPB_Respiratory_Effects_Exam_Revision.pptx') print(f"Total slides: {len(prs.slides)}") for i, slide in enumerate(prs.slides, 1): texts = [] for shape in slide.shapes: if shape.has_text_frame: t = shape.text_frame.text.strip()[:80] if t: texts.append(t) print(f" Slide {i}: {texts[0] if texts else 'NO TEXT'}") PYEOF
CPB Respiratory Effects Exam Revision
Presentation · PPTX
| # | Slide Title |
|---|---|
| 1 | Title Slide |
| 2 | Overview / Table of Contents |
| 3 | Why Are the Lungs Uniquely Vulnerable During CPB? |
| 4 | Two Main Pathways of Lung Injury (Inflammatory vs Mechanical) |
| 5 | SIRS — Triggers, Key Mediators, Pulmonary Effects |
| 6 | Atelectasis — Mechanism, ABG Values, Clinical Features |
| 7 | Surfactant Dysfunction — Pathophysiology & Management |
| 8 | Pulmonary Oedema & Capillary Leak — 3-column slide |
| 9 | V/Q Mismatch & Gas Exchange — with exact numbers |
| 10 | Pulmonary Mechanics Changes (compliance, FRC, spirometry) |
| 11 | Phrenic Nerve Palsy & Diaphragm Dysfunction |
| 12 | Pump Lung / ALI / ARDS — Berlin criteria + management |
| 13 | Pulmonary Hypertension Post-CPB |
| 14 | Bronchospasm & Airway Changes |
| 15 | Post-CPB Respiratory Management (intra-op → ICU → post-extubation) |
| 16 | Stress Response & Its Pulmonary Consequences (Miller's Anesthesia) |
| 17 | Summary Comparison Table (10 parameters side-by-side) |
| 18 | Exam Quick-Recall: Numbers, Mediators, Management Pearls |
Low v/Q

"Regions of low V/Q have low ventilation relative to perfusion, usually because ventilation is decreased. Because ventilation is low relative to perfusion, pulmonary capillary blood from these regions has a low PO₂ and high PCO₂." — Costanzo Physiology, 7th ed.
| Condition | V/Q | Alveolar O₂ | Alveolar CO₂ | Capillary blood |
|---|---|---|---|---|
| Normal | ~0.8 | ~100 mmHg | ~40 mmHg | Well oxygenated |
| Low V/Q | 0.01–0.8 | ↓ (e.g. 60–90 mmHg) | ↑ | Poorly oxygenated, ↑CO₂ |
| True shunt | 0 | = Mixed venous | = Mixed venous | Not oxygenated at all |
| High V/Q | >1 | ↑ | ↓ | Well oxygenated (wasted ventilation) |
| Dead space | ∞ | = Inspired air | ≈0 | No perfusion |
"The best clinical approach to hypoxemia due to low V/Q areas is to increase inspired oxygen... small to moderate amounts of supplemental O₂ corrects this type of hypoxemia." — Murray & Nadel's Respiratory Medicine

"HPV is most evident during one-lung ventilation where flow through the non-ventilated lung is reduced by 50%. HPV is inhibited by inhalational anaesthetics and high concentrations of inspired oxygen." — Barash Clinical Anaesthesia, 9th ed.
| Parameter | Finding | Why |
|---|---|---|
| PaO₂ | ↓ | Poorly oxygenated blood from low V/Q units mixes into arterial blood |
| PaCO₂ | Normal or slight ↑ | Central chemoreceptors increase RR to compensate; CO₂ is buffered more easily than O₂ |
| A-a gradient | ↑ | Confirms the problem is in the lung, not just hypoventilation |
| Response to O₂ | ✓ Good | Distinguishes from true shunt |
| Feature | Low V/Q | True Shunt (V/Q = 0) |
|---|---|---|
| Ventilation | Present (reduced) | Absent |
| Response to 100% O₂ | PaO₂ rises significantly | PaO₂ barely rises |
| A-a gradient | Elevated | Elevated |
| Examples | COPD, asthma, mild atelectasis | Lobar consolidation, intracardiac shunt, ARDS |
| Treatment | O₂ supplementation | Reduce the shunt (PEEP, prone, treat cause) |