Create a PowerPoint presentation for diabetes mellitus and diabetic emergencies covering essential physiology, definitions, Pathophysiology, clinical features, natural history, investigations, and management

Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Reading File
Finding Sources
Finding Sources
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Searching Images

diabetes mellitus pathophysiology insulin glucose

Reading File
Searching Images

diabetic ketoacidosis DKA pathophysiology management

Reading File
Searching Images

diabetes type 1 type 2 classification comparison

Running Command

mkdir -p /home/daytona/workspace/diabetes-pptx && ls /home/daytona/workspace/diabetes-pptx/

Writing File

~/diabetes-pptx/build.js

const pptxgen = require("pptxgenjs");
const { execSync } = require("child_process");

// ─── Fetch images ─────────────────────────────────────────────────────────────
const imgUrls = [
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_09c4761b1c4dcfc1ed149f3f7dcb1e685afc10b3eb50c0f77460459e58eecf50.jpg",  // T2DM hyperglycemia pathophysiology
  "https://cdn.orris.care/cdss_images/pmc_clinical_VQA_941c21066dfd3864f40b5622a42c85b1791757b3d5bc203e73b2853099bfe1a8.jpg",  // Insulin signaling GLUT-4
  "https://cdn.orris.care/cdss_images/GLGCA_3094724_1763331160817_d5c1f005-88e2-415b-bd53-3321ea5ff15d.png",                    // DM Classification table
  "https://cdn.orris.care/cdss_images/HARRISON_1763035986492_e2de3a37-3e6e-4ec4-9178-bf8624edacba.png",                        // DKA/HHS lab values table
];

let imgs = [];
try {
  const raw = execSync(
    `node /home/daytona/skills/shared/scripts/fetch_images.js ${imgUrls.map(u => `"${u}"`).join(" ")}`,
    { timeout: 60000 }
  ).toString();
  imgs = JSON.parse(raw);
} catch(e) {
  console.error("Image fetch error:", e.message);
  imgs = imgUrls.map(url => ({ url, base64: null, error: e.message }));
}

// ─── Theme ────────────────────────────────────────────────────────────────────
const DARK_BLUE  = "0A2647";   // dominant background on title/section slides
const MID_BLUE   = "144272";   // card backgrounds
const ACCENT     = "205295";   // accent headers
const LIGHT_BLUE = "2C74B3";   // highlight bars
const WHITE      = "FFFFFF";
const NEAR_WHITE = "E8F4FD";
const GOLD       = "F4A927";
const SOFT_GRAY  = "D6E8FA";
const TEXT_DARK  = "0A2647";

const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Diabetes Mellitus & Diabetic Emergencies";
pres.author = "Medical Education";

// ─── Helper: slide background ─────────────────────────────────────────────────
function setBg(slide, color) {
  slide.background = { color };
}

// ─── Helper: section title slide ──────────────────────────────────────────────
function addSectionSlide(pres, num, title, subtitle) {
  const s = pres.addSlide();
  setBg(s, DARK_BLUE);
  // left accent bar
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 0.18, h: 5.625, fill: { color: GOLD } });
  // section number
  s.addText(`0${num}`, { x: 0.3, y: 0.8, w: 1.2, h: 1, fontSize: 52, bold: true, color: GOLD, fontFace: "Calibri" });
  // title
  s.addText(title, { x: 0.3, y: 1.9, w: 9.2, h: 1.2, fontSize: 34, bold: true, color: WHITE, fontFace: "Calibri" });
  if (subtitle) {
    s.addText(subtitle, { x: 0.3, y: 3.1, w: 9.2, h: 0.8, fontSize: 18, color: SOFT_GRAY, fontFace: "Calibri", italic: true });
  }
  return s;
}

// ─── Helper: content slide with title bar ─────────────────────────────────────
function addContentSlide(pres, title, bgColor) {
  const s = pres.addSlide();
  setBg(s, bgColor || NEAR_WHITE);
  // title bar
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 0.72, fill: { color: DARK_BLUE } });
  s.addText(title, { x: 0.18, y: 0.05, w: 9.4, h: 0.62, fontSize: 20, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle" });
  // bottom accent line
  s.addShape(pres.ShapeType.rect, { x: 0, y: 5.42, w: 10, h: 0.2, fill: { color: LIGHT_BLUE } });
  s.addText("Diabetes Mellitus & Diabetic Emergencies  |  Medical Education", {
    x: 0.2, y: 5.42, w: 9.6, h: 0.2, fontSize: 8, color: WHITE, fontFace: "Calibri", valign: "middle"
  });
  return s;
}

// ─── Helper: two-column layout ────────────────────────────────────────────────
function addTwoColSlide(pres, title, leftTitle, leftItems, rightTitle, rightItems) {
  const s = addContentSlide(pres, title);
  // Left card
  s.addShape(pres.ShapeType.rect, { x: 0.15, y: 0.85, w: 4.65, h: 4.45, fill: { color: MID_BLUE }, line: { color: MID_BLUE } });
  s.addText(leftTitle, { x: 0.25, y: 0.88, w: 4.45, h: 0.42, fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri" });
  const leftBullets = leftItems.map((t, i) => ({ text: t, options: { bullet: true, breakLine: i < leftItems.length - 1, fontSize: 11, color: WHITE, fontFace: "Calibri" } }));
  s.addText(leftBullets, { x: 0.25, y: 1.32, w: 4.45, h: 3.8 });
  // Right card
  s.addShape(pres.ShapeType.rect, { x: 5.2, y: 0.85, w: 4.65, h: 4.45, fill: { color: ACCENT }, line: { color: ACCENT } });
  s.addText(rightTitle, { x: 5.3, y: 0.88, w: 4.45, h: 0.42, fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri" });
  const rightBullets = rightItems.map((t, i) => ({ text: t, options: { bullet: true, breakLine: i < rightItems.length - 1, fontSize: 11, color: WHITE, fontFace: "Calibri" } }));
  s.addText(rightBullets, { x: 5.3, y: 1.32, w: 4.45, h: 3.8 });
  return s;
}

// ─── Helper: bullet slide ─────────────────────────────────────────────────────
function addBulletSlide(pres, title, items, noteText) {
  const s = addContentSlide(pres, title);
  const bullets = items.map((item, i) => {
    if (typeof item === "string") {
      return { text: item, options: { bullet: true, breakLine: i < items.length - 1, fontSize: 13, color: TEXT_DARK, fontFace: "Calibri" } };
    } else {
      // { text, bold, indent, color }
      return { text: item.text, options: { bullet: !item.indent, indentLevel: item.indent ? 1 : 0, breakLine: i < items.length - 1, fontSize: item.bold ? 14 : 12, bold: item.bold || false, color: item.color || TEXT_DARK, fontFace: "Calibri" } };
    }
  });
  s.addText(bullets, { x: 0.3, y: 0.85, w: 9.4, h: 4.5 });
  return s;
}

// ─── Helper: card grid (2x2 or 1x4) ─────────────────────────────────────────
function addCardGrid(pres, title, cards) {
  // cards: [{title, items[]}]  max 4
  const s = addContentSlide(pres, title);
  const positions = [
    { x: 0.15, y: 0.82 }, { x: 5.1, y: 0.82 },
    { x: 0.15, y: 3.1  }, { x: 5.1, y: 3.1  }
  ];
  const colors = [MID_BLUE, ACCENT, LIGHT_BLUE, "1B4F8A"];
  cards.forEach((card, i) => {
    const p = positions[i];
    const col = colors[i];
    s.addShape(pres.ShapeType.rect, { x: p.x, y: p.y, w: 4.75, h: 2.15, fill: { color: col } });
    s.addText(card.title, { x: p.x + 0.1, y: p.y + 0.05, w: 4.55, h: 0.38, fontSize: 12, bold: true, color: GOLD, fontFace: "Calibri" });
    const bItems = card.items.map((t, j) => ({ text: t, options: { bullet: true, breakLine: j < card.items.length - 1, fontSize: 10, color: WHITE, fontFace: "Calibri" } }));
    s.addText(bItems, { x: p.x + 0.1, y: p.y + 0.44, w: 4.55, h: 1.65 });
  });
  return s;
}

// ─── Slide 1: TITLE ───────────────────────────────────────────────────────────
{
  const s = pres.addSlide();
  setBg(s, DARK_BLUE);
  // Decorative circles
  s.addShape(pres.ShapeType.ellipse, { x: 7.6, y: -0.8, w: 4.0, h: 4.0, fill: { color: MID_BLUE }, line: { color: MID_BLUE } });
  s.addShape(pres.ShapeType.ellipse, { x: 8.2, y: 3.2, w: 2.5, h: 2.5, fill: { color: ACCENT }, line: { color: ACCENT } });
  // Gold accent bar
  s.addShape(pres.ShapeType.rect, { x: 0, y: 2.55, w: 10, h: 0.08, fill: { color: GOLD } });
  // Main title
  s.addText("DIABETES MELLITUS", { x: 0.5, y: 0.5, w: 7.5, h: 1.1, fontSize: 40, bold: true, color: WHITE, fontFace: "Calibri", charSpacing: 2 });
  s.addText("& DIABETIC EMERGENCIES", { x: 0.5, y: 1.55, w: 7.5, h: 0.9, fontSize: 28, bold: true, color: GOLD, fontFace: "Calibri", charSpacing: 1 });
  // Sub
  s.addText("Physiology · Pathophysiology · Clinical Features · Investigations · Management", {
    x: 0.5, y: 2.72, w: 8.5, h: 0.6, fontSize: 14, color: SOFT_GRAY, fontFace: "Calibri", italic: true
  });
  // bottom info
  s.addText("Goldman-Cecil Medicine  |  Harrison's Principles  |  Medical Education 2026", {
    x: 0.5, y: 5.1, w: 9, h: 0.35, fontSize: 11, color: SOFT_GRAY, fontFace: "Calibri"
  });
}

// ─── Slide 2: AGENDA ─────────────────────────────────────────────────────────
{
  const s = addContentSlide(pres, "Agenda");
  setBg(s, DARK_BLUE);
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 0.72, fill: { color: LIGHT_BLUE } });
  s.addText("Agenda", { x: 0.18, y: 0.05, w: 9.4, h: 0.62, fontSize: 20, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle" });
  const topics = [
    ["01", "Essential Physiology", "Insulin synthesis, glucose homeostasis, counter-regulatory hormones"],
    ["02", "Definitions & Classification", "WHO/ADA criteria, types of diabetes mellitus"],
    ["03", "Pathophysiology", "Type 1 (autoimmune), Type 2 (insulin resistance + β-cell failure)"],
    ["04", "Clinical Features & Natural History", "Symptoms, complications, disease progression"],
    ["05", "Investigations", "Diagnosis, HbA1c, OGTT, monitoring"],
    ["06", "Management", "Lifestyle, pharmacotherapy, targets"],
    ["07", "Diabetic Emergencies", "DKA, HHS, Hypoglycemia — recognition & management"],
  ];
  topics.forEach((t, i) => {
    const col = i % 2 === 0 ? MID_BLUE : ACCENT;
    const yp = 0.82 + i * 0.64;
    s.addShape(pres.ShapeType.rect, { x: 0.2, y: yp, w: 9.6, h: 0.58, fill: { color: col } });
    s.addText(t[0], { x: 0.3, y: yp + 0.05, w: 0.55, h: 0.48, fontSize: 14, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle" });
    s.addText(t[1], { x: 0.9, y: yp + 0.05, w: 2.8, h: 0.48, fontSize: 13, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle" });
    s.addText(t[2], { x: 3.75, y: yp + 0.05, w: 5.9, h: 0.48, fontSize: 11, color: SOFT_GRAY, fontFace: "Calibri", valign: "middle", italic: true });
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 01: ESSENTIAL PHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 1, "Essential Physiology", "Insulin synthesis, glucose homeostasis & counter-regulatory hormones");

// Slide: Insulin — Structure & Synthesis
addTwoColSlide(pres,
  "Insulin — Structure & Synthesis",
  "Biosynthesis",
  [
    "Produced by pancreatic β-cells in islets of Langerhans",
    "Gene on chromosome 11; mRNA → preproinsulin",
    "Preproinsulin → proinsulin (ER) → insulin + C-peptide (Golgi)",
    "Stored as hexameric zinc complex in secretory granules",
    "Glucose-stimulated secretion: biphasic (early ~1–3 min; sustained ~2 h)",
    "C-peptide: equimolar to insulin; marker of endogenous secretion",
  ],
  "Structure & Key Actions",
  [
    "51 amino acids: A-chain (21 aa) + B-chain (30 aa) connected by 2 disulfide bonds",
    "Binds insulin receptor tyrosine kinase → IRS-1/2 → PI3K/AKT",
    "GLUT-4 translocation → glucose uptake in muscle & adipose",
    "Promotes glycogen synthesis, protein synthesis, lipogenesis",
    "Inhibits gluconeogenesis, glycogenolysis, lipolysis, ketogenesis",
    "Half-life: ~5 min; degraded by liver (50%) and kidney",
  ]
);

// Slide: Glucose Homeostasis
{
  const s = addContentSlide(pres, "Glucose Homeostasis");
  // Left image area
  if (imgs[1] && imgs[1].base64) {
    s.addImage({ data: imgs[1].base64, x: 5.5, y: 0.82, w: 4.3, h: 3.5 });
  }
  const bullets = [
    { text: "Normal fasting plasma glucose: 70–100 mg/dL (3.9–5.6 mmol/L)", bold: true },
    { text: "Postprandial glucose peak: <140 mg/dL at 2 h" },
    { text: "Renal threshold for glycosuria: ~180–200 mg/dL", bold: false },
    { text: "After a meal: ↑ glucose → ↑ insulin, ↓ glucagon" },
    { text: "Fasting state: ↓ insulin → hepatic glucose output via gluconeogenesis + glycogenolysis" },
    { text: "Counter-regulatory hormones (glucagon, cortisol, GH, catecholamines) raise glucose" },
    { text: "Insulin:glucagon ratio governs hepatic glucose output" },
    { text: "Glucose enters cells via GLUT transporters (GLUT-2 in liver/pancreas; GLUT-4 in muscle/fat)" },
  ];
  const bItems = bullets.map((b, i) => ({
    text: b.text,
    options: { bullet: true, breakLine: i < bullets.length - 1, fontSize: b.bold ? 13 : 12, bold: b.bold || false, color: TEXT_DARK, fontFace: "Calibri" }
  }));
  s.addText(bItems, { x: 0.3, y: 0.85, w: 5.1, h: 4.45 });
}

// Slide: Counter-regulatory Hormones
addCardGrid(pres, "Counter-Regulatory Hormones", [
  { title: "Glucagon (α-cells)", items: ["Secreted in response to hypoglycemia & amino acids", "Stimulates glycogenolysis & gluconeogenesis", "Increases hepatic ketone production", "Suppressed by insulin and hyperglycemia"] },
  { title: "Epinephrine & Norepinephrine", items: ["Rapid response to hypoglycemia (<3.8 mmol/L)", "Inhibit insulin secretion", "Stimulate glucagon secretion & hepatic glucose output", "Cause adrenergic symptoms (palpitations, tremor, sweating)"] },
  { title: "Cortisol", items: ["Increases gluconeogenesis substrates (amino acids)", "Promotes insulin resistance in muscle", "Impairs GLUT-4 translocation", "Elevated in stress, Cushing syndrome → hyperglycemia"] },
  { title: "Growth Hormone", items: ["Stimulates IGF-1 in liver", "Anti-insulin: promotes lipolysis & gluconeogenesis", "Dawn phenomenon: GH surge overnight → AM hyperglycemia in T1DM", "Acromegaly → secondary diabetes"] },
]);


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 02: DEFINITIONS & CLASSIFICATION
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 2, "Definitions & Classification", "WHO/ADA diagnostic criteria and disease taxonomy");

// Slide: Definition of Diabetes
addBulletSlide(pres, "Definition of Diabetes Mellitus", [
  { text: "Diabetes mellitus (DM) is a group of metabolic diseases characterized by:", bold: true },
  { text: "Hyperglycemia resulting from defects in insulin secretion, insulin action, or both", indent: true },
  { text: "Chronic hyperglycemia is associated with long-term damage to multiple organs", indent: true },
  { text: "Affects >500 million people worldwide; 7th leading cause of death in the USA", indent: true },
  { text: "WHO Diagnostic Criteria (any one of the following):", bold: true, color: ACCENT },
  { text: "Fasting plasma glucose (FPG) ≥ 7.0 mmol/L (126 mg/dL)  [8-h fast]", indent: true },
  { text: "2-hour plasma glucose ≥ 11.1 mmol/L (200 mg/dL) during 75g OGTT", indent: true },
  { text: "HbA1c ≥ 6.5% (48 mmol/mol) — confirmed by repeat testing if asymptomatic", indent: true },
  { text: "Random plasma glucose ≥ 11.1 mmol/L + classic hyperglycaemic symptoms", indent: true },
  { text: "Pre-diabetes thresholds:", bold: true, color: ACCENT },
  { text: "Impaired fasting glucose (IFG): FPG 6.1–6.9 mmol/L  |  HbA1c 5.7–6.4%", indent: true },
  { text: "Impaired glucose tolerance (IGT): 2-h OGTT 7.8–11.0 mmol/L", indent: true },
]);

// Slide: Classification
{
  const s = addContentSlide(pres, "Classification of Diabetes Mellitus (ADA/WHO)");
  if (imgs[2] && imgs[2].base64) {
    s.addImage({ data: imgs[2].base64, x: 5.5, y: 0.82, w: 4.3, h: 4.55 });
  }
  const items = [
    { text: "TYPE 1 — Immune-mediated β-cell destruction", bold: true, color: DARK_BLUE },
    { text: "Absolute insulin deficiency; autoimmune (HLA-DR3/DR4, anti-GAD, anti-IA2)", indent: true },
    { text: "TYPE 2 — Progressive β-cell failure + insulin resistance", bold: true, color: DARK_BLUE },
    { text: "Relative insulin deficiency; obesity-related; accounts for ~90% of cases", indent: true },
    { text: "GESTATIONAL DIABETES MELLITUS (GDM)", bold: true, color: DARK_BLUE },
    { text: "Diagnosed in 2nd/3rd trimester; resolves after delivery; ↑ T2DM risk later", indent: true },
    { text: "OTHER SPECIFIC TYPES", bold: true, color: DARK_BLUE },
    { text: "MODY (monogenic), pancreatic disease, endocrinopathies (Cushing, acromegaly)", indent: true },
    { text: "Drug-induced (corticosteroids, clozapine, SGLT2i → euDKA)", indent: true },
    { text: "Infections (rubella, CMV — rare)", indent: true },
  ];
  const bItems = items.map((item, i) => ({
    text: item.text,
    options: { bullet: !item.indent, indentLevel: item.indent ? 1 : 0, breakLine: i < items.length - 1, fontSize: item.bold ? 13 : 11.5, bold: item.bold || false, color: item.color || TEXT_DARK, fontFace: "Calibri" }
  }));
  s.addText(bItems, { x: 0.3, y: 0.85, w: 5.0, h: 4.5 });
}

// Slide: Type 1 vs Type 2 Comparison
{
  const s = addContentSlide(pres, "Type 1 vs Type 2 Diabetes — Key Differences");
  const headers = ["Feature", "Type 1", "Type 2"];
  const rows = [
    ["Age of onset", "Usually <30 yrs (peak: childhood)", "Usually >40 yrs (increasingly younger)"],
    ["Body habitus", "Normal / underweight", "Overweight / obese (>85%)"],
    ["Onset", "Acute / subacute", "Insidious (years)"],
    ["Pathogenesis", "Autoimmune β-cell destruction", "Insulin resistance + β-cell dysfunction"],
    ["Insulin level", "Absent / very low", "Normal, elevated, or low (late)"],
    ["C-peptide", "Undetectable", "Detectable"],
    ["Autoantibodies", "Anti-GAD, anti-IA2, anti-ZnT8", "Absent"],
    ["Ketosis", "Prone (DKA)", "Resistant (until late)"],
    ["Treatment", "Insulin mandatory", "Lifestyle → oral agents → insulin"],
    ["HLA association", "DR3, DR4", "No strong HLA link"],
  ];
  const colW = [2.1, 3.7, 3.7];
  const colX = [0.12, 2.24, 5.96];
  // header
  headers.forEach((h, ci) => {
    s.addShape(pres.ShapeType.rect, { x: colX[ci], y: 0.78, w: colW[ci], h: 0.38, fill: { color: DARK_BLUE } });
    s.addText(h, { x: colX[ci] + 0.05, y: 0.78, w: colW[ci] - 0.1, h: 0.38, fontSize: 11, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle" });
  });
  rows.forEach((row, ri) => {
    const yp = 1.18 + ri * 0.40;
    const bg = ri % 2 === 0 ? SOFT_GRAY : WHITE;
    row.forEach((cell, ci) => {
      s.addShape(pres.ShapeType.rect, { x: colX[ci], y: yp, w: colW[ci], h: 0.38, fill: { color: ci === 0 ? ACCENT : bg }, line: { color: "CCCCCC", pt: 0.5 } });
      s.addText(cell, { x: colX[ci] + 0.05, y: yp, w: colW[ci] - 0.1, h: 0.38, fontSize: 10, bold: ci === 0, color: ci === 0 ? WHITE : TEXT_DARK, fontFace: "Calibri", valign: "middle" });
    });
  });
}


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 03: PATHOPHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 3, "Pathophysiology", "Mechanisms of hyperglycemia in Type 1 and Type 2 DM");

// Type 1 pathophysiology
addBulletSlide(pres, "Pathophysiology — Type 1 Diabetes Mellitus", [
  { text: "Autoimmune Destruction of β-cells (Immune-Mediated)", bold: true, color: ACCENT },
  { text: "Genetic susceptibility: HLA class II alleles (HLA-DR3, HLA-DR4) on chromosome 6p21" },
  { text: "Environmental triggers: enteroviruses (Coxsackievirus B), dietary antigens (early cow's milk)" },
  { text: "Molecular mimicry: viral antigens resemble islet cell proteins → autoreactive T-cells" },
  { text: "CD4+ & CD8+ T-lymphocyte-mediated destruction of β-cells (insulitis)" },
  { text: "Circulating autoantibodies: anti-GAD65, anti-IA2, anti-insulin (ICA), anti-ZnT8" },
  { text: "Progressive β-cell loss over months to years before clinical diagnosis" },
  { text: "Absolute insulin deficiency → unopposed catabolic state", bold: true, color: ACCENT },
  { text: "↑ Glucagon → glycogenolysis + gluconeogenesis → hyperglycemia" },
  { text: "↑ Lipolysis → free fatty acids → hepatic ketogenesis (acetoacetate, β-hydroxybutyrate, acetone)" },
  { text: "Osmotic diuresis (glycosuria) → dehydration, electrolyte loss → DKA if untreated" },
  { text: "~90% β-cell mass must be destroyed before clinical hyperglycemia appears" },
]);

// Type 2 pathophysiology
{
  const s = addContentSlide(pres, "Pathophysiology — Type 2 Diabetes Mellitus");
  if (imgs[0] && imgs[0].base64) {
    s.addImage({ data: imgs[0].base64, x: 5.5, y: 0.82, w: 4.3, h: 3.6 });
    s.addText("Multi-organ contribution to hyperglycemia in T2DM", { x: 5.5, y: 4.42, w: 4.3, h: 0.35, fontSize: 9, color: ACCENT, fontFace: "Calibri", italic: true, align: "center" });
  }
  const items = [
    { text: "The 'Ominous Octet' (DeFronzo) — Multiple organ defects:", bold: true },
    { text: "Insulin resistance (muscle): reduced GLUT-4 translocation; IRS-1 phosphorylation impaired by lipids", indent: true },
    { text: "β-cell failure (pancreas): progressive loss of first-phase insulin secretion; glucolipotoxicity; amyloid deposition (IAPP)", indent: true },
    { text: "Liver: excessive gluconeogenesis; resistance to insulin suppression of hepatic glucose output", indent: true },
    { text: "α-cell dysfunction: paradoxical hyperglucagonemia in hyperglycaemic state", indent: true },
    { text: "Brain: impaired satiety signalling, insulin resistance centrally", indent: true },
    { text: "Kidney: increased glucose reabsorption via SGLT2 (upregulated in T2DM)", indent: true },
    { text: "Risk factors amplifying pathophysiology:", bold: true },
    { text: "Obesity (BMI ≥30): visceral fat → proinflammatory cytokines (TNF-α, IL-6), ↓ adiponectin, ↑ FFA" },
    { text: "Genetic: TCF7L2, KCNJ11 polymorphisms impair insulin secretion" },
    { text: "Metabolic progression: normoglycaemia → pre-diabetes → overt T2DM over years-decades" },
  ];
  const bItems = items.map((item, i) => ({
    text: item.text,
    options: { bullet: !item.indent, indentLevel: item.indent ? 1 : 0, breakLine: i < items.length - 1, fontSize: item.bold ? 13 : 11, bold: item.bold || false, color: item.color || TEXT_DARK, fontFace: "Calibri" }
  }));
  s.addText(bItems, { x: 0.3, y: 0.85, w: 5.0, h: 4.5 });
}


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 04: CLINICAL FEATURES & NATURAL HISTORY
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 4, "Clinical Features & Natural History", "Symptoms, complications, and disease trajectory");

// Clinical features
addTwoColSlide(pres,
  "Clinical Features of Diabetes Mellitus",
  "Classic Symptoms (\"3 Ps\")",
  [
    "Polyuria — osmotic diuresis once glucose >180–200 mg/dL",
    "Polydipsia — compensatory thirst from volume depletion",
    "Polyphagia — cellular energy deprivation despite hyperglycaemia",
    "Weight loss — catabolism; glycosuria; loss of calories in urine",
    "Fatigue — poor glucose utilization in cells",
    "Blurred vision — hyperosmolar lens swelling",
    "Recurrent infections — impaired neutrophil function in hyperglycaemia",
    "Acanthosis nigricans — insulin resistance marker (Type 2)",
    "Candidal infections (genital, oral) — glucose-rich mucosa",
  ],
  "Type 1-Specific Presentation",
  [
    "Acute onset, often presenting in DKA",
    "Kussmaul breathing (deep, sighing respirations) in DKA",
    "Fruity breath (acetone)",
    "Nausea, vomiting, abdominal pain",
    "Age: typically <30 years",
    "\"Honeymoon phase\": partial β-cell recovery 3–6 months after diagnosis; reduced insulin need",
    "Lipoatrophy / lipohypertrophy at injection sites",
    "Type 2: often asymptomatic for years; identified on routine screening",
  ]
);

// Microvascular complications
addCardGrid(pres, "Chronic Complications — Microvascular", [
  { title: "Diabetic Retinopathy", items: [
    "Most common cause of blindness in working-age adults",
    "Non-proliferative (NPDR): microaneurysms, haemorrhages, exudates",
    "Proliferative (PDR): neovascularisation, vitreous haemorrhage, retinal detachment",
    "Screening: annual fundoscopy from diagnosis (T2) or 5 yrs after (T1)",
    "Rx: laser photocoagulation, anti-VEGF (ranibizumab)",
  ]},
  { title: "Diabetic Nephropathy", items: [
    "Leading cause of end-stage renal disease globally",
    "Stages: microalbuminuria → macroalbuminuria → ↓ GFR → ESRD",
    "Kimmelstiel-Wilson nodules: pathognomonic on biopsy",
    "Glomerular basement membrane thickening; mesangial expansion",
    "Screening: urine ACR annually; ACEI/ARB for proteinuria",
    "SGLT2 inhibitors (empagliflozin) reduce progression",
  ]},
  { title: "Diabetic Neuropathy", items: [
    "Most common: distal symmetric sensorimotor polyneuropathy",
    "\"Glove & stocking\" pattern; loss of vibration/proprioception first",
    "Charcot arthropathy: bony destruction due to painless trauma",
    "Autonomic neuropathy: orthostatic hypotension, gastroparesis, ED",
    "Mononeuropathies: CN3 palsy (pupil spared), carpal tunnel",
    "Pain Rx: duloxetine, gabapentin, pregabalin",
  ]},
  { title: "Diabetic Foot", items: [
    "Combination of neuropathy + peripheral vascular disease",
    "Neuropathic ulcers: painless, punched out, pressure points (metatarsal heads)",
    "Ischaemic ulcers: painful, on toes/heels, poor pulses",
    "Annual foot exam; monofilament testing",
    "Leading cause of non-traumatic amputation",
    "Multidisciplinary care: podiatry, vascular surgery, orthotics",
  ]},
]);

// Macrovascular complications
addBulletSlide(pres, "Chronic Complications — Macrovascular & Natural History", [
  { text: "Macrovascular Disease (2–2.5× higher CV risk than non-diabetics)", bold: true, color: ACCENT },
  { text: "Coronary artery disease: commonest cause of death in T2DM; often \"silent\" MI" },
  { text: "Cerebrovascular disease: stroke risk 1.5–3× higher; lacunar infarcts common" },
  { text: "Peripheral arterial disease: ABI <0.9; claudication; critical limb ischaemia" },
  { text: "Heart failure: both HFrEF and HFpEF; SGLT2i reduce hospitalisation significantly" },
  { text: "Each 18 mg/dL (1 mmol/L) rise in fasting glucose → 17% ↑ cardiovascular event risk" },
  { text: "Natural History Trajectory", bold: true, color: ACCENT },
  { text: "T1DM: Rapid β-cell destruction → life-long insulin dependency from onset; complications appear ~5–10 yrs after diagnosis" },
  { text: "T2DM: Pre-diabetes (5–10 yrs) → early T2DM → progressive β-cell failure → complications over decades" },
  { text: "T2DM prognosis: life expectancy at 50 years is ~6 years lower than non-diabetics" },
  { text: "With optimal multi-factorial control (glucose + BP + lipids): risk of blindness, ESRD, amputation each <1%" },
]);


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 05: INVESTIGATIONS
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 5, "Investigations", "Diagnosis, monitoring and evaluation of complications");

// Diagnostic tests
addBulletSlide(pres, "Investigations — Diagnosis & Monitoring", [
  { text: "DIAGNOSTIC TESTS", bold: true, color: ACCENT },
  { text: "Fasting Plasma Glucose (FPG): ≥7.0 mmol/L (126 mg/dL) after 8-h fast; simple, cheap, reproducible" },
  { text: "Oral Glucose Tolerance Test (OGTT): 75 g glucose; 2-h PG ≥11.1 mmol/L (200 mg/dL)" },
  { text: "HbA1c: ≥6.5% (48 mmol/mol); reflects 3-month average glucose; not affected by short-term changes" },
  { text: "Random PG: ≥11.1 mmol/L + symptoms; no fasting required" },
  { text: "Note: Two abnormal results required if asymptomatic; one result if symptomatic hyperglycaemia" },
  { text: "MONITORING", bold: true, color: ACCENT },
  { text: "HbA1c: every 3 months if not at target; every 6 months if stable and at target" },
  { text: "Self-monitoring of blood glucose (SMBG): finger-prick capillary glucose; essential in insulin users" },
  { text: "Continuous glucose monitoring (CGM): interstitial glucose q5–15 min; TIR (time-in-range) 70–180 mg/dL target >70%" },
  { text: "Fructosamine: reflects 2–3 week average; useful in haemoglobinopathies, haemolysis, pregnancy" },
  { text: "C-peptide: low in T1DM; normal/high in T2DM; distinguishes T1 from T2 in uncertain cases" },
  { text: "COMPLICATION SCREENING (ANNUAL)", bold: true, color: ACCENT },
  { text: "Urine albumin:creatinine ratio (ACR); eGFR; lipid panel; fundoscopy; foot exam; BP; ECG" },
]);

// Lab interpretation table
{
  const s = addContentSlide(pres, "Glycaemic Targets & Key Lab Values");
  const tableData = [
    ["Parameter", "Normal", "Pre-diabetes", "Diabetes"],
    ["FPG (mmol/L)", "<5.6", "5.6–6.9", "≥7.0"],
    ["2-h OGTT (mmol/L)", "<7.8", "7.8–11.0", "≥11.1"],
    ["HbA1c (%)", "<5.7", "5.7–6.4", "≥6.5"],
    ["", "", "", ""],
    ["Treatment Target", "Most adults", "Tight control", "Relaxed"],
    ["HbA1c target (%)", "–", "<6.5", "7.0–8.0"],
    ["Fasting glucose (mmol/L)", "–", "4.4–7.2", "4.4–7.2"],
    ["Postprandial (mmol/L)", "–", "<10.0", "<10.0"],
    ["BP target (mmHg)", "–", "<130/80", "<130/80"],
    ["LDL-C target (mmol/L)", "–", "<1.8 (high CV risk)", "<1.8–2.6"],
  ];
  const colW = [3.0, 2.3, 2.2, 2.2];
  const colX = [0.12, 3.14, 5.46, 7.7];
  const hdrColors = [DARK_BLUE, MID_BLUE, ACCENT, LIGHT_BLUE];
  tableData.forEach((row, ri) => {
    const yp = 0.82 + ri * 0.42;
    row.forEach((cell, ci) => {
      const isHdr = ri === 0 || ri === 5;
      const bg = isHdr ? hdrColors[ci] : (ri % 2 === 0 ? SOFT_GRAY : WHITE);
      s.addShape(pres.ShapeType.rect, { x: colX[ci], y: yp, w: colW[ci], h: 0.40, fill: { color: bg }, line: { color: "CCCCCC", pt: 0.5 } });
      s.addText(cell, { x: colX[ci] + 0.05, y: yp, w: colW[ci] - 0.1, h: 0.40, fontSize: isHdr ? 11 : 10.5, bold: isHdr || ci === 0, color: isHdr ? WHITE : TEXT_DARK, fontFace: "Calibri", valign: "middle" });
    });
  });
}


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 06: MANAGEMENT
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 6, "Management", "Lifestyle, pharmacotherapy & cardiovascular risk reduction");

// T1 management
addBulletSlide(pres, "Management — Type 1 Diabetes", [
  { text: "Insulin is mandatory — no alternative", bold: true, color: ACCENT },
  { text: "Regimens:", bold: true },
  { text: "Basal-bolus (MDI): long-acting (glargine, detemir, degludec) once/twice daily + rapid-acting (lispro, aspart, glulisine) before meals" },
  { text: "Continuous subcutaneous insulin infusion (CSII/pump): most physiological; allows micro-dosing and temp basal rates" },
  { text: "DAFNE: Dose Adjustment For Normal Eating — carbohydrate counting framework" },
  { text: "Adjuncts:", bold: true },
  { text: "CGM with hybrid closed-loop (artificial pancreas) → automated insulin delivery" },
  { text: "Pramlintide (amylin analogue) — blunts postprandial glucose in select patients" },
  { text: "Monitoring:", bold: true },
  { text: "HbA1c target <7.0% (<53 mmol/mol) for most adults; individualised" },
  { text: "CGM Time-in-Range (TIR) 70–180 mg/dL: >70% target" },
  { text: "Sick-day rules: never stop insulin; increase monitoring; check ketones" },
  { text: "Transplantation:", bold: true },
  { text: "Pancreas or islet cell transplantation for brittle T1DM or concurrent kidney transplant" },
]);

// T2 management algorithm
{
  const s = addContentSlide(pres, "Management — Type 2 Diabetes: Stepwise Algorithm");
  // Step boxes
  const steps = [
    { n: "Step 1", title: "Lifestyle Modification (All patients)", items: ["Medical nutrition therapy: Mediterranean/DASH diet; ↓ refined carbs", "Physical activity: 150 min/week moderate intensity aerobic", "Weight loss: 5–10% reduces HbA1c 0.5–1.0%", "Smoking cessation; alcohol restriction", "Diabetes self-management education (DSME)"] },
    { n: "Step 2", title: "First-line Pharmacotherapy", items: ["Metformin: 1st-line (if eGFR ≥30); decreases hepatic glucose output; weight neutral/↓", "SGLT2 inhibitors: empagliflozin, dapagliflozin — prefer if HF or CKD", "GLP-1 RA: semaglutide, liraglutide — prefer if overweight + CVD risk"] },
    { n: "Step 3", title: "Add-on Agents", items: ["DPP-4 inhibitors: sitagliptin, saxagliptin — weight neutral; low hypoglycaemia risk", "Pioglitazone: if metabolic syndrome; caution: fluid retention, fracture risk", "Sulfonylureas: gliclazide, glimepiride — risk of hypoglycaemia; declining use"] },
    { n: "Step 4", title: "Insulin Initiation", items: ["When HbA1c persistently >10% or β-cell failure", "Start: basal insulin (glargine, NPH) bedtime or morning", "Intensify: premixed or basal-bolus regimen as needed", "Add GLP-1 RA to basal insulin to limit weight gain"] },
  ];
  const cols = [0.12, 5.06];
  const rows2 = [0.82, 3.12];
  const bgCols = [MID_BLUE, ACCENT, LIGHT_BLUE, "1B4F8A"];
  steps.forEach((step, i) => {
    const cx = cols[i % 2];
    const cy = rows2[Math.floor(i / 2)];
    s.addShape(pres.ShapeType.rect, { x: cx, y: cy, w: 4.8, h: 2.2, fill: { color: bgCols[i] } });
    s.addShape(pres.ShapeType.rect, { x: cx, y: cy, w: 4.8, h: 0.3, fill: { color: GOLD } });
    s.addText(`${step.n}: ${step.title}`, { x: cx + 0.1, y: cy, w: 4.6, h: 0.3, fontSize: 10, bold: true, color: DARK_BLUE, fontFace: "Calibri", valign: "middle" });
    const bItems = step.items.map((t, j) => ({ text: t, options: { bullet: true, breakLine: j < step.items.length - 1, fontSize: 9.5, color: WHITE, fontFace: "Calibri" } }));
    s.addText(bItems, { x: cx + 0.1, y: cy + 0.33, w: 4.6, h: 1.8 });
  });
}

// Drug table
{
  const s = addContentSlide(pres, "Pharmacotherapy Summary — Antidiabetic Agents");
  const headers = ["Drug Class", "Example", "Mechanism", "Key Benefit", "Caution"];
  const rows3 = [
    ["Metformin", "Metformin", "↓ Hepatic glucose output, ↑ insulin sensitivity", "Weight ↓, CV safe, cheap", "Lactic acidosis if eGFR<30"],
    ["SGLT2i", "Empagliflozin", "↓ Renal glucose reabsorption (glucosuria)", "HF, CKD protection; weight ↓", "UTI/genital fungal; DKA risk"],
    ["GLP-1 RA", "Semaglutide", "↑ Insulin, ↓ glucagon, ↑ satiety", "Weight ↓↓, CV & renal protection", "GI side-effects; pancreatitis"],
    ["DPP-4i", "Sitagliptin", "↑ Endogenous GLP-1 & GIP", "Weight neutral, low hypoglycaemia", "HF risk (saxagliptin)"],
    ["Sulfonylurea", "Gliclazide", "↑ Insulin secretion (β-cell K+ATP channel)", "Cheap; proven efficacy", "Hypoglycaemia, weight gain"],
    ["Thiazolidinedione", "Pioglitazone", "PPAR-γ agonist → ↑ insulin sensitivity", "Metabolic syndrome, NASH", "Fluid retention, fractures, HF"],
    ["Insulin", "Glargine/Aspart", "Direct glucose uptake via GLUT-4", "Unlimited efficacy ceiling", "Hypoglycaemia, weight gain"],
  ];
  const colW2 = [1.65, 1.45, 2.45, 2.2, 2.0];
  const colX2 = [0.1, 1.77, 3.24, 5.71, 7.93];
  // header row
  headers.forEach((h, ci) => {
    s.addShape(pres.ShapeType.rect, { x: colX2[ci], y: 0.78, w: colW2[ci], h: 0.34, fill: { color: DARK_BLUE } });
    s.addText(h, { x: colX2[ci] + 0.04, y: 0.78, w: colW2[ci] - 0.08, h: 0.34, fontSize: 10, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle" });
  });
  rows3.forEach((row, ri) => {
    const yp = 1.14 + ri * 0.56;
    const bg = ri % 2 === 0 ? SOFT_GRAY : WHITE;
    row.forEach((cell, ci) => {
      s.addShape(pres.ShapeType.rect, { x: colX2[ci], y: yp, w: colW2[ci], h: 0.54, fill: { color: ci === 0 ? ACCENT : bg }, line: { color: "CCCCCC", pt: 0.5 } });
      s.addText(cell, { x: colX2[ci] + 0.04, y: yp, w: colW2[ci] - 0.08, h: 0.54, fontSize: 9.5, bold: ci === 0, color: ci === 0 ? WHITE : TEXT_DARK, fontFace: "Calibri", valign: "middle", wrap: true });
    });
  });
}

// CV risk reduction
addBulletSlide(pres, "Cardiovascular Risk Reduction in Diabetes", [
  { text: "Diabetics are treated as 'CVD-equivalent' — aggressive risk factor management mandatory", bold: true },
  { text: "Blood Pressure:", bold: true, color: ACCENT },
  { text: "Target <130/80 mmHg for most; first-line: ACEi or ARB (especially with proteinuria)" },
  { text: "Avoid ACEi + ARB combination (↑ AKI, hyperkalaemia risk)" },
  { text: "Lipid Management:", bold: true, color: ACCENT },
  { text: "Statin therapy for all T2DM >40 years or with CVD; LDL-C target <1.8 mmol/L (high risk)" },
  { text: "Ezetimibe or PCSK9 inhibitors if statin-intolerant or target not reached" },
  { text: "Antiplatelet:", bold: true, color: ACCENT },
  { text: "Aspirin 75 mg: secondary prevention (established CVD); not routine for primary prevention" },
  { text: "Cardioprotective Medications:", bold: true, color: ACCENT },
  { text: "SGLT2 inhibitors (empagliflozin, canagliflozin): reduce HF hospitalisation, CV death, renal progression — EMPA-REG, CANVAS, CREDENCE trials" },
  { text: "GLP-1 RA (liraglutide, semaglutide): reduce MACE (LEADER, SUSTAIN-6 trials)" },
  { text: "Finerenone (non-steroidal MRA): reduces CKD progression and CV events in T2DM + CKD" },
]);


// ═══════════════════════════════════════════════════════════════════════════════
// SECTION 07: DIABETIC EMERGENCIES
// ═══════════════════════════════════════════════════════════════════════════════
addSectionSlide(pres, 7, "Diabetic Emergencies", "DKA · Hyperosmolar Hyperglycaemic State · Hypoglycaemia");

// DKA definition & precipitants
addBulletSlide(pres, "Diabetic Ketoacidosis (DKA) — Definition & Precipitants", [
  { text: "DKA Diagnostic Triad (the 'D-K-A'):", bold: true, color: ACCENT },
  { text: "D — Diabetes: glucose ≥13.9 mmol/L (250 mg/dL) OR known diabetes" },
  { text: "K — Ketones: urine ketones ≥2+ OR serum β-hydroxybutyrate ≥3.0 mmol/L" },
  { text: "A — Acidosis: arterial/venous pH <7.3 OR serum bicarbonate <15 mmol/L" },
  { text: "Predominantly Type 1 DM; increasingly seen in T2DM (esp. SGLT2i — euglycaemic DKA)", bold: false },
  { text: "Mortality: ~1–4%; higher at extremes of age and with severe precipitating illness" },
  { text: "Precipitants — MOST COMMON:", bold: true, color: ACCENT },
  { text: "Infections (pneumonia, UTI, cellulitis): ~30–40% of cases" },
  { text: "Inadequate insulin / non-adherence: ~20–30%" },
  { text: "New-onset T1DM (first presentation): ~10–15%" },
  { text: "Acute coronary syndrome / MI — always rule out in DKA" },
  { text: "Other precipitants: CVA, pulmonary embolism, acute pancreatitis, burns, drugs (corticosteroids, clozapine, SGLT2i), Cushing syndrome, thyrotoxicosis" },
]);

// DKA pathophysiology
{
  const s = addContentSlide(pres, "DKA — Pathophysiology");
  s.addShape(pres.ShapeType.rect, { x: 0.15, y: 0.82, w: 9.7, h: 0.38, fill: { color: ACCENT } });
  s.addText("Absolute insulin deficiency + counter-regulatory hormone excess (glucagon ↑↑, catecholamines ↑, cortisol ↑)", {
    x: 0.25, y: 0.82, w: 9.5, h: 0.38, fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle"
  });
  // Flow diagram with shapes
  const flowItems = [
    { x: 0.2, y: 1.28, w: 2.9, h: 0.7, bg: MID_BLUE, text: "↑ Glycogenolysis\n↑ Gluconeogenesis\n↑ Hepatic glucose output" },
    { x: 3.55, y: 1.28, w: 2.9, h: 0.7, bg: ACCENT, text: "↑ Lipolysis\n↑ Free fatty acids → liver\n↑ Ketone production" },
    { x: 6.9, y: 1.28, w: 2.9, h: 0.7, bg: LIGHT_BLUE, text: "Glucose & ketones\nin circulation ↑↑\n(↓ utilisation)" },
    { x: 0.2, y: 2.35, w: 4.2, h: 0.7, bg: "1B4F8A", text: "Hyperglycaemia → Osmotic diuresis\n→ ↓ Na, ↓ K, ↓ PO4, ↓ Mg\n→ Dehydration + hypovolaemia" },
    { x: 5.6, y: 2.35, w: 4.2, h: 0.7, bg: "6B3A8A", text: "Ketoacidosis (pH <7.3, HCO3 <15)\n→ Kussmaul breathing\n→ Anion gap metabolic acidosis" },
    { x: 0.2, y: 3.45, w: 9.6, h: 0.6, bg: DARK_BLUE, text: "Clinical: Nausea, vomiting, polyuria, polydipsia, abdominal pain, lethargy → coma | Fruity breath (acetone) | Kussmaul respirations" },
    { x: 0.2, y: 4.2, w: 9.6, h: 0.6, bg: "8B0000", text: "Complications: cerebral oedema (esp. children), hypokalaemia (life-threatening!), aspiration pneumonia, AKI, thromboembolism" },
  ];
  flowItems.forEach(f => {
    s.addShape(pres.ShapeType.rect, { x: f.x, y: f.y, w: f.w, h: f.h, fill: { color: f.bg } });
    s.addText(f.text, { x: f.x + 0.08, y: f.y + 0.04, w: f.w - 0.16, h: f.h - 0.08, fontSize: 10, color: WHITE, fontFace: "Calibri", valign: "middle", align: "center" });
  });
}

// DKA investigations
{
  const s = addContentSlide(pres, "DKA — Investigations");
  if (imgs[3] && imgs[3].base64) {
    s.addImage({ data: imgs[3].base64, x: 4.8, y: 0.82, w: 5.05, h: 4.55 });
    s.addText("Lab values in DKA, HHS, euglycaemic DKA", { x: 4.8, y: 5.25, w: 5.05, h: 0.2, fontSize: 8, color: ACCENT, fontFace: "Calibri", italic: true, align: "center" });
  }
  const items = [
    { text: "BEDSIDE", bold: true, color: ACCENT },
    { text: "Blood glucose (BM) — typically 13.9–33.3 mmol/L (250–600 mg/dL)" },
    { text: "Urinalysis: glycosuria, ketonuria (2+ or more)" },
    { text: "Capillary β-hydroxybutyrate: ≥3.0 mmol/L" },
    { text: "BLOOD TESTS", bold: true, color: ACCENT },
    { text: "ABG / VBG: pH <7.3; pCO2 low (compensatory); HCO3 <15 mmol/L" },
    { text: "U&E: Na (often falsely low), K (⚠️ may be ↑ despite total body K+ deficit — monitor closely!)" },
    { text: "Serum ketones (β-hydroxybutyrate); amylase (often raised non-specifically in DKA)" },
    { text: "FBC: WBC may be raised (stress response, not always infection)" },
    { text: "Blood cultures, CRP, chest X-ray (if precipitant suspected)" },
    { text: "ECG: tall peaked T-waves if hyperkalaemia; ST changes if ACS" },
    { text: "Anion Gap: elevated (>12 mmol/L) = hyperchloraemic + ketoacid anions" },
  ];
  const bItems = items.map((item, i) => ({
    text: item.text,
    options: { bullet: !item.bold, breakLine: i < items.length - 1, fontSize: item.bold ? 12 : 10.5, bold: item.bold || false, color: item.color || TEXT_DARK, fontFace: "Calibri" }
  }));
  s.addText(bItems, { x: 0.25, y: 0.85, w: 4.4, h: 4.45 });
}

// DKA management
{
  const s = addContentSlide(pres, "DKA — Management: The '5 Fs'");
  const fItems = [
    { f: "FLUIDS", color: LIGHT_BLUE, content: "0.9% NaCl: 1L over 1 h → 1L/2 h × 2 → 1L/4 h × 2 → 1L/8 h (titrate to response)\n⚠️ Add 10% dextrose when glucose <14 mmol/L (do NOT stop insulin!)" },
    { f: "FIXED-RATE INSULIN", color: ACCENT, content: "0.1 units/kg/h IV infusion (e.g. Actrapid in 0.9% NaCl)\nDo NOT give bolus insulin (risk of cerebral oedema in children)\nContinue until: pH >7.3, HCO3 >15, ketones <0.6 mmol/L" },
    { f: "POTASSIUM", color: MID_BLUE, content: "⚠️ K+ falls rapidly with insulin therapy — check before starting\nIf K+ 3.5–5.5: add 40 mmol/L KCl to IV fluids\nIf K+ <3.5: hold insulin; replace K+ urgently\nIf K+ >5.5: no KCl; reassess frequently" },
    { f: "FIND & TREAT PRECIPITANT", color: "1B4F8A", content: "Antibiotics if infection; ACS management; thrombolysis if PE\nReview all medications; check HbA1c, autoantibodies\nAvoid routine bicarbonate (only pH <6.9 under specialist guidance)" },
    { f: "FLUIDS — TRANSITION", color: "6B3A8A", content: "Switch to SC insulin when: eating & drinking; glucose <14; ketones <0.3 mmol/L; pH >7.3\nOverlap SC + IV insulin by 30–60 min before stopping IV infusion\nReview and optimise long-term insulin regimen before discharge" },
  ];
  fItems.forEach((item, i) => {
    const cy = 0.82 + i * 0.93;
    s.addShape(pres.ShapeType.rect, { x: 0.15, y: cy, w: 9.7, h: 0.87, fill: { color: item.color } });
    s.addText(item.f, { x: 0.25, y: cy + 0.04, w: 1.8, h: 0.79, fontSize: 12, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle" });
    s.addText(item.content, { x: 2.1, y: cy + 0.04, w: 7.6, h: 0.79, fontSize: 10.5, color: WHITE, fontFace: "Calibri", valign: "middle" });
  });
}

// HHS
addTwoColSlide(pres,
  "Hyperosmolar Hyperglycaemic State (HHS)",
  "Definition & Pathophysiology",
  [
    "Glucose >33.3 mmol/L (600 mg/dL) — typically much higher than DKA",
    "Plasma osmolality >320 mOsm/kg",
    "pH usually >7.30; HCO3 >18 mmol/L (ketosis absent or mild)",
    "Insufficient oral intake + osmotic diuresis → profound dehydration",
    "Residual insulin suppresses ketogenesis (unlike DKA)",
    "Occurs mainly in elderly T2DM; insidious onset over days-weeks",
    "Often precipitated by: infection, MI, CVA, GI illness, diuretics",
    "Mortality up to 20% (much higher than DKA)",
    "Mixed HHS-DKA occurs in some T2DM patients",
  ],
  "Clinical Features & Management",
  [
    "Profound dehydration: fluid deficit 8–10 L",
    "Neurological: confusion, drowsiness → coma (hallmark)",
    "Seizures, focal neurological deficits",
    "No Kussmaul breathing, no fruity breath",
    "Thrombosis risk: DVT/PE — prophylactic LMWH mandatory",
    "MANAGEMENT:",
    "Cautious fluid replacement (slower than DKA) — 0.9% NaCl",
    "Avoid rapid osmolality correction (>3 mOsm/kg/h → cerebral oedema)",
    "Low-dose insulin ONLY after fluids (insulin alone → fatal ↓ osmolality)",
    "Potassium replacement as per DKA protocol",
    "Identify and treat precipitant urgently",
  ]
);

// Hypoglycaemia
addBulletSlide(pres, "Hypoglycaemia — Definition, Features & Management", [
  { text: "Definition: plasma glucose <4.0 mmol/L (72 mg/dL) in diabetic patients; <2.8 mmol/L non-diabetic", bold: true, color: ACCENT },
  { text: "Whipple's Triad: (1) symptoms of hypoglycaemia + (2) low glucose + (3) relief with glucose correction" },
  { text: "Neuroglycopenic symptoms (glucose <3.0 mmol/L):", bold: true },
  { text: "Confusion, difficulty concentrating, drowsiness, seizures, focal deficits, coma" },
  { text: "Adrenergic/autonomic symptoms (early warning, glucose ~3.5 mmol/L):", bold: true },
  { text: "Sweating, tremor, palpitations, hunger, anxiety, pallor" },
  { text: "Hypoglycaemia unawareness: loss of adrenergic symptoms (common in long-standing T1DM, recurrent hypoglycaemia, autonomic neuropathy, β-blocker use)" },
  { text: "Common causes:", bold: true, color: ACCENT },
  { text: "Excess insulin dose, delayed/missed meal, increased exercise, alcohol, renal failure (↓ insulin clearance)" },
  { text: "MANAGEMENT:", bold: true, color: ACCENT },
  { text: "Conscious & able to swallow: 15–20 g fast-acting glucose (glucose tabs, juice, regular soda); repeat BM after 15 min (Rule of 15)" },
  { text: "Impaired consciousness/IV access: 75–100 mL 20% dextrose IV OR glucagon 1 mg IM/SC/IN" },
  { text: "Inpatient: 10% dextrose infusion; identify and treat cause" },
  { text: "Discharge advice: sick-day rules; adjust insulin/medications; refer to diabetes team" },
]);

// Comparison DKA vs HHS
{
  const s = addContentSlide(pres, "DKA vs HHS — Comparison at a Glance");
  const headers2 = ["Feature", "DKA", "HHS", "Hypoglycaemia"];
  const rows4 = [
    ["Glucose (mmol/L)", "13.9–33.3", ">33.3 (often >50)", "<4.0"],
    ["pH", "<7.30", ">7.30", "Normal"],
    ["HCO3 (mmol/L)", "<15", ">18", "Normal"],
    ["Ketones", "+++", "+/−", "Absent"],
    ["Osmolality (mOsm/kg)", "300–320", ">320 (often >380)", "Normal"],
    ["Onset", "Hours", "Days–weeks", "Minutes"],
    ["LOC", "Variable", "Often coma", "Can seize/coma"],
    ["Dehydration", "Moderate (3–6 L)", "Profound (8–10 L)", "Absent"],
    ["Key treatment", "Insulin + fluids + K+", "Fluids first, then insulin", "Glucose/glucagon"],
    ["Mortality", "~1–4%", "~10–20%", "<1% (if treated)"],
  ];
  const colW3 = [2.3, 2.5, 2.5, 2.4];
  const colX3 = [0.12, 2.44, 4.96, 7.48];
  headers2.forEach((h, ci) => {
    const hCol = [DARK_BLUE, MID_BLUE, ACCENT, LIGHT_BLUE][ci];
    s.addShape(pres.ShapeType.rect, { x: colX3[ci], y: 0.78, w: colW3[ci], h: 0.36, fill: { color: hCol } });
    s.addText(h, { x: colX3[ci] + 0.04, y: 0.78, w: colW3[ci] - 0.08, h: 0.36, fontSize: 11, bold: true, color: ci === 0 ? GOLD : WHITE, fontFace: "Calibri", valign: "middle" });
  });
  rows4.forEach((row, ri) => {
    const yp = 1.16 + ri * 0.40;
    row.forEach((cell, ci) => {
      const bg = ci === 0 ? ACCENT : (ri % 2 === 0 ? SOFT_GRAY : WHITE);
      s.addShape(pres.ShapeType.rect, { x: colX3[ci], y: yp, w: colW3[ci], h: 0.38, fill: { color: bg }, line: { color: "CCCCCC", pt: 0.5 } });
      s.addText(cell, { x: colX3[ci] + 0.04, y: yp, w: colW3[ci] - 0.08, h: 0.38, fontSize: 10, bold: ci === 0, color: ci === 0 ? WHITE : TEXT_DARK, fontFace: "Calibri", valign: "middle" });
    });
  });
}

// ─── FINAL SLIDE: Key Take-Homes ─────────────────────────────────────────────
{
  const s = pres.addSlide();
  setBg(s, DARK_BLUE);
  s.addShape(pres.ShapeType.rect, { x: 0, y: 0, w: 10, h: 0.72, fill: { color: GOLD } });
  s.addText("Key Take-Home Messages", { x: 0.2, y: 0.08, w: 9.6, h: 0.56, fontSize: 20, bold: true, color: DARK_BLUE, fontFace: "Calibri", valign: "middle" });
  const msgs = [
    "DM is a chronic metabolic disease driven by insulin deficiency and/or resistance — both T1 and T2 share the endpoint of hyperglycaemia-mediated organ damage.",
    "Diagnosis requires objective biochemical confirmation — HbA1c ≥6.5%, FPG ≥7.0 mmol/L, or 2h-OGTT ≥11.1 mmol/L.",
    "T1DM needs insulin from day 1; T2DM is stepwise — lifestyle → metformin → combinations with SGLT2i / GLP-1 RA preferred for CV/renal benefit.",
    "HbA1c target 7.0% (53 mmol/mol) for most; individualise based on age, comorbidities, hypoglycaemia risk.",
    "DKA: Insulin deficiency + counter-regulatory excess → hyperglycaemia + ketoacidosis + dehydration; treat with fluids, fixed-rate insulin, potassium. Never stop insulin even when glucose normalises.",
    "HHS: Profound hyperglycaemia, dehydration, hyperosmolality without significant ketosis; treat with cautious fluid replacement FIRST, then low-dose insulin — mortality up to 20%.",
    "Hypoglycaemia: BM <4.0 mmol/L; treat conscious patients with 15–20 g fast glucose; unconscious → IV dextrose or glucagon IM.",
  ];
  msgs.forEach((msg, i) => {
    const yp = 0.82 + i * 0.67;
    const bg = i % 2 === 0 ? MID_BLUE : ACCENT;
    s.addShape(pres.ShapeType.rect, { x: 0.15, y: yp, w: 0.52, h: 0.57, fill: { color: GOLD } });
    s.addText(`${i + 1}`, { x: 0.15, y: yp, w: 0.52, h: 0.57, fontSize: 18, bold: true, color: DARK_BLUE, fontFace: "Calibri", valign: "middle", align: "center" });
    s.addShape(pres.ShapeType.rect, { x: 0.69, y: yp, w: 9.16, h: 0.57, fill: { color: bg } });
    s.addText(msg, { x: 0.79, y: yp, w: 9.0, h: 0.57, fontSize: 10.5, color: WHITE, fontFace: "Calibri", valign: "middle" });
  });
}

// ─── WRITE FILE ───────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/diabetes-pptx/Diabetes_Mellitus_and_Emergencies.pptx" })
  .then(() => console.log("✅ Presentation saved successfully!"))
  .catch(err => { console.error("❌ Error:", err); process.exit(1); });
Your credits are exhausted. Your daily credits reset tomorrow, or you can purchase a top-up for more.
This is a shared conversation. Sign in to Orris to start your own chat.