Make proper notes of what I have written exactly but more systematic

Reading File
Running Command

cd /home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/ && python3 -c " import pdfplumber with pdfplumber.open('Examination of newborn.pdf') as pdf: print(f'Total pages: {len(pdf.pages)}') for i, page in enumerate(pdf.pages): text = page.extract_text() print(f'--- PAGE {i+1} ---') print(text) print() "

Running Command

cd /home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/ && python3 -c " import pytesseract from pdf2image import convert_from_path from PIL import Image pages = convert_from_path('Examination of newborn.pdf', dpi=200) print(f'Total pages: {len(pages)}') for i, page in enumerate(pages): text = pytesseract.image_to_string(page) print(f'--- PAGE {i+1} ---') print(text) print() " 2>&1 | head -300

Running Command

cd /home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/ && python3 -c " from pdf2image import convert_from_path pages = convert_from_path('Examination of newborn.pdf', dpi=200) for i, page in enumerate(pages): page.save(f'/home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/page_{i+1}.png') print(f'Saved page {i+1}') "

Reading File
Reading File
Reading File
Reading File
Reading File
Reading File
Running Command

ls /home/daytona/workspace/

Running Command

mkdir -p /home/daytona/workspace/newborn-exam-notes

Writing File

~/newborn-exam-notes/create_notes.js

const {
  Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
  HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
  VerticalAlign, UnderlineType
} = require('docx');
const fs = require('fs');

// ── helpers ────────────────────────────────────────────────────────────────
const heading1 = (text) => new Paragraph({
  text,
  heading: HeadingLevel.HEADING_1,
  spacing: { before: 300, after: 100 },
});

const heading2 = (text) => new Paragraph({
  text,
  heading: HeadingLevel.HEADING_2,
  spacing: { before: 200, after: 80 },
});

const heading3 = (text) => new Paragraph({
  text,
  heading: HeadingLevel.HEADING_3,
  spacing: { before: 160, after: 60 },
});

const bullet = (text, level = 0) => new Paragraph({
  children: [new TextRun({ text, size: 22 })],
  bullet: { level },
  spacing: { before: 40, after: 40 },
});

const subBullet = (text) => bullet(text, 1);

const para = (text, bold = false) => new Paragraph({
  children: [new TextRun({ text, bold, size: 22 })],
  spacing: { before: 60, after: 60 },
});

const note = (label, value) => new Paragraph({
  children: [
    new TextRun({ text: label + ': ', bold: true, size: 22 }),
    new TextRun({ text: value, size: 22 }),
  ],
  spacing: { before: 40, after: 40 },
  indent: { left: 360 },
});

const divider = () => new Paragraph({
  children: [new TextRun({ text: '', size: 22 })],
  border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: 'AAAAAA' } },
  spacing: { before: 160, after: 160 },
});

// ── comparison table: Caput Succedaneum vs Cephalhaematoma ─────────────────
const compTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    new TableRow({
      tableHeader: true,
      children: [
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Feature', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
          verticalAlign: VerticalAlign.CENTER,
        }),
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Caput Succedaneum', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
          verticalAlign: VerticalAlign.CENTER,
        }),
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Cephalhaematoma', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
          verticalAlign: VerticalAlign.CENTER,
        }),
      ],
    }),
    // Row 1
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Location relative to periosteum', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Above periosteum (subgaleal)', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Below periosteum (subperiosteal)', size: 22 })] })] }),
      ],
    }),
    // Row 2
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Crosses suture lines?', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Yes', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'No (confined to one bone)', size: 22 })] })] }),
      ],
    }),
    // Row 3
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Onset', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Present at birth', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Hours after birth', size: 22 })] })] }),
      ],
    }),
    // Row 4
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Resolution', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Days', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Weeks–months; may calcify', size: 22 })] })] }),
      ],
    }),
    // Row 5
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Jaundice risk', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Low', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Yes (blood reabsorption)', size: 22 })] })] }),
      ],
    }),
  ],
});

// ── jaundice table ─────────────────────────────────────────────────────────
const jaundiceTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    new TableRow({
      tableHeader: true,
      children: [
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Type', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
        }),
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Bilirubin Level (term)', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
        }),
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Bilirubin Level (pre-term)', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
        }),
        new TableCell({
          children: [new Paragraph({ children: [new TextRun({ text: 'Timing / Notes', bold: true, size: 22, color: 'FFFFFF' })] })],
          shading: { fill: '2E74B5', type: ShadingType.CLEAR },
        }),
      ],
    }),
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Mild (icteric)', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '5 mg/dL', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '-', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '', size: 22 })] })] }),
      ],
    }),
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Moderate', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '15 mg/dL', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '-', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '', size: 22 })] })] }),
      ],
    }),
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Complete/Severe', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '25 mg/dL', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '-', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '', size: 22 })] })] }),
      ],
    }),
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Physiologic', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '≤12 mg/dL', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '≤15 mg/dL', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Appears after 24 hrs; resolves before 7 days', size: 22 })] })] }),
      ],
    }),
    new TableRow({
      children: [
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Pathologic', size: 22, bold: true, color: 'C00000' })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '>15 mg/dL', size: 22, bold: true, color: 'C00000' })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: '-', size: 22 })] })] }),
        new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Appears within 24 hrs of birth', size: 22, bold: true, color: 'C00000' })] })] }),
      ],
    }),
  ],
});

// ── document ───────────────────────────────────────────────────────────────
const doc = new Document({
  styles: {
    paragraphStyles: [
      {
        id: 'Heading1',
        name: 'Heading 1',
        run: { bold: true, size: 32, color: '1F3864' },
        paragraph: { spacing: { before: 300, after: 120 } },
      },
      {
        id: 'Heading2',
        name: 'Heading 2',
        run: { bold: true, size: 26, color: '2E74B5' },
        paragraph: { spacing: { before: 200, after: 80 } },
      },
      {
        id: 'Heading3',
        name: 'Heading 3',
        run: { bold: true, size: 22, color: '2E74B5' },
        paragraph: { spacing: { before: 160, after: 60 } },
      },
    ],
  },
  sections: [
    {
      children: [

        // ── TITLE ──────────────────────────────────────────────────────────
        new Paragraph({
          children: [new TextRun({ text: 'Examination of the Newborn', bold: true, size: 40, color: '1F3864' })],
          alignment: AlignmentType.CENTER,
          spacing: { before: 0, after: 200 },
        }),
        new Paragraph({
          children: [new TextRun({ text: 'Systematic Clinical Notes', size: 24, color: '595959', italics: true })],
          alignment: AlignmentType.CENTER,
          spacing: { before: 0, after: 400 },
        }),

        // ── SECTION A: PHYSICAL EXAMINATION ───────────────────────────────
        heading1('A. Physical Examination (Head-to-Toe)'),

        // 1. HEAD
        heading2('1. Head'),
        heading3('Diff: Caput Succedaneum vs Cephalhaematoma'),
        new Paragraph({ children: [new TextRun({ text: '', size: 22 })], spacing: { before: 60, after: 60 } }),
        compTable,
        new Paragraph({ children: [new TextRun({ text: '', size: 22 })], spacing: { before: 100, after: 60 } }),
        note('Jaundice test', 'Cephalhaematoma carries higher jaundice risk due to blood reabsorption'),

        divider(),

        // 2. EYE
        heading2('2. Eye'),
        bullet('Epicanthic fold - assess for Down syndrome or other dysmorphic features'),
        bullet('Color - note scleral color (jaundice = yellow, anemia = pale)'),

        divider(),

        // 3. EAR
        heading2('3. Ear'),
        bullet('Inspect position, shape, and any pre-auricular tags or sinuses'),

        divider(),

        // 4. NECK
        heading2('4. Neck'),
        bullet('Swelling'),
        subBullet('Tumor (e.g. sternomastoid tumor / fibromatosis colli)'),
        subBullet('Thyroglossal cyst - midline, moves with swallowing and tongue protrusion'),
        bullet('Cystic hygroma (lymphatic malformation) - POST side - requires surgical management'),
        bullet('Webbing of neck - associated with Turner syndrome'),

        divider(),

        // 5. CHEST
        heading2('5. Chest'),
        bullet('Symmetry - assess for collapse'),
        bullet('Intercostal (IC) recession - sign of respiratory distress'),
        para('Auscultation:', true),
        subBullet('Heart sounds: normal HR = 110-170 bpm'),
        subBullet('Lung sounds: RR > 60 = tachypnoea'),

        divider(),

        // 6. ABDOMEN
        heading2('6. Abdomen'),
        bullet('Umbilical swelling'),
        bullet('Umbilical hernia'),
        bullet('Liver enlargement (hepatomegaly)'),
        bullet('Gastroschisis - deficiency / defect of abdominal wall'),

        divider(),

        // 7. GENITALIA
        heading2('7. Genitalia'),
        para('Male (♂):', true),
        subBullet('Scrotum - inspect for undescended testes'),
        subBullet('Penis - inspect for hypospadias / epispadias'),
        para('Female (♀):', true),
        subBullet('Labia minora'),
        subBullet('Labia majora - enlarged in adrenal hyperplasia (congenital adrenal hyperplasia / CAH)'),

        divider(),

        // 8. FINGERS, LIMBS, TOES & BONES
        heading2('8. Fingers, Limbs, Toes & Bones'),
        bullet('Fingers - count digits; check for polydactyly / syndactyly'),
        bullet('Toes - inspect similarly'),
        bullet('Bones - assess tone and symmetry'),
        bullet('Talipes equinovarus (club foot) - deformity of the feet'),

        divider(),

        // ── SECTION B: POST EXAMINATION FINDINGS ──────────────────────────
        heading1('B. POST Examination Findings'),

        heading2('Head'),
        bullet('Hydrocephalus - requires surgery / shunt'),
        bullet('Anencephalus - incompatible with life; leads to termination of pregnancy (TOP)'),

        heading2('Neck'),
        bullet('Cystic hygroma'),
        bullet('Webbing of neck (pterygium colli) - associated with Turner syndrome'),

        heading2('Back'),
        bullet('Spinal cord defects:'),
        subBullet('Spina bifida open - cord visualized externally (myelomeningocele)'),
        subBullet('Spina bifida closed - skin-covered; no need for termination of pregnancy'),

        divider(),

        // ── SECTION C: AFTER EXAMINATION ──────────────────────────────────
        heading1('C. After Examination'),
        bullet('Advise mother to breastfeed (BF) within 30 minutes of delivery'),

        heading2('Reflexes'),
        bullet('Rooting reflex'),
        bullet('Sucking reflex'),
        bullet('Grasping reflex'),
        bullet('Moro reflex'),

        divider(),

        // ── SECTION D: ASSESS B/F (BREASTFEEDING) ─────────────────────────
        heading1('D. Assess Breastfeeding (B/F)'),

        heading2('1. Urine Output'),
        bullet('Normal: >5 times/24 hours'),

        heading2('2. Dehydration'),
        bullet('Sign: Anterior fontanelle - depressed'),

        heading2('3. Abdomen'),
        bullet('Liver enlarged (hepatomegaly) OR normal'),
        bullet('Bulging hypochondrium - suggests IUGR'),
        bullet('Depressed hypochondrium'),
        bullet('Scaphoid abdomen'),

        divider(),

        // ── SECTION E: MECONIUM ────────────────────────────────────────────
        heading1('E. Meconium'),
        bullet('Meconium passed in-utero = sign of fetal distress'),
        bullet('Causes:'),
        subBullet('Fetal hypoxia'),
        subBullet('Fetal asphyxia'),
        subBullet('Birth asphyxia (BA)'),

        divider(),

        // ── SECTION F: JAUNDICE ────────────────────────────────────────────
        heading1('F. Jaundice (Neonatal Hyperbilirubinaemia)'),
        new Paragraph({ children: [new TextRun({ text: '', size: 22 })], spacing: { before: 60, after: 60 } }),
        jaundiceTable,
        new Paragraph({ children: [new TextRun({ text: '', size: 22 })], spacing: { before: 100, after: 60 } }),

        divider(),

        // ── SECTION G: UMBILICAL SEPSIS ───────────────────────────────────
        heading1('G. Umbilical Sepsis (Omphalitis)'),
        new Paragraph({
          children: [
            new TextRun({ text: '1st sign: ', bold: true, size: 22, color: 'C00000' }),
            new TextRun({ text: 'Reluctant to feed', size: 22, color: 'C00000', italics: true }),
          ],
          spacing: { before: 60, after: 60 },
        }),

        heading2('Clinical Features'),
        bullet('Red / erythematous umbilicus'),
        bullet('Swollen / oedematous'),
        bullet('Foul-smelling discharge'),

        heading2('Complication'),
        bullet('Critical: infection tracks via umbilical vein'),
        subBullet('→ Portal circulation → Liver abscess'),

        heading2('Management'),
        bullet('Immediate Rx: Broad-spectrum antibiotics'),
        bullet('Prophylaxis: Chlorhexidine application right after delivery'),

      ],
    },
  ],
});

Packer.toBuffer(doc).then((buffer) => {
  fs.writeFileSync('/home/daytona/workspace/newborn-exam-notes/Examination_of_Newborn_Notes.docx', buffer);
  console.log('Done!');
}).catch(err => {
  console.error('Error:', err);
  process.exit(1);
});
Running Command

cd /home/daytona/workspace/newborn-exam-notes && node create_notes.js 2>&1

Running Command

python3 /home/daytona/skills/docx/scripts/office/validate.py /home/daytona/workspace/newborn-exam-notes/Examination_of_Newborn_Notes.docx 2>&1

Running Command

python3 -c " from zipfile import ZipFile z = ZipFile('/home/daytona/workspace/newborn-exam-notes/Examination_of_Newborn_Notes.docx') print('Files in docx:', z.namelist()[:10]) # Quick sanity check - read document.xml content = z.read('word/document.xml').decode('utf-8') print('document.xml length:', len(content)) print('First 200 chars:', content[:200]) "

The document is valid and well-formed. Here are your organized notes:

Examination of Newborn Notes

Word Document · DOCX


Here is a summary of everything captured from your notes, now systematically structured:

Examination of the Newborn - Organized Notes

A. Physical Examination (Head-to-Toe)

1. Head - Diff: Caput Succedaneum vs Cephalhaematoma
FeatureCaput SuccedaneumCephalhaematoma
LocationAbove periosteumBelow periosteum
Crosses suture lines?YesNo
OnsetAt birthHours after birth
ResolutionDaysWeeks-months
Jaundice riskLowYes (blood reabsorption)
2. Eye - Epicanthic fold; Color
3. Ear - Position, shape, pre-auricular tags
4. Neck - Swelling: tumor / thyroglossal cyst; Cystic hygroma (POST - surgical); Webbing of neck (Turner syndrome)
5. Chest - Symmetry, IC recession; Heart: 110-170 bpm; Lungs: RR >60 = tachypnoea
6. Abdomen - Umbilical swelling, umbilical hernia, liver enlargement, gastroschisis (abdominal wall defect)
7. Genitalia - Male: scrotum, penis; Female: labia minora, labia majora (enlarged in adrenal hyperplasia)
8. Fingers, Limbs, Toes & Bones - Count digits; Talipes equinovarus (club foot)

B. POST Examination Findings

  • Head: Hydrocephalus (surgery/shunt); Anencephalus (TOP)
  • Neck: Cystic hygroma; Webbing of neck
  • Back: Spina bifida open (cord visualized) / closed (skin-covered, no TOP needed)

C. After Examination

  • Advise mother to breastfeed within 30 minutes
  • Reflexes: Rooting, Sucking, Grasping, Moro

D. Assess Breastfeeding

  1. Urine output >5 times/24 hrs = normal
  2. Dehydration - anterior fontanelle depressed
  3. Abdomen - liver enlarged/normal; bulging hypochondrium (IUGR); scaphoid abdomen

E. Meconium

  • Passed in-utero = fetal distress
  • Causes: fetal hypoxia, fetal asphyxia, birth asphyxia

F. Jaundice

TypeTermPre-termTiming
Physiologic≤12 mg/dL≤15 mg/dLAfter 24 hrs; resolves before 7 days
Pathologic>15 mg/dL-Within 24 hrs of birth
Mild (icteric)5 mg/dL-
Moderate15 mg/dL-
Complete/severe25 mg/dL-

G. Umbilical Sepsis (Omphalitis)

  • 1st sign: Reluctant to feed
  • Features: red, swollen, foul-smelling
  • Complication: umbilical vein → portal circulation → liver abscess
  • Rx: immediate broad-spectrum antibiotics
  • Prophylaxis: Chlorhexidine right after delivery

Do the same for this also...along with wherever diagram and pic and flowchart is necessary

Running Command

cd /home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/ && python3 -c " from pdf2image import convert_from_path pages = convert_from_path('downloadfile(7).PDF', dpi=200) print(f'Total pages: {len(pages)}') for i, page in enumerate(pages): page.save(f'/home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/new_page_{i+1}.png') print(f'Saved page {i+1}') "

Reading File
Reading File
Running Command

cd /home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/ && python3 -c " from pdf2image import convert_from_path from PIL import Image pages = convert_from_path('downloadfile(7).PDF', dpi=120) for i, page in enumerate(pages): page = page.convert('RGB') page.save(f'/home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/new_sm_{i+1}.jpg', 'JPEG', quality=70) import os sz = os.path.getsize(f'/home/daytona/workspace/attachments/1de93b3d-ba62-44c8-909d-b3d799ba6d71/new_sm_{i+1}.jpg') print(f'Page {i+1}: {sz} bytes') "

Reading File
Reading File
Reading File
Reading File
Reading File
Writing File

~/newborn-exam-notes/create_anaemia_notes.js

const {
  Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
  HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
  VerticalAlign, PageBreak
} = require('docx');
const fs = require('fs');

// ── helpers ────────────────────────────────────────────────────────────────
const BLUE  = '1F3864';
const MID   = '2E74B5';
const RED   = 'C00000';
const GREEN = '375623';
const GREY  = '595959';
const LBLUE = 'D6E4F0';
const LRED  = 'FADADD';
const LYELL = 'FFF9C4';
const LGREY = 'F2F2F2';
const WHITE = 'FFFFFF';

const h1 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 32, color: BLUE })],
  heading: HeadingLevel.HEADING_1,
  spacing: { before: 320, after: 120 },
  border: { bottom: { style: BorderStyle.SINGLE, size: 8, color: MID } },
});

const h2 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 26, color: MID })],
  heading: HeadingLevel.HEADING_2,
  spacing: { before: 220, after: 80 },
});

const h3 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 22, color: GREEN })],
  heading: HeadingLevel.HEADING_3,
  spacing: { before: 160, after: 60 },
});

const bullet = (text, level = 0, color = '000000') => new Paragraph({
  children: [new TextRun({ text, size: 22, color })],
  bullet: { level },
  spacing: { before: 40, after: 40 },
});

const subBullet = (text, color) => bullet(text, 1, color);

const para = (runs) => new Paragraph({
  children: runs,
  spacing: { before: 60, after: 60 },
});

const bold = (text, color = '000000', size = 22) =>
  new TextRun({ text, bold: true, color, size });

const normal = (text, color = '000000', size = 22) =>
  new TextRun({ text, color, size });

const italic = (text, color = GREY) =>
  new TextRun({ text, italics: true, color, size: 22 });

const spacer = () => new Paragraph({ children: [new TextRun('')], spacing: { before: 80, after: 80 } });

const divider = () => new Paragraph({
  children: [new TextRun({ text: '' })],
  border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: 'CCCCCC' } },
  spacing: { before: 160, after: 160 },
});

// ── cell helpers ───────────────────────────────────────────────────────────
const hdrCell = (text, fill = MID) => new TableCell({
  children: [new Paragraph({ children: [new TextRun({ text, bold: true, size: 22, color: WHITE })] })],
  shading: { fill, type: ShadingType.CLEAR },
  verticalAlign: VerticalAlign.CENTER,
});

const dataCell = (text, fill = WHITE, color = '000000', bold_ = false) => new TableCell({
  children: [new Paragraph({ children: [new TextRun({ text, bold: bold_, size: 22, color })] })],
  shading: { fill, type: ShadingType.CLEAR },
  verticalAlign: VerticalAlign.CENTER,
});

const hdrRow = (...labels) => new TableRow({
  tableHeader: true,
  children: labels.map(l => hdrCell(l)),
});

// ── FLOWCHART as shaded box ─────────────────────────────────────────────────
// We simulate flowcharts with indented shaded text blocks
const flowBox = (text, fill = LBLUE, color = BLUE, bold_ = true) => new Paragraph({
  children: [new TextRun({ text, bold: bold_, size: 22, color })],
  shading: { fill, type: ShadingType.CLEAR },
  alignment: AlignmentType.CENTER,
  spacing: { before: 60, after: 0 },
  border: {
    top: { style: BorderStyle.SINGLE, size: 6, color: MID },
    bottom: { style: BorderStyle.SINGLE, size: 6, color: MID },
    left: { style: BorderStyle.SINGLE, size: 6, color: MID },
    right: { style: BorderStyle.SINGLE, size: 6, color: MID },
  },
});

const arrow = (text = '▼') => new Paragraph({
  children: [new TextRun({ text, size: 22, color: GREY })],
  alignment: AlignmentType.CENTER,
  spacing: { before: 0, after: 0 },
});

// ── CLASSIFICATION TABLE: Related to Cause ─────────────────────────────────
const causeClassTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Category', 'Sub-type', 'Investigation'),
    new TableRow({ children: [
      dataCell('A. Marrow Problem', LBLUE, BLUE, true),
      dataCell('(1) Fe / B12 / Folate / Erythropoietin deficiency\n(Nutritional)', LGREY),
      dataCell('CBC, PBF', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('', LBLUE),
      dataCell('(2) Aplasia / Hypoplasia / Myelodysplasia\n→ Aplastic (e.g. Parvovirus B19)', LGREY),
      dataCell('Bone Marrow, PBF', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('', LBLUE),
      dataCell('(3) Infiltration', LGREY),
      dataCell('CBC, PBF, BM', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('B. Peripheral Removal', LRED, RED, true),
      dataCell('→ Blood loss (History)\n→ Haemolysis\n→ Hypersplenism / SLE', LRED),
      dataCell('History, PBF, Haemolysis markers', LRED),
    ]}),
  ],
});

// ── CLASSIFICATION TABLE: Morphological ────────────────────────────────────
const morphClassTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Morphology', 'MCV', 'MCH', 'MCHC', 'Cause / Notes'),
    new TableRow({ children: [
      dataCell('Microcytic Hypochromic', LRED, RED, true),
      dataCell('↓ Low', LRED),
      dataCell('↓ Low', LRED),
      dataCell('↓↓ Low', LRED),
      dataCell('Fe deficiency\nThalassaemia\nSideroblastic\nChronic disease', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Normocytic Normochromic', LGREY, '000000', true),
      dataCell('Normal', LGREY),
      dataCell('Normal', LGREY),
      dataCell('Normal', LGREY),
      dataCell('Haemolysis\nBleeding\nChronic inflammation / infection\nRenal failure', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Macrocytic / Megaloblastic', LYELL, '5C4000', true),
      dataCell('↑↑ High', LYELL),
      dataCell('↑ High', LYELL),
      dataCell('Normal', LYELL),
      dataCell('Defective haemoglobinisation\nVit B12 / Folate deficiency\n→ Cytoplasmic problem\n→ DNA defect (nuclear)\n→ Fewer cell divisions', LYELL),
    ]}),
  ],
});

// ── CBC INDICES TABLE ───────────────────────────────────────────────────────
const cbcTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Index', 'Stands For', 'What It Measures', 'Clinical Relevance'),
    new TableRow({ children: [
      dataCell('MCH', LBLUE, BLUE, true),
      dataCell('Mean Corpuscular Haemoglobin', LBLUE),
      dataCell('Amount of Hb in each RBC', LBLUE),
      dataCell('Correlates with colour of RBC', LBLUE),
    ]}),
    new TableRow({ children: [
      dataCell('MCHC', LGREY, GREEN, true),
      dataCell('Mean Corpuscular Hb Concentration', LGREY),
      dataCell('Density / colour / concentration of Hb', LGREY),
      dataCell('Best index for hypochromia', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('MCV', LRED, RED, true),
      dataCell('Mean Corpuscular Volume', LRED),
      dataCell('Size of RBC', LRED),
      dataCell('↑ macrocytic; ↓ microcytic', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('RDW', LYELL, '5C4000', true),
      dataCell('Red cell Distribution Width', LYELL),
      dataCell('Variation in RBC size', LYELL),
      dataCell('Normal: 11.5–14.5%; ↑ in Fe def, mixed deficiency', LYELL),
    ]}),
  ],
});

// ── IRON DEFICIENCY vs THALASSAEMIA TABLE ──────────────────────────────────
const feVsThalTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Feature', 'Iron Deficiency Anaemia', 'β-Thalassaemia'),
    new TableRow({ children: [
      dataCell('Hb', LGREY),
      dataCell('Low (e.g. 9.0)', LGREY),
      dataCell('Low (e.g. 9.0)', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('RBC count', LRED),
      dataCell('↓ Low (~3)', LRED),
      dataCell('↑ High (late stage; may ↑ due to ineffective erythropoiesis)', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('MCH', LBLUE),
      dataCell('↓ Low', LBLUE),
      dataCell('↓ Low', LBLUE),
    ]}),
    new TableRow({ children: [
      dataCell('MCHC', LGREY),
      dataCell('↓↓ Very low', LGREY),
      dataCell('↓ Low', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Target cells', LRED),
      dataCell('Absent / rare', LRED),
      dataCell('Present (thin cells that "miss" Hb - heme + globin deficit)', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('RDW', LBLUE),
      dataCell('↑ Increased', LBLUE),
      dataCell('Normal or mildly ↑', LBLUE),
    ]}),
    new TableRow({ children: [
      dataCell('Mentzer Index', LGREY),
      dataCell('>13 → Fe def', LGREY),
      dataCell('<13 → Thalassaemia', LGREY),
    ]}),
  ],
});

// ── NORMOCYTIC CAUSES TABLE ─────────────────────────────────────────────────
const normocyticTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Cause', 'Hb', 'MCV / NCU', 'MCH / MCHC', 'Key Finding'),
    new TableRow({ children: [
      dataCell('Haemolysis', LRED, RED, true),
      dataCell('↓ 8', LRED),
      dataCell('NCU (Normal)', LRED),
      dataCell('Normal', LRED),
      dataCell('↑ Reticulocytes\nHaemolysis markers\nUnconjugated bilirubin ↑', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Bleeding (acute)', LGREY, '000000', true),
      dataCell('↓', LGREY),
      dataCell('Normal', LGREY),
      dataCell('Normal', LGREY),
      dataCell('History of blood loss\nNormal MCV early', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Chronic inf / Inflammation', LYELL, '5C4000', true),
      dataCell('↓', LYELL),
      dataCell('Normal / slightly ↓', LYELL),
      dataCell('Normal / slightly ↓', LYELL),
      dataCell('Reticulocyte normal or low', LYELL),
    ]}),
    new TableRow({ children: [
      dataCell('Renal failure', LBLUE, BLUE, true),
      dataCell('↓', LBLUE),
      dataCell('Normal', LBLUE),
      dataCell('Normal', LBLUE),
      dataCell('↓ Erythropoietin; reticulocyte ↓', LBLUE),
    ]}),
  ],
});

// ── INVESTIGATIONS TABLE ────────────────────────────────────────────────────
const invTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Investigation', 'Abbreviation', 'What It Shows'),
    new TableRow({ children: [
      dataCell('Complete Blood Count', LBLUE, BLUE, true),
      dataCell('CBC', LBLUE),
      dataCell('Hb, RBC, WBC, Platelet, indices (MCV/MCH/MCHC/RDW)', LBLUE),
    ]}),
    new TableRow({ children: [
      dataCell('Peripheral Blood Film', LGREY, '000000', true),
      dataCell('PBF', LGREY),
      dataCell('RBC morphology - reticulocytes, target cells, sickle cells', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Bone Marrow Biopsy', LRED, RED, true),
      dataCell('BM', LRED),
      dataCell('Marrow cellularity, blasts, fibrosis, infiltration', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Reticulocyte Count', LYELL, '5C4000', true),
      dataCell('Retic', LYELL),
      dataCell('Bone marrow response; ↑ in haemolysis/bleeding, ↓ in aplasia', LYELL),
    ]}),
    new TableRow({ children: [
      dataCell('Serum Bilirubin (unconjugated)', LRED, RED, true),
      dataCell('UB', LRED),
      dataCell('Marker of haemolysis', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Iron Studies', LBLUE, BLUE, true),
      dataCell('Fe / TIBC / Ferritin', LBLUE),
      dataCell('Distinguish Fe def from ACD / thalassaemia', LBLUE),
    ]}),
  ],
});

// ── IRON THERAPY TABLE ─────────────────────────────────────────────────────
const ironRxTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Route', 'When Used', 'Notes'),
    new TableRow({ children: [
      dataCell('Oral (PO)', LGREY, GREEN, true),
      dataCell('1st line in most cases', LGREY),
      dataCell('Ferrous sulphate; take on empty stomach; SE: GI upset', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Parenteral (IV/IM)', LRED, RED, true),
      dataCell('Non-compliant patient\nMalabsorption\nSevere anaemia near term', LRED),
      dataCell('IV iron sucrose preferred over IM (less pain, no tattooing)', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Blood Transfusion', LYELL, '5C4000', true),
      dataCell('Hb < 7 g/dL with severe symptoms\nNear term delivery (<34 weeks)\nCardiac symptoms', LYELL),
      dataCell('1 unit packed RBC raises Hb by ~1 g/dL\nUsed sparingly in pregnancy', LYELL),
    ]}),
  ],
});

// ── COMPLICATIONS TABLE ─────────────────────────────────────────────────────
const compTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('Complication', 'Mechanism', 'Notes'),
    new TableRow({ children: [
      dataCell('Preterm labour', LRED, RED, true),
      dataCell('Uterine hypoxia triggers contractions', LRED),
      dataCell('', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('IUGR / SGA baby', LGREY),
      dataCell('Reduced O2 delivery to placenta / fetus', LGREY),
      dataCell('', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Cardiac failure', LRED, RED, true),
      dataCell('Compensatory tachycardia → high output failure', LRED),
      dataCell('', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Postpartum haemorrhage', LGREY),
      dataCell('Anaemia reduces uterine contractility reserve', LGREY),
      dataCell('', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('Maternal mortality', LRED, RED, true),
      dataCell('Due to above complications compounding', LRED),
      dataCell('Leading cause of maternal death in developing countries', LRED),
    ]}),
  ],
});

// ── RDW TABLE ──────────────────────────────────────────────────────────────
const rdwTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    hdrRow('RDW Result', 'MCV', 'Likely Diagnosis'),
    new TableRow({ children: [
      dataCell('↑ RDW', LRED, RED, true),
      dataCell('Low MCV', LRED),
      dataCell('Iron deficiency anaemia (early)', LRED),
    ]}),
    new TableRow({ children: [
      dataCell('Normal RDW', LGREY),
      dataCell('Low MCV', LGREY),
      dataCell('Thalassaemia trait', LGREY),
    ]}),
    new TableRow({ children: [
      dataCell('↑ RDW', LYELL, '5C4000', true),
      dataCell('High MCV', LYELL),
      dataCell('B12 / Folate deficiency', LYELL),
    ]}),
    new TableRow({ children: [
      dataCell('Normal RDW', LBLUE, BLUE, true),
      dataCell('Normal MCV', LBLUE),
      dataCell('Anaemia of chronic disease / aplastic anaemia', LBLUE),
    ]}),
  ],
});

// ─────────────────────────────────────────────────────────────────────────────
// DOCUMENT
// ─────────────────────────────────────────────────────────────────────────────
const doc = new Document({
  sections: [{
    children: [

      // TITLE
      new Paragraph({
        children: [new TextRun({ text: 'Integrated Teaching: Anaemia', bold: true, size: 44, color: BLUE })],
        alignment: AlignmentType.CENTER,
        spacing: { before: 0, after: 100 },
      }),
      new Paragraph({
        children: [new TextRun({ text: 'Systematic Notes with Classifications, Indices & Flowcharts', italics: true, size: 24, color: GREY })],
        alignment: AlignmentType.CENTER,
        spacing: { before: 0, after: 400 },
      }),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION A: APPROACH TO ANAEMIA'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Presenting Complaint (Q)'),
      bullet('Toy / exertional breathlessness + palpitations → history: last 6 weeks'),

      spacer(),

      // FLOWCHART: Approach to Anaemia
      h2('Flowchart 1 — Approach to a Patient with Anaemia'),
      flowBox('ANAEMIA (low Hb on CBC)', LBLUE, BLUE),
      arrow(),
      flowBox('Classify by: (1) Related to Cause   |   (2) Morphologically', LGREY, MID),
      arrow(),
      new Table({
        width: { size: 100, type: WidthType.PERCENTAGE },
        rows: [
          new TableRow({ children: [
            new TableCell({
              children: [
                new Paragraph({ children: [bold('A. Marrow Problem', BLUE)], alignment: AlignmentType.CENTER }),
                new Paragraph({ children: [normal('(1) Nutritional deficiency: Fe / B12 / Folate / Erythropoietin → CBC, PBF', MID)], spacing: { before: 40 } }),
                new Paragraph({ children: [normal('(2) Aplasia / Hypoplasia / Myelodysplasia → Aplastic — Bone Marrow, PBF', MID)], spacing: { before: 40 } }),
                new Paragraph({ children: [normal('(3) Infiltration → CBC, PBF, BM', MID)], spacing: { before: 40 } }),
              ],
              shading: { fill: LBLUE, type: ShadingType.CLEAR },
            }),
            new TableCell({
              children: [
                new Paragraph({ children: [bold('B. Peripheral Removal', RED)], alignment: AlignmentType.CENTER }),
                new Paragraph({ children: [normal('→ Blood loss (History)', RED)], spacing: { before: 40 } }),
                new Paragraph({ children: [normal('→ Haemolysis (PBF, unconjugated bilirubin)', RED)], spacing: { before: 40 } }),
                new Paragraph({ children: [normal('→ Hypersplenism / SLE', RED)], spacing: { before: 40 } }),
              ],
              shading: { fill: LRED, type: ShadingType.CLEAR },
            }),
          ]}),
        ],
      }),

      spacer(),
      h3('Key Investigations per Pathway'),
      causeClassTable,
      spacer(),

      // PBF DIAGRAM section
      h2('Peripheral Blood Film (PBF) — Key Findings'),
      new Paragraph({
        children: [
          bold('Reticulocytosis: ', MID),
          normal('Immature RBCs released when marrow is responding (seen in haemolysis / blood loss)'),
        ],
        spacing: { before: 60, after: 40 },
      }),
      new Paragraph({
        children: [
          bold('Platelets (PLT): ', MID),
          normal('Reactive thrombocytosis — marker of response / active haemorrhage'),
        ],
        spacing: { before: 40, after: 40 },
      }),
      new Paragraph({
        children: [
          bold('Markers of Haemolysis: ', RED),
          normal('↑ Unconjugated bilirubin (heme breakdown)'),
        ],
        spacing: { before: 40, after: 40 },
      }),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION B: MORPHOLOGICAL CLASSIFICATION'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Flowchart 2 — Morphological Classification of Anaemia'),
      flowBox('MCV → Size of RBC', LBLUE, BLUE),
      arrow('▼  ▼  ▼'),
      new Table({
        width: { size: 100, type: WidthType.PERCENTAGE },
        rows: [
          new TableRow({ children: [
            hdrCell('MICROCYTIC\n(↓ MCV)', MID),
            hdrCell('NORMOCYTIC\n(Normal MCV)', GREEN),
            hdrCell('MACROCYTIC\n(↑↑ MCV)', '7B3F00'),
          ]}),
          new TableRow({ children: [
            dataCell('Fe deficiency\nThalassaemia\nSideroblastic\nAnaemia of chronic disease', LRED),
            dataCell('Haemolysis\nBleeding (acute)\nChronic disease\nRenal failure', LGREY),
            dataCell('B12 / Folate deficiency\nMegaloblastic\nLiver disease\nHypothyroidism', LYELL),
          ]}),
          new TableRow({ children: [
            dataCell('MCHC ↓↓\nMCH ↓', LRED),
            dataCell('MCHC Normal\nMCH Normal', LGREY),
            dataCell('MCHC Normal\nMCH ↑', LYELL),
          ]}),
        ],
      }),

      spacer(),
      h2('Full Morphological Classification Table'),
      morphClassTable,

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION C: CBC INDICES IN DEPTH'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('MCH vs MCHC — Key Distinction'),
      new Paragraph({
        children: [
          bold('MCH ', MID), normal('= Amount of Hb per RBC  '),
          bold('| ', GREY),
          bold('MCHC ', GREEN), normal('= Density / Colour / Concentration of Hb in RBC'),
        ],
        spacing: { before: 60, after: 80 },
        shading: { fill: LGREY, type: ShadingType.CLEAR },
        border: {
          left: { style: BorderStyle.THICK, size: 12, color: MID },
        },
        indent: { left: 240 },
      }),

      h2('RBC Colour: Hypochromic vs Normochromic vs Hyperchromic'),
      new Paragraph({
        children: [normal('Central pallor of normal RBC = ', GREY), bold('>1/3 of diameter', RED)],
        spacing: { before: 40, after: 60 },
      }),
      new Table({
        width: { size: 100, type: WidthType.PERCENTAGE },
        rows: [
          new TableRow({ children: [
            hdrCell('Hypochromic', MID),
            hdrCell('Normochromic', GREEN),
            hdrCell('Hyperchromic', '7B3F00'),
          ]}),
          new TableRow({ children: [
            dataCell('Central pallor > 1/3\nPale, washed-out RBC\nSeen in Fe deficiency', LRED),
            dataCell('Central pallor ≤ 1/3\nNormal appearance', LGREY),
            dataCell('No central pallor\nDark-staining RBC\nSeen in spherocytosis', LYELL),
          ]}),
          new TableRow({ children: [
            dataCell('MCHC ↓↓', LRED, RED, true),
            dataCell('MCHC Normal', LGREY, GREEN, true),
            dataCell('MCHC ↑', LYELL, '7B3F00', true),
          ]}),
        ],
      }),

      spacer(),
      h2('Full CBC Indices Reference Table'),
      cbcTable,

      spacer(),
      h2('RDW — Red Cell Distribution Width'),
      para([bold('Normal range: ', MID), normal('11.5 – 14.5%')]),
      para([bold('↑ RDW: ', RED), normal('Anisocytosis — wide variation in RBC size')]),
      para([bold('Interpretation with MCV:', GREY)]),
      rdwTable,

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION D: IRON DEFICIENCY vs THALASSAEMIA'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Flowchart 3 — Microcytic Anaemia Differentiation'),
      flowBox('Microcytic Anaemia (↓ MCV)', LRED, RED),
      arrow(),
      new Table({
        width: { size: 100, type: WidthType.PERCENTAGE },
        rows: [
          new TableRow({ children: [
            hdrCell('Iron Deficiency Anaemia', MID),
            hdrCell('β-Thalassaemia', '7B3F00'),
          ]}),
          new TableRow({ children: [
            dataCell('Heme ✗\nGlobin ✓\n↓ Hb synthesis\nRBC count ↓', LRED),
            dataCell('Heme ✓\nGlobin ✗\nHb 9.0; RBC ↑ (late stage)\nMany target cells on PBF', LYELL),
          ]}),
        ],
      }),
      spacer(),
      para([bold('Mentzer Index = MCV ÷ RBC count', BLUE)]),
      new Table({
        width: { size: 60, type: WidthType.PERCENTAGE },
        rows: [
          hdrRow('Result', 'Interpretation'),
          new TableRow({ children: [
            dataCell('>13', LRED, RED, true),
            dataCell('Favours Iron Deficiency Anaemia', LRED),
          ]}),
          new TableRow({ children: [
            dataCell('<13', LYELL, '7B3F00', true),
            dataCell('Favours Thalassaemia', LYELL),
          ]}),
        ],
      }),
      spacer(),
      h2('Detailed Comparison Table'),
      feVsThalTable,

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION E: NORMOCYTIC ANAEMIA'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Normocytic Normochromic Causes & Investigations'),
      normocyticTable,

      spacer(),

      h2('Haemolysis — Investigations (in addition to CBC)'),
      bullet('↑ Platelet (reactive thrombocytosis)'),
      bullet('↑ Reticulocyte count'),
      bullet('Haemolysis markers: ↑ Unconjugated bilirubin, ↑ LDH, ↓ Haptoglobin'),

      spacer(),
      h2('Normocytic Anaemia — Hb 8, NCU'),
      para([bold('Causes: ', RED), normal('Haemolysis | Bleeding | Chronic infection / inflammation | Renal failure')]),
      para([bold('PBF: ', MID), normal('Reticulocytosis (if marrow responding), No morphological change in RBC size')]),

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION F: MEGALOBLASTIC / MACROCYTIC ANAEMIA'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Mechanism (from notes)'),
      flowBox('↑↑ MCV (Macrocyte)', LYELL, '7B3F00'),
      arrow(),
      flowBox('Defective Haemoglobinisation → Cytoplasmic problem', LYELL, '5C4000'),
      arrow(),
      flowBox('DNA defect (nuclear) → Fewer cell divisions', LYELL, '5C4000'),
      spacer(),
      para([bold('Key concept: ', MID), normal('Cytoplasm grows (Hb made) but nucleus cannot divide properly → large cells with relatively normal Hb')]),
      bullet('Causes: Vit B12 deficiency, Folate deficiency'),
      bullet('MCV ↑↑, MCH ↑, MCHC normal'),
      bullet('Hypersegmented neutrophils on PBF'),

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION G: INVESTIGATIONS SUMMARY'),
      // ═══════════════════════════════════════════════════════════════════════

      invTable,

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION H: ANAEMIA IN PREGNANCY'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Q1 — 4 Important Complications of Anaemia During Pregnancy'),
      compTable,

      spacer(),
      h2('Q2 — Routes of Iron Therapy in Pregnancy'),
      ironRxTable,

      spacer(),
      h2('Indications of Blood Transfusion During Pregnancy'),
      bullet('Hb < 7 g/dL with symptoms (breathlessness, cardiac signs)'),
      bullet('Near-term delivery (< 34 weeks gestation) with severe anaemia'),
      bullet('Haemodynamic instability'),
      bullet('Symptomatic cardiac compromise'),
      bullet('Patient unwilling / unable to take oral / IV iron (rare)'),

      spacer(),

      // ═══════════════════════════════════════════════════════════════════════
      h1('SECTION I: THALASSAEMIA — EXTRA NOTES'),
      // ═══════════════════════════════════════════════════════════════════════

      h2('Thalassaemia on PBF'),
      bullet('Target cells (leptocytes) — heme present but central Hb is very low → "bulls-eye" appearance'),
      bullet('Hb 9.0; RBC ↑ in late stage (ineffective erythropoiesis stimulus)'),
      bullet('MCH ↓, MCHC ↓ (mild compared to Fe def)'),
      bullet('RBC count often higher than in Fe deficiency (Mentzer Index < 13)'),

      h2('Thalassaemia — spider diagram (from notes)'),
      new Paragraph({
        children: [new TextRun({
          text:
            '                  Thalassaemia\n' +
            '                 /    |    \\   |\n' +
            '            RBC  Hb  MCH  MCHC\n' +
            '           (late↑)(9.0)(↓) (↓)\n' +
            '              |       |     |\n' +
            '         Heme ✓   Globin ✗  Target cells',
          size: 20, color: '3D3D3D', font: 'Courier New'
        })],
        shading: { fill: LGREY, type: ShadingType.CLEAR },
        spacing: { before: 80, after: 80 },
        indent: { left: 360 },
      }),

      divider(),

      // FOOTER NOTE
      new Paragraph({
        children: [italic('Notes compiled from Integrated Teaching session on Anaemia (06.06.26). All indices and classifications as per original handwritten notes.')],
        alignment: AlignmentType.CENTER,
        spacing: { before: 100, after: 60 },
      }),
    ],
  }],
});

Packer.toBuffer(doc).then((buf) => {
  fs.writeFileSync('/home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx', buf);
  console.log('Done!');
}).catch(e => { console.error(e); process.exit(1); });
Running Command

cd /home/daytona/workspace/newborn-exam-notes && node create_anaemia_notes.js 2>&1

Running Command

python3 -c " from zipfile import ZipFile z = ZipFile('/home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx') content = z.read('word/document.xml').decode('utf-8') print('Valid XML, length:', len(content)) import os print('File size:', os.path.getsize('/home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx'), 'bytes') "

Done! Here's your document:

Anaemia Integrated Teaching Notes

Word Document · DOCX


Here's what's in the notes, fully systematized across 9 sections:

What's inside

Section A — Approach to Anaemia

  • Presenting complaint: exertional breathlessness + palpitations
  • Flowchart 1: Anaemia → classify by Cause (Marrow Problem vs Peripheral Removal) with investigations mapped to each pathway

Section B — Morphological Classification

  • Flowchart 2: MCV → Microcytic | Normocytic | Macrocytic with causes and indices in a 3-column colour-coded table

Section C — CBC Indices In Depth

  • MCH vs MCHC explained
  • RBC colour diagram: Hypochromic / Normochromic / Hyperchromic with central pallor rule (>1/3)
  • Full MCH, MCHC, MCV, RDW reference table
  • RDW interpretation table (MCV + RDW → diagnosis)

Section D — Iron Deficiency vs Thalassaemia

  • Flowchart 3: Microcytic anaemia differentiation
  • Heme ✗ / Globin ✗ distinction
  • Mentzer Index: >13 = Fe def, <13 = Thalassaemia
  • Full comparison table (Hb, RBC, MCH, MCHC, target cells, RDW)

Section E — Normocytic Anaemia

  • Haemolysis, bleeding, chronic disease, renal failure
  • Investigations: reticulocytes, unconjugated bilirubin, CBC

Section F — Megaloblastic/Macrocytic Anaemia

  • Flowchart: ↑↑ MCV → Cytoplasmic problem → DNA defect → Fewer cell divisions
  • B12 / Folate deficiency mechanism

Section G — Investigations Summary Table

  • CBC, PBF, Bone Marrow, Reticulocyte count, Serum Bilirubin, Iron studies

Section H — Anaemia in Pregnancy (SAQs)

  • Q1: 4 complications table (preterm labour, IUGR, cardiac failure, PPH, maternal mortality)
  • Q2: Routes of iron therapy table (oral, parenteral, blood transfusion + indications)

Section I — Thalassaemia Extra Notes

  • Target cells, spider diagram, PBF findings

Why is it downloading in .Json format

That's a browser/interface issue, not a problem with the file itself. The file is a valid .docx - it's just being served without the correct MIME type, so your browser defaults to saving it as .json.
Fix: just rename it after downloading.
  1. Download the file (it will save as something like Anaemia_Integrated_Teaching_Notes.docx.json or similar)
  2. Rename it - remove the .json extension so it ends in .docx
  3. Open with Microsoft Word or Google Docs
The file contents are correct - renaming is all that's needed. Word reads .docx by extension and the internal XML is valid.
Alternatively, if you want to open it directly in Google Docs:
  1. Go to drive.google.com
  2. Upload the downloaded file (even with the wrong extension)
  3. Right-click → "Open with Google Docs" - it will parse the XML correctly regardless of the filename extension

Create a PDF version of these notes for easier sharing

Running Command

ls /home/daytona/workspace/newborn-exam-notes/

Running Command

python3 /home/daytona/skills/docx/scripts/office/soffice.py --headless --convert-to pdf /home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx --outdir /home/daytona/workspace/newborn-exam-notes/ 2>&1

Running Command

# Try with soffice directly soffice --headless --convert-to pdf /home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx --outdir /home/daytona/workspace/newborn-exam-notes/ 2>&1

Running Command

# Try writing to /tmp first then copy soffice --headless --convert-to pdf /home/daytona/workspace/newborn-exam-notes/Anaemia_Integrated_Teaching_Notes.docx --outdir /tmp/ 2>&1 echo "Exit: $?" ls /tmp/*.pdf 2>&1

Running Command

# Copy both PDFs to workspace and also convert the Newborn notes docx cp /tmp/Anaemia_Integrated_Teaching_Notes.pdf /home/daytona/workspace/newborn-exam-notes/ # Also check if Newborn docx exists and convert it ls /home/daytona/workspace/newborn-exam-notes/

Running Command

# Also convert the Newborn Examination notes soffice --headless --convert-to pdf /home/daytona/workspace/newborn-exam-notes/Examination_of_Newborn_Notes.docx --outdir /tmp/ 2>&1 && cp /tmp/Examination_of_Newborn_Notes.pdf /home/daytona/workspace/newborn-exam-notes/ echo "Exit: $?" ls -lh /home/daytona/workspace/newborn-exam-notes/*.pdf

Running Command

# Locate the Newborn docx find /home/daytona/workspace -name "*.docx" 2>/dev/null

Running Command

ls /home/daytona/workspace/newborn-exam-notes/

Writing File

~/newborn-exam-notes/create_newborn_notes.js

const {
  Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
  HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
  VerticalAlign, UnderlineType
} = require('docx');
const fs = require('fs');

const BLUE  = '1F3864';
const MID   = '2E74B5';
const RED   = 'C00000';
const GREEN = '375623';
const GREY  = '595959';
const LBLUE = 'D6E4F0';
const LRED  = 'FADADD';
const LGREY = 'F2F2F2';
const WHITE = 'FFFFFF';

const h1 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 32, color: BLUE })],
  heading: HeadingLevel.HEADING_1,
  spacing: { before: 320, after: 120 },
  border: { bottom: { style: BorderStyle.SINGLE, size: 8, color: MID } },
});
const h2 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 26, color: MID })],
  heading: HeadingLevel.HEADING_2,
  spacing: { before: 220, after: 80 },
});
const h3 = (text) => new Paragraph({
  children: [new TextRun({ text, bold: true, size: 22, color: GREEN })],
  heading: HeadingLevel.HEADING_3,
  spacing: { before: 160, after: 60 },
});
const bullet = (text, level = 0, color = '000000') => new Paragraph({
  children: [new TextRun({ text, size: 22, color })],
  bullet: { level },
  spacing: { before: 40, after: 40 },
});
const subBullet = (text, color) => bullet(text, 1, color);
const spacer = () => new Paragraph({ children: [new TextRun('')], spacing: { before: 80, after: 80 } });
const divider = () => new Paragraph({
  children: [new TextRun({ text: '' })],
  border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: 'CCCCCC' } },
  spacing: { before: 160, after: 160 },
});
const note = (label, value) => new Paragraph({
  children: [
    new TextRun({ text: label + ': ', bold: true, size: 22 }),
    new TextRun({ text: value, size: 22 }),
  ],
  spacing: { before: 40, after: 40 },
  indent: { left: 360 },
});
const hdrCell = (text) => new TableCell({
  children: [new Paragraph({ children: [new TextRun({ text, bold: true, size: 22, color: WHITE })] })],
  shading: { fill: MID, type: ShadingType.CLEAR },
  verticalAlign: VerticalAlign.CENTER,
});
const dataCell = (text, fill = WHITE, color = '000000', bold_ = false) => new TableCell({
  children: [new Paragraph({ children: [new TextRun({ text, bold: bold_, size: 22, color })] })],
  shading: { fill, type: ShadingType.CLEAR },
  verticalAlign: VerticalAlign.CENTER,
});

// ── comparison table: Caput Succedaneum vs Cephalhaematoma ─────────────────
const compTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    new TableRow({ tableHeader: true, children: [hdrCell('Feature'), hdrCell('Caput Succedaneum'), hdrCell('Cephalhaematoma')] }),
    new TableRow({ children: [dataCell('Location relative to periosteum'), dataCell('Above periosteum (subgaleal)', LGREY), dataCell('Below periosteum (subperiosteal)', LGREY)] }),
    new TableRow({ children: [dataCell('Crosses suture lines?', LBLUE), dataCell('Yes', LBLUE), dataCell('No (confined to one bone)', LBLUE)] }),
    new TableRow({ children: [dataCell('Onset'), dataCell('Present at birth', LGREY), dataCell('Hours after birth', LGREY)] }),
    new TableRow({ children: [dataCell('Resolution', LBLUE), dataCell('Days', LBLUE), dataCell('Weeks–months; may calcify', LBLUE)] }),
    new TableRow({ children: [dataCell('Jaundice risk'), dataCell('Low', LGREY), dataCell('Yes (blood reabsorption)', LRED)] }),
  ],
});

// ── jaundice table ─────────────────────────────────────────────────────────
const jaundiceTable = new Table({
  width: { size: 100, type: WidthType.PERCENTAGE },
  rows: [
    new TableRow({ tableHeader: true, children: [hdrCell('Type'), hdrCell('Bilirubin (term)'), hdrCell('Bilirubin (pre-term)'), hdrCell('Timing / Notes')] }),
    new TableRow({ children: [dataCell('Mild (icteric)'), dataCell('5 mg/dL'), dataCell('-'), dataCell('')] }),
    new TableRow({ children: [dataCell('Moderate', LGREY), dataCell('15 mg/dL', LGREY), dataCell('-', LGREY), dataCell('', LGREY)] }),
    new TableRow({ children: [dataCell('Complete/Severe'), dataCell('25 mg/dL'), dataCell('-'), dataCell('')] }),
    new TableRow({ children: [dataCell('Physiologic', LBLUE), dataCell('≤12 mg/dL', LBLUE), dataCell('≤15 mg/dL', LBLUE), dataCell('After 24 hrs; resolves before 7 days', LBLUE)] }),
    new TableRow({ children: [dataCell('Pathologic', LRED, RED, true), dataCell('>15 mg/dL', LRED, RED, true), dataCell('-', LRED), dataCell('Appears WITHIN 24 hrs of birth', LRED, RED, true)] }),
  ],
});

const doc = new Document({
  sections: [{
    children: [
      new Paragraph({ children: [new TextRun({ text: 'Examination of the Newborn', bold: true, size: 44, color: BLUE })], alignment: AlignmentType.CENTER, spacing: { before: 0, after: 100 } }),
      new Paragraph({ children: [new TextRun({ text: 'Systematic Clinical Notes', italics: true, size: 24, color: GREY })], alignment: AlignmentType.CENTER, spacing: { before: 0, after: 400 } }),

      h1('A. Physical Examination (Head-to-Toe)'),
      h2('1. Head'),
      h3('Diff: Caput Succedaneum vs Cephalhaematoma'),
      spacer(), compTable, spacer(),
      note('Jaundice test', 'Cephalhaematoma carries higher jaundice risk due to blood reabsorption'),
      divider(),

      h2('2. Eye'),
      bullet('Epicanthic fold — assess for Down syndrome or other dysmorphic features'),
      bullet('Color — note scleral color (jaundice = yellow; anaemia = pale)'),
      divider(),

      h2('3. Ear'),
      bullet('Inspect position, shape, and any pre-auricular tags or sinuses'),
      divider(),

      h2('4. Neck'),
      bullet('Swelling:'),
      subBullet('Tumor (e.g. sternomastoid tumor / fibromatosis colli)'),
      subBullet('Thyroglossal cyst — midline; moves with swallowing and tongue protrusion'),
      bullet('Cystic hygroma (lymphatic malformation) — POST side — requires surgical management'),
      bullet('Webbing of neck — associated with Turner syndrome'),
      divider(),

      h2('5. Chest'),
      bullet('Symmetry — assess for collapse'),
      bullet('Intercostal (IC) recession — sign of respiratory distress'),
      new Paragraph({ children: [new TextRun({ text: 'Auscultation:', bold: true, size: 22 })], spacing: { before: 60, after: 40 }, indent: { left: 360 } }),
      subBullet('Heart sounds: normal HR = 110–170 bpm'),
      subBullet('Lung sounds: RR > 60 = tachypnoea'),
      divider(),

      h2('6. Abdomen'),
      bullet('Umbilical swelling'),
      bullet('Umbilical hernia'),
      bullet('Liver enlargement (hepatomegaly)'),
      bullet('Gastroschisis — deficiency / defect of abdominal wall'),
      divider(),

      h2('7. Genitalia'),
      new Paragraph({ children: [new TextRun({ text: 'Male (♂):', bold: true, size: 22 })], spacing: { before: 60, after: 40 }, indent: { left: 360 } }),
      subBullet('Scrotum — inspect for undescended testes'),
      subBullet('Penis — inspect for hypospadias / epispadias'),
      new Paragraph({ children: [new TextRun({ text: 'Female (♀):', bold: true, size: 22 })], spacing: { before: 60, after: 40 }, indent: { left: 360 } }),
      subBullet('Labia minora'),
      subBullet('Labia majora — enlarged in adrenal hyperplasia (CAH)'),
      divider(),

      h2('8. Fingers, Limbs, Toes & Bones'),
      bullet('Fingers — count digits; check for polydactyly / syndactyly'),
      bullet('Toes — inspect similarly'),
      bullet('Bones — assess tone and symmetry'),
      bullet('Talipes equinovarus (club foot) — deformity of the feet'),
      divider(),

      h1('B. POST Examination Findings'),
      h2('Head'),
      bullet('Hydrocephalus — requires surgery / shunt'),
      bullet('Anencephalus — incompatible with life; leads to termination of pregnancy (TOP)'),
      h2('Neck'),
      bullet('Cystic hygroma'),
      bullet('Webbing of neck (pterygium colli) — associated with Turner syndrome'),
      h2('Back'),
      bullet('Spinal cord defects:'),
      subBullet('Spina bifida open — cord visualized externally (myelomeningocele)'),
      subBullet('Spina bifida closed — skin-covered; no need for termination of pregnancy'),
      divider(),

      h1('C. After Examination'),
      bullet('Advise mother to breastfeed (BF) within 30 minutes of delivery'),
      h2('Reflexes'),
      bullet('Rooting reflex'),
      bullet('Sucking reflex'),
      bullet('Grasping reflex'),
      bullet('Moro reflex'),
      divider(),

      h1('D. Assess Breastfeeding (B/F)'),
      h2('1. Urine Output'),
      bullet('Normal: >5 times / 24 hours'),
      h2('2. Dehydration'),
      bullet('Sign: Anterior fontanelle — depressed'),
      h2('3. Abdomen'),
      bullet('Liver enlarged (hepatomegaly) OR normal'),
      bullet('Bulging hypochondrium — suggests IUGR'),
      bullet('Depressed hypochondrium'),
      bullet('Scaphoid abdomen'),
      divider(),

      h1('E. Meconium'),
      bullet('Meconium passed in-utero = sign of fetal distress'),
      bullet('Causes:'),
      subBullet('Fetal hypoxia'),
      subBullet('Fetal asphyxia'),
      subBullet('Birth asphyxia (BA)'),
      divider(),

      h1('F. Jaundice (Neonatal Hyperbilirubinaemia)'),
      spacer(), jaundiceTable, spacer(),
      divider(),

      h1('G. Umbilical Sepsis (Omphalitis)'),
      new Paragraph({
        children: [new TextRun({ text: '1st sign: Reluctant to feed', bold: true, size: 22, color: RED })],
        spacing: { before: 60, after: 60 },
      }),
      h2('Clinical Features'),
      bullet('Red / erythematous umbilicus'),
      bullet('Swollen / oedematous'),
      bullet('Foul-smelling discharge'),
      h2('Complication'),
      bullet('Critical: infection tracks via umbilical vein'),
      subBullet('→ Portal circulation → Liver abscess'),
      h2('Management'),
      bullet('Immediate Rx: Broad-spectrum antibiotics'),
      bullet('Prophylaxis: Chlorhexidine application right after delivery'),

      divider(),
      new Paragraph({ children: [new TextRun({ text: 'Notes compiled from handwritten notes — Examination of Newborn.', italics: true, size: 20, color: GREY })], alignment: AlignmentType.CENTER }),
    ],
  }],
});

Packer.toBuffer(doc).then((buf) => {
  fs.writeFileSync('/home/daytona/workspace/newborn-exam-notes/Examination_of_Newborn_Notes.docx', buf);
  console.log('Done!');
}).catch(e => { console.error(e); process.exit(1); });
Running Command

cd /home/daytona/workspace/newborn-exam-notes && node create_newborn_notes.js 2>&1 && soffice --headless --convert-to pdf Examination_of_Newborn_Notes.docx --outdir /tmp/ 2>&1 && cp /tmp/Examination_of_Newborn_Notes.pdf /home/daytona/workspace/newborn-exam-notes/ && echo "Both done" && ls -lh /home/daytona/workspace/newborn-exam-notes/*.pdf

Both PDFs are ready:
Anaemia (Integrated Teaching):

Anaemia Integrated Teaching Notes

PDF Document · PDF

Examination of Newborn:

Examination of Newborn Notes

PDF Document · PDF

These are proper .pdf files — no renaming needed, they'll open directly in any PDF viewer or browser. You can also share them on WhatsApp, email, or upload to Drive without any format issues.
This is a shared conversation. Sign in to Orris to start your own chat.