Analyse the file and prepare flowcharts whichever is necessary

Reading File
Running Command

python3 << 'EOF' import pdfplumber pdf_path = "/tmp/workspace/attachments/30b0c033-39d5-4176-a161-77b4bef34be9/Diabetes Mellitus-converted.pdf" with pdfplumber.open(pdf_path) as pdf: print(f"Total pages: {len(pdf.pages)}") full_text = "" for i, page in enumerate(pdf.pages): text = page.extract_text() if text: full_text += f"\n\n--- PAGE {i+1} ---\n{text}" print(full_text[:8000]) EOF

Running Command

python3 << 'EOF' import pdfplumber pdf_path = "/tmp/workspace/attachments/30b0c033-39d5-4176-a161-77b4bef34be9/Diabetes Mellitus-converted.pdf" with pdfplumber.open(pdf_path) as pdf: full_text = "" for i, page in enumerate(pdf.pages): text = page.extract_text() if text: full_text += f"\n\n--- PAGE {i+1} ---\n{text}" print(full_text[8000:]) EOF

Running Command

mkdir -p /tmp/workspace/diabetes-flowcharts && python3 << 'PYEOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.patches as mpatches from matplotlib.patches import FancyBboxPatch, FancyArrowPatch import numpy as np def draw_box(ax, x, y, w, h, text, facecolor='#D6EAF8', edgecolor='#2980B9', fontsize=9, bold=False, style='round,pad=0.1', text_color='#1A252F'): box = FancyBboxPatch((x - w/2, y - h/2), w, h, boxstyle=style, facecolor=facecolor, edgecolor=edgecolor, lw=1.5) ax.add_patch(box) weight = 'bold' if bold else 'normal' ax.text(x, y, text, ha='center', va='center', fontsize=fontsize, weight=weight, color=text_color, wrap=True, multialignment='center') def arrow(ax, x1, y1, x2, y2, color='#2C3E50'): ax.annotate('', xy=(x2, y2), xytext=(x1, y1), arrowprops=dict(arrowstyle='->', color=color, lw=1.5)) # ===== FLOWCHART 1: CLASSIFICATION OF DM ===== fig, ax = plt.subplots(figsize=(14, 10)) ax.set_xlim(0, 14) ax.set_ylim(0, 10) ax.axis('off') fig.patch.set_facecolor('#F8F9FA') # Title ax.text(7, 9.5, 'CLASSIFICATION OF DIABETES MELLITUS', ha='center', va='center', fontsize=14, weight='bold', color='#1A252F') ax.text(7, 9.1, '(ADA Standards of Medical Care 2018)', ha='center', va='center', fontsize=9, color='#555555') # Top box draw_box(ax, 7, 8.4, 4.5, 0.7, 'DIABETES MELLITUS', facecolor='#2C3E50', edgecolor='#1A252F', fontsize=12, bold=True, text_color='white') # Arrow down arrow(ax, 7, 8.05, 7, 7.7) # Branching line ax.plot([2, 12], [7.5, 7.5], color='#2980B9', lw=1.5) for x in [2, 5, 8.5, 12]: ax.plot([x, x], [7.5, 7.2], color='#2980B9', lw=1.5) ax.annotate('', xy=(x, 7.1), xytext=(x, 7.2), arrowprops=dict(arrowstyle='->', color='#2980B9', lw=1.5)) # Four main types draw_box(ax, 2, 6.5, 3.2, 0.9, 'TYPE 1 DIABETES\n(Immune-mediated)', facecolor='#EBF5FB', bold=True, fontsize=9) draw_box(ax, 5, 6.5, 3.2, 0.9, 'TYPE 2 DIABETES\n(Insulin Resistance)', facecolor='#E8F8F5', bold=True, fontsize=9) draw_box(ax, 8.5, 6.5, 3.2, 0.9, 'GESTATIONAL DM\n(2nd/3rd Trimester)', facecolor='#FEF9E7', bold=True, fontsize=9) draw_box(ax, 12, 6.5, 3.2, 0.9, 'OTHER SPECIFIC\nTYPES', facecolor='#FDEDEC', bold=True, fontsize=9) # Type 1 subtypes arrow(ax, 2, 6.05, 2, 5.7) ax.plot([0.8, 3.2], [5.5, 5.5], color='#85C1E9', lw=1.2) for x2, lbl in [(0.8, 'Type 1a\nAutoimmune\nbeta cell\ndestruction'), (3.2, 'Type 1b\nRare, not\nimmune\nmediated')]: ax.plot([x2, x2], [5.5, 5.2], color='#85C1E9', lw=1.2) ax.annotate('', xy=(x2, 5.1), xytext=(x2, 5.2), arrowprops=dict(arrowstyle='->', color='#85C1E9', lw=1.2)) draw_box(ax, x2, 4.5, 2.1, 1.0, lbl, facecolor='#D6EAF8', fontsize=8) # Type 2 details arrow(ax, 5, 6.05, 5, 5.7) draw_box(ax, 5, 5.2, 3.2, 0.9, '• Defects in insulin receptors\n• Insulin resistance\n• Beta cell insufficiency', facecolor='#D5F5E3', fontsize=8) # Type 2 three defects arrow(ax, 5, 4.75, 5, 4.3) draw_box(ax, 5, 3.85, 3.3, 0.7, '3 KEY DEFECTS', facecolor='#1E8449', edgecolor='#145A32', fontsize=9, bold=True, text_color='white') arrow(ax, 5, 3.5, 5, 3.1) for i, (x3, lbl3) in enumerate([(3.5, '↑ Hepatic\nglucose release'), (5, 'Impaired insulin\nsecretion'), (6.5, 'Insulin\nresistance')]): ax.plot([3.5, 6.5], [3.0, 3.0], color='#27AE60', lw=1.2) ax.plot([x3, x3], [3.0, 2.8], color='#27AE60', lw=1.2) ax.annotate('', xy=(x3, 2.6), xytext=(x3, 2.8), arrowprops=dict(arrowstyle='->', color='#27AE60', lw=1.2)) draw_box(ax, x3, 2.2, 1.8, 0.65, lbl3, facecolor='#D5F5E3', fontsize=7.5) # GDM details arrow(ax, 8.5, 6.05, 8.5, 5.7) draw_box(ax, 8.5, 5.25, 3.2, 0.75, '• 2nd/3rd trimester\n• Not prior to gestation', facecolor='#FEF3CD', fontsize=8) # Other types arrow(ax, 12, 6.05, 12, 5.7) for i, (y4, lbl4) in enumerate([(5.3, 'Monogenic DM\n(MODY, neonatal)'), (4.55, 'Exocrine Pancreas\n(CF, pancreatitis)'), (3.8, 'Drug-induced\n(steroids, HIV Rx)')]): draw_box(ax, 12, y4, 3.0, 0.6, lbl4, facecolor='#FADBD8', fontsize=7.5) if i < 2: arrow(ax, 12, y4 - 0.3, 12, y4 - 0.45) plt.tight_layout(pad=0.5) plt.savefig('/tmp/workspace/diabetes-flowcharts/fc1_classification.png', dpi=150, bbox_inches='tight', facecolor='#F8F9FA') plt.close() print("FC1 saved") PYEOF

Running Command

python3 << 'PYEOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch import textwrap def box(ax, x, y, w, h, text, fc='#D6EAF8', ec='#2980B9', fs=8.5, bold=False, tc='#1A252F', style='round,pad=0.1'): p = FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle=style, facecolor=fc, edgecolor=ec, lw=1.5) ax.add_patch(p) ax.text(x, y, text, ha='center', va='center', fontsize=fs, weight='bold' if bold else 'normal', color=tc, multialignment='center') def arr(ax, x1,y1,x2,y2, c='#2C3E50'): ax.annotate('', xy=(x2,y2), xytext=(x1,y1), arrowprops=dict(arrowstyle='->', color=c, lw=1.5)) # ===== FC2: DIAGNOSIS ===== fig, ax = plt.subplots(figsize=(13, 10)) ax.set_xlim(0,13); ax.set_ylim(0,10); ax.axis('off') fig.patch.set_facecolor('#F8F9FA') ax.text(6.5, 9.65, 'DIAGNOSIS OF DIABETES MELLITUS', ha='center', fontsize=14, weight='bold', color='#1A252F') ax.text(6.5, 9.3, 'ADA Criteria (Standards of Medical Care in Diabetes)', ha='center', fontsize=9, color='#555') box(ax,6.5,8.75,5,0.7,'PATIENT WITH SUSPECTED DIABETES', fc='#2C3E50', ec='#1A252F', fs=11, bold=True, tc='white') arr(ax,6.5,8.4,6.5,8.05) box(ax,6.5,7.75,7,0.55,'Perform one or more diagnostic tests', fc='#EBF5FB', fs=9) arr(ax,6.5,7.47,6.5,7.1) # Branching ax.plot([1.8,11.2],[6.9,6.9], color='#2980B9', lw=1.5) for xp in [1.8,5.5,9.2,11.2]: ax.plot([xp,xp],[6.9,6.6], color='#2980B9', lw=1.5) ax.annotate('', xy=(xp,6.5), xytext=(xp,6.6), arrowprops=dict(arrowstyle='->', color='#2980B9', lw=1.5)) box(ax,1.8,6.1,2.9,0.65,'FPG\n(Fasting Plasma Glucose)', fc='#EAF2FF', fs=8, bold=True) box(ax,5.5,6.1,2.9,0.65,'2-h OGTT\n(75g glucose)', fc='#EAF2FF', fs=8, bold=True) box(ax,9.2,6.1,2.9,0.65,'HbA1c\nTest', fc='#EAF2FF', fs=8, bold=True) box(ax,11.2,6.1,2.9,0.65,'Random\nPlasma Glucose', fc='#EAF2FF', fs=8, bold=True) arr(ax,1.8,5.77,1.8,5.4) arr(ax,5.5,5.77,5.5,5.4) arr(ax,9.2,5.77,9.2,5.4) arr(ax,11.2,5.77,11.2,5.4) # Two zones - Prediabetes and Diabetes for each test # FPG box(ax,1.8,5.1,2.9,0.55,'100–125 mg/dL\n(Prediabetes/IFG)', fc='#FEF9E7', ec='#F39C12', fs=7.5) arr(ax,1.8,4.83,1.8,4.47) box(ax,1.8,4.2,2.9,0.55,'≥ 126 mg/dL\n(DIABETES)', fc='#FADBD8', ec='#C0392B', fs=7.5, bold=True) # OGTT box(ax,5.5,5.1,2.9,0.55,'140–199 mg/dL\n(Prediabetes/IGT)', fc='#FEF9E7', ec='#F39C12', fs=7.5) arr(ax,5.5,4.83,5.5,4.47) box(ax,5.5,4.2,2.9,0.55,'≥ 200 mg/dL\n(DIABETES)', fc='#FADBD8', ec='#C0392B', fs=7.5, bold=True) # HbA1c box(ax,9.2,5.1,2.9,0.55,'5.7–6.4%\n(Prediabetes)', fc='#FEF9E7', ec='#F39C12', fs=7.5) arr(ax,9.2,4.83,9.2,4.47) box(ax,9.2,4.2,2.9,0.55,'≥ 6.5%\n(DIABETES)', fc='#FADBD8', ec='#C0392B', fs=7.5, bold=True) # Random box(ax,11.2,5.1,2.9,0.55,'Classic symptoms\n+ random glucose', fc='#FEF9E7', ec='#F39C12', fs=7.5) arr(ax,11.2,4.83,11.2,4.47) box(ax,11.2,4.2,2.9,0.55,'≥ 200 mg/dL\n(DIABETES)', fc='#FADBD8', ec='#C0392B', fs=7.5, bold=True) # Merge arrows to outcomes for xp2 in [1.8, 5.5, 9.2, 11.2]: arr(ax, xp2, 3.92, xp2, 3.65) ax.plot([xp2, xp2], [3.65, 3.45], color='#7D3C98', lw=1.3) ax.plot([1.8, 11.2], [3.45, 3.45], color='#7D3C98', lw=1.3) ax.plot([6.5, 6.5], [3.45, 3.2], color='#7D3C98', lw=1.3) ax.annotate('', xy=(6.5, 3.1), xytext=(6.5, 3.2), arrowprops=dict(arrowstyle='->', color='#7D3C98', lw=1.5)) box(ax,6.5,2.75,7.5,0.6,'CONFIRMED DIABETES MELLITUS\n(Any 1 criterion positive; repeat on subsequent day if asymptomatic)', fc='#C0392B', ec='#7B241C', fs=9, bold=True, tc='white') # Lower split: Prediabetes and Notes arr(ax, 4.5, 4.85, 4.5, 4.1) # Prediabetes label between yellow boxes ax.text(6.5, 5.45, 'PREDIABETES ZONE', ha='center', fontsize=8.5, color='#B7770D', weight='bold') # HbA1c note arr(ax, 6.5, 2.45, 6.5, 1.95) box(ax,6.5,1.65,11,0.55, 'HbA1c = avg plasma glucose over 60–90 days | Normal: 4–6% | Risk for complications at ≥ 6.5%', fc='#EAF2FF', fs=8) plt.tight_layout(pad=0.3) plt.savefig('/tmp/workspace/diabetes-flowcharts/fc2_diagnosis.png', dpi=150, bbox_inches='tight', facecolor='#F8F9FA') plt.close() print("FC2 saved") PYEOF

Running Command

python3 << 'PYEOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch def box(ax, x, y, w, h, text, fc='#D6EAF8', ec='#2980B9', fs=8, bold=False, tc='#1A252F', style='round,pad=0.1'): p = FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle=style, facecolor=fc, edgecolor=ec, lw=1.5) ax.add_patch(p) ax.text(x, y, text, ha='center', va='center', fontsize=fs, weight='bold' if bold else 'normal', color=tc, multialignment='center') def arr(ax, x1,y1,x2,y2, c='#2C3E50'): ax.annotate('', xy=(x2,y2), xytext=(x1,y1), arrowprops=dict(arrowstyle='->', color=c, lw=1.5)) # ===== FC3: PERIOPERATIVE MANAGEMENT ===== fig, ax = plt.subplots(figsize=(14, 18)) ax.set_xlim(0,14); ax.set_ylim(0,18); ax.axis('off') fig.patch.set_facecolor('#F8F9FA') ax.text(7, 17.65, 'PERIOPERATIVE MANAGEMENT OF DIABETIC PATIENT', ha='center', fontsize=13, weight='bold', color='#1A252F') ax.text(7, 17.3, 'Anaesthetic Implications', ha='center', fontsize=9, color='#555') box(ax,7,16.8,6,0.7,'DIABETIC PATIENT FOR SURGERY', fc='#1A252F', ec='#000', fs=12, bold=True, tc='white') arr(ax,7,16.45,7,16.1) # ---- PREOPERATIVE ---- box(ax,7,15.8,10,0.55,'STEP 1: PREOPERATIVE EVALUATION', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,15.52,7,15.22) # 4 columns for history cols = [2, 5, 9, 12.5] labels = ['CNS\n• Peripheral neuropathy\n• Headache/syncope\n• TIA/stroke', 'CVS\n• Silent MI\n• Hypertension\n• CCF\n• Erectile dysfunction', 'GIT/Renal\n• Gastroparesis\n• Postprandial vomiting\n• Renal failure (>55y)', 'Medications\n• Oral hypoglycemics\n• Insulin regimen\n• Prior anesthesia'] ax.plot([0.5,13.5],[15.15,15.15], color='#2980B9', lw=1.2) for xp, lbl in zip(cols, labels): ax.plot([xp,xp],[15.15,14.95], color='#2980B9', lw=1.2) ax.annotate('', xy=(xp,14.85), xytext=(xp,14.95), arrowprops=dict(arrowstyle='->', color='#2980B9', lw=1.3)) box(ax,xp,14.35,2.9,0.85,lbl, fc='#EBF5FB', fs=7.5) arr(ax,7,13.92,7,13.6) box(ax,7,13.35,10.5,0.5,'STEP 2: EXAMINATION', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,13.1,7,12.8) exam_items = ['Vitals &\northostatic BP', 'Airway exam\n(Stiff joint\nsyndrome)', 'Prayer sign\nPalm print\nsign', 'Fundoscopy\n(Retinopathy)', 'Autonomic\nneuropathy\ntests'] ex_cols = [1.5, 4, 7, 10, 12.5] ax.plot([0.5,13.5],[12.75,12.75], color='#27AE60', lw=1.2) for xp, lbl in zip(ex_cols, exam_items): ax.plot([xp,xp],[12.75,12.55], color='#27AE60', lw=1.2) ax.annotate('', xy=(xp,12.45), xytext=(xp,12.55), arrowprops=dict(arrowstyle='->', color='#27AE60', lw=1.3)) box(ax,xp,12.1,2.4,0.6,lbl, fc='#D5F5E3', ec='#27AE60', fs=7.5) arr(ax,7,11.8,7,11.5) box(ax,7,11.25,10.5,0.5,'STEP 3: INVESTIGATIONS', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,11.0,7,10.72) box(ax,7,10.45,12,0.5,'CBC • RFT • ECG/TMT (silent MI) • CXR (cardiomegaly) • PFT • HbA1c • Microalbuminuria', fc='#EAF2FF', fs=8) arr(ax,7,10.2,7,9.9) # Choice of anesthesia box(ax,7,9.65,10.5,0.5,'STEP 4: CHOICE OF ANESTHETIC TECHNIQUE', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,9.4,7,9.1) ax.plot([2.5,11.5],[9.0,9.0], color='#8E44AD', lw=1.5) ax.plot([2.5,2.5],[9.0,8.8], color='#8E44AD', lw=1.5) ax.annotate('', xy=(2.5,8.7), xytext=(2.5,8.8), arrowprops=dict(arrowstyle='->', color='#8E44AD', lw=1.5)) ax.plot([11.5,11.5],[9.0,8.8], color='#8E44AD', lw=1.5) ax.annotate('', xy=(11.5,8.7), xytext=(11.5,8.8), arrowprops=dict(arrowstyle='->', color='#8E44AD', lw=1.5)) box(ax,2.5,8.3,4.2,0.7,'REGIONAL ANESTHESIA\n✓ Technique of CHOICE', fc='#D2B4DE', ec='#7D3C98', fs=9, bold=True) box(ax,11.5,8.3,4.2,0.7,'GENERAL ANESTHESIA\n(when regional not feasible)', fc='#FAD7A0', ec='#E67E22', fs=9, bold=True) box(ax,2.5,7.35,4.2,1.5, '✓ Avoids aspiration\n✓ Patient awake (detects hypoglycemia)\n✓ Reduced DVT\n✓ Good post-op analgesia\n✗ Exaggerated hypotension\n✗ Risk of epidural abscess', fc='#F5EEF8', ec='#7D3C98', fs=7.5) box(ax,11.5,7.35,4.2,1.5, '✓ Better cardiovascular stability\n✓ Airway protected\n✗ Difficult intubation\n✗ Hard to detect hypoglycemia\n✗ Altered drug elimination\n✗ Increased stress response', fc='#FEF5E7', ec='#E67E22', fs=7.5) arr(ax,7,6.55,7,6.25) # Preop drug management box(ax,7,6.0,10.5,0.5,'STEP 5: PREOPERATIVE DRUG MANAGEMENT', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,5.75,7,5.45) drug_items = ['Oral hypoglycemics\nstop 24–48h\nbefore surgery', 'Sulfonylureas: avoid\nentire periop period\n(blocks K-ATP channels)', 'SC Insulin:\n2/3 dose night before\n1/2 morning NPH\n(hold regular)', 'Insulin Pump:\nDecrease overnight\nrate by 30%', 'Glargine users:\n2/3 glargine +\nfull lispro night\nbefore; hold morning'] dx = [1.4, 3.9, 7, 10.1, 12.6] ax.plot([0.5,13.5],[5.4,5.4], color='#E74C3C', lw=1.2) for xp2, lbl2 in zip(dx, drug_items): ax.plot([xp2,xp2],[5.4,5.2], color='#E74C3C', lw=1.2) ax.annotate('', xy=(xp2,5.1), xytext=(xp2,5.2), arrowprops=dict(arrowstyle='->', color='#E74C3C', lw=1.3)) box(ax,xp2,4.5,2.4,1.0,lbl2, fc='#FDEDEC', ec='#E74C3C', fs=7) arr(ax,7,4.0,7,3.7) box(ax,7,3.45,10.5,0.5,'STEP 6: INTRAOPERATIVE MANAGEMENT', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,3.2,7,2.9) box(ax,7,2.55,12.5,0.65, 'Target BG: 120–180 mg/dL | Start insulin infusion ≥2h before surgery\n' '1 U insulin lowers BG ~25–30 mg/dL | Initial rate: Total daily dose ÷ 24 (typical: 0.02 U/kg/hr)\n' 'Accompany with 5% Dextrose/0.45% NS + 20 mEq KCl at 100–150 mL/hr | Check BG every 30–60 min', fc='#EAFAF1', ec='#1E8449', fs=8) arr(ax,7,2.22,7,1.92) box(ax,7,1.65,10.5,0.5,'STEP 7: POSTOPERATIVE CARE', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,1.4,7,1.1) box(ax,7,0.75,12,0.55, 'Maintain BG 140–180 mg/dL (ADA) | Initiate insulin if BG > 180 mg/dL | Monitor for hypoglycemia', fc='#EBF5FB', fs=8) plt.tight_layout(pad=0.3) plt.savefig('/tmp/workspace/diabetes-flowcharts/fc3_perioperative.png', dpi=130, bbox_inches='tight', facecolor='#F8F9FA') plt.close() print("FC3 saved") PYEOF

Running Command

python3 << 'PYEOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch def box(ax, x, y, w, h, text, fc='#D6EAF8', ec='#2980B9', fs=8, bold=False, tc='#1A252F', style='round,pad=0.1'): p = FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle=style, facecolor=fc, edgecolor=ec, lw=1.5) ax.add_patch(p) ax.text(x, y, text, ha='center', va='center', fontsize=fs, weight='bold' if bold else 'normal', color=tc, multialignment='center') def arr(ax, x1,y1,x2,y2, c='#2C3E50'): ax.annotate('', xy=(x2,y2), xytext=(x1,y1), arrowprops=dict(arrowstyle='->', color=c, lw=1.5)) # ===== FC4: DKA PATHOPHYSIOLOGY + MANAGEMENT ===== fig, ax = plt.subplots(figsize=(14, 20)) ax.set_xlim(0,14); ax.set_ylim(0,20); ax.axis('off') fig.patch.set_facecolor('#F8F9FA') ax.text(7,19.65,'DIABETIC KETOACIDOSIS (DKA)', ha='center', fontsize=14, weight='bold', color='#922B21') ax.text(7,19.3,'Pathophysiology & Management', ha='center', fontsize=9, color='#555') # --- PATHOPHYSIOLOGY --- box(ax,7,18.85,6,0.65,'PATHOPHYSIOLOGY', fc='#922B21', ec='#641E16', fs=12, bold=True, tc='white') box(ax,7,18.15,9.5,0.55,'Relative / Absolute INSULIN DEFICIENCY + ↑ Counter-regulatory hormones\n(Glucagon, Catecholamines, Cortisol, Growth Hormone)', fc='#FDEDEC', ec='#E74C3C', fs=8.5) arr(ax,7,17.87,7,17.57) # Two pathways ax.plot([3.5,10.5],[17.5,17.5], color='#E74C3C', lw=1.5) for xp in [3.5, 10.5]: ax.plot([xp,xp],[17.5,17.3], color='#E74C3C', lw=1.5) ax.annotate('', xy=(xp,17.2), xytext=(xp,17.3), arrowprops=dict(arrowstyle='->', color='#E74C3C', lw=1.5)) box(ax,3.5,16.85,6,0.6,'↑ Gluconeogenesis + ↑ Glycogenolysis\n→ HYPERGLYCEMIA', fc='#FADBD8', ec='#C0392B', fs=8.5, bold=True) box(ax,10.5,16.85,6,0.6,'Unrestrained Lipolysis\n→ Free Fatty Acids → KETONES', fc='#FADBD8', ec='#C0392B', fs=8.5, bold=True) arr(ax,3.5,16.55,3.5,16.25) arr(ax,10.5,16.55,10.5,16.25) box(ax,3.5,15.95,6,0.55,'Osmotic Diuresis\n(Glucosuria → Loss of Na, K, Phosphate, Water)', fc='#FDEBD0', ec='#E67E22', fs=8) box(ax,10.5,15.95,6,0.55,'Ketones: 3-β-hydroxybutyrate (predominant)\nAcetone, Acetoacetate', fc='#FDEBD0', ec='#E67E22', fs=8) arr(ax,10.5,15.67,10.5,15.37) box(ax,10.5,15.1,6,0.5,'H⁺ from ketone dissociation\n→ METABOLIC ACIDOSIS', fc='#FADBD8', ec='#C0392B', fs=8.5, bold=True) # Triad ax.plot([3.5,10.5],[14.75,14.75], color='#C0392B', lw=1.3) ax.plot([3.5,3.5],[15.67,14.75], color='#C0392B', lw=1.3) ax.plot([7,7],[14.75,14.55], color='#C0392B', lw=1.3) ax.annotate('', xy=(7,14.45), xytext=(7,14.55), arrowprops=dict(arrowstyle='->', color='#C0392B', lw=1.5)) ax.plot([10.5,10.5],[14.82,14.75], color='#C0392B', lw=1.3) box(ax,7,14.2,9,0.55,'CLASSICAL TRIAD: HYPERGLYCEMIA + KETONEMIA + METABOLIC ACIDOSIS', fc='#C0392B', ec='#7B241C', fs=10, bold=True, tc='white') arr(ax,7,13.92,7,13.62) # --- DIAGNOSIS CRITERIA --- box(ax,7,13.35,8,0.55,'DIAGNOSTIC CRITERIA', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,13.07,7,12.77) box(ax,7,12.5,12.5,0.55,'Ketonemia ≥ 3.0 mmol/L (or 2+ ketonuria) | Blood glucose > 11 mmol/L | Bicarbonate < 15 mmol/L or pH < 7.3', fc='#EBF5FB', fs=8.5) arr(ax,7,12.22,7,11.92) # --- INITIAL MANAGEMENT --- box(ax,7,11.65,8,0.55,'INITIAL MANAGEMENT (ABCDE Approach)', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,11.37,7,11.07) steps = ['Airway\nprotection', 'Fluid\nresuscitation\n(1st priority)', 'Insulin\nadministration', 'Assess\nseverity', 'Identify\ncause'] sx = [1.2, 3.8, 7, 10.2, 12.8] ax.plot([0.5,13.5],[11.0,11.0], color='#117A65', lw=1.2) for xp, lbl in zip(sx, steps): ax.plot([xp,xp],[11.0,10.8], color='#117A65', lw=1.2) ax.annotate('', xy=(xp,10.7), xytext=(xp,10.8), arrowprops=dict(arrowstyle='->', color='#117A65', lw=1.3)) box(ax,xp,10.35,2.2,0.65,lbl, fc='#D5F5E3', ec='#1E8449', fs=7.5) arr(ax,7,10.02,7,9.72) # --- FLUID RESUSCITATION --- box(ax,7,9.45,8,0.55,'FLUID RESUSCITATION', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,9.17,7,8.87) box(ax,7,8.55,12.5,0.65, '• Crystalloids with Na 130–154 mmol/L preferred\n• Balanced crystalloids → faster acidosis resolution + less hyperchloraemic acidosis\n• If shocked: 500 mL bolus over < 15 min, then reassess', fc='#EBF5FB', fs=8) arr(ax,7,8.22,7,7.92) # --- INSULIN --- box(ax,7,7.65,8,0.55,'INSULIN ADMINISTRATION (FRIII)', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,7.37,7,7.07) box(ax,7,6.7,12.5,0.75, '• FRIII: 50 U human soluble insulin in 50 mL 0.9% NaCl (1U/mL)\n' '• Rate: 0.1 U/kg/hr (= 7 mL/hr for 70 kg patient) | Max: 15 U/hr\n' '• Targets: BG ↓ 3 mmol/L/hr | Ketones ↓ 0.5 mmol/L/hr | Bicarb ↑ 3 mmol/L/hr', fc='#EAF2FF', ec='#2980B9', fs=8) arr(ax,7,6.32,7,6.02) # Resolution box(ax,7,5.75,8,0.55,'RESOLUTION OF DKA', fc='#1F618D', ec='#154360', fs=11, bold=True, tc='white') arr(ax,7,5.47,7,5.17) box(ax,7,4.85,9,0.65,'pH > 7.3 AND Bicarbonate > 15 mmol/L AND Blood ketones < 0.6 mmol/L\n→ STOP FRIII (only after administering SC insulin)', fc='#D5F5E3', ec='#1E8449', fs=8.5, bold=True) arr(ax,7,4.52,7,4.22) # Critical care referral box(ax,7,3.95,8,0.55,'CRITICAL CARE REFERRAL CRITERIA', fc='#922B21', ec='#641E16', fs=11, bold=True, tc='white') arr(ax,7,3.67,7,3.37) box(ax,7,2.85,12.5,0.95, 'GCS < 12 | Blood ketones > 6 mmol/L | Bicarbonate < 5 mmol/L | pH < 7.0\n' 'Hypokalaemia on admission (< 3.5 mmol/L) | SpO₂ < 92% on air\n' 'Systolic BP < 90 mmHg | HR < 60 or > 100 bpm | Anion gap > 16', fc='#FDEDEC', ec='#C0392B', fs=8) arr(ax,7,2.37,7,2.07) box(ax,7,1.75,7,0.55,'Admit to Level 2/3 Critical Care Facility', fc='#C0392B', ec='#7B241C', fs=10, bold=True, tc='white') plt.tight_layout(pad=0.3) plt.savefig('/tmp/workspace/diabetes-flowcharts/fc4_dka.png', dpi=130, bbox_inches='tight', facecolor='#F8F9FA') plt.close() print("FC4 saved") PYEOF

Running Command

python3 << 'PYEOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import FancyBboxPatch def box(ax, x, y, w, h, text, fc='#D6EAF8', ec='#2980B9', fs=8, bold=False, tc='#1A252F', style='round,pad=0.1'): p = FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle=style, facecolor=fc, edgecolor=ec, lw=1.5) ax.add_patch(p) ax.text(x, y, text, ha='center', va='center', fontsize=fs, weight='bold' if bold else 'normal', color=tc, multialignment='center') def arr(ax, x1,y1,x2,y2, c='#2C3E50'): ax.annotate('', xy=(x2,y2), xytext=(x1,y1), arrowprops=dict(arrowstyle='->', color=c, lw=1.5)) # ===== FC5: GLYCEMIC REGIMENS ===== fig, ax = plt.subplots(figsize=(14, 16)) ax.set_xlim(0,14); ax.set_ylim(0,16); ax.axis('off') fig.patch.set_facecolor('#F8F9FA') ax.text(7,15.65,'PERIOPERATIVE GLYCEMIC REGIMENS', ha='center', fontsize=14, weight='bold', color='#1A252F') ax.text(7,15.25,'Insulin Management Protocols for Diabetic Surgical Patients', ha='center', fontsize=9, color='#555') box(ax,7,14.75,7,0.65,'DIABETIC PATIENT REQUIRING SURGERY', fc='#1A252F', ec='#000', fs=12, bold=True, tc='white') arr(ax,7,14.42,7,14.12) # Decision diamond shape using a rotated square box(ax,7,13.7,6.5,0.65,'Determine extent of surgery and glycemic control needed', fc='#EBF5FB', fs=9) arr(ax,7,13.37,7,13.07) ax.plot([1.5,12.5],[12.85,12.85], color='#2980B9', lw=1.5) # 5 regimens regx = [1.3, 3.8, 7, 10.2, 12.8] regtitles = ['1. SLIDING SCALE', '2. CLASSIC\nNON-TIGHT CTRL', '3. TIGHT CONTROL\n(Regimen I & II)', '4. GIK REGIMEN', '5. ALBERTI\nREGIMEN'] regfc = ['#D6EAF8','#D5F5E3','#FADBD8','#FEF9E7','#F5EEF8'] regec = ['#2980B9','#1E8449','#C0392B','#F39C12','#7D3C98'] for xp in regx: ax.plot([xp,xp],[12.85,12.65], color='#2980B9', lw=1.2) ax.annotate('', xy=(xp,12.55), xytext=(xp,12.65), arrowprops=dict(arrowstyle='->', color='#2980B9', lw=1.3)) for xp, tit, fc, ec in zip(regx, regtitles, regfc, regec): box(ax,xp,12.2,2.2,0.6,tit, fc=fc, ec=ec, fs=8, bold=True) arr(ax,1.3,11.9,1.3,11.6) box(ax,1.3,11.15,2.2,0.8,'✓ Easy to calculate\n✗ Not for major surgery\n✗ Poor glucose control', fc='#EBF5FB', ec='#2980B9', fs=7.5) arr(ax,3.8,11.9,3.8,11.6) box(ax,3.8,10.7,2.3,1.7, 'NPO from midnight\n5% dextrose at\n125 mL/hr from 6AM\nHalf morning insulin SC\nContinue intra-op\nSliding scale post-op', fc='#D5F5E3', ec='#1E8449', fs=7.5) arr(ax,7,11.9,7,11.6) box(ax,7,10.5,2.3,2.1, 'Target: BG 79–120 mg/dL\n\nIndications:\n• Type 1 DM\n• Pregnant diabetics\n• Major surgery\n• ICU stay\n• CPB surgery\n• DKA surgery', fc='#FADBD8', ec='#C0392B', fs=7.5) # Regimen I detail arr(ax,7,9.49,7,9.19) box(ax,7,8.9,2.4,0.55,'REGIMEN I DETAIL', fc='#C0392B', ec='#7B241C', fs=8, bold=True, tc='white') arr(ax,7,8.62,7,8.32) box(ax,7,7.85,3.2,0.85, '5% Dextrose 50 mL/hr + Insulin piggyback\n(50U in 250 mL NS)\nRate = BG/150 (or BG/100 if steroids/obese)\nRepeat BG every 4h\nTreat hypoglycemia: 15 mL 50% dextrose', fc='#FDFEFE', ec='#E74C3C', fs=7.5) arr(ax,10.2,11.9,10.2,11.6) box(ax,10.2,10.85,2.3,1.4, '10% Dextrose +\nInsulin in 500 mL\n(250g glucose +\n50U insulin / 24h)\n✓ Prevents hypo\n& hyperglycemia\n✗ New bag needed\nif BG out of range', fc='#FEF9E7', ec='#F39C12', fs=7.5) arr(ax,12.8,11.9,12.8,11.6) box(ax,12.8,10.55,2.3,1.9, '500 mL 10% dextrose\n+ 10 mmol KCl\n+ 15 IU insulin\nInfuse at 100 mL/hr\n(= 3 IU/hr)\nCheck BG 2-hourly\nAdjust rate per BG\n✓ Simple, safe,\ninexpensive\n✗ No K+ correction', fc='#F5EEF8', ec='#7D3C98', fs=7.5) # Watt-Hirsch arr(ax,7,7.42,7,7.12) box(ax,7,6.85,5,0.5,'6. WATT-HIRSCH (Variable Rate) REGIMEN', fc='#154360', ec='#1A252F', fs=9, bold=True, tc='white') arr(ax,7,6.6,7,6.3) box(ax,7,5.95,10,0.65, 'Glucose at 5 g/hr + K⁺ at 2–4 mEq/hr + Insulin at 0.5–1 IU/hr\nMeasure BG hourly | Insulin piggybacked with glucose OR separate infusion', fc='#EAF2FF', ec='#2980B9', fs=8.5) arr(ax,7,5.62,7,5.32) # Vellore box(ax,7,5.05,5,0.5,'7. VELLORE REGIMEN', fc='#154360', ec='#1A252F', fs=9, bold=True, tc='white') arr(ax,7,4.8,7,4.5) box(ax,7,4.25,10,0.5,'Simple, safe, inexpensive | Disadvantage: Potassium levels are not corrected', fc='#EAF2FF', fs=8) # Key summary arr(ax,7,3.99,7,3.69) box(ax,7,3.35,12,0.65, 'KEY TARGETS: Fasting BG: 90–130 mg/dL | Peak post-prandial BG: < 180 mg/dL | HbA1c: < 7%', fc='#1A252F', ec='#000', fs=9, bold=True, tc='white') arr(ax,7,3.02,7,2.72) box(ax,7,2.4,12,0.65, 'INTRAOPERATIVE TARGET: 120–180 mg/dL | Avoid BG > 200 mg/dL (glycosuria + impaired wound healing)\n' 'POSTOPERATIVE TARGET (ADA, critically ill): 140–180 mg/dL | Initiate insulin if BG > 180 mg/dL', fc='#EAFAF1', ec='#1E8449', fs=8) plt.tight_layout(pad=0.3) plt.savefig('/tmp/workspace/diabetes-flowcharts/fc5_glycemic_regimens.png', dpi=130, bbox_inches='tight', facecolor='#F8F9FA') plt.close() print("FC5 saved") PYEOF

Running Command

python3 << 'PYEOF' from reportlab.lib.pagesizes import A4, landscape from reportlab.platypus import SimpleDocTemplate, Image, Spacer, Paragraph from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.units import cm from reportlab.lib import colors import os # Output file output_path = '/tmp/workspace/diabetes-flowcharts/Diabetes_Mellitus_Flowcharts.pdf' # Images and titles flowcharts = [ ('/tmp/workspace/diabetes-flowcharts/fc1_classification.png', 'Flowchart 1: Classification of Diabetes Mellitus'), ('/tmp/workspace/diabetes-flowcharts/fc2_diagnosis.png', 'Flowchart 2: Diagnosis of Diabetes Mellitus (ADA Criteria)'), ('/tmp/workspace/diabetes-flowcharts/fc3_perioperative.png', 'Flowchart 3: Perioperative Management of the Diabetic Patient'), ('/tmp/workspace/diabetes-flowcharts/fc4_dka.png', 'Flowchart 4: Diabetic Ketoacidosis - Pathophysiology & Management'), ('/tmp/workspace/diabetes-flowcharts/fc5_glycemic_regimens.png', 'Flowchart 5: Perioperative Glycemic Regimens'), ] doc = SimpleDocTemplate( output_path, pagesize=landscape(A4), rightMargin=1*cm, leftMargin=1*cm, topMargin=1.5*cm, bottomMargin=1*cm ) styles = getSampleStyleSheet() title_style = ParagraphStyle( 'FlowchartTitle', parent=styles['Heading2'], fontSize=13, textColor=colors.HexColor('#1A252F'), spaceAfter=6, spaceBefore=12 ) story = [] # Cover page cover_style = ParagraphStyle('Cover', parent=styles['Title'], fontSize=20, textColor=colors.HexColor('#1A252F'), spaceAfter=20) story.append(Spacer(1, 3*cm)) story.append(Paragraph('Diabetes Mellitus & Anaesthetic Implications', cover_style)) story.append(Spacer(1, 0.5*cm)) story.append(Paragraph('Clinical Flowcharts', ParagraphStyle('Sub', parent=styles['Heading2'], fontSize=14, textColor=colors.HexColor('#2980B9')))) story.append(Spacer(1, 0.5*cm)) toc_items = [ '1. Classification of Diabetes Mellitus', '2. Diagnosis of Diabetes Mellitus (ADA Criteria)', '3. Perioperative Management of the Diabetic Patient', '4. Diabetic Ketoacidosis - Pathophysiology & Management', '5. Perioperative Glycemic Regimens', ] for item in toc_items: story.append(Paragraph(item, ParagraphStyle('TOC', parent=styles['Normal'], fontSize=11, leftIndent=20, spaceAfter=6, textColor=colors.HexColor('#2C3E50')))) from reportlab.platypus import PageBreak story.append(PageBreak()) # Available area in landscape A4 page_w = landscape(A4)[0] - 2*cm # 27.7 cm page_h_avail = landscape(A4)[1] - 4*cm # ~ 17 cm for img_path, title in flowcharts: story.append(Paragraph(title, title_style)) from PIL import Image as PILImage pil_img = PILImage.open(img_path) img_w, img_h = pil_img.size # pixels # Scale to fit page width scale = page_w / img_w disp_w = page_w disp_h = img_h * scale # If too tall, scale down further if disp_h > page_h_avail: scale2 = page_h_avail / disp_h disp_w = disp_w * scale2 disp_h = page_h_avail story.append(Image(img_path, width=disp_w, height=disp_h)) story.append(PageBreak()) doc.build(story) print(f"PDF created: {output_path}") print(f"File size: {os.path.getsize(output_path) / 1024:.1f} KB") PYEOF

All 5 flowcharts have been created and compiled into a single PDF. Here's a summary of everything produced:

Diabetes Mellitus - Flowcharts

I analysed the 31-page PDF (by Dr. J. Edward Johnson - Anaesthetic Management of DM) and identified 5 key areas that warranted flowcharts. All are compiled in the download below:

Diabetes Mellitus Flowcharts

PDF Document · PDF


What each flowchart covers:

Flowchart 1 - Classification of DM
  • ADA 2018 classification tree: Type 1a/1b, Type 2, Gestational DM, Other specific types
  • Type 2 three key defects (↑ hepatic glucose, impaired secretion, insulin resistance)
  • Subtypes of "other specific types" (MODY, exocrine, drug-induced)
Flowchart 2 - Diagnosis of DM
  • All 4 ADA diagnostic tests: FPG, 2-h OGTT, HbA1c, Random plasma glucose
  • Clear prediabetes vs. confirmed DM cut-offs for each test
  • HbA1c significance note (60-90 day average; risk starts at ≥6.5%)
Flowchart 3 - Perioperative Management (7-step)
  • Step-by-step from preop history (CNS/CVS/GIT/Renal) through examination (prayer sign, stiff joint, fundoscopy) to investigations
  • Choice between Regional vs. General anaesthesia with pros/cons
  • Preoperative drug management (insulin pump, glargine, sulfonylureas)
  • Intraoperative and postoperative glucose targets
Flowchart 4 - DKA Pathophysiology & Management
  • Full pathophysiology from insulin deficiency → hyperglycemia + ketogenesis → classical triad
  • Diagnostic criteria (ketones ≥3 mmol/L, BG >11, bicarb <15 / pH <7.3)
  • ABCDE resuscitation, fluid choice (balanced crystalloids), FRIII insulin protocol (0.1 U/kg/hr)
  • Resolution criteria and critical care referral triggers (9 criteria listed)
Flowchart 5 - Glycemic Regimens
  • All 7 perioperative regimens: Sliding Scale, Classic Non-Tight, Tight Control (Regimen I & II), GIK, Alberti, Watt-Hirsch, Vellore
  • Advantages/disadvantages per regimen
  • Glucose targets for fasting, post-prandial, intraoperative, and postoperative phases
This is a shared conversation. Sign in to Orris to start your own chat.