Create presentation on insomnia !
mkdir -p /home/daytona/workspace/insomnia-pptx && ls /home/daytona/workspace/ins…
~/insomnia-pptx/insomnia.js
const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Insomnia: A Clinical Overview";
pres.author = "Orris Medical";
// ─── COLOR PALETTE ───────────────────────────────────────────────────────────
const DARK_BG = "0D1F2D"; // deep navy (dominant ~65%)
const MID_BG = "1A3347"; // slate navy (supporting)
const ACCENT = "3ABAB4"; // teal accent
const ACCENT2 = "E8734A"; // warm coral
const WHITE = "F2F5F7";
const LIGHT_GRAY= "B8C6D1";
const YELLOW = "F5C843";
// ─── HELPERS ─────────────────────────────────────────────────────────────────
function titleBar(slide, text, subtitle) {
// full-width dark header bar
slide.addShape(pres.ShapeType.rect, {
x: 0, y: 0, w: 10, h: 1.1,
fill: { color: DARK_BG }, line: { color: DARK_BG }
});
// accent stripe
slide.addShape(pres.ShapeType.rect, {
x: 0, y: 1.05, w: 10, h: 0.07,
fill: { color: ACCENT }, line: { color: ACCENT }
});
slide.addText(text, {
x: 0.35, y: 0.1, w: 9.3, h: 0.85,
fontSize: 22, bold: true, color: WHITE, valign: "middle", margin: 0
});
if (subtitle) {
slide.addText(subtitle, {
x: 0.35, y: 0.72, w: 9.3, h: 0.35,
fontSize: 11, color: ACCENT, italic: true, margin: 0
});
}
}
function iconCircle(slide, x, y, r, color) {
slide.addShape(pres.ShapeType.ellipse, {
x, y, w: r, h: r,
fill: { color }, line: { color }
});
}
function accentBox(slide, x, y, w, h, color) {
slide.addShape(pres.ShapeType.rect, {
x, y, w, h,
fill: { color, transparency: 88 },
line: { color, width: 1.5 }
});
}
function bullet(text, level, bold) {
return {
text,
options: {
bullet: { indent: (level || 0) * 20 + 20 },
fontSize: level === 1 ? 13 : 14.5,
color: level === 1 ? LIGHT_GRAY : WHITE,
bold: bold || false,
breakLine: true
}
};
}
function lastBullet(text, level) {
return {
text,
options: {
bullet: { indent: (level || 0) * 20 + 20 },
fontSize: level === 1 ? 13 : 14.5,
color: level === 1 ? LIGHT_GRAY : WHITE,
breakLine: false
}
};
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 1 — TITLE
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
// Full dark background
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
// Large teal accent rectangle on left
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:0.18, h:5.625, fill:{color:ACCENT}, line:{color:ACCENT} });
// Decorative circles
iconCircle(s, 7.6, 0.4, 1.5, MID_BG);
iconCircle(s, 8.1, 0.8, 0.9, DARK_BG);
iconCircle(s, 7.8, 3.8, 2.2, MID_BG);
iconCircle(s, 8.5, 4.2, 1.0, DARK_BG);
// Moon icon text
s.addText("🌙", { x: 7.9, y: 1.0, w: 1.2, h: 1.2, fontSize: 64, align: "center" });
s.addText("INSOMNIA", {
x: 0.5, y: 1.2, w: 7.0, h: 1.2,
fontSize: 54, bold: true, color: WHITE, charSpacing: 6, margin: 0
});
s.addText("A Clinical Overview", {
x: 0.5, y: 2.5, w: 6.5, h: 0.55,
fontSize: 22, color: ACCENT, italic: true, margin: 0
});
// Horizontal rule
s.addShape(pres.ShapeType.line, {
x: 0.5, y: 3.15, w: 7.5, h: 0,
line: { color: ACCENT2, width: 2 }
});
s.addText("Definition | Classification | Pathophysiology | Diagnosis | Treatment", {
x: 0.5, y: 3.3, w: 9.0, h: 0.4,
fontSize: 12, color: LIGHT_GRAY, italic: true, margin: 0
});
s.addText("Sources: Bradley & Daroff's Neurology • Kaplan & Sadock's Comprehensive Textbook of Psychiatry • Harrison's Internal Medicine", {
x: 0.5, y: 5.15, w: 9.2, h: 0.3,
fontSize: 8.5, color: LIGHT_GRAY, italic: true, margin: 0
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 2 — OVERVIEW / AGENDA
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Agenda");
const topics = [
{ num: "01", label: "Definition & Epidemiology", icon: "📋" },
{ num: "02", label: "Classification (ICSD-III & DSM-5)", icon: "🗂️" },
{ num: "03", label: "Pathophysiology & Risk Factors", icon: "🧠" },
{ num: "04", label: "Clinical Features & Comorbidities", icon: "🩺" },
{ num: "05", label: "Diagnosis & Assessment Tools", icon: "🔍" },
{ num: "06", label: "Non-Pharmacological Treatment (CBT-I)", icon: "💬" },
{ num: "07", label: "Pharmacological Treatment", icon: "💊" },
{ num: "08", label: "Special Populations & Summary", icon: "👥" },
];
const cols = [
topics.slice(0, 4),
topics.slice(4, 8)
];
cols.forEach((col, ci) => {
col.forEach((t, ti) => {
const x = 0.4 + ci * 4.9;
const y = 1.3 + ti * 0.98;
accentBox(s, x, y, 4.5, 0.78, ci === 0 ? ACCENT : ACCENT2);
s.addText(`${t.icon} ${t.num}`, {
x: x + 0.12, y: y + 0.1, w: 0.95, h: 0.55,
fontSize: 13, color: ACCENT, bold: true, margin: 0
});
s.addText(t.label, {
x: x + 1.0, y: y + 0.12, w: 3.3, h: 0.55,
fontSize: 13.5, color: WHITE, valign: "middle", margin: 0
});
});
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 3 — DEFINITION & EPIDEMIOLOGY
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Definition & Epidemiology", "The most common sleep disorder worldwide");
// Definition box
accentBox(s, 0.3, 1.25, 9.4, 1.15, ACCENT);
s.addText("DEFINITION", { x: 0.5, y: 1.28, w: 2.0, h: 0.3, fontSize: 9, color: ACCENT, bold: true, charSpacing:2, margin:0 });
s.addText(
"An inability to initiate, maintain sleep, or early awakening, despite an adequate opportunity for sleep, leading to poor sleep quality, lack of feeling restored, dissatisfaction with sleep and impaired daytime functioning.",
{ x: 0.5, y: 1.55, w: 9.0, h: 0.75, fontSize: 13, color: WHITE, margin: 0 }
);
// Stats cards
const stats = [
{ val: "~35%", label: "of adults report\ninsomnia complaints" },
{ val: "10%", label: "have persistent\nchronic insomnia" },
{ val: "2–5×", label: "increased risk of\nsubsequent depression" },
{ val: "#1", label: "most common\nsleep disorder" },
];
stats.forEach((st, i) => {
const x = 0.3 + i * 2.38;
s.addShape(pres.ShapeType.rect, { x, y: 2.58, w: 2.18, h: 1.45, fill:{color:MID_BG}, line:{color:ACCENT, width:1.2} });
s.addText(st.val, { x: x+0.05, y: 2.62, w: 2.08, h: 0.68, fontSize: 28, bold: true, color: ACCENT, align: "center", margin:0 });
s.addText(st.label, { x: x+0.05, y: 3.28, w: 2.08, h: 0.65, fontSize: 11, color: LIGHT_GRAY, align: "center", margin:0 });
});
// Health consequences
s.addText("Key Health Consequences:", { x: 0.3, y: 4.2, w: 4.5, h: 0.3, fontSize: 12, color: ACCENT2, bold: true, margin:0 });
s.addText([
bullet("Increased mortality & morbidity from CAD, hypertension, obesity, DM"),
bullet("Impaired work performance and quality of life"),
lastBullet("Suicidal behaviour risk (2–5× higher with comorbid depression)")
], { x: 0.3, y: 4.5, w: 9.4, h: 0.9, fontSize: 12, color: WHITE, margin:0 });
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 4 — CLASSIFICATION
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Classification", "ICSD-III • DSM-5 • ICD-10");
// ICSD-III column
s.addShape(pres.ShapeType.rect, { x:0.3, y:1.25, w:4.4, h:0.38, fill:{color:ACCENT}, line:{color:ACCENT} });
s.addText("ICSD-III (AASM 2014)", { x:0.35, y:1.25, w:4.3, h:0.38, fontSize:13, bold:true, color:DARK_BG, valign:"middle", margin:0 });
const icsd = [
{ label: "Short-term Insomnia Disorder", detail: "Duration < 3 months; related to identifiable stressor" },
{ label: "Chronic Insomnia Disorder", detail: "≥ 3 nights/week, ≥ 3 months; significant daytime impairment" },
{ label: "Other Insomnia Disorder", detail: "Does not meet full criteria for the above two categories" },
];
icsd.forEach((item, i) => {
const y = 1.75 + i * 0.98;
accentBox(s, 0.3, y, 4.4, 0.82, ACCENT);
s.addText(`${i+1}. ${item.label}`, { x:0.5, y:y+0.04, w:4.1, h:0.35, fontSize:12.5, bold:true, color:ACCENT, margin:0 });
s.addText(item.detail, { x:0.5, y:y+0.37, w:4.1, h:0.4, fontSize:11, color:LIGHT_GRAY, margin:0 });
});
// DSM-5 column
s.addShape(pres.ShapeType.rect, { x:5.0, y:1.25, w:4.7, h:0.38, fill:{color:ACCENT2}, line:{color:ACCENT2} });
s.addText("DSM-5 Criteria", { x:5.05, y:1.25, w:4.6, h:0.38, fontSize:13, bold:true, color:DARK_BG, valign:"middle", margin:0 });
const dsm = [
"Dissatisfaction with sleep quantity or quality",
"One or more: difficulty initiating, maintaining sleep or early-morning awakening",
"Significant distress or functional impairment",
"Sleep difficulty ≥ 3 nights/week",
"Present for ≥ 3 months",
"Not explained by another sleep disorder, substance, or medical condition",
];
s.addText(dsm.map((d, i) => ({
text: `${i+1}. ${d}`,
options: { fontSize: 12, color: i < 2 ? WHITE : LIGHT_GRAY, breakLine: i < dsm.length - 1 }
})), { x:5.05, y:1.75, w:4.55, h:2.8, margin:6 });
// Subtypes note
accentBox(s, 0.3, 4.68, 9.4, 0.72, ACCENT2);
s.addText("📌 Duration matters: Acute (<3 months) vs. Chronic (≥3 months, ≥3 nights/week). Comorbid insomnia no longer classified as 'secondary' — bidirectional relationship recognised.", {
x:0.5, y:4.72, w:9.0, h:0.62, fontSize:11.5, color:WHITE, margin:0
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 5 — PATHOPHYSIOLOGY
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Pathophysiology", "Hyperarousal, Neurochemistry & the 3-P Model");
// 3-P Model header
s.addText("THE 3-P MODEL (Spielman)", { x:0.3, y:1.22, w:9.4, h:0.32, fontSize:11, bold:true, color:YELLOW, charSpacing:2, margin:0 });
const threeP = [
{ title: "Predisposing", color: ACCENT, items: ["Female sex, older age", "Genetic vulnerability", "Anxious temperament", "Hyperactive HPA axis"] },
{ title: "Precipitating", color: ACCENT2, items: ["Acute stress / life events", "Medical or psychiatric illness", "Medications (MAOIs, stimulants)", "Shift work, travel (jet lag)"] },
{ title: "Perpetuating", color: YELLOW, items: ["Extended time in bed", "Daytime napping", "Conditioned arousal (bed = worry)", "Dysfunctional sleep beliefs"] },
];
threeP.forEach((p, i) => {
const x = 0.3 + i * 3.18;
s.addShape(pres.ShapeType.rect, { x, y:1.6, w:3.0, h:0.38, fill:{color:p.color}, line:{color:p.color} });
s.addText(p.title.toUpperCase(), { x:x+0.08, y:1.6, w:2.84, h:0.38, fontSize:12, bold:true, color:DARK_BG, valign:"middle", margin:0 });
p.items.forEach((item, j) => {
s.addText(`• ${item}`, { x:x+0.1, y:2.05+j*0.36, w:2.8, h:0.33, fontSize:11.5, color: j===0?WHITE:LIGHT_GRAY, margin:0 });
});
});
// Neurochemistry section
s.addShape(pres.ShapeType.line, { x:0.3, y:3.68, w:9.4, h:0, line:{color:ACCENT, width:1} });
s.addText("NEUROCHEMICAL BASIS", { x:0.3, y:3.74, w:9.4, h:0.28, fontSize:10, bold:true, color:ACCENT, charSpacing:2, margin:0 });
const neuro = [
{ label: "GABA-A ↓", detail: "Reduced inhibitory tone → cortical & limbic hyperarousal" },
{ label: "Orexin ↑", detail: "Hypocretin over-activation maintains wake state; target of suvorexant" },
{ label: "HPA Axis ↑", detail: "Elevated cortisol & CRH; chronic activation perpetuates insomnia" },
{ label: "Glymphatic", detail: "Sleep-dependent brain waste clearance impaired in chronic insomnia" },
];
neuro.forEach((n, i) => {
const x = 0.3 + i * 2.38;
s.addShape(pres.ShapeType.rect, { x, y:4.08, w:2.22, h:1.25, fill:{color:MID_BG}, line:{color:ACCENT, width:1} });
s.addText(n.label, { x:x+0.08, y:4.12, w:2.06, h:0.36, fontSize:13, bold:true, color:ACCENT, margin:0 });
s.addText(n.detail, { x:x+0.08, y:4.46, w:2.06, h:0.75, fontSize:10.5, color:LIGHT_GRAY, margin:0 });
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 6 — CLINICAL FEATURES & COMORBIDITIES
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Clinical Features & Comorbidities", "What patients report and what co-exists");
// Night-time symptoms
s.addShape(pres.ShapeType.rect, { x:0.3, y:1.25, w:4.3, h:0.38, fill:{color:MID_BG}, line:{color:ACCENT, width:1.5} });
s.addText("🌙 Nocturnal Symptoms", { x:0.38, y:1.25, w:4.14, h:0.38, fontSize:13, bold:true, color:ACCENT, valign:"middle", margin:0 });
s.addText([
bullet("Difficulty falling asleep (sleep-onset insomnia)"),
bullet("Frequent nocturnal awakenings (sleep-maintenance)"),
bullet("Early-morning awakening with inability to return to sleep"),
bullet("Unrefreshing, non-restorative sleep"),
lastBullet("Short total sleep time (<6 hours objectively)")
], { x:0.3, y:1.68, w:4.3, h:2.2, margin:6, fontSize:13, color:WHITE });
// Daytime symptoms
s.addShape(pres.ShapeType.rect, { x:5.0, y:1.25, w:4.7, h:0.38, fill:{color:MID_BG}, line:{color:ACCENT2, width:1.5} });
s.addText("☀️ Daytime Consequences", { x:5.08, y:1.25, w:4.54, h:0.38, fontSize:13, bold:true, color:ACCENT2, valign:"middle", margin:0 });
s.addText([
bullet("Fatigue and reduced energy"),
bullet("Cognitive impairment (memory, attention, concentration)"),
bullet("Mood disturbance (irritability, anxiety, low mood)"),
bullet("Impaired work / school performance"),
bullet("Increased accident risk"),
lastBullet("Reduced quality of life")
], { x:5.0, y:1.68, w:4.7, h:2.2, margin:6, fontSize:13, color:WHITE });
// Comorbidities
s.addShape(pres.ShapeType.line, { x:0.3, y:3.98, w:9.4, h:0, line:{color:ACCENT, width:1} });
s.addText("COMMON COMORBIDITIES", { x:0.3, y:4.04, w:9.4, h:0.28, fontSize:10, bold:true, color:ACCENT, charSpacing:2, margin:0 });
const comorbidities = [
{ cat: "Psychiatric", items: "Depression, Anxiety, PTSD, Substance use" },
{ cat: "Medical", items: "Pain syndromes, GERD, COPD, Heart failure, DM" },
{ cat: "Sleep disorders", items: "Obstructive Sleep Apnoea (OSA), RLS, Periodic limb movements" },
{ cat: "Neurological", items: "Dementia, Parkinson's disease, Stroke" },
];
comorbidities.forEach((c, i) => {
const x = 0.3 + i * 2.38;
accentBox(s, x, 4.38, 2.22, 1.0, i % 2 === 0 ? ACCENT : ACCENT2);
s.addText(c.cat, { x:x+0.1, y:4.42, w:2.04, h:0.3, fontSize:11, bold:true, color: i % 2 === 0 ? ACCENT : ACCENT2, margin:0 });
s.addText(c.items, { x:x+0.1, y:4.7, w:2.04, h:0.62, fontSize:10, color:LIGHT_GRAY, margin:0 });
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 7 — DIAGNOSIS & ASSESSMENT
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Diagnosis & Assessment", "Clinical evaluation, questionnaires & sleep diary");
// Clinical diagnostic criteria box
accentBox(s, 0.3, 1.25, 9.4, 1.15, ACCENT);
s.addText("DIAGNOSTIC CRITERIA (Chronic Insomnia Disorder — AASM 2014)", {
x:0.5, y:1.28, w:9.0, h:0.28, fontSize:9.5, bold:true, color:ACCENT, charSpacing:2, margin:0
});
s.addText(
"Sleep disturbance ≥ 3 nights/week for ≥ 3 months | Adequate sleep opportunity | Significant daytime impairment | Not better explained by another sleep or mental disorder",
{ x:0.5, y:1.55, w:9.0, h:0.72, fontSize:12.5, color:WHITE, margin:0 }
);
// Assessment tools
s.addText("ASSESSMENT TOOLS", { x:0.3, y:2.55, w:9.4, h:0.28, fontSize:10, bold:true, color:YELLOW, charSpacing:2, margin:0 });
const tools = [
{ name: "Sleep Diary (2 weeks)", desc: "Gold standard self-report; records bed time, wake time, sleep latency, naps, caffeine, alcohol, exercise. Identifies patterns." },
{ name: "ISI — Insomnia Severity Index", desc: "7-item validated questionnaire; score 0–28. >14 = moderate–severe clinical insomnia." },
{ name: "PSG (Polysomnography)", desc: "Not routinely required; indicated when OSA, PLMD, or parasomnias are suspected." },
{ name: "Actigraphy", desc: "Wrist-worn motion sensor; estimates sleep-wake patterns over days–weeks. Useful for circadian rhythm disorders." },
];
tools.forEach((t, i) => {
const x = 0.3 + (i % 2) * 4.9;
const y = 2.92 + Math.floor(i / 2) * 1.22;
accentBox(s, x, y, 4.55, 1.1, i < 2 ? ACCENT : ACCENT2);
s.addText(t.name, { x:x+0.12, y:y+0.06, w:4.3, h:0.32, fontSize:12.5, bold:true, color: i < 2 ? ACCENT : ACCENT2, margin:0 });
s.addText(t.desc, { x:x+0.12, y:y+0.38, w:4.3, h:0.65, fontSize:11, color:LIGHT_GRAY, margin:0 });
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 8 — NON-PHARMACOLOGICAL TREATMENT (CBT-I)
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Non-Pharmacological Treatment", "CBT-I — First-Line Therapy");
// CBT-I headline
accentBox(s, 0.3, 1.25, 9.4, 0.68, ACCENT);
s.addText("Cognitive Behavioural Therapy for Insomnia (CBT-I)", {
x:0.5, y:1.28, w:9.0, h:0.3, fontSize:14.5, bold:true, color:ACCENT, margin:0
});
s.addText("Endorsed as FIRST-LINE by AASM, ACP, and multiple guideline panels. Safe, long-lasting, superior to medication alone. Typically 6–10 weekly sessions.", {
x:0.5, y:1.56, w:9.0, h:0.3, fontSize:11.5, color:WHITE, margin:0
});
// CBT-I components
const components = [
{ title: "Stimulus Control", icon: "🛏️", body: "Bed only for sleep & sex. Get out of bed if awake >20 min. Strict rise time regardless of sleep quality." },
{ title: "Sleep Restriction", icon: "⏰", body: "Temporarily reduce time in bed to match actual sleep time; increases sleep drive and efficiency." },
{ title: "Cognitive Restructuring", icon: "🧠", body: "Challenge dysfunctional beliefs: 'I need 8 h or I'll be ruined'. Reduce catastrophising about sleep loss." },
{ title: "Relaxation Therapy", icon: "🧘", body: "Progressive muscle relaxation, diaphragmatic breathing, guided imagery to lower physiologic arousal." },
];
components.forEach((c, i) => {
const x = 0.3 + (i % 2) * 4.9;
const y = 2.08 + Math.floor(i / 2) * 1.38;
s.addShape(pres.ShapeType.rect, { x, y, w:4.55, h:1.22, fill:{color:MID_BG}, line:{color:ACCENT, width:1} });
s.addText(`${c.icon} ${c.title}`, { x:x+0.12, y:y+0.06, w:4.3, h:0.36, fontSize:13, bold:true, color:ACCENT, margin:0 });
s.addText(c.body, { x:x+0.12, y:y+0.42, w:4.3, h:0.74, fontSize:11, color:LIGHT_GRAY, margin:0 });
});
// Sleep hygiene footer
s.addShape(pres.ShapeType.rect, { x:0.3, y:4.82, w:9.4, h:0.58, fill:{color:MID_BG}, line:{color:YELLOW, width:1} });
s.addText("💡 Sleep Hygiene: No caffeine/alcohol after lunch • Avoid screens 2 h before bed • Keep bedroom dark and cool • Exercise regularly • Restrict naps to <30 min before 3 PM", {
x:0.5, y:4.85, w:9.0, h:0.5, fontSize:11, color:WHITE, margin:0
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 9 — PHARMACOLOGICAL TREATMENT
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Pharmacological Treatment", "Drug classes, mechanisms & AASM recommendations");
const drugs = [
{
cls: "Z-Drugs (BzRA)", color: ACCENT,
drugs: "Zolpidem, Eszopiclone, Zaleplon",
mech: "Non-selective GABA-A positive allosteric modulators",
notes: "First-choice for acute insomnia. Tolerance after 1–2 months. Rebound in up to 71%. Short-term use preferred."
},
{
cls: "Benzodiazepines", color: ACCENT2,
drugs: "Temazepam, Triazolam, Flurazepam",
mech: "GABA-A potentiation; ↓ sleep latency, ↑ TST; ↓ SWS & REM",
notes: "Useful for acute stress/hospitalisation insomnia. Dependence risk. Avoid in elderly (Beers Criteria)."
},
{
cls: "Orexin Antagonists", color: YELLOW,
drugs: "Suvorexant, Lemborexant",
mech: "Block hypocretin/orexin receptors → promote sleep onset & maintenance",
notes: "Newest FDA-approved class. Approved for Alzheimer's (suvorexant). Preferred in elderly over BZDs."
},
{
cls: "Melatonin Agonists", color: ACCENT,
drugs: "Ramelteon, Tasimelteon",
mech: "MT1 / MT2 receptor agonism; regulates circadian sleep-wake cycle",
notes: "Safe in elderly. Limited efficacy data. Useful for circadian-component insomnia and sleep-onset issues."
},
{
cls: "Low-dose Antidepressants", color: ACCENT2,
drugs: "Doxepin (≤6 mg), Trazodone, Mirtazapine",
mech: "Histamine H1 blockade (doxepin); 5-HT2 antagonism (trazodone)",
notes: "Off-label except doxepin. Doxepin >6 mg avoid in elderly. Trazodone widely used, limited RCT evidence."
},
{
cls: "Sedating Antipsychotics", color: YELLOW,
drugs: "Quetiapine, Olanzapine (off-label)",
mech: "H1, 5-HT2 antagonism",
notes: "No systematic evidence supports routine use; risks outweigh benefits. Reserve for psychiatric comorbidity."
},
];
drugs.forEach((d, i) => {
const col = i % 3;
const row = Math.floor(i / 3);
const x = 0.25 + col * 3.22;
const y = 1.25 + row * 2.12;
s.addShape(pres.ShapeType.rect, { x, y, w:3.05, h:2.0, fill:{color:MID_BG}, line:{color:d.color, width:1.5} });
s.addShape(pres.ShapeType.rect, { x, y, w:3.05, h:0.32, fill:{color:d.color}, line:{color:d.color} });
s.addText(d.cls, { x:x+0.08, y:y+0.02, w:2.9, h:0.28, fontSize:11, bold:true, color:DARK_BG, margin:0 });
s.addText(d.drugs, { x:x+0.08, y:y+0.36, w:2.9, h:0.3, fontSize:10.5, bold:true, color:WHITE, margin:0 });
s.addText(`⚡ ${d.mech}`, { x:x+0.08, y:y+0.68, w:2.9, h:0.52, fontSize:9.5, color:LIGHT_GRAY, italic:true, margin:0 });
s.addShape(pres.ShapeType.line, { x:x+0.08, y:y+1.2, w:2.89, h:0, line:{color:d.color, width:0.5} });
s.addText(`📌 ${d.notes}`, { x:x+0.08, y:y+1.23, w:2.9, h:0.7, fontSize:9.5, color:LIGHT_GRAY, margin:0 });
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 10 — SPECIAL POPULATIONS & TREATMENT ALGORITHM
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
titleBar(s, "Special Populations & Treatment Algorithm", "Tailoring therapy to the patient");
// Algorithm (left)
s.addText("TREATMENT ALGORITHM", { x:0.3, y:1.22, w:5.2, h:0.28, fontSize:10, bold:true, color:YELLOW, charSpacing:2, margin:0 });
const steps = [
{ step: "1", label: "Identify & treat underlying comorbidities", color: ACCENT },
{ step: "2", label: "Implement sleep hygiene education", color: ACCENT },
{ step: "3", label: "CBT-I (first-line for chronic insomnia)", color: ACCENT2 },
{ step: "4", label: "Pharmacotherapy if acute stress or CBT-I unavailable", color: ACCENT2 },
{ step: "5", label: "Combination CBT-I + short-term pharmacotherapy", color: YELLOW },
{ step: "6", label: "Review, taper medication, maintain CBT-I gains", color: YELLOW },
];
steps.forEach((st, i) => {
const y = 1.58 + i * 0.57;
s.addShape(pres.ShapeType.ellipse, { x:0.3, y:y, w:0.44, h:0.44, fill:{color:st.color}, line:{color:st.color} });
s.addText(st.step, { x:0.3, y:y+0.02, w:0.44, h:0.4, fontSize:13, bold:true, color:DARK_BG, align:"center", margin:0 });
s.addText(st.label, { x:0.84, y:y+0.04, w:4.5, h:0.38, fontSize:12, color:WHITE, valign:"middle", margin:0 });
if (i < steps.length - 1) {
s.addShape(pres.ShapeType.line, { x:0.52, y:y+0.46, w:0, h:0.1, line:{color:st.color, width:1.5} });
}
});
// Special populations (right)
s.addText("SPECIAL POPULATIONS", { x:5.65, y:1.22, w:4.0, h:0.28, fontSize:10, bold:true, color:YELLOW, charSpacing:2, margin:0 });
const pops = [
{ pop: "Elderly", icon: "👴", note: "Beers Criteria: avoid BZDs, Z-drugs, TCAs, antihistamines. Prefer CBT-I, suvorexant (approved in AD), ramelteon." },
{ pop: "Pregnant", icon: "🤰", note: "CBT-I first. Pharmacotherapy avoided in 1st trimester. Doxylamine + B6 considered safe for sleep-associated nausea." },
{ pop: "Psychiatric comorbidity", icon: "🧠", note: "Treat both simultaneously. Sedating antidepressants (trazodone, mirtazapine) can address both insomnia and depression." },
{ pop: "Hospitalised / Acute", icon: "🏥", note: "Short-acting benzodiazepines or Z-drugs appropriate for brief, acute insomnia. Minimise use and duration." },
];
pops.forEach((p, i) => {
const y = 1.58 + i * 0.98;
accentBox(s, 5.55, y, 4.2, 0.84, i % 2 === 0 ? ACCENT : ACCENT2);
s.addText(`${p.icon} ${p.pop}`, { x:5.68, y:y+0.04, w:4.0, h:0.3, fontSize:12.5, bold:true, color: i % 2 === 0 ? ACCENT : ACCENT2, margin:0 });
s.addText(p.note, { x:5.68, y:y+0.36, w:4.0, h:0.44, fontSize:10, color:LIGHT_GRAY, margin:0 });
});
}
// ─────────────────────────────────────────────────────────────────────────────
// SLIDE 11 — SUMMARY / KEY TAKE-AWAYS
// ─────────────────────────────────────────────────────────────────────────────
{
const s = pres.addSlide();
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:10, h:5.625, fill:{color:DARK_BG}, line:{color:DARK_BG} });
// Accent stripe
s.addShape(pres.ShapeType.rect, { x:0, y:0, w:0.18, h:5.625, fill:{color:ACCENT}, line:{color:ACCENT} });
s.addText("KEY TAKE-AWAYS", {
x:0.5, y:0.25, w:9.0, h:0.55,
fontSize:22, bold:true, color:WHITE, charSpacing:4, margin:0
});
s.addShape(pres.ShapeType.line, { x:0.5, y:0.85, w:9.0, h:0, line:{color:ACCENT, width:2} });
const takeaways = [
{ n:"1", text:"Insomnia affects ~35% of adults; 10% have chronic insomnia with significant daytime impairment.", col:ACCENT },
{ n:"2", text:"ICSD-III classifies into Short-term and Chronic insomnia; DSM-5 requires ≥3 nights/week for ≥3 months.", col:ACCENT2 },
{ n:"3", text:"Pathophysiology centres on hyperarousal (cognitive, cortical, physiologic), maladaptive conditioning, and HPA axis dysregulation.", col:ACCENT },
{ n:"4", text:"CBT-I is endorsed as FIRST-LINE treatment — superior to pharmacotherapy alone with durable long-term benefits.", col:ACCENT2 },
{ n:"5", text:"Z-drugs and BZDs are effective short-term; orexin antagonists (suvorexant) represent the newest class and are preferred in elderly/AD.", col:ACCENT },
{ n:"6", text:"Avoid sedative hypnotics in the elderly; the 2019 AGS Beers Criteria strongly recommends against BZDs, Z-drugs, TCAs and antihistamines in older adults.", col:ACCENT2 },
];
takeaways.forEach((t, i) => {
const y = 0.98 + i * 0.74;
s.addShape(pres.ShapeType.ellipse, { x:0.4, y:y+0.04, w:0.42, h:0.42, fill:{color:t.col}, line:{color:t.col} });
s.addText(t.n, { x:0.4, y:y+0.04, w:0.42, h:0.42, fontSize:13, bold:true, color:DARK_BG, align:"center", valign:"middle", margin:0 });
s.addText(t.text, { x:0.98, y:y+0.04, w:8.8, h:0.52, fontSize:12.5, color:WHITE, valign:"middle", margin:0 });
});
s.addText("Sources: Bradley & Daroff's Neurology in Clinical Practice • Kaplan & Sadock's Comprehensive Textbook of Psychiatry • Harrison's 22E", {
x:0.5, y:5.32, w:9.0, h:0.22, fontSize:8, color:LIGHT_GRAY, italic:true, margin:0
});
}
// ─────────────────────────────────────────────────────────────────────────────
// WRITE FILE
// ─────────────────────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/insomnia-pptx/Insomnia_Clinical_Overview.pptx" })
.then(() => console.log("DONE: /home/daytona/workspace/insomnia-pptx/Insomnia_Clinical_Overview.pptx"))
.catch(e => { console.error(e); process.exit(1); });
cd /home/daytona/workspace/insomnia-pptx && node insomnia.js
ls -lh /home/daytona/workspace/insomnia-pptx/Insomnia_Clinical_Overview.pptx
Insomnia Clinical Overview
Presentation · PPTX
| Slide | Content |
|---|---|
| 1 | Title slide |
| 2 | Agenda (8 topics) |
| 3 | Definition & Epidemiology (4 stat cards: 35% prevalence, 10% chronic, 2-5x depression risk) |
| 4 | Classification — ICSD-III (3 types) vs. DSM-5 criteria side-by-side |
| 5 | Pathophysiology — 3-P Model (Spielman) + 4 neurochemical mechanisms (GABA, Orexin, HPA, Glymphatic) |
| 6 | Clinical Features — nocturnal vs. daytime symptoms + comorbidities grid |
| 7 | Diagnosis & Assessment — diagnostic criteria + 4 tools (Sleep Diary, ISI, PSG, Actigraphy) |
| 8 | Non-Pharmacological Treatment — CBT-I components (Stimulus Control, Sleep Restriction, Cognitive Restructuring, Relaxation) + Sleep Hygiene rules |
| 9 | Pharmacological Treatment — 6 drug-class cards (Z-drugs, BZDs, Orexin antagonists, Melatonin agonists, Low-dose antidepressants, Sedating antipsychotics) with mechanism + clinical notes |
| 10 | Special Populations & 6-step Treatment Algorithm |
| 11 | Key Take-Aways (6 evidence-based points) |
Create ppt on insomnia full depth for 4th year mbbs student
~/insomnia-pptx/insomnia_mbbs.js
const pptxgen = require("pptxgenjs");
const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Insomnia – Full Depth for 4th Year MBBS";
// ─── PALETTE ─────────────────────────────────────────────────────────────────
const C = {
bg: "0B1A27", // deep navy
mid: "152B3E", // medium navy
panel: "1C3650", // panel bg
teal: "2EC4B6", // primary accent
coral: "E76F51", // secondary accent
gold: "F4A261", // tertiary accent
purple: "9B72CF", // quaternary
white: "F0F4F7",
lt: "A8C0D1", // light text
dim: "6B8FA3", // dimmed text
dark: "0B1A27",
green: "52B788",
red: "E63946",
yellow: "FFD166",
};
// ─── HELPERS ─────────────────────────────────────────────────────────────────
const rect = (s, x,y,w,h, fill, lineColor, lineW) => s.addShape(pres.ShapeType.rect,
{x,y,w,h, fill:{color:fill}, line:{color:lineColor||fill, width:lineW||0}});
const ellipse = (s, x,y,w,h, fill) => s.addShape(pres.ShapeType.ellipse,
{x,y,w,h, fill:{color:fill}, line:{color:fill}});
const line = (s, x,y,w, color, thick) => s.addShape(pres.ShapeType.line,
{x,y, w, h:0, line:{color, width:thick||1}});
const txt = (s, text, x,y,w,h, opts) => s.addText(text,
{x,y,w,h, margin:0, ...opts});
function header(s, title, sub, accentColor) {
rect(s, 0,0, 10,1.05, C.bg);
rect(s, 0,1.02, 10,0.06, accentColor||C.teal);
txt(s, title, 0.35,0.08, 8.5,0.68, {fontSize:21, bold:true, color:C.white, valign:"middle"});
if (sub) txt(s, sub, 0.35,0.7, 9.2,0.3, {fontSize:10.5, color:accentColor||C.teal, italic:true});
}
function tagBox(s, x,y, label, value, accent) {
rect(s, x,y, 2.1,1.1, C.panel, accent, 1.2);
txt(s, value, x+0.08,y+0.04, 1.94,0.55, {fontSize:26, bold:true, color:accent, align:"center"});
txt(s, label, x+0.08,y+0.58, 1.94,0.46, {fontSize:10, color:C.lt, align:"center"});
}
function pill(s, x,y, text, accent) {
rect(s, x,y, 0.08,0.3, accent);
txt(s, text, x+0.16,y+0.01, 4.2,0.28, {fontSize:12, color:C.white});
}
function bulletList(s, items, x,y,w,color,size) {
const rows = items.map((it, i) => ({
text: it,
options: { bullet:{indent:18}, fontSize:size||12.5, color:color||C.white, breakLine: i<items.length-1 }
}));
s.addText(rows, {x,y,w, h: items.length*0.36, margin:0});
}
function sectionDivider(s, num, title, subtitle, accent) {
rect(s, 0,0, 10,5.625, C.bg);
rect(s, 0,0, 0.22,5.625, accent);
rect(s, 0.22,2.1, 9.78,1.5, C.mid);
txt(s, num, 0.5,1.4, 2,1.0, {fontSize:72, bold:true, color:accent, opacity:30});
txt(s, title.toUpperCase(), 0.5,2.2, 9.2,0.75, {fontSize:34, bold:true, color:C.white, charSpacing:3});
if (subtitle) txt(s, subtitle, 0.5,3.05, 9.2,0.45, {fontSize:15, color:C.lt, italic:true});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 1 — TITLE
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
// vertical accent bar
rect(s,0,0, 0.22,5.625, C.teal);
// large glow circle
ellipse(s, 6.2, 0.8, 3.8, 3.8, C.mid);
ellipse(s, 7.0, 1.4, 2.2, 2.2, C.panel);
txt(s,"🌙", 7.2,1.0, 1.6,1.6, {fontSize:72, align:"center"});
txt(s,"INSOMNIA", 0.5,0.7, 7.0,1.6, {fontSize:58, bold:true, color:C.white, charSpacing:5});
txt(s,"Full Clinical Depth – 4th Year MBBS", 0.5,2.38, 7.2,0.5, {fontSize:17, color:C.teal, italic:true});
line(s, 0.5,3.0, 7.2, C.coral, 2);
txt(s,"Department of Medicine & Psychiatry", 0.5,3.15, 6.5,0.35, {fontSize:13, color:C.lt});
// topic pills
const topics = ["Sleep Physiology","Epidemiology","Classification","Pathophysiology",
"Clinical Features","Diagnosis","Non-Pharm Rx","Pharmacotherapy","Special Populations"];
topics.forEach((t,i) => {
const col = i % 3;
const row = Math.floor(i/3);
const x = 0.5 + col*3.0;
const y = 3.65 + row*0.46;
rect(s, x,y, 2.72,0.36, C.panel, C.teal, 0.5);
txt(s, t, x+0.1,y+0.04, 2.52,0.28, {fontSize:10.5, color:C.white, valign:"middle"});
});
txt(s,"Sources: Harrison's 22E • Goldman-Cecil Medicine • Kaplan & Sadock's Comprehensive Psychiatry • Bradley & Daroff's Neurology • Murray & Nadel's Respiratory Medicine",
0.5,5.38, 9.2,0.2, {fontSize:7.5, color:C.dim, italic:true});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 2 — SECTION DIVIDER: SLEEP PHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"01","Sleep Physiology","Normal sleep architecture — essential foundation for understanding insomnia", C.teal);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 3 — NORMAL SLEEP ARCHITECTURE
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Normal Sleep Architecture","Two-process model & NREM/REM cycles", C.teal);
// Two-process model
rect(s,0.3,1.2, 4.3,1.5, C.panel, C.teal,1);
txt(s,"THE TWO-PROCESS MODEL", 0.42,1.23, 4.06,0.28, {fontSize:9, bold:true, color:C.teal, charSpacing:2});
txt(s,[
{text:"Process C (Circadian):", options:{bold:true, color:C.gold, fontSize:12, breakLine:true}},
{text:"Suprachiasmatic nucleus (SCN) → 24-h wake/sleep timing via light-dark cycle\n", options:{fontSize:11.5, color:C.white}},
{text:"Process S (Homeostatic):", options:{bold:true, color:C.coral, fontSize:12, breakLine:true}},
{text:"Adenosine accumulates with wakefulness → increasing sleep pressure", options:{fontSize:11.5, color:C.white}},
], {x:0.42,y:1.52, w:4.06,h:1.1, margin:0});
// Sleep stages table
rect(s,4.85,1.2, 4.85,1.5, C.panel, C.teal,1);
txt(s,"SLEEP STAGES (AASM Scoring)", 4.97,1.23, 4.7,0.28, {fontSize:9, bold:true, color:C.teal, charSpacing:2});
const stages = [
["Stage","EEG","% Total","Function"],
["N1 (NREM 1)","Mixed, theta 4-8Hz","5%","Transition; easily aroused"],
["N2 (NREM 2)","Sleep spindles, K-complex","45%","Memory consolidation"],
["N3 (SWS)","Delta <2Hz, >20%","25%","Restorative, growth hormone"],
["REM","Mixed freq, low amp","25%","Dreams, emotional processing"],
];
stages.forEach((row, ri) => {
const y = 1.52 + ri*0.235;
const colors = [C.teal, C.lt, C.lt, C.lt, C.lt];
const bg = ri===0 ? C.mid : (ri%2===0 ? C.panel : C.bg);
rect(s, 4.85,y, 4.85,0.23, bg);
row.forEach((cell, ci) => {
const xc = 4.87 + ci*1.2;
txt(s, cell, xc,y+0.02, 1.15,0.2,
{fontSize: ri===0 ? 9 : 9.5,
bold: ri===0 || ci===0,
color: ri===0 ? C.teal : (ci===0 ? C.gold : C.lt)});
});
});
// Sleep cycle diagram (text-based)
rect(s,0.3,2.82, 9.4,0.28, C.mid);
txt(s,"NORMAL SLEEP HYPNOGRAM — 7-8 hours (4-5 cycles × ~90 min each, REM lengthens with each cycle)", 0.42,2.84, 9.2,0.24, {fontSize:9.5, color:C.teal, bold:true});
const cycleData = [
{label:"Cycle 1",nrem:"N3 dominant",rem:"REM ~10 min"},
{label:"Cycle 2",nrem:"N3 moderate",rem:"REM ~20 min"},
{label:"Cycle 3",nrem:"N2 dominant",rem:"REM ~30 min"},
{label:"Cycle 4",nrem:"N2 only",rem:"REM ~45 min"},
];
cycleData.forEach((c,i) => {
const x = 0.3 + i*2.38;
const accent = [C.teal,C.coral,C.gold,C.purple][i];
rect(s, x,3.14, 2.22,1.4, C.panel, accent,1);
txt(s, c.label, x+0.08,3.17, 2.06,0.26, {fontSize:11.5, bold:true, color:accent});
txt(s, "NREM: "+c.nrem, x+0.08,3.44, 2.06,0.26, {fontSize:10.5, color:C.lt});
txt(s, c.rem, x+0.08,3.7, 2.06,0.26, {fontSize:10.5, color:C.white});
rect(s, x+0.08,4.0, 2.06,0.42, accent, accent);
txt(s, i===0?"N3↑":i===1?"N3+N2":i===2?"N2↑":"REM↑↑↑", x+0.08,4.05, 2.06,0.34, {fontSize:10, bold:true, color:C.dark, align:"center"});
});
// Key facts
rect(s,0.3,4.6, 9.4,0.78, C.panel, C.green,1);
txt(s,"⚕ Clinical pearls: Sleep latency < 20 min normal | NREM 75% / REM 25% of total sleep | Sleep efficiency > 85% normal | Slow-wave sleep (N3) decreases with age", 0.45,4.64, 9.1,0.66, {fontSize:11.5, color:C.white});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 4 — SECTION DIVIDER: DEFINITION & EPIDEMIOLOGY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"02","Definition & Epidemiology","Who gets insomnia, how common, and why it matters", C.coral);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 5 — DEFINITION & EPIDEMIOLOGY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Definition & Epidemiology","Most common sleep disorder worldwide", C.coral);
// Definition box
rect(s,0.3,1.22, 9.4,1.05, C.panel, C.teal,1.5);
txt(s,"DEFINITION (AASM 2014)", 0.45,1.25, 4,0.26, {fontSize:9, bold:true, color:C.teal, charSpacing:2});
txt(s,"Inability to initiate or maintain sleep, or early morning awakening, despite adequate opportunity for sleep → poor sleep quality, unrefreshed feeling, daytime impairment, and dissatisfaction with sleep.",
0.45,1.5, 9.1,0.68, {fontSize:13, color:C.white});
// Epidemiology stat cards
const stats = [
{v:"~35%", l:"Adults with\ninsomnia complaints", c:C.teal},
{v:"10%", l:"Have chronic\npersistent insomnia", c:C.coral},
{v:"2–5×", l:"Increased risk of\ndepression", c:C.gold},
{v:"F > M", l:"Female sex\nmore affected", c:C.purple},
];
stats.forEach((st,i) => tagBox(s, 0.3+i*2.38, 2.38, st.l, st.v, st.c));
// Risk factors
rect(s,0.3,3.6, 4.55,1.78, C.panel, C.gold,1);
txt(s,"RISK FACTORS", 0.45,3.63, 4.3,0.26, {fontSize:9, bold:true, color:C.gold, charSpacing:2});
bulletList(s,[
"Older age & female sex",
"Lower socioeconomic status / poor education",
"Psychiatric disorders (depression, anxiety)",
"Chronic medical illness (pain, cardiac, neuro)",
"Obsessive-compulsive traits, frequent rumination",
"Shift work, jet lag, poor sleep hygiene",
], 0.42,3.92, 4.3, C.white, 11.5);
// Consequences
rect(s,5.1,3.6, 4.55,1.78, C.panel, C.red,1);
txt(s,"HEALTH CONSEQUENCES", 5.25,3.63, 4.3,0.26, {fontSize:9, bold:true, color:C.red, charSpacing:2});
bulletList(s,[
"Impaired cognition, memory, concentration",
"Occupational dysfunction, accidents",
"↑ Risk CAD, hypertension, diabetes, obesity",
"↑ Mortality (esp. men with short sleep + insomnia)",
"2–5× risk of developing MDD; suicidal behaviour",
"Reduced quality of life and social functioning",
], 5.25,3.92, 4.3, C.white, 11.5);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 6 — SECTION DIVIDER: CLASSIFICATION
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"03","Classification","ICSD-III • DSM-5 • Subtypes", C.gold);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 7 — CLASSIFICATION
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Classification of Insomnia","ICSD-III (AASM 2014) | DSM-5 | Clinical Subtypes", C.gold);
// ICSD-III
rect(s,0.3,1.2, 3.0,0.34, C.teal);
txt(s,"ICSD-III — 3 Types", 0.38,1.2, 2.84,0.34, {fontSize:12, bold:true, color:C.dark, valign:"middle"});
const icsd = [
{t:"Short-term Insomnia", d:"Duration < 3 months; identifiable stressor; resolves with stressor", c:C.teal},
{t:"Chronic Insomnia Disorder", d:"≥ 3 nights/wk for ≥ 3 months; significant daytime impairment", c:C.coral},
{t:"Other Insomnia Disorder", d:"Does not meet full criteria; used rarely as a category", c:C.gold},
];
icsd.forEach((it,i) => {
const y = 1.6 + i*0.95;
rect(s,0.3,y, 3.0,0.88, C.panel, it.c,1);
txt(s,`${i+1}. ${it.t}`, 0.42,y+0.04, 2.76,0.3, {fontSize:11.5, bold:true, color:it.c});
txt(s,it.d, 0.42,y+0.34, 2.76,0.5, {fontSize:10.5, color:C.lt});
});
// DSM-5 Criteria
rect(s,3.55,1.2, 3.0,0.34, C.coral);
txt(s,"DSM-5 Criteria", 3.63,1.2, 2.84,0.34, {fontSize:12, bold:true, color:C.white, valign:"middle"});
const dsm5 = [
"Dissatisfaction with sleep quality/quantity",
"≥ 1 of: difficulty initiating, maintaining sleep, or early awakening with inability to return",
"Clinically significant distress or functional impairment",
"≥ 3 nights per week",
"≥ 3 months duration",
"Adequate opportunity for sleep",
"Not explained by another sleep or mental disorder, substances",
];
rect(s,3.55,1.6, 3.0,3.0, C.panel, C.coral,1);
dsm5.forEach((item,i) => {
const y = 1.66 + i*0.4;
ellipse(s, 3.62,y+0.06, 0.18,0.18, i<2?C.coral:C.dim);
txt(s,item, 3.86,y+0.01, 2.6,0.36, {fontSize:10.5, color:i<2?C.white:C.lt});
});
// Subtypes (Goldman-Cecil)
rect(s,6.8,1.2, 2.9,0.34, C.gold);
txt(s,"Clinical Subtypes", 6.88,1.2, 2.74,0.34, {fontSize:12, bold:true, color:C.dark, valign:"middle"});
const subtypes = [
{t:"Psychophysiologic", d:"Conditioned arousal; bed = wakefulness; sleeps better away from home"},
{t:"Idiopathic", d:"Onset in childhood; lifelong; impaired inherent sleep mechanisms"},
{t:"Paradoxical\n(Sleep-state misperception)", d:"Normal PSG but patient believes they did not sleep"},
{t:"Adjustment insomnia", d:"Acute stressor; usually self-limiting"},
];
subtypes.forEach((it,i) => {
const y = 1.6 + i*0.98;
rect(s,6.8,y, 2.9,0.9, C.panel, C.gold,0.8);
txt(s,it.t, 6.9,y+0.04, 2.7,0.3, {fontSize:11, bold:true, color:C.gold});
txt(s,it.d, 6.9,y+0.36, 2.7,0.5, {fontSize:9.8, color:C.lt});
});
// Note
rect(s,0.3,4.6, 9.4,0.78, C.panel, C.green,1);
txt(s,"📌 Important shift: 'Secondary insomnia' is OBSOLETE — comorbid insomnia is now used because causation cannot always be proven. Insomnia has a bidirectional relationship with depression, anxiety, and pain.", 0.45,4.63, 9.1,0.7, {fontSize:11.5, color:C.white});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 8 — SECTION DIVIDER: PATHOPHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"04","Pathophysiology","Hyperarousal model • Neurochemistry • 3-P model", C.purple);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 9 — PATHOPHYSIOLOGY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Pathophysiology of Insomnia","Hyperarousal is the central unifying concept", C.purple);
// Hyperarousal central concept
rect(s,0.3,1.2, 9.4,0.58, C.panel, C.purple,1.5);
txt(s,"CORE MECHANISM: HYPERAROUSAL STATE",0.45,1.22, 5,0.26, {fontSize:9,bold:true,color:C.purple,charSpacing:2});
txt(s,"Patients with insomnia show elevated brain metabolic rates during NREM sleep — cognitive, cortical, and physiologic hyperarousal prevents normal sleep-promoting processes.", 0.45,1.48, 9.1,0.26, {fontSize:12, color:C.white});
// 3P Model
txt(s,"THE 3-P MODEL (Spielman)", 0.3,1.9, 9.4,0.28, {fontSize:10, bold:true, color:C.yellow, charSpacing:2});
const threeP = [
{h:"PREDISPOSING", c:C.teal, items:["Female sex, older age, genetics","Anxious/obsessive temperament","Hyperactive HPA axis; ↑ CRH","First-degree relative with insomnia"]},
{h:"PRECIPITATING", c:C.coral, items:["Acute life stressor (bereavement, job loss)","Medical/surgical illness, hospitalisation","Medications (MAOIs, stimulants, steroids)","Jet lag, shift work, travel"]},
{h:"PERPETUATING", c:C.gold, items:["Extended time in bed (↓ sleep efficiency)","Daytime napping (↓ sleep drive)","Conditioned arousal — bed = wakefulness","Dysfunctional beliefs about sleep (catastrophising)"]},
];
threeP.forEach((p,i) => {
const x = 0.3+i*3.18;
rect(s,x,2.22, 3.0,0.32, p.c);
txt(s,p.h, x+0.08,2.22, 2.84,0.32, {fontSize:11,bold:true,color:C.dark,valign:"middle"});
p.items.forEach((it,j) => {
const y = 2.58+j*0.36;
rect(s,x+0.08,y+0.06, 0.12,0.12, p.c);
txt(s,it, x+0.26,y+0.01, 2.64,0.3, {fontSize:11,color:j===0?C.white:C.lt});
});
});
// Neurochemical mechanisms
line(s,0.3,4.06, 9.4, C.purple,1);
txt(s,"NEUROCHEMICAL BASIS", 0.3,4.1, 9.4,0.26, {fontSize:9,bold:true,color:C.purple,charSpacing:2});
const neuro = [
{k:"GABA-A ↓", v:"Reduced GABAergic inhibition → cortical & limbic hyperexcitability. Benzodiazepines and Z-drugs act here.", c:C.teal},
{k:"Orexin/Hypocretin ↑", v:"Excess orexin maintains wakefulness. Suvorexant/lemborexant block OX1/OX2 receptors to promote sleep.", c:C.coral},
{k:"HPA Axis ↑", v:"↑ CRH, cortisol, ACTH. Chronic stress perpetuates insomnia via hypothalamic activation.", c:C.gold},
{k:"Adenosine ↓", v:"Insufficient adenosine accumulation (caffeine blocks A1/A2A) → inadequate homeostatic sleep drive.", c:C.purple},
];
neuro.forEach((n,i) => {
const x = 0.3+i*2.38;
rect(s,x,4.4, 2.22,1.0, C.panel, n.c,1);
txt(s,n.k, x+0.08,4.44, 2.06,0.28, {fontSize:11.5,bold:true,color:n.c});
txt(s,n.v, x+0.08,4.72, 2.06,0.64, {fontSize:9.5,color:C.lt});
});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 10 — CLINICAL FEATURES
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Clinical Features","Nocturnal complaints • Daytime consequences • Timing patterns", C.green);
// Nocturnal
rect(s,0.3,1.2, 4.4,0.32, C.mid);
txt(s,"🌙 NOCTURNAL SYMPTOMS", 0.42,1.2, 4.2,0.32, {fontSize:12,bold:true,color:C.teal,valign:"middle"});
bulletList(s,[
"Sleep-onset insomnia — difficulty falling asleep (latency >20-30 min)",
"Sleep-maintenance insomnia — frequent awakenings (WASO >30 min)",
"Terminal insomnia — early morning awakening (>30 min before desired)",
"Non-restorative, unrefreshing sleep",
"Short total sleep time (objective <6 h)",
"Mixed pattern — any combination of the above",
], 0.3,1.56, 4.4, C.white, 12);
// Daytime
rect(s,5.2,1.2, 4.5,0.32, C.mid);
txt(s,"☀️ DAYTIME CONSEQUENCES", 5.32,1.2, 4.3,0.32, {fontSize:12,bold:true,color:C.coral,valign:"middle"});
bulletList(s,[
"Fatigue, low energy",
"Impaired attention, concentration & memory",
"Mood disturbance: irritability, anxiety, dysphoria",
"Occupational/academic impairment",
"Increased accident risk (driving, machinery)",
"Somatic symptoms: headache, GI complaints",
"Social withdrawal & reduced QoL",
], 5.2,1.56, 4.5, C.white, 12);
// Timing clue box
rect(s,0.3,3.78, 9.4,0.28, C.mid);
txt(s,"TIMING OF INSOMNIA → DIAGNOSTIC CLUES", 0.42,3.79, 9.2,0.26, {fontSize:9,bold:true,color:C.yellow,charSpacing:2});
const timing = [
{t:"Sleep-onset", d:"Suggests: delayed sleep phase disorder, sleep phobia, anxiety, poor sleep hygiene"},
{t:"Sleep-maintenance", d:"Suggests: depression, OSA, RLS, PLMD, pain, nocturia, cardiac/respiratory disease"},
{t:"Early morning awakening", d:"Strongly suggests: MDD, advanced sleep phase syndrome"},
{t:"Non-restorative sleep", d:"Suggests: fibromyalgia, undiagnosed OSA, mood disorders"},
];
timing.forEach((ti,i) => {
const x = 0.3+i*2.38;
rect(s,x,4.1, 2.22,1.28, C.panel, [C.teal,C.coral,C.gold,C.purple][i],1);
txt(s,ti.t, x+0.08,4.13, 2.06,0.28, {fontSize:11,bold:true,color:[C.teal,C.coral,C.gold,C.purple][i]});
txt(s,ti.d, x+0.08,4.42, 2.06,0.9, {fontSize:10,color:C.lt});
});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 11 — COMORBIDITIES
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Comorbidities & Differential Diagnosis","What co-exists with insomnia and what to rule out", C.coral);
// Comorbidities 2 columns
rect(s,0.3,1.2, 4.55,0.3, C.coral);
txt(s,"PSYCHIATRIC COMORBIDITIES", 0.42,1.2, 4.3,0.3, {fontSize:11,bold:true,color:C.white,valign:"middle"});
const psych = [
{c:"Major Depressive Disorder", d:"50–80% of MDD have insomnia; early-morning awakening hallmark"},
{c:"Anxiety Disorders", d:"GAD, PTSD — hyperarousal, rumination at bedtime"},
{c:"Bipolar Disorder", d:"Insomnia during mania; hypersomnia in depression"},
{c:"Schizophrenia", d:"Circadian disruption; medication side effects"},
{c:"Substance Use Disorders", d:"Alcohol → suppresses REM; rebound insomnia on withdrawal"},
];
psych.forEach((it,i) => {
const y = 1.54+i*0.72;
rect(s,0.3,y, 4.55,0.65, C.panel, C.dim,0.5);
txt(s,it.c, 0.42,y+0.04, 4.3,0.26, {fontSize:12,bold:true,color:C.coral});
txt(s,it.d, 0.42,y+0.3, 4.3,0.32, {fontSize:10.5,color:C.lt});
});
// Medical comorbidities
rect(s,5.1,1.2, 4.6,0.3, C.gold);
txt(s,"MEDICAL COMORBIDITIES & DDx", 5.22,1.2, 4.3,0.3, {fontSize:11,bold:true,color:C.dark,valign:"middle"});
const medical = [
{c:"Obstructive Sleep Apnoea (OSA)", d:"Fragments sleep; snoring, witnessed apnoeas, obesity — PSG to differentiate"},
{c:"Restless Legs Syndrome (RLS)", d:"Sleep-onset insomnia + irresistible urge to move legs at rest"},
{c:"Periodic Limb Movement Disorder", d:"Involuntary leg jerks → repeated arousals → sleep-maintenance insomnia"},
{c:"Chronic Pain Syndromes", d:"Fibromyalgia, arthritis, cancer pain — pain → arousal cycle"},
{c:"Cardiac/Respiratory Disorders", d:"Heart failure (orthopnoea), COPD (nocturnal hypoxia), asthma"},
];
medical.forEach((it,i) => {
const y = 1.54+i*0.72;
rect(s,5.1,y, 4.6,0.65, C.panel, C.dim,0.5);
txt(s,it.c, 5.22,y+0.04, 4.35,0.26, {fontSize:12,bold:true,color:C.gold});
txt(s,it.d, 5.22,y+0.3, 4.35,0.32, {fontSize:10.5,color:C.lt});
});
// Drugs causing insomnia
rect(s,0.3,5.1, 9.4,0.38, C.panel, C.red,1);
txt(s,"💊 Drugs causing insomnia: SSRIs/SNRIs (activating), MAOIs, corticosteroids, stimulants (amphetamines, methylphenidate), theophylline, beta-agonists, decongestants (pseudoephedrine), caffeine, levodopa", 0.45,5.13, 9.1,0.32, {fontSize:10.5,color:C.white});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 12 — DIAGNOSIS
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Diagnosis & Clinical Assessment","History • Questionnaires • Investigations • Sleep Diary", C.teal);
// Diagnostic criteria box
rect(s,0.3,1.22, 9.4,0.68, C.panel, C.teal,1.5);
txt(s,"CHRONIC INSOMNIA DISORDER — DIAGNOSTIC CRITERIA (AASM / DSM-5)", 0.45,1.24, 8,0.26, {fontSize:9,bold:true,color:C.teal,charSpacing:2});
txt(s,"Sleep difficulty ≥ 3 nights/week | Duration ≥ 3 months | Adequate sleep opportunity | Significant daytime impairment | Not explained by another primary sleep disorder, medical condition, or substance", 0.45,1.5, 9.1,0.34, {fontSize:12, color:C.white});
// History checklist
rect(s,0.3,2.02, 3.08,0.28, C.mid);
txt(s,"CLINICAL HISTORY", 0.42,2.02, 2.9,0.28, {fontSize:10,bold:true,color:C.gold,valign:"middle"});
bulletList(s,[
"24-h sleep-wake schedule & diary",
"Onset, duration, frequency",
"Precipitating events",
"Daytime functioning (work, driving)",
"Medications (present & recent)",
"Psychiatric & medical history",
"Bed-partner history (snoring, kicks)",
"Substance: caffeine, alcohol, nicotine",
], 0.3,2.34, 3.08, C.white, 11);
// Assessment tools
rect(s,3.6,2.02, 3.0,0.28, C.mid);
txt(s,"ASSESSMENT TOOLS", 3.72,2.02, 2.8,0.28, {fontSize:10,bold:true,color:C.coral,valign:"middle"});
const tools = [
{n:"Sleep Diary (2 weeks)", d:"Gold standard self-report — records TST, SOL, WASO, SE, naps, substances"},
{n:"ISI (Insomnia Severity Index)", d:"7 items; 0–28 score; >14 = clinically significant; widely used"},
{n:"PSQI (Pittsburgh Sleep Quality Index)", d:"19 items; 7 components; score >5 = poor sleeper"},
{n:"ESS (Epworth Sleepiness Scale)", d:"Daytime sleepiness; if high → suspect OSA/narcolepsy"},
{n:"Actigraphy", d:"Wrist-worn; 7–14 days; estimates sleep-wake patterns objectively"},
];
tools.forEach((t,i) => {
const y = 2.34+i*0.6;
rect(s,3.6,y, 3.0,0.54, C.panel, C.coral,0.5);
txt(s,t.n, 3.72,y+0.04, 2.76,0.22, {fontSize:11,bold:true,color:C.coral});
txt(s,t.d, 3.72,y+0.27, 2.76,0.24, {fontSize:9.5,color:C.lt});
});
// PSG indications
rect(s,6.82,2.02, 2.88,0.28, C.mid);
txt(s,"POLYSOMNOGRAPHY", 6.94,2.02, 2.7,0.28, {fontSize:10,bold:true,color:C.teal,valign:"middle"});
rect(s,6.82,2.34, 2.88,1.2, C.panel, C.teal,1);
txt(s,"⚠️ NOT routinely indicated\nfor uncomplicated insomnia\n\nINDICATIONS for PSG:", 6.94,2.38, 2.66,0.82, {fontSize:10.5,color:C.white});
bulletList(s,[
"Suspected OSA or PLMD",
"Paradoxical insomnia",
"Treatment-refractory cases",
"Safety-sensitive occupation",
], 6.94,3.22, 2.66, C.lt, 10.5);
// Key definitions
rect(s,0.3,4.55, 9.4,0.85, C.panel, C.yellow,1);
txt(s,"KEY PARAMETERS TO DOCUMENT:", 0.45,4.58, 5,0.26, {fontSize:9,bold:true,color:C.yellow,charSpacing:2});
const params = [
"SOL (Sleep Onset Latency): normal <20 min",
"TST (Total Sleep Time): target 7–9 h adults",
"WASO (Wake After Sleep Onset): normal <30 min",
"SE (Sleep Efficiency = TST/TIB × 100): normal >85%",
"TIB (Time in Bed)",
];
params.forEach((p,i) => {
const x = i < 3 ? 0.35 : 5.15;
const y = i < 3 ? 4.85+i*0.0 : 4.85+(i-3)*0.0;
// column layout
});
txt(s,[
{text:"SOL < 20 min normal | TST 7–9 h adults | WASO < 30 min | SE = TST/TIB × 100% (normal >85%) | TIB = Time in Bed", options:{fontSize:11.5,color:C.white}},
], {x:0.45,y:4.86, w:9.1,h:0.45, margin:0});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 13 — SECTION DIVIDER: NON-PHARMACOLOGICAL
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"05","Non-Pharmacological Treatment","CBT-I: the evidence-based first-line therapy", C.green);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 14 — CBT-I IN DEPTH
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Cognitive Behavioural Therapy for Insomnia (CBT-I)","First-line for chronic insomnia — superior to pharmacotherapy alone", C.green);
// Evidence box
rect(s,0.3,1.22, 9.4,0.56, C.panel, C.green,1.5);
txt(s,"EVIDENCE BASE: AASM, ACP, British Sleep Society all endorse CBT-I as FIRST-LINE for chronic insomnia. RCTs show effects are durable (maintained at 12-month follow-up) vs. medication where benefits are lost on discontinuation. CBT-I + medication > medication alone.",
0.45,1.26, 9.1,0.48, {fontSize:11.5,color:C.white});
// 5 core components
txt(s,"FIVE CORE COMPONENTS OF CBT-I", 0.3,1.88, 9.4,0.28, {fontSize:9.5,bold:true,color:C.yellow,charSpacing:2});
const components = [
{
n:"1. Stimulus Control",
c:C.teal,
b:"Pavlovian reconditioning — break the bed-wakefulness association",
rules:[
"Use bed ONLY for sleep and sex",
"Get out of bed if awake >20 min",
"Return only when sleepy",
"Same wake time 7 days/week",
"No daytime napping",
]
},
{
n:"2. Sleep Restriction",
c:C.coral,
b:"Temporarily restrict TIB to actual TST → builds homeostatic sleep pressure",
rules:[
"Calculate mean TST from sleep diary",
"Set TIB = TST (minimum 5.5 h)",
"Increases sleep efficiency to >85%",
"Then gradually extend TIB by 15–20 min",
"Caution: daytime sleepiness, driving risk",
]
},
{
n:"3. Cognitive Restructuring",
c:C.gold,
b:"Identify and challenge dysfunctional beliefs about sleep",
rules:[
'"I must sleep 8 h or tomorrow is ruined"',
'"I have no control over my sleep"',
"Reframe: sleep variability is normal",
"Reduce catastrophising about lost sleep",
"Worry postponement technique",
]
},
{
n:"4. Relaxation Therapy",
c:C.purple,
b:"Reduce physiologic and cognitive arousal",
rules:[
"Progressive muscle relaxation (PMR)",
"Diaphragmatic breathing (4-7-8 method)",
"Guided imagery / mindfulness",
"Paradoxical intention (try to stay awake)",
"Biofeedback in specialised centres",
]
},
];
components.forEach((comp,i) => {
const col = i % 2;
const row = Math.floor(i/2);
const x = 0.3+col*4.9;
const y = 2.22+row*1.55;
rect(s,x,y, 4.55,1.45, C.panel, comp.c,1);
rect(s,x,y, 4.55,0.3, comp.c);
txt(s,comp.n, x+0.1,y+0.02, 4.35,0.26, {fontSize:12,bold:true,color:C.dark});
txt(s,comp.b, x+0.1,y+0.33, 4.35,0.24, {fontSize:10,color:C.lt,italic:true});
comp.rules.slice(0,4).forEach((r,ri) => {
txt(s,`• ${r}`, x+0.1,y+0.6+ri*0.2, 4.3,0.2, {fontSize:10.5,color:C.white});
});
});
// Sleep hygiene table
rect(s,0.3,5.12, 9.4,0.36, C.panel, C.yellow,1);
txt(s,"⚡ SLEEP HYGIENE (adjunct, not sufficient alone): No caffeine/alcohol after lunch • No screens 2 h before bed • Regular exercise • Keep bedroom dark & cool (18–20°C) • Naps < 30 min before 3 PM • Consistent sleep-wake schedule", 0.45,5.15, 9.1,0.3, {fontSize:10.5,color:C.white});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 15 — SECTION DIVIDER: PHARMACOTHERAPY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
sectionDivider(s,"06","Pharmacotherapy","Drug classes, mechanisms, doses & clinical selection", C.coral);
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 16 — PHARMACOTHERAPY — GABA-ACTING DRUGS
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Pharmacotherapy — GABA-Acting Agents","Benzodiazepines & Z-drugs (BzRAs)", C.coral);
// Header bar
rect(s,0.3,1.22, 9.4,0.28, C.mid);
txt(s,"MECHANISM: Positive allosteric modulation of GABA-A receptors → ↑ chloride influx → neuronal inhibition → ↓ arousal systems (VLPO pathway)", 0.42,1.24, 9.1,0.24, {fontSize:11.5,color:C.white});
// BZD drugs table
rect(s,0.3,1.58, 4.6,0.28, C.coral);
txt(s,"BENZODIAZEPINES", 0.42,1.58, 4.5,0.28, {fontSize:11.5,bold:true,color:C.white,valign:"middle"});
const bzds = [
["Drug","Dose","T½ (h)","Indication / Notes"],
["Triazolam","0.125–0.25 mg","1.5–5.5","Sleep onset; short T½; amnesia risk at high dose"],
["Temazepam","15–30 mg","8–20","Sleep maintenance; intermediate T½; preferred"],
["Lorazepam","0.5–2 mg","10–20","Acute insomnia; also anxiety; dependence risk"],
["Flurazepam","15–30 mg","47–100","Active metabolite >1 day; daytime sedation; avoid elderly"],
["Clonazepam","0.5–2 mg","20–50","RLS/PLMD; long T½; accumulates"],
];
bzds.forEach((row,ri) => {
const bg = ri===0 ? C.mid : (ri%2===0 ? C.panel : C.bg);
rect(s,0.3,1.88+ri*0.38, 4.6,0.36, bg);
const widths = [1.0,0.7,0.72,2.1];
let xc = 0.32;
row.forEach((cell,ci) => {
txt(s,cell, xc,1.9+ri*0.38, widths[ci],0.32, {fontSize:ri===0?9:10.5, bold:ri===0||ci===0, color:ri===0?C.coral:(ci===0?C.gold:C.lt)});
xc += widths[ci]+0.04;
});
});
// Key BZD effects
rect(s,0.3,4.02, 4.6,0.26, C.mid);
txt(s,"EFFECTS ON SLEEP ARCHITECTURE", 0.42,4.02, 4.4,0.26, {fontSize:9.5,bold:true,color:C.gold,charSpacing:1});
bulletList(s,[
"↓ Sleep latency, ↑ TST, ↑ sleep efficiency",
"↓ REM sleep (suppress dream sleep)",
"↓ Slow-wave sleep (N3) — non-restorative",
"Tolerance after 1–2 months; rebound insomnia 71%",
], 0.3,4.3, 4.6, C.white, 11);
// Z-drugs
rect(s,5.1,1.58, 4.6,0.28, C.teal);
txt(s,"Z-DRUGS (Non-BZD BzRAs)", 5.22,1.58, 4.5,0.28, {fontSize:11.5,bold:true,color:C.dark,valign:"middle"});
const zdrugs = [
["Drug","Dose","T½","Notes"],
["Zolpidem","5–10 mg","2–4 h","Most prescribed; α1-selective; complex sleep behaviours"],
["Zaleplon","5–20 mg","1–2 h","Shortest T½; sleep onset only; safe mid-night dose"],
["Eszopiclone","1–3 mg","5–8 h","Longest-approved (6-month studies); metallic taste"],
["Zopiclone","3.75–7.5 mg","5 h","Widely used outside US; similar to eszopiclone"],
];
zdrugs.forEach((row,ri) => {
const bg = ri===0 ? C.mid : (ri%2===0 ? C.panel : C.bg);
rect(s,5.1,1.88+ri*0.4, 4.6,0.38, bg);
const widths = [1.0,0.7,0.7,2.12];
let xc = 5.12;
row.forEach((cell,ci) => {
txt(s,cell, xc,1.9+ri*0.4, widths[ci],0.34, {fontSize:ri===0?9:10.5, bold:ri===0||ci===0, color:ri===0?C.teal:(ci===0?C.gold:C.lt)});
xc += widths[ci]+0.04;
});
});
rect(s,5.1,4.02, 4.6,0.26, C.mid);
txt(s,"Z-DRUGS vs BZDs", 5.22,4.02, 4.4,0.26, {fontSize:9.5,bold:true,color:C.teal,charSpacing:1});
bulletList(s,[
"α1-selective → less muscle relaxation/amnesia vs BZDs",
"No reduction in REM or delta sleep (zolpidem)",
"Complex sleep behaviours: sleep-walking, sleep-eating, sleep-driving",
"Recommended max 2–4 weeks; rebound on stopping",
], 5.1,4.3, 4.6, C.white, 11);
// Warning box
rect(s,0.3,5.08, 9.4,0.38, C.panel, C.red,1);
txt(s,"⚠️ BEERS CRITERIA 2019 (AGS): Strong recommendation AGAINST benzodiazepines, Z-drugs, TCAs (>6 mg doxepin), and first-generation antihistamines for sleep in OLDER ADULTS (↑ fall, confusion, cognitive impairment risk)", 0.45,5.11, 9.1,0.32, {fontSize:11,color:C.white});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 17 — PHARMACOTHERAPY — NOVEL AGENTS
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Pharmacotherapy — Novel & Alternative Agents","Orexin antagonists • Melatonin agonists • Antidepressants", C.gold);
// Orexin antagonists
rect(s,0.3,1.22, 9.4,0.26, C.mid);
txt(s,"OREXIN (HYPOCRETIN) RECEPTOR ANTAGONISTS — Newest FDA-approved class for insomnia", 0.42,1.24, 9.1,0.22, {fontSize:11.5,bold:true,color:C.gold});
const orexinDrugs = [
{n:"Suvorexant",d:"10–20 mg",h:"OX1+OX2 block (dual)",note:"Approved insomnia incl. AD patients; needs 7 h after dosing; morning sedation", c:C.gold},
{n:"Lemborexant",d:"5–10 mg",h:"OX1+OX2 block (faster dissociation)",note:"Better kinetics than suvorexant; ↓ morning sedation; no head-to-head studies", c:C.coral},
{n:"Daridorexant",d:"25–50 mg",h:"Dual orexin antagonist",note:"Newest; improves next-day functioning; approved 2022", c:C.teal},
];
orexinDrugs.forEach((d,i) => {
const x = 0.3+i*3.18;
rect(s,x,1.52, 3.0,1.52, C.panel, d.c,1.2);
rect(s,x,1.52, 3.0,0.3, d.c);
txt(s,d.n, x+0.1,1.54, 2.8,0.26, {fontSize:13,bold:true,color:C.dark});
txt(s,`Dose: ${d.d}`, x+0.1,1.86, 2.8,0.26, {fontSize:11,bold:true,color:d.c});
txt(s,`MOA: ${d.h}`, x+0.1,2.12, 2.8,0.26, {fontSize:10.5,color:C.lt,italic:true});
txt(s,d.note, x+0.1,2.38, 2.8,0.6, {fontSize:10,color:C.white});
});
txt(s,"Side effects: morning sedation, hypnagogic hallucinations, sleep paralysis (rare — similar to narcolepsy symptoms)", 0.3,3.08, 9.4,0.26, {fontSize:11,color:C.lt,italic:true});
// Melatonin agonists
line(s,0.3,3.38, 9.4, C.teal,0.8);
txt(s,"MELATONIN AGONISTS", 0.3,3.42, 4,0.26, {fontSize:9.5,bold:true,color:C.teal,charSpacing:2});
const melat = [
{n:"Ramelteon 8 mg",note:"MT1/MT2 agonist; no abuse potential; best for sleep-onset/circadian; approved AD patients"},
{n:"Tasimelteon",note:"Circadian rhythm disorders in blind patients; non-24-h sleep-wake disorder"},
];
melat.forEach((m,i) => {
rect(s,0.3+i*4.9,3.72, 4.55,0.58, C.panel, C.teal,1);
txt(s,m.n, 0.42+i*4.9,3.76, 4.3,0.26, {fontSize:12,bold:true,color:C.teal});
txt(s,m.note, 0.42+i*4.9,4.0, 4.3,0.26, {fontSize:10.5,color:C.lt});
});
// Antidepressants & others
line(s,0.3,4.38, 9.4, C.purple,0.8);
txt(s,"ANTIDEPRESSANTS & OTHER SEDATING AGENTS", 0.3,4.42, 9,0.26, {fontSize:9.5,bold:true,color:C.purple,charSpacing:2});
const antideps = [
{n:"Trazodone 25–100 mg",m:"5-HT2 antagonist, H1 block",note:"Off-label; widely used; T½ 5–9 h; no abuse potential"},
{n:"Doxepin ≤6 mg",m:"H1 antagonism",note:"FDA-approved at low dose; sleep maintenance; Beers: avoid >6 mg, avoid in delirium risk"},
{n:"Mirtazapine 7.5–15 mg",m:"H1+5HT2 antagonism",note:"Off-label; useful with comorbid depression + insomnia; weight gain"},
{n:"Diphenhydramine (OTC)",m:"H1 antagonist",note:"Tolerance within days; anticholinergic; AVOID in elderly"},
];
antideps.forEach((a,i) => {
const x = 0.3+(i%2)*4.9;
const y = 4.72+(Math.floor(i/2)*0.0);
if (i<2) {
rect(s,x,4.72, 4.55,0.64, C.panel, C.purple,0.8);
txt(s,a.n, x+0.1,4.76, 4.3,0.24, {fontSize:11.5,bold:true,color:C.purple});
txt(s,`MOA: ${a.m} | ${a.note}`, x+0.1,5.0, 4.3,0.3, {fontSize:10,color:C.lt});
}
});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 18 — DRUG SELECTION & TREATMENT ALGORITHM
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Drug Selection & Treatment Algorithm","Matching the drug to the patient's insomnia type", C.teal);
// Algorithm
txt(s,"STEP-BY-STEP TREATMENT ALGORITHM", 0.3,1.22, 6,0.28, {fontSize:9.5,bold:true,color:C.yellow,charSpacing:2});
const steps = [
{n:"Step 1", t:"Treat underlying cause", d:"Address comorbid depression, anxiety, pain, OSA, medications before adding hypnotics", c:C.teal},
{n:"Step 2", t:"Sleep hygiene education", d:"Implement for ALL patients regardless of severity", c:C.teal},
{n:"Step 3", t:"CBT-I (first-line)", d:"Chronic insomnia: 6–10 sessions. BBTI (4 sessions) if resources limited", c:C.green},
{n:"Step 4", t:"Pharmacotherapy", d:"Acute insomnia or while awaiting CBT-I: short-acting BzRA or orexin antagonist", c:C.coral},
{n:"Step 5", t:"Combination therapy", d:"CBT-I + short-term medication superior to either alone", c:C.gold},
{n:"Step 6", t:"Taper & maintain", d:"Gradual taper of medication; maintain CBT-I strategies", c:C.purple},
];
steps.forEach((st,i) => {
const col = i < 3 ? 0 : 1;
const row = i < 3 ? i : i-3;
const x = 0.3+col*4.9;
const y = 1.54+row*1.04;
rect(s,x,y, 4.55,0.96, C.panel, st.c,1);
ellipse(s,x+0.14,y+0.3, 0.38,0.38, st.c);
txt(s,st.n, x+0.14,y+0.3, 0.38,0.38, {fontSize:9.5,bold:true,color:C.dark,align:"center",valign:"middle"});
txt(s,st.t, x+0.62,y+0.06, 3.8,0.3, {fontSize:13,bold:true,color:st.c});
txt(s,st.d, x+0.62,y+0.38, 3.8,0.52, {fontSize:11,color:C.lt});
});
// Drug selection guide
txt(s,"DRUG CHOICE BY INSOMNIA TYPE (AASM)", 0.3,4.62, 9.4,0.26, {fontSize:9.5,bold:true,color:C.teal,charSpacing:2});
rect(s,0.3,4.9, 9.4,0.56, C.panel, C.dim,0.5);
txt(s,[
{text:"Sleep ONSET: ", options:{bold:true,color:C.coral,fontSize:11}},
{text:"Zaleplon, triazolam, ramelteon | ", options:{color:C.white,fontSize:11}},
{text:" Sleep MAINTENANCE: ", options:{bold:true,color:C.gold,fontSize:11}},
{text:"Eszopiclone, zolpidem CR, temazepam, suvorexant, lemborexant | ", options:{color:C.white,fontSize:11}},
{text:" BOTH: ", options:{bold:true,color:C.teal,fontSize:11}},
{text:"Eszopiclone, zolpidem CR, suvorexant", options:{color:C.white,fontSize:11}},
], {x:0.42,y:4.93, w:9.0,h:0.5, margin:0});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 19 — SPECIAL POPULATIONS
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
header(s,"Special Populations","Elderly • Pregnancy • Paediatric • Psychiatric comorbidity", C.purple);
const pops = [
{
icon:"👴", title:"ELDERLY", c:C.gold,
x:0.3, y:1.2, w:4.55, h:2.0,
points:[
"Most susceptible to drug side effects",
"↑ fall risk, confusion, cognitive impairment",
"Beers Criteria: AVOID BZDs, Z-drugs, TCAs (>6 mg), antihistamines",
"PREFER: CBT-I (first-line), suvorexant (approved in AD), ramelteon (safe, low efficacy)",
"Doxepin ≤6 mg: FDA-approved for sleep maintenance in elderly",
"Treat comorbid depression, pain, OSA first",
]
},
{
icon:"🤰", title:"PREGNANCY", c:C.teal,
x:5.1, y:1.2, w:4.6, h:2.0,
points:[
"CBT-I: safe and recommended first-line",
"Pharmacotherapy: AVOID in 1st trimester if possible",
"Common causes: nocturia, foetal movements, heartburn, anxiety",
"Doxylamine + B6: safe for sleep-associated nausea in 1st trimester",
"Short-term zolpidem if essential (lowest dose, 3rd trimester preferred)",
"Avoid BZDs (neonatal withdrawal, 'floppy infant syndrome')",
]
},
{
icon:"🧠", title:"PSYCHIATRIC COMORBIDITY", c:C.coral,
x:0.3, y:3.3, w:4.55, h:2.06,
points:[
"Treat both disorders simultaneously — bidirectional",
"MDD + insomnia: sedating antidepressant (mirtazapine, trazodone)",
"Treating insomnia → ↑ antidepressant response, ↓ relapse",
"Anxiety: CBT-I + SSRI; avoid BZDs long-term",
"PTSD: prazosin for nightmares; CBT-I for sleep disruption",
"Schizophrenia: low-dose quetiapine (off-label); address medications",
]
},
{
icon:"🏥", title:"HOSPITALISED / ACUTE ILLNESS", c:C.green,
x:5.1, y:3.3, w:4.6, h:2.06,
points:[
"Non-pharmacological first: sleep hygiene, light control, noise reduction",
"Short-acting BZDs or Z-drugs for brief, severe insomnia",
"ICU: melatonin for circadian realignment (low evidence)",
"Avoid long-acting BZDs (↑ delirium risk)",
"Delirium risk: reassess medications, treat pain, orient patient",
"Discharge planning: taper hypnotics started in hospital",
]
},
];
pops.forEach(p => {
rect(s,p.x,p.y, p.w,p.h, C.panel, p.c,1);
rect(s,p.x,p.y, p.w,0.32, p.c);
txt(s,`${p.icon} ${p.title}`, p.x+0.1,p.y+0.02, p.w-0.2,0.28, {fontSize:12,bold:true,color:C.dark});
bulletList(s, p.points, p.x+0.1, p.y+0.36, p.w-0.2, C.white, 10.5);
});
}
// ═══════════════════════════════════════════════════════════════════════════
// SLIDE 20 — EXAM HIGH-YIELD SUMMARY
// ═══════════════════════════════════════════════════════════════════════════
{
const s = pres.addSlide();
rect(s,0,0,10,5.625, C.bg);
rect(s,0,0, 0.22,5.625, C.teal);
txt(s,"HIGH-YIELD EXAM POINTS", 0.45,0.1, 9.2,0.52, {fontSize:22,bold:true,color:C.white,charSpacing:3});
line(s,0.45,0.68, 9.1, C.teal, 2);
const points = [
{n:"1", t:"Definition", d:"Inability to initiate/maintain sleep + adequate opportunity + daytime impairment", c:C.teal},
{n:"2", t:"Chronic vs Acute", d:"Chronic = ≥3 nights/wk for ≥3 months; Acute = <3 months (short-term)", c:C.coral},
{n:"3", t:"Most common sleep disorder", d:"35% intermittent; 10% chronic; F > M; ↑ with age, psychiatric illness", c:C.gold},
{n:"4", t:"Pathophysiology", d:"Hyperarousal (cognitive + cortical + physiologic) + 3-P model + ↓GABA / ↑Orexin / ↑HPA", c:C.purple},
{n:"5", t:"Early-morning awakening", d:"Hallmark of Major Depressive Disorder — key clinical clue", c:C.teal},
{n:"6", t:"First-line treatment", d:"CBT-I (cognitive behavioural therapy) — all guidelines; superior & more durable than drugs", c:C.green},
{n:"7", t:"First-line drug (acute)", d:"Z-drugs (zolpidem, zaleplon, eszopiclone) or short-acting BZD for acute/short-term", c:C.coral},
{n:"8", t:"Newest drug class", d:"Orexin receptor antagonists: suvorexant, lemborexant, daridorexant — block wake-promoting orexin", c:C.gold},
{n:"9", t:"AVOID in elderly", d:"BZDs, Z-drugs, TCAs >6 mg, antihistamines (Beers 2019) — ↑ falls, confusion, cognitive impairment", c:C.red},
{n:"10", t:"Rebound insomnia", d:"Occurs in up to 71% after BZD discontinuation — taper slowly", c:C.purple},
];
points.forEach((p,i) => {
const col = i < 5 ? 0 : 1;
const row = i < 5 ? i : i-5;
const x = 0.3+col*4.9;
const y = 0.78+row*0.92;
rect(s,x,y, 4.55,0.84, C.panel, p.c,0.8);
ellipse(s,x+0.1,y+0.2, 0.44,0.44, p.c);
txt(s,p.n, x+0.1,y+0.2, 0.44,0.44, {fontSize:13,bold:true,color:C.dark,align:"center",valign:"middle"});
txt(s,p.t, x+0.64,y+0.06, 3.8,0.28, {fontSize:12.5,bold:true,color:p.c});
txt(s,p.d, x+0.64,y+0.36, 3.8,0.42, {fontSize:11,color:C.lt});
});
txt(s,"Sources: Harrison's 22E (p.259-261) • Goldman-Cecil Medicine • Kaplan & Sadock's Comprehensive Textbook of Psychiatry • Murray & Nadel's Respiratory Medicine • Bradley & Daroff's Neurology in Clinical Practice",
0.3,5.42, 9.4,0.18, {fontSize:7.5,color:C.dim,italic:true});
}
// ═══════════════════════════════════════════════════════════════════════════
// WRITE
// ═══════════════════════════════════════════════════════════════════════════
pres.writeFile({fileName:"/home/daytona/workspace/insomnia-pptx/Insomnia_MBBS_FullDepth.pptx"})
.then(()=>console.log("DONE"))
.catch(e=>{console.error(e);process.exit(1);});
Failed to create session: unauthorized: authentication failed: Bearer token is invalid
We encountered an error while processing your request. Please try again or reach out to us for help.