from Guyton and Hall textbook of medical physiology, 4th South Asia edition write a 5 mark short note on circulatory shock -define,classify,stages,physiological principles of management
| Type | Mechanism | Examples |
|---|---|---|
| 1. Cardiogenic | Decreased cardiac pumping ability | Myocardial infarction, severe arrhythmias, myocarditis, valvular dysfunction - carries ~70% mortality |
| 2. Hypovolemic | Decreased venous return due to reduced blood volume | Hemorrhage, severe dehydration, plasma loss (burns) |
| 3. Distributive (Vasodilatory) | Normal or high cardiac output but abnormal tissue perfusion | Septic shock, neurogenic shock, anaphylactic shock |
| 4. Obstructive | Impaired blood flow from/to the heart (non-cardiac pump failure) | Massive pulmonary embolism, cardiac tamponade |
summarise this answer in form of tables , flowcharts and diagrams
ls -la /tmp/workspace/ 2>/dev/null || echo "workspace empty or missing"
mkdir -p /tmp/workspace/circulatory-shock && python3 -c "import matplotlib; import reportlab; print('libs ok')"
~/circulatory-shock/build_shock_pdf.py
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import FancyBboxPatch, FancyArrowPatch
import matplotlib.gridspec as gridspec
import numpy as np
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch, cm
from reportlab.platypus import (SimpleDocTemplate, Paragraph, Spacer, Table,
TableStyle, Image, HRFlowable, PageBreak)
from reportlab.lib.enums import TA_CENTER, TA_LEFT
import os
OUT_DIR = '/tmp/workspace/circulatory-shock'
os.makedirs(OUT_DIR, exist_ok=True)
# ─────────────────────────────────────────────────────────────
# FIGURE 1: Classification Table (as matplotlib figure)
# ─────────────────────────────────────────────────────────────
def make_classification_table():
fig, ax = plt.subplots(figsize=(12, 4))
ax.axis('off')
cols = ['Type', 'Mechanism', 'Cardiac Output', 'SVR', 'Key Examples']
rows = [
['Cardiogenic', 'Pump failure', '↓↓', '↑↑', 'MI, arrhythmia, myocarditis\n(~70% mortality)'],
['Hypovolemic', 'Reduced blood volume\n→ ↓ venous return', '↓↓', '↑↑', 'Haemorrhage, burns,\ndehydration'],
['Distributive\n(Vasodilatory)', 'Abnormal peripheral\nvascular tone', 'Normal/↑', '↓↓', 'Septic, neurogenic,\nanaphylactic shock'],
['Obstructive', 'Mechanical block to\nblood flow', '↓↓', '↑↑', 'Pulmonary embolism,\ncardiac tamponade'],
]
col_widths = [1.6, 2.4, 1.4, 1.0, 2.6]
table = ax.table(
cellText=rows,
colLabels=cols,
loc='center',
cellLoc='center',
colWidths=col_widths
)
table.auto_set_font_size(False)
table.set_fontsize(9.5)
table.scale(1, 2.2)
# Header style
for j in range(len(cols)):
table[0, j].set_facecolor('#1a3a5c')
table[0, j].set_text_props(color='white', fontweight='bold')
# Row colours
row_colors = ['#d6e4f0', '#eaf4fb', '#d6e4f0', '#eaf4fb']
for i, rc in enumerate(row_colors, start=1):
for j in range(len(cols)):
table[i, j].set_facecolor(rc)
ax.set_title('TABLE 1: Classification of Circulatory Shock',
fontsize=13, fontweight='bold', pad=12, color='#1a3a5c')
plt.tight_layout()
path = f'{OUT_DIR}/fig1_classification.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='white')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# FIGURE 2: Stages of Shock Flowchart
# ─────────────────────────────────────────────────────────────
def make_stages_flowchart():
fig, ax = plt.subplots(figsize=(14, 9))
ax.set_xlim(0, 14)
ax.set_ylim(0, 9)
ax.axis('off')
ax.set_facecolor('#f8fbff')
fig.patch.set_facecolor('#f8fbff')
def box(ax, x, y, w, h, text, fc, ec='#333333', fs=9, bold=False, tc='black'):
rect = FancyBboxPatch((x - w/2, y - h/2), w, h,
boxstyle='round,pad=0.12', facecolor=fc,
edgecolor=ec, linewidth=1.8)
ax.add_patch(rect)
weight = 'bold' if bold else 'normal'
ax.text(x, y, text, ha='center', va='center', fontsize=fs,
fontweight=weight, color=tc,
wrap=True, multialignment='center')
def arrow(ax, x1, y1, x2, y2, color='#444444'):
ax.annotate('', xy=(x2, y2), xytext=(x1, y1),
arrowprops=dict(arrowstyle='->', color=color, lw=2.0))
# Title
ax.text(7, 8.6, 'FIGURE 1: Stages of Circulatory Shock (Guyton & Hall)',
ha='center', va='center', fontsize=13, fontweight='bold', color='#1a3a5c')
# Trigger box
box(ax, 7, 7.8, 4.5, 0.7, 'PRECIPITATING EVENT\n(e.g. Haemorrhage / Pump Failure / Vasodilation)',
'#2c5f8a', '#1a3a5c', fs=9, bold=True, tc='white')
arrow(ax, 7, 7.45, 7, 6.85)
# Stage 1
box(ax, 7, 6.5, 4.8, 0.65,
'STAGE 1 – NON-PROGRESSIVE (Compensated)',
'#27ae60', '#1e8449', fs=9.5, bold=True, tc='white')
arrow(ax, 7, 6.18, 7, 5.65)
# Compensatory mechanisms box
comp_text = ('Sympathetic reflexes (↑HR, vasoconstriction)\n'
'RAAS activation → Angiotensin II\n'
'ADH/Vasopressin secretion\n'
'Reverse stress-relaxation of vessels\n'
'Fluid shift: interstitium → capillaries')
box(ax, 7, 5.1, 5.8, 1.0, comp_text, '#d5f5e3', '#27ae60', fs=8.5)
# Recovery arrow (left branch)
ax.annotate('', xy=(2.5, 5.8), xytext=(4.1, 5.1),
arrowprops=dict(arrowstyle='->', color='#27ae60', lw=2.0))
box(ax, 1.6, 5.8, 1.8, 0.5, 'RECOVERY\n(Full)', '#a9dfbf', '#27ae60', fs=8, bold=True)
# Arrow down if uncontrolled
arrow(ax, 7, 4.6, 7, 4.05)
ax.text(7.3, 4.35, 'If uncontrolled / severe', ha='left', fontsize=8, color='#e74c3c', style='italic')
# Stage 2
box(ax, 7, 3.7, 4.8, 0.65,
'STAGE 2 – PROGRESSIVE',
'#e67e22', '#ca6f1e', fs=9.5, bold=True, tc='white')
arrow(ax, 7, 3.38, 7, 2.8)
# Positive feedback loops
prog_text = ('Positive feedback / vicious cycles:\n'
'↓Coronary flow → ↓Myocardial function\n'
'Vasomotor failure → generalised vasodilation\n'
'RBC sludging → capillary blockage\n'
'↑Capillary permeability → further ↓ blood volume\n'
'Lysosomal enzyme release → cell damage\n'
'Lactic acidosis → impairs heart & vessels')
box(ax, 7, 2.25, 5.8, 1.0, prog_text, '#fdebd0', '#e67e22', fs=8.5)
arrow(ax, 7, 1.75, 7, 1.2)
ax.text(7.3, 1.47, 'Without therapy', ha='left', fontsize=8, color='#e74c3c', style='italic')
# Stage 3
box(ax, 7, 0.85, 4.8, 0.65,
'STAGE 3 – IRREVERSIBLE',
'#c0392b', '#922b21', fs=9.5, bold=True, tc='white')
irrev_text = ('ATP/Creatine phosphate depleted\n'
'Adenosine → Uric acid (cannot re-enter cells)\n'
'Massive tissue necrosis → Death')
box(ax, 7, 0.2, 5.2, 0.5, irrev_text, '#fadbd8', '#c0392b', fs=8)
# Therapy label (right side)
box(ax, 12.2, 3.7, 2.2, 0.5, 'Therapy can\nreverse', '#aed6f1', '#2e86c1', fs=8)
ax.annotate('', xy=(9.4, 3.7), xytext=(11.1, 3.7),
arrowprops=dict(arrowstyle='<-', color='#2e86c1', lw=1.8))
box(ax, 12.2, 0.85, 2.2, 0.5, 'Therapy\nfails', '#f1948a', '#c0392b', fs=8)
ax.annotate('', xy=(9.4, 0.85), xytext=(11.1, 0.85),
arrowprops=dict(arrowstyle='<-', color='#c0392b', lw=1.8))
plt.tight_layout()
path = f'{OUT_DIR}/fig2_stages_flowchart.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='#f8fbff')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# FIGURE 3: Compensatory mechanisms mind-map style
# ─────────────────────────────────────────────────────────────
def make_compensatory_diagram():
fig, ax = plt.subplots(figsize=(13, 8))
ax.set_xlim(0, 13)
ax.set_ylim(0, 8)
ax.axis('off')
ax.set_facecolor('#fdfefe')
fig.patch.set_facecolor('#fdfefe')
ax.text(6.5, 7.7, 'FIGURE 2: Compensatory Mechanisms in Non-Progressive Shock',
ha='center', va='center', fontsize=13, fontweight='bold', color='#1a3a5c')
# Central node
centre = (6.5, 4.0)
circle = plt.Circle(centre, 1.05, color='#1a3a5c', zorder=3)
ax.add_patch(circle)
ax.text(centre[0], centre[1], 'Shock\n(↓ Cardiac\nOutput)', ha='center',
va='center', fontsize=9.5, fontweight='bold', color='white', zorder=4)
# Satellites
satellites = [
(1.5, 6.5, '#2980b9', 'Sympathetic\nReflexes',
'• ↑ HR (up to 180 bpm)\n• Arteriolar constriction\n• Venous constriction\n• Activated in 30 sec'),
(1.5, 2.0, '#8e44ad', 'RAAS',
'• ↑ Renin → Ang II\n• Arteriolar constriction\n• ↓ Renal Na+/H2O loss\n• Active in 10–60 min'),
(6.5, 0.5, '#16a085', 'Fluid Shifts',
'• Interstitial → capillary\n• Intestinal absorption\n• ↑ Thirst & salt appetite\n• Takes 1–48 hrs'),
(11.5, 2.0, '#d35400', 'Vasopressin\n(ADH)',
'• Vasoconstriction\n• ↑ Renal water retention\n• Posterior pituitary\n• Active in 10–60 min'),
(11.5, 6.5, '#27ae60', 'Adrenal\nMedulla',
'• ↑ Epinephrine\n• ↑ Norepinephrine\n• ↑ HR & vasoconstriction\n• Activated in 30 sec'),
(6.5, 7.2, '#c0392b', 'Reverse Stress\nRelaxation',
'• Vessels contract\n• around ↓ blood volume\n• Maintains filling\n• pressure'),
]
for (sx, sy, sc, stitle, stext) in satellites:
# Draw satellite box
bw, bh = 2.5, 1.5
rect = FancyBboxPatch((sx - bw/2, sy - bh/2), bw, bh,
boxstyle='round,pad=0.1', facecolor=sc+'33',
edgecolor=sc, linewidth=2.0)
ax.add_patch(rect)
ax.text(sx, sy + 0.35, stitle, ha='center', va='center',
fontsize=8.5, fontweight='bold', color=sc)
ax.text(sx, sy - 0.25, stext, ha='center', va='center',
fontsize=7.2, color='#222222')
# Arrow from centre to satellite
dx = sx - centre[0]
dy = sy - centre[1]
dist = (dx**2 + dy**2)**0.5
ux, uy = dx/dist, dy/dist
x1 = centre[0] + ux * 1.07
y1 = centre[1] + uy * 1.07
x2 = sx - ux * (bw/2 + 0.05)
y2 = sy - uy * (bh/2 + 0.05)
ax.annotate('', xy=(x2, y2), xytext=(x1, y1),
arrowprops=dict(arrowstyle='->', color=sc, lw=2.0))
plt.tight_layout()
path = f'{OUT_DIR}/fig3_compensatory.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='#fdfefe')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# FIGURE 4: Progressive Shock – Positive Feedback Cycles
# ─────────────────────────────────────────────────────────────
def make_positive_feedback():
fig, ax = plt.subplots(figsize=(13, 7.5))
ax.set_xlim(0, 13)
ax.set_ylim(0, 7.5)
ax.axis('off')
ax.set_facecolor('#fff9f9')
fig.patch.set_facecolor('#fff9f9')
ax.text(6.5, 7.2, 'FIGURE 3: Progressive Shock – Positive Feedback Vicious Cycles',
ha='center', va='center', fontsize=13, fontweight='bold', color='#922b21')
def rbox(ax, x, y, w, h, text, fc, ec, fs=8.5):
rect = FancyBboxPatch((x - w/2, y - h/2), w, h,
boxstyle='round,pad=0.1', facecolor=fc,
edgecolor=ec, linewidth=1.8)
ax.add_patch(rect)
ax.text(x, y, text, ha='center', va='center', fontsize=fs,
multialignment='center', color='#111111')
def arr(ax, x1, y1, x2, y2, color='#c0392b', label=''):
ax.annotate('', xy=(x2, y2), xytext=(x1, y1),
arrowprops=dict(arrowstyle='->', color=color, lw=1.8))
if label:
mx, my = (x1+x2)/2, (y1+y2)/2
ax.text(mx+0.1, my, label, fontsize=7.5, color=color, style='italic')
# Central
rbox(ax, 6.5, 3.8, 2.6, 0.7, '↓ Cardiac Output\n↓ Arterial Pressure',
'#f9ebea', '#c0392b', fs=9.5)
# Cycle 1 – Cardiac depression
rbox(ax, 2.0, 5.8, 2.8, 0.7, '↓ Coronary blood flow\n→ Myocardial weakening', '#fadbd8', '#c0392b')
arr(ax, 5.2, 4.1, 3.4, 5.5, '#c0392b')
arr(ax, 2.0, 5.45, 5.2, 4.0, '#c0392b')
ax.text(1.0, 4.8, 'Cycle 1:\nCardiac\nDepression', fontsize=7.5, color='#c0392b',
ha='center', style='italic')
# Cycle 2 – Vasomotor failure
rbox(ax, 11.0, 5.8, 2.8, 0.7, 'Vasomotor centre\nischaemia → Vasodilation', '#fadbd8', '#c0392b')
arr(ax, 7.8, 4.1, 9.6, 5.5, '#c0392b')
arr(ax, 11.0, 5.45, 7.8, 4.0, '#c0392b')
ax.text(12.0, 4.8, 'Cycle 2:\nVasomotor\nFailure', fontsize=7.5, color='#c0392b',
ha='center', style='italic')
# Cycle 3 – Capillary failure
rbox(ax, 2.0, 1.8, 2.8, 0.7, '↑ Capillary permeability\n→ Fluid loss to tissues', '#fadbd8', '#e67e22')
arr(ax, 5.2, 3.5, 3.4, 2.1, '#e67e22')
arr(ax, 2.0, 2.15, 5.2, 3.5, '#e67e22')
ax.text(1.0, 2.8, 'Cycle 3:\nCapillary\nFailure', fontsize=7.5, color='#e67e22',
ha='center', style='italic')
# Cycle 4 – Cellular deterioration
rbox(ax, 11.0, 1.8, 2.8, 0.7, 'Lysosomal enzymes\nreleased → Cell damage', '#fadbd8', '#8e44ad')
arr(ax, 7.8, 3.5, 9.6, 2.1, '#8e44ad')
arr(ax, 11.0, 2.15, 7.8, 3.5, '#8e44ad')
ax.text(12.0, 2.8, 'Cycle 4:\nCellular\nDeterioration', fontsize=7.5, color='#8e44ad',
ha='center', style='italic')
# Bottom - metabolic acidosis
rbox(ax, 6.5, 0.7, 4.0, 0.6, 'Lactic Acidosis + RBC Sludging → ↓ Tissue perfusion', '#f9ebea', '#e74c3c')
arr(ax, 6.5, 3.45, 6.5, 1.0, '#e74c3c')
plt.tight_layout()
path = f'{OUT_DIR}/fig4_positive_feedback.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='#fff9f9')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# FIGURE 5: Treatment / Management flowchart
# ─────────────────────────────────────────────────────────────
def make_management_flowchart():
fig, ax = plt.subplots(figsize=(14, 9))
ax.set_xlim(0, 14)
ax.set_ylim(0, 9)
ax.axis('off')
ax.set_facecolor('#f0f8ff')
fig.patch.set_facecolor('#f0f8ff')
ax.text(7, 8.7, 'FIGURE 4: Physiological Principles of Management of Circulatory Shock',
ha='center', va='center', fontsize=12, fontweight='bold', color='#1a3a5c')
def box(ax, x, y, w, h, text, fc, ec, fs=8.8, bold=False, tc='black'):
rect = FancyBboxPatch((x - w/2, y - h/2), w, h,
boxstyle='round,pad=0.12', facecolor=fc,
edgecolor=ec, linewidth=2.0)
ax.add_patch(rect)
weight = 'bold' if bold else 'normal'
ax.text(x, y, text, ha='center', va='center', fontsize=fs,
fontweight=weight, color=tc, multialignment='center')
# Top: Patient in shock
box(ax, 7, 8.1, 4.5, 0.7, 'PATIENT IN CIRCULATORY SHOCK',
'#1a3a5c', '#0d2137', fs=10, bold=True, tc='white')
# Step 1 - Positioning
box(ax, 2.2, 6.8, 3.6, 0.85,
'STEP 1\nTrendelenburg Position\n(Head down, feet up 12")',
'#d6eaf8', '#2e86c1', fs=8.5)
ax.text(2.2, 6.2, '↑ Venous return\n↑ Cardiac output', ha='center',
fontsize=7.5, color='#2e86c1', style='italic')
# Step 2 - O2
box(ax, 6.2, 6.8, 3.2, 0.85,
'STEP 2\nOxygen Therapy\n(Limited benefit)',
'#d5f5e3', '#27ae60', fs=8.5)
ax.text(6.2, 6.2, 'Problem = poor transport\nnot oxygenation', ha='center',
fontsize=7.5, color='#27ae60', style='italic')
# Arrows from top box
for tx in [2.2, 6.2]:
ax.annotate('', xy=(tx, 7.2), xytext=(7, 7.75),
arrowprops=dict(arrowstyle='->', color='#555', lw=1.5))
# Step 3 - Replacement
box(ax, 11, 6.8, 3.8, 0.85,
'STEP 3\nReplacement Therapy',
'#fdebd0', '#d35400', fs=8.5, bold=True)
ax.annotate('', xy=(11, 7.2), xytext=(7, 7.75),
arrowprops=dict(arrowstyle='->', color='#555', lw=1.5))
# Replacement sub-boxes
rep_items = [
(9.5, 5.5, 'Whole Blood\nTransfusion', '#fef9e7', '#f39c12', 'Best for\nhaemorrhage'),
(11.5, 5.5, 'Plasma\nTransfusion', '#fef9e7', '#f39c12', 'When whole blood\nnot available\n(covers to Hct 50%)'),
(13.2, 5.5, 'Dextran\nSolution', '#fef9e7', '#f39c12', 'Colloid osmotic\nagent; large\npolysaccharide'),
]
ax.annotate('', xy=(11, 6.38), xytext=(11, 6.38),
arrowprops=dict(arrowstyle='->', color='#d35400', lw=1.5))
for (rx, ry, rt, rfc, rec, rn) in rep_items:
box(ax, rx, ry, 1.7, 0.65, rt, rfc, rec, fs=8)
ax.text(rx, ry - 0.55, rn, ha='center', fontsize=7, color='#555')
ax.annotate('', xy=(rx, ry + 0.33), xytext=(11, 6.38),
arrowprops=dict(arrowstyle='->', color='#d35400', lw=1.2))
# Step 4 - Sympathomimetics
box(ax, 3.5, 3.8, 4.0, 0.85,
'STEP 4\nSympathomimetic Drugs\n(Distributive shock)',
'#e8daef', '#8e44ad', fs=8.5, bold=True)
ax.text(3.5, 3.2, 'Norepinephrine / Epinephrine\nNeurogenic shock ✓\nAnaphylaxis ✓\nHaemorrhagic shock ✗', ha='center',
fontsize=7.5, color='#8e44ad', style='italic')
ax.annotate('', xy=(3.5, 4.23), xytext=(5.5, 7.42),
arrowprops=dict(arrowstyle='->', color='#8e44ad', lw=1.5))
# Step 5 - Corticosteroids
box(ax, 10.5, 3.8, 4.0, 0.85,
'STEP 5\nCorticosteroids\n(Severe / Septic shock)',
'#fadbd8', '#c0392b', fs=8.5, bold=True)
ax.text(10.5, 3.15, '1. ↑ Cardiac strength\n2. Stabilise lysosomes\n3. Aid cellular glucose metabolism\n4. Relative adrenal insufficiency\n in septic shock', ha='center',
fontsize=7.5, color='#c0392b')
ax.annotate('', xy=(10.5, 4.23), xytext=(8.5, 7.42),
arrowprops=dict(arrowstyle='->', color='#c0392b', lw=1.5))
# Bottom goal box
box(ax, 7, 0.8, 5.5, 0.75,
'GOAL: Restore Cardiac Output & Tissue Perfusion\nbefore irreversible stage',
'#1a3a5c', '#0d2137', fs=9.5, bold=True, tc='white')
ax.annotate('', xy=(7, 1.18), xytext=(3.5, 3.38),
arrowprops=dict(arrowstyle='->', color='#444', lw=1.5))
ax.annotate('', xy=(7, 1.18), xytext=(10.5, 3.38),
arrowprops=dict(arrowstyle='->', color='#444', lw=1.5))
plt.tight_layout()
path = f'{OUT_DIR}/fig5_management.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='#f0f8ff')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# FIGURE 6: Haemorrhage vs. Blood Volume table
# ─────────────────────────────────────────────────────────────
def make_haemorrhage_table():
fig, ax = plt.subplots(figsize=(11, 3.2))
ax.axis('off')
cols = ['Blood Loss', 'Cardiac Output', 'Arterial Pressure', 'Compensatory Status', 'Clinical Stage']
rows = [
['< 10%', 'Normal', 'Normal', 'Fully compensated', 'Non-progressive'],
['10–20%', '↓ Moderate', 'Normal (maintained)', 'Partially compensated', 'Non-progressive'],
['20–40%', '↓↓ Significant', '↓ Falling', 'Overwhelmed', 'Progressive'],
['> 40–45%', '↓↓↓ Severe', '↓↓ Critical / Zero', 'Failed', 'Irreversible'],
]
tbl = ax.table(cellText=rows, colLabels=cols, loc='center', cellLoc='center')
tbl.auto_set_font_size(False)
tbl.set_fontsize(9.5)
tbl.scale(1, 2.1)
for j in range(len(cols)):
tbl[0, j].set_facecolor('#1a3a5c')
tbl[0, j].set_text_props(color='white', fontweight='bold')
row_colors = ['#d6e4f0', '#eaf4fb', '#fdebd0', '#fadbd8']
for i, rc in enumerate(row_colors, start=1):
for j in range(len(cols)):
tbl[i, j].set_facecolor(rc)
ax.set_title('TABLE 2: Relationship Between Blood Loss and Shock Severity (Guyton & Hall)',
fontsize=11, fontweight='bold', pad=10, color='#1a3a5c')
plt.tight_layout()
path = f'{OUT_DIR}/fig6_haemorrhage.png'
plt.savefig(path, dpi=160, bbox_inches='tight', facecolor='white')
plt.close()
return path
# ─────────────────────────────────────────────────────────────
# BUILD PDF
# ─────────────────────────────────────────────────────────────
def build_pdf(fig_paths):
pdf_path = f'{OUT_DIR}/Circulatory_Shock_Summary.pdf'
doc = SimpleDocTemplate(pdf_path, pagesize=A4,
topMargin=1.5*cm, bottomMargin=1.5*cm,
leftMargin=1.5*cm, rightMargin=1.5*cm)
styles = getSampleStyleSheet()
title_style = ParagraphStyle('title', parent=styles['Title'],
fontSize=16, textColor=colors.HexColor('#1a3a5c'),
spaceAfter=6, alignment=TA_CENTER)
sub_style = ParagraphStyle('sub', parent=styles['Normal'],
fontSize=10, textColor=colors.HexColor('#555555'),
spaceAfter=14, alignment=TA_CENTER)
head_style = ParagraphStyle('head', parent=styles['Heading2'],
fontSize=11, textColor=colors.HexColor('#1a3a5c'),
spaceBefore=10, spaceAfter=4)
story = []
# Cover title
story.append(Spacer(1, 0.3*cm))
story.append(Paragraph('CIRCULATORY SHOCK', title_style))
story.append(Paragraph('Visual Summary — Tables, Flowcharts & Diagrams', sub_style))
story.append(Paragraph('Source: Guyton and Hall Textbook of Medical Physiology, 4th South Asia Edition, Chapter 24',
ParagraphStyle('src', parent=styles['Normal'], fontSize=8.5,
textColor=colors.HexColor('#777777'), alignment=TA_CENTER)))
story.append(HRFlowable(width='100%', thickness=2, color=colors.HexColor('#1a3a5c'), spaceAfter=14))
# Definition box (as inline table)
def_data = [['DEFINITION'],
['Circulatory shock is a state of generalized inadequate blood flow through the\n'
'body such that tissues are damaged due to insufficient delivery of oxygen and\n'
'nutrients. The cardiovascular system itself deteriorates, creating a self-worsening\n'
'cycle. It can occur WITH or WITHOUT decreased cardiac output.']]
def_tbl = Table(def_data, colWidths=[16.5*cm])
def_tbl.setStyle(TableStyle([
('BACKGROUND', (0,0), (0,0), colors.HexColor('#1a3a5c')),
('TEXTCOLOR', (0,0), (0,0), colors.white),
('FONTNAME', (0,0), (0,0), 'Helvetica-Bold'),
('FONTSIZE', (0,0), (0,0), 11),
('ALIGN', (0,0), (-1,-1), 'CENTER'),
('BACKGROUND', (0,1), (0,1), colors.HexColor('#eaf4fb')),
('FONTSIZE', (0,1), (0,1), 9.5),
('TOPPADDING', (0,0), (-1,-1), 7),
('BOTTOMPADDING', (0,0), (-1,-1), 7),
('LEFTPADDING', (0,0), (-1,-1), 10),
('BOX', (0,0), (-1,-1), 1.5, colors.HexColor('#1a3a5c')),
]))
story.append(def_tbl)
story.append(Spacer(1, 0.4*cm))
# Add figures
fig_labels = [
('TABLE 1: Classification of Circulatory Shock', fig_paths[0]),
('FIGURE 1: Stages of Circulatory Shock Flowchart', fig_paths[1]),
('FIGURE 2: Compensatory Mechanisms (Non-Progressive Stage)', fig_paths[2]),
('FIGURE 3: Progressive Shock — Positive Feedback Vicious Cycles', fig_paths[3]),
('FIGURE 4: Physiological Principles of Management', fig_paths[4]),
('TABLE 2: Blood Loss vs. Shock Severity', fig_paths[5]),
]
page_w = A4[0] - 3*cm
for label, fpath in fig_labels:
story.append(Paragraph(label, head_style))
img = Image(fpath, width=page_w, height=page_w * 0.55)
story.append(img)
story.append(Spacer(1, 0.5*cm))
# Footer note
story.append(HRFlowable(width='100%', thickness=1, color=colors.HexColor('#aaaaaa'), spaceBefore=8))
story.append(Paragraph(
'All content sourced from: Guyton and Hall Textbook of Medical Physiology, 4th South Asia Edition (ISBN: 9780443111013), Chapter 24, pp. 298–307.',
ParagraphStyle('footer', parent=styles['Normal'], fontSize=7.5,
textColor=colors.HexColor('#888888'), alignment=TA_CENTER)))
doc.build(story)
return pdf_path
# ─────────────────────────────────────────────────────────────
# MAIN
# ─────────────────────────────────────────────────────────────
print("Building figures...")
f1 = make_classification_table()
print(f" Fig1: {f1}")
f2 = make_stages_flowchart()
print(f" Fig2: {f2}")
f3 = make_compensatory_diagram()
print(f" Fig3: {f3}")
f4 = make_positive_feedback()
print(f" Fig4: {f4}")
f5 = make_management_flowchart()
print(f" Fig5: {f5}")
f6 = make_haemorrhage_table()
print(f" Fig6: {f6}")
print("Building PDF...")
pdf = build_pdf([f1, f2, f3, f4, f5, f6])
print(f"PDF ready: {pdf}")
cd /tmp/workspace/circulatory-shock && python3 build_shock_pdf.py 2>&1
ls -lh /tmp/workspace/circulatory-shock/
Circulatory Shock Summary
PDF Document · PDF
| Visual | Content |
|---|---|
| Table 1 | Classification of shock - all 4 types with mechanism, CO, SVR, examples |
| Figure 1 (Flowchart) | 3 Stages of shock - non-progressive → progressive → irreversible, with decision branches |
| Figure 2 (Mind Map) | 7 compensatory mechanisms in Stage 1 radiating from a central "shock" node |
| Figure 3 (Diagram) | 4 positive feedback vicious cycles driving progressive shock |
| Figure 4 (Flowchart) | Physiological management - all 5 treatment principles with mechanisms and indications |
| Table 2 | Blood loss % vs. cardiac output / arterial pressure / clinical stage |
table 1 is not clear ,regenerate it and give it properly
~/circulatory-shock/regen_table1.py
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.patches import FancyBboxPatch
import numpy as np
OUT = '/tmp/workspace/circulatory-shock/fig1_classification_v2.png'
fig, ax = plt.subplots(figsize=(16, 7))
ax.set_xlim(0, 16)
ax.set_ylim(0, 7)
ax.axis('off')
fig.patch.set_facecolor('#f4f8fc')
# ── Title ────────────────────────────────────────────────────────────────────
ax.text(8, 6.65, 'TABLE 1: Classification of Circulatory Shock',
ha='center', va='center', fontsize=15, fontweight='bold',
color='#1a3a5c',
bbox=dict(boxstyle='round,pad=0.4', facecolor='#1a3a5c',
edgecolor='#1a3a5c'))
ax.texts[-1].set_color('white')
# ── Column headers ────────────────────────────────────────────────────────────
headers = ['TYPE', 'MECHANISM', 'CARDIAC\nOUTPUT', 'SVR', 'KEY EXAMPLES', 'MORTALITY /\nNOTES']
col_x = [1.0, 4.2, 6.9, 8.4, 10.6, 14.0]
col_w = [2.4, 2.6, 1.8, 1.8, 3.8, 3.6]
HEADER_Y = 5.85
HEADER_H = 0.65
for i, (hdr, cx, cw) in enumerate(zip(headers, col_x, col_w)):
rect = FancyBboxPatch((cx - cw/2, HEADER_Y - HEADER_H/2), cw, HEADER_H,
boxstyle='square,pad=0', facecolor='#1a3a5c',
edgecolor='white', linewidth=1.5)
ax.add_patch(rect)
ax.text(cx, HEADER_Y, hdr, ha='center', va='center',
fontsize=9.5, fontweight='bold', color='white')
# ── Row data ──────────────────────────────────────────────────────────────────
rows = [
{
'label': 'CARDIOGENIC',
'color': '#c0392b',
'light': '#fadbd8',
'mechanism': 'Cardiac pump failure\n→ ↓ stroke volume',
'co': '↓↓',
'svr': '↑↑',
'examples': '• Myocardial infarction\n• Severe arrhythmias\n• Myocarditis\n• Valvular dysfunction',
'notes': '~70% mortality\nMost lethal type\nHeart cannot pump\nblood forward',
},
{
'label': 'HYPOVOLEMIC',
'color': '#e67e22',
'light': '#fdebd0',
'mechanism': '↓ Blood/plasma volume\n→ ↓ venous return\n→ ↓ cardiac output',
'co': '↓↓',
'svr': '↑↑',
'examples': '• Haemorrhage\n• Burns (plasma loss)\n• Severe dehydration\n• Vomiting / diarrhoea',
'notes': 'Most common type\n>40–45% blood loss\nfatal\nSymp. reflexes\ncompensate up to\n30–40% loss',
},
{
'label': 'DISTRIBUTIVE\n(Vasodilatory)',
'color': '#8e44ad',
'light': '#e8daef',
'mechanism': 'Massive vasodilation\n→ maldistribution of\nblood flow; tissues\nmisperfused',
'co': 'Normal\nor ↑',
'svr': '↓↓',
'examples': '• Septic shock\n (bacterial toxins)\n• Neurogenic shock\n (spinal/brain injury)\n• Anaphylactic shock\n (histamine release)',
'notes': 'Normal or high CO\nbut tissues starved\nSeptic: fever,\ntachycardia, leukocytosis\nDIC in late sepsis',
},
{
'label': 'OBSTRUCTIVE',
'color': '#2980b9',
'light': '#d6eaf8',
'mechanism': 'Mechanical block to\nblood flow → ↓ CO\ndespite normal heart\n& blood volume',
'co': '↓↓',
'svr': '↑↑',
'examples': '• Massive pulmonary\n embolism\n• Cardiac tamponade\n• Tension pneumothorax\n• Aortic stenosis',
'notes': 'Non-cardiac cause\nof ↓ CO\nRemove obstruction\nto treat (surgical\nor thrombolysis)',
},
]
ROW_H = 1.15
START_Y = 5.20 # top edge of first data row (centre)
for r_idx, row in enumerate(rows):
cy = START_Y - r_idx * ROW_H
fc = row['light']
ec = row['color']
# Full-row background
bg = FancyBboxPatch((0.2, cy - ROW_H/2 + 0.02), 15.6, ROW_H - 0.04,
boxstyle='square,pad=0', facecolor=fc,
edgecolor=ec, linewidth=1.2)
ax.add_patch(bg)
# Left colour stripe (type label)
stripe = FancyBboxPatch((0.2, cy - ROW_H/2 + 0.02), 2.0, ROW_H - 0.04,
boxstyle='square,pad=0', facecolor=row['color'],
edgecolor='none')
ax.add_patch(stripe)
ax.text(1.2, cy, row['label'], ha='center', va='center',
fontsize=9.5, fontweight='bold', color='white')
# Mechanism
ax.text(col_x[1], cy, row['mechanism'], ha='center', va='center',
fontsize=8.5, color='#222222', multialignment='center')
# CO
co_color = '#c0392b' if '↓' in row['co'] else '#27ae60'
ax.text(col_x[2], cy, row['co'], ha='center', va='center',
fontsize=14, fontweight='bold', color=co_color)
# SVR
svr_color = '#c0392b' if '↑' in row['svr'] else '#27ae60'
ax.text(col_x[3], cy, row['svr'], ha='center', va='center',
fontsize=14, fontweight='bold', color=svr_color)
# Examples
ax.text(col_x[4], cy, row['examples'], ha='center', va='center',
fontsize=8.2, color='#222222', multialignment='left')
# Notes
ax.text(col_x[5], cy, row['notes'], ha='center', va='center',
fontsize=7.8, color='#333333', multialignment='center',
style='italic')
# Vertical dividers
for dvx in [2.2, 5.2, 6.85, 8.35, 12.55]:
ax.plot([dvx, dvx], [cy - ROW_H/2 + 0.04, cy + ROW_H/2 - 0.04],
color='#aaaaaa', lw=0.8, ls='--')
# ── Outer border ─────────────────────────────────────────────────────────────
outer = FancyBboxPatch((0.18, START_Y - len(rows)*ROW_H + ROW_H/2 - 0.02),
15.64, len(rows)*ROW_H + HEADER_H/2 + 0.55,
boxstyle='round,pad=0.05', facecolor='none',
edgecolor='#1a3a5c', linewidth=2.5)
ax.add_patch(outer)
# ── Legend ────────────────────────────────────────────────────────────────────
legend_items = [
mpatches.Patch(color='#fadbd8', label='Cardiogenic'),
mpatches.Patch(color='#fdebd0', label='Hypovolemic'),
mpatches.Patch(color='#e8daef', label='Distributive'),
mpatches.Patch(color='#d6eaf8', label='Obstructive'),
]
ax.legend(handles=legend_items, loc='lower center', ncol=4,
fontsize=8, framealpha=0.8,
bbox_to_anchor=(0.5, -0.01))
# ── Footer source ─────────────────────────────────────────────────────────────
ax.text(8, 0.15,
'Source: Guyton & Hall Textbook of Medical Physiology, 4th South Asia Ed., Ch. 24, pp. 298–307',
ha='center', va='center', fontsize=7.5, color='#888888', style='italic')
plt.tight_layout(pad=0.3)
plt.savefig(OUT, dpi=180, bbox_inches='tight', facecolor='#f4f8fc')
plt.close()
print(f"Saved: {OUT}")
cd /tmp/workspace/circulatory-shock && python3 regen_table1.py 2>&1
~/circulatory-shock/rebuild_pdf_v2.py
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.platypus import (SimpleDocTemplate, Paragraph, Spacer, Table,
TableStyle, Image, HRFlowable)
from reportlab.lib.enums import TA_CENTER
import os
OUT_DIR = '/tmp/workspace/circulatory-shock'
PDF_PATH = f'{OUT_DIR}/Circulatory_Shock_Summary_v2.pdf'
doc = SimpleDocTemplate(PDF_PATH, pagesize=A4,
topMargin=1.5*cm, bottomMargin=1.5*cm,
leftMargin=1.5*cm, rightMargin=1.5*cm)
styles = getSampleStyleSheet()
title_style = ParagraphStyle('title', parent=styles['Title'],
fontSize=16, textColor=colors.HexColor('#1a3a5c'),
spaceAfter=6, alignment=TA_CENTER)
sub_style = ParagraphStyle('sub', parent=styles['Normal'],
fontSize=10, textColor=colors.HexColor('#555555'),
spaceAfter=14, alignment=TA_CENTER)
head_style = ParagraphStyle('head', parent=styles['Heading2'],
fontSize=11, textColor=colors.HexColor('#1a3a5c'),
spaceBefore=10, spaceAfter=4)
story = []
story.append(Spacer(1, 0.3*cm))
story.append(Paragraph('CIRCULATORY SHOCK', title_style))
story.append(Paragraph('Visual Summary — Tables, Flowcharts & Diagrams', sub_style))
story.append(Paragraph('Source: Guyton and Hall Textbook of Medical Physiology, 4th South Asia Edition, Chapter 24',
ParagraphStyle('src', parent=styles['Normal'], fontSize=8.5,
textColor=colors.HexColor('#777777'), alignment=TA_CENTER)))
story.append(HRFlowable(width='100%', thickness=2, color=colors.HexColor('#1a3a5c'), spaceAfter=14))
# Definition box
def_data = [['DEFINITION'],
['Circulatory shock is a state of generalized inadequate blood flow through the body '
'such that tissues are damaged due to insufficient delivery of oxygen and nutrients. '
'The cardiovascular system itself deteriorates, creating a self-worsening cycle. '
'It can occur WITH or WITHOUT decreased cardiac output.']]
def_tbl = Table(def_data, colWidths=[16.5*cm])
def_tbl.setStyle(TableStyle([
('BACKGROUND', (0,0), (0,0), colors.HexColor('#1a3a5c')),
('TEXTCOLOR', (0,0), (0,0), colors.white),
('FONTNAME', (0,0), (0,0), 'Helvetica-Bold'),
('FONTSIZE', (0,0), (0,0), 11),
('ALIGN', (0,0), (-1,-1), 'CENTER'),
('BACKGROUND', (0,1), (0,1), colors.HexColor('#eaf4fb')),
('FONTSIZE', (0,1), (0,1), 9.5),
('TOPPADDING', (0,0), (-1,-1), 7),
('BOTTOMPADDING', (0,0), (-1,-1), 7),
('LEFTPADDING', (0,0), (-1,-1), 10),
('BOX', (0,0), (-1,-1), 1.5, colors.HexColor('#1a3a5c')),
]))
story.append(def_tbl)
story.append(Spacer(1, 0.4*cm))
page_w = A4[0] - 3*cm
fig_labels = [
('TABLE 1: Classification of Circulatory Shock (All 4 Types)',
f'{OUT_DIR}/fig1_classification_v2.png', 0.42),
('FIGURE 1: Stages of Circulatory Shock Flowchart',
f'{OUT_DIR}/fig2_stages_flowchart.png', 0.58),
('FIGURE 2: Compensatory Mechanisms (Non-Progressive Stage)',
f'{OUT_DIR}/fig3_compensatory.png', 0.56),
('FIGURE 3: Progressive Shock — Positive Feedback Vicious Cycles',
f'{OUT_DIR}/fig4_positive_feedback.png', 0.54),
('FIGURE 4: Physiological Principles of Management',
f'{OUT_DIR}/fig5_management.png', 0.60),
('TABLE 2: Blood Loss vs. Shock Severity',
f'{OUT_DIR}/fig6_haemorrhage.png', 0.30),
]
for label, fpath, ratio in fig_labels:
story.append(Paragraph(label, head_style))
img = Image(fpath, width=page_w, height=page_w * ratio)
story.append(img)
story.append(Spacer(1, 0.5*cm))
story.append(HRFlowable(width='100%', thickness=1, color=colors.HexColor('#aaaaaa'), spaceBefore=8))
story.append(Paragraph(
'All content sourced from: Guyton and Hall Textbook of Medical Physiology, 4th South Asia Edition (ISBN: 9780443111013), Chapter 24, pp. 298–307.',
ParagraphStyle('footer', parent=styles['Normal'], fontSize=7.5,
textColor=colors.HexColor('#888888'), alignment=TA_CENTER)))
doc.build(story)
print(f"PDF ready: {PDF_PATH}")
cd /tmp/workspace/circulatory-shock && python3 rebuild_pdf_v2.py 2>&1
fig1 classification v2
Image · PNG
Circulatory Shock Summary v2
PDF Document · PDF
from Guyton and Hall textbook of medical physiology, 4th South Asia edition write a 5 mark short note on .Connections of Unipolar and Bipolar Limb Leads while regarding ECG