What does this indicate
| Type | Count | % |
|---|---|---|
| Obstructive (airway blockage) | 36 | 82% |
| Central (brain signal failure) | 6 | 14% |
| Mixed | 2 | 5% |
Important: This is a screening report, not a final diagnosis. A formal in-lab or home polysomnography ordered by a physician is needed to confirm severity and guide treatment. Please share this report with a doctor promptly given the significant oxygen dip to 81%.
Create a summary document explaining this report for a family member
ls -la /home/daytona/workspace/ && ls /home/daytona/skills/docx/
mkdir -p /home/daytona/workspace/sleep-report && ls /home/daytona/skills/docx/scripts/
~/sleep-report/create_summary.js
const {
Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
HeadingLevel, AlignmentType, LevelFormat, BorderStyle, WidthType,
ShadingType, VerticalAlign, PageNumber, Header, Footer
} = require('docx');
const fs = require('fs');
// ---- Colour palette ----
const RED = "C0392B";
const ORANGE = "E67E22";
const GREEN = "27AE60";
const BLUE = "1A5276";
const LGREY = "F2F3F4";
const WHITE = "FFFFFF";
// ---- Helper: shaded table cell ----
function shadedCell(text, bgColor, textColor, bold, widthPct) {
return new TableCell({
width: { size: widthPct, type: WidthType.PERCENTAGE },
shading: { type: ShadingType.CLEAR, fill: bgColor },
verticalAlign: VerticalAlign.CENTER,
children: [new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { before: 80, after: 80 },
children: [new TextRun({ text, color: textColor || "000000", bold: bold || false, size: 22, font: "Arial" })]
})]
});
}
// ---- Helper: plain paragraph ----
function para(text, opts = {}) {
return new Paragraph({
alignment: opts.center ? AlignmentType.CENTER : AlignmentType.LEFT,
spacing: { before: opts.before || 80, after: opts.after || 80 },
children: [new TextRun({
text,
bold: opts.bold || false,
size: opts.size || 22,
color: opts.color || "000000",
font: "Arial",
italics: opts.italic || false
})]
});
}
// ---- Helper: bullet item ----
function bullet(text, bold_prefix) {
const children = bold_prefix
? [new TextRun({ text: bold_prefix, bold: true, size: 22, font: "Arial" }),
new TextRun({ text, size: 22, font: "Arial" })]
: [new TextRun({ text, size: 22, font: "Arial" })];
return new Paragraph({
numbering: { reference: "bullets", level: 0 },
spacing: { before: 60, after: 60 },
children
});
}
// ---- Helper: section heading bar ----
function sectionBar(text, color) {
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [new TableRow({ children: [
new TableCell({
shading: { type: ShadingType.CLEAR, fill: color },
borders: { top: { style: BorderStyle.NONE }, bottom: { style: BorderStyle.NONE }, left: { style: BorderStyle.NONE }, right: { style: BorderStyle.NONE } },
children: [new Paragraph({
spacing: { before: 100, after: 100 },
children: [new TextRun({ text, bold: true, color: WHITE, size: 26, font: "Arial" })]
})]
})
]})]
});
}
// ---- Main document ----
const doc = new Document({
numbering: {
config: [{
reference: "bullets",
levels: [{ level: 0, format: LevelFormat.BULLET, text: "\u2022", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } } }]
}]
},
styles: {
default: { document: { run: { font: "Arial", size: 22 } } }
},
sections: [{
properties: { page: { margin: { top: 1080, bottom: 1080, left: 1080, right: 1080 } } },
headers: {
default: new Header({
children: [new Paragraph({
alignment: AlignmentType.RIGHT,
spacing: { after: 0 },
children: [new TextRun({ text: "Sleep Study Summary | Tariq Ahmad Peerzada", size: 18, color: "888888", font: "Arial" })]
})]
})
},
footers: {
default: new Footer({
children: [new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "This document is for family information only and does not replace medical advice.", size: 16, color: "888888", italics: true, font: "Arial" })]
})]
})
},
children: [
// ============================================================
// TITLE BLOCK
// ============================================================
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [new TableRow({ children: [
new TableCell({
shading: { type: ShadingType.CLEAR, fill: BLUE },
borders: { top: { style: BorderStyle.NONE }, bottom: { style: BorderStyle.NONE }, left: { style: BorderStyle.NONE }, right: { style: BorderStyle.NONE } },
children: [
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 160, after: 40 },
children: [new TextRun({ text: "Sleep Study Results", bold: true, color: WHITE, size: 48, font: "Arial" })] }),
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 0, after: 40 },
children: [new TextRun({ text: "A Plain-Language Explanation for Family Members", color: "BDC3C7", size: 24, font: "Arial", italics: true })] }),
new Paragraph({ alignment: AlignmentType.CENTER, spacing: { before: 0, after: 160 },
children: [new TextRun({ text: "Patient: Tariq Ahmad Peerzada | Test Date: 10 June 2026 | Report: 11 June 2026", color: "AEB6BF", size: 20, font: "Arial" })] }),
]
})
]})]
}),
new Paragraph({ spacing: { before: 200, after: 0 }, children: [] }),
// ============================================================
// WHAT IS THIS TEST?
// ============================================================
sectionBar("What Is This Test?", BLUE),
new Paragraph({ spacing: { before: 100, after: 60 }, children: [
new TextRun({ text: "Tariq wore a small device made by ResMed (called an ApneaLink) while sleeping at home. It recorded how he breathed, his oxygen level in the blood, and his pulse throughout the night. This is called a ", size: 22, font: "Arial" }),
new TextRun({ text: "home sleep apnea test", bold: true, size: 22, font: "Arial" }),
new TextRun({ text: ".", size: 22, font: "Arial" })
]}),
new Paragraph({ spacing: { before: 60, after: 120 }, children: [
new TextRun({ text: "The recording lasted about ", size: 22, font: "Arial" }),
new TextRun({ text: "6 hours and 19 minutes", bold: true, size: 22, font: "Arial" }),
new TextRun({ text: " (from 9:23 PM to 3:42 AM).", size: 22, font: "Arial" })
]}),
// ============================================================
// OVERALL RESULT
// ============================================================
sectionBar("Overall Result: Moderate Sleep Apnea Detected", RED),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "The device placed Tariq's result in the ", size: 22, font: "Arial" }),
new TextRun({ text: "red zone", bold: true, color: RED, size: 22, font: "Arial" }),
new TextRun({ text: ' -- labelled "Suspected Pathological Breathing Disorder" with a score of 21. This means he has a real and medically significant sleep breathing problem that needs attention.', size: 22, font: "Arial" })
]}),
// Risk bar visual table
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [new TableRow({ children: [
shadedCell("Normal Range (0-5)", "27AE60", WHITE, true, 35),
shadedCell("Mild (5-15)", "F39C12", WHITE, true, 25),
shadedCell("Moderate (15-29)", "E74C3C", WHITE, true, 25),
shadedCell("TARIQ: Score 21 >>>", "922B21", WHITE, true, 15),
]})]
}),
new Paragraph({ spacing: { before: 80, after: 160 }, children: [
new TextRun({ text: "His score of 21 places him squarely in the moderate category.", italics: true, size: 20, color: "666666", font: "Arial" })
]}),
// ============================================================
// WHAT IS SLEEP APNEA?
// ============================================================
sectionBar("What Is Sleep Apnea?", BLUE),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "Sleep apnea means the airway ", size: 22, font: "Arial" }),
new TextRun({ text: "repeatedly blocks or collapses during sleep", bold: true, size: 22, font: "Arial" }),
new TextRun({ text: ". Each time this happens, breathing stops for 10 seconds or longer. The brain briefly wakes the body to restart breathing -- often without the person knowing. This can happen dozens of times per hour.", size: 22, font: "Arial" })
]}),
new Paragraph({ spacing: { before: 60, after: 80 }, children: [
new TextRun({ text: "The result is: broken, poor-quality sleep, and dangerously low oxygen levels.", bold: true, size: 22, font: "Arial" })
]}),
// ============================================================
// KEY NUMBERS EXPLAINED
// ============================================================
sectionBar("Key Numbers Explained", BLUE),
new Paragraph({ spacing: { before: 120, after: 60 }, children: [
new TextRun({ text: "AHI (Apnea-Hypopnea Index) = 20 per hour", bold: true, size: 24, font: "Arial" })
]}),
para("This is the most important number. It counts how many times per hour breathing stopped or became very shallow. Tariq stopped breathing or nearly stopped 20 times every hour of sleep.", { before: 60, after: 60 }),
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({ children: [
shadedCell("AHI Range", "1A5276", WHITE, true, 40),
shadedCell("What It Means", "1A5276", WHITE, true, 35),
shadedCell("Tariq's Status", "1A5276", WHITE, true, 25),
]}),
new TableRow({ children: [
shadedCell("0 - 4", GREEN, WHITE, false, 40),
shadedCell("Normal", GREEN, WHITE, false, 35),
shadedCell("", GREEN, WHITE, false, 25),
]}),
new TableRow({ children: [
shadedCell("5 - 14", "F39C12", WHITE, false, 40),
shadedCell("Mild Sleep Apnea", "F39C12", WHITE, false, 35),
shadedCell("", "F39C12", WHITE, false, 25),
]}),
new TableRow({ children: [
shadedCell("15 - 29", "E74C3C", WHITE, false, 40),
shadedCell("Moderate Sleep Apnea", "E74C3C", WHITE, false, 35),
shadedCell("Tariq = 20", "E74C3C", WHITE, true, 25),
]}),
new TableRow({ children: [
shadedCell("30+", "922B21", WHITE, false, 40),
shadedCell("Severe Sleep Apnea", "922B21", WHITE, false, 35),
shadedCell("", "922B21", WHITE, false, 25),
]}),
]
}),
new Paragraph({ spacing: { before: 120, after: 60 }, children: [
new TextRun({ text: "Types of Breathing Pauses Detected", bold: true, size: 24, font: "Arial" })
]}),
para("Out of 44 total apneas (complete pauses) and 70 hypopneas (shallow breaths):"),
bullet(" 36 events (82%) -- Obstructive: the throat physically blocked.", "Obstructive Apneas:"),
bullet(" 6 events (14%) -- Central: the brain briefly failed to send the signal to breathe.", "Central Apneas:"),
bullet(" 2 events (5%) -- Mixed: a combination of both.", "Mixed Apneas:"),
para("The majority are obstructive, which is the most common and most treatable type.", { before: 80, after: 120, italic: true, color: "555555" }),
// ============================================================
// OXYGEN LEVELS - THE MOST URGENT FINDING
// ============================================================
sectionBar("Oxygen Levels During Sleep -- The Most Urgent Finding", RED),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "This is the most worrying part of the report.", bold: true, color: RED, size: 22, font: "Arial" })
]}),
para("When we breathe normally, the blood oxygen level (SpO2) should stay between 95-100%. When breathing stops, oxygen falls. Here is what happened with Tariq:"),
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({ children: [
shadedCell("Measurement", BLUE, WHITE, true, 45),
shadedCell("Tariq's Result", BLUE, WHITE, true, 30),
shadedCell("Normal", BLUE, WHITE, true, 25),
]}),
new TableRow({ children: [
shadedCell("Average oxygen all night", LGREY, "000000", false, 45),
shadedCell("90%", ORANGE, WHITE, true, 30),
shadedCell("95% - 100%", GREEN, WHITE, false, 25),
]}),
new TableRow({ children: [
shadedCell("Lowest oxygen recorded", LGREY, "000000", false, 45),
shadedCell("81%", "C0392B", WHITE, true, 30),
shadedCell("> 90%", GREEN, WHITE, false, 25),
]}),
new TableRow({ children: [
shadedCell("Time below 90% oxygen", LGREY, "000000", false, 45),
shadedCell("220 minutes (60% of the night)", "C0392B", WHITE, true, 30),
shadedCell("< 1 minute", GREEN, WHITE, false, 25),
]}),
new TableRow({ children: [
shadedCell("Baseline oxygen (awake)", LGREY, "000000", false, 45),
shadedCell("93%", ORANGE, WHITE, true, 30),
shadedCell("> 95%", GREEN, WHITE, false, 25),
]}),
]
}),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "Tariq spent ", size: 22, font: "Arial" }),
new TextRun({ text: "more than half the night with dangerously low oxygen", bold: true, color: RED, size: 22, font: "Arial" }),
new TextRun({ text: ". An oxygen level of 81% is significantly below safe levels and puts stress on the heart and brain.", size: 22, font: "Arial" })
]}),
// ============================================================
// WHAT HAPPENS IF UNTREATED
// ============================================================
sectionBar("Why This Needs to Be Treated", ORANGE),
para("Moderate sleep apnea with the level of oxygen drops seen here, if left untreated, increases risk for:"),
bullet("High blood pressure (Tariq already has this)", ""),
bullet("Heart disease and irregular heart rhythms", ""),
bullet("Worsening of diabetes (also already listed in his report)", ""),
bullet("Stroke", ""),
bullet("Severe daytime sleepiness and fatigue", ""),
bullet("Poor memory and concentration", ""),
bullet("Depression and mood changes", ""),
new Paragraph({ spacing: { before: 80, after: 120 }, children: [
new TextRun({ text: "The good news: ", bold: true, size: 22, font: "Arial", color: GREEN }),
new TextRun({ text: "This condition is very treatable. With proper treatment, most people feel significantly better and reduce their health risks.", size: 22, font: "Arial" })
]}),
// ============================================================
// TREATMENT
// ============================================================
sectionBar("Treatment -- What Comes Next", GREEN),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "Step 1: See a Sleep Specialist", bold: true, size: 24, font: "Arial", color: BLUE })
]}),
para("The report itself recommends referral to a sleep specialist for a full diagnostic sleep study (polysomnography). This is the proper next step to confirm the diagnosis and decide on treatment."),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "Step 2: CPAP Therapy (Most Likely Treatment)", bold: true, size: 24, font: "Arial", color: BLUE })
]}),
para("For moderate OSA, the standard and most effective treatment is CPAP (Continuous Positive Airway Pressure). It is a small bedside device that sends gentle air pressure through a mask to keep the airway open during sleep."),
bullet("Not painful or dangerous", ""),
bullet("Most people feel dramatically better within days of starting", ""),
bullet("Raises blood oxygen back to normal levels", ""),
bullet("Reduces strain on the heart", ""),
new Paragraph({ spacing: { before: 100, after: 80 }, children: [
new TextRun({ text: "Step 3: Lifestyle Support", bold: true, size: 24, font: "Arial", color: BLUE })
]}),
bullet("Weight loss even by a small amount (5-10 kg) can significantly reduce OSA severity", ""),
bullet("Avoid sleeping flat on the back -- sleeping on the side helps", ""),
bullet("Avoid alcohol especially in the evenings", ""),
bullet("Keep blood pressure and diabetes well controlled", ""),
// ============================================================
// SUMMARY BOX
// ============================================================
new Paragraph({ spacing: { before: 200, after: 80 }, children: [] }),
sectionBar("Summary in Simple Terms", BLUE),
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [new TableRow({ children: [
new TableCell({
shading: { type: ShadingType.CLEAR, fill: "EBF5FB" },
borders: {
top: { style: BorderStyle.SINGLE, size: 4, color: BLUE },
bottom: { style: BorderStyle.SINGLE, size: 4, color: BLUE },
left: { style: BorderStyle.SINGLE, size: 4, color: BLUE },
right: { style: BorderStyle.SINGLE, size: 4, color: BLUE }
},
children: [
new Paragraph({ spacing: { before: 120, after: 80 }, children: [
new TextRun({ text: "Tariq's breathing stopped or became very shallow about 20 times every hour during sleep.", size: 22, font: "Arial" })
]}),
new Paragraph({ spacing: { before: 80, after: 80 }, children: [
new TextRun({ text: "His blood oxygen dropped to as low as 81% and stayed dangerously low for more than half the night.", bold: true, size: 22, font: "Arial", color: RED })
]}),
new Paragraph({ spacing: { before: 80, after: 80 }, children: [
new TextRun({ text: "This is called Moderate Obstructive Sleep Apnea. It is a real medical condition that needs treatment.", size: 22, font: "Arial" })
]}),
new Paragraph({ spacing: { before: 80, after: 120 }, children: [
new TextRun({ text: "The most important action right now is to book an appointment with a doctor or sleep specialist as soon as possible.", bold: true, size: 22, font: "Arial", color: GREEN })
]}),
]
})
]})]
}),
// Disclaimer
new Paragraph({ spacing: { before: 240, after: 60 }, children: [
new TextRun({ text: "Note: ", bold: true, size: 18, font: "Arial", color: "888888" }),
new TextRun({ text: "This summary is based on a home sleep screening device (ResMed ApneaLink, recorded 10 June 2026). Home sleep tests do not replace a full overnight sleep study. The findings must be reviewed and confirmed by a qualified physician before any treatment is started.", size: 18, font: "Arial", color: "888888", italics: true })
]}),
]
}]
});
Packer.toBuffer(doc).then(buffer => {
fs.writeFileSync('/home/daytona/workspace/sleep-report/Sleep_Study_Summary_Tariq.docx', buffer);
console.log('Document created successfully.');
}).catch(err => {
console.error('Error:', err);
process.exit(1);
});
cd /home/daytona/workspace/sleep-report && node create_summary.js
python /home/daytona/skills/docx/scripts/office/validate.py /home/daytona/workspace/sleep-report/Sleep_Study_Summary_Tariq.docx
python3 -c "import zipfile; z = zipfile.ZipFile('/home/daytona/workspace/sleep-report/Sleep_Study_Summary_Tariq.docx'); print('Valid ZIP. Files:', z.namelist()[:8])"
Sleep Study Summary Tariq
Word Document · DOCX