preparation of patient information leaflet word doc

Asking for Preferences
Asking for Preferences
Asking for Preferences
Reading File
Reading File
Reading File
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Running Command

ls -la /home/daytona/workspace/ && mkdir -p /home/daytona/workspace/hypertension-leaflet

Writing File

~/hypertension-leaflet/create_leaflet.js

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

const doc = new Document({
  styles: {
    default: {
      document: {
        run: {
          font: 'Arial',
          size: 22,
        },
      },
    },
    paragraphStyles: [
      {
        id: 'Heading1',
        name: 'Heading 1',
        basedOn: 'Normal',
        next: 'Normal',
        quickFormat: true,
        run: { font: 'Arial', size: 34, bold: true },
        paragraph: { spacing: { before: 240, after: 140 }, outlineLevel: 0 },
      },
      {
        id: 'Heading2',
        name: 'Heading 2',
        basedOn: 'Normal',
        next: 'Normal',
        quickFormat: true,
        run: { font: 'Arial', size: 28, bold: true },
        paragraph: { spacing: { before: 200, after: 100 }, outlineLevel: 1 },
      },
    ],
  },
  numbering: {
    config: [
      {
        reference: 'bullet-list',
        levels: [
          {
            level: 0,
            format: LevelFormat.BULLET,
            text: '•',
            alignment: AlignmentType.LEFT,
            style: {
              paragraph: { indent: { left: 720, hanging: 360 } },
            },
          },
        ],
      },
    ],
  },
  sections: [
    {
      properties: {
        page: {
          size: { width: 12240, height: 15840 },
          margin: { top: 1200, right: 1200, bottom: 1200, left: 1200 },
        },
      },
      children: [
        new Paragraph({
          heading: HeadingLevel.HEADING_1,
          alignment: AlignmentType.CENTER,
          children: [new TextRun('Patient Information Leaflet: Hypertension')],
        }),
        new Paragraph({
          alignment: AlignmentType.CENTER,
          spacing: { after: 220 },
          children: [
            new TextRun({
              text: 'For general adult patients | Language: lay + clinical',
              italics: true,
              size: 20,
            }),
          ],
        }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('1) What is hypertension?')],
        }),
        new Paragraph({
          children: [
            new TextRun('Hypertension means blood pressure that stays higher than normal over time. Blood pressure is measured as systolic/diastolic (for example, 130/80 mm Hg).'),
          ],
        }),
        new Paragraph({ text: 'Common categories used in clinics:', spacing: { after: 60 } }),
        new Paragraph({
          text: 'Elevated BP: systolic 120–129 and diastolic below 80 mm Hg',
          numbering: { reference: 'bullet-list', level: 0 },
        }),
        new Paragraph({
          text: 'Stage 1 hypertension: systolic 130–139 or diastolic 80–89 mm Hg',
          numbering: { reference: 'bullet-list', level: 0 },
        }),
        new Paragraph({
          text: 'Stage 2 hypertension: systolic 140 or higher, or diastolic 90 or higher',
          numbering: { reference: 'bullet-list', level: 0 },
        }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('2) Why does hypertension matter?')],
        }),
        new Paragraph({ text: 'Over time, uncontrolled high blood pressure can damage blood vessels and organs.' }),
        new Paragraph({ text: 'Possible complications include:', spacing: { after: 40 } }),
        new Paragraph({ text: 'Heart attack and heart failure', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Stroke', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Kidney damage/failure', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Peripheral vascular disease and aortic disease', numbering: { reference: 'bullet-list', level: 0 } }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('3) Risk factors')],
        }),
        new Paragraph({ text: 'Some factors cannot be changed, and others can be improved.' }),
        new Paragraph({ text: 'Non-modifiable:', spacing: { after: 40 } }),
        new Paragraph({ text: 'Increasing age', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Family history/genetic tendency', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Modifiable:', spacing: { before: 80, after: 40 } }),
        new Paragraph({ text: 'Excess body weight/obesity', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'High salt intake and unhealthy diet', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Physical inactivity', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Heavy alcohol use and smoking', numbering: { reference: 'bullet-list', level: 0 } }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('4) Symptoms and warning signs')],
        }),
        new Paragraph({
          text: 'Many people have no symptoms, so hypertension is often called a “silent” condition. Regular checks are important.',
        }),
        new Paragraph({
          text: 'Seek urgent care if blood pressure is very high (around 180/120 mm Hg or above) with symptoms such as severe headache, chest pain, breathlessness, confusion, weakness, or vision changes.',
        }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('5) How is it diagnosed?')],
        }),
        new Paragraph({
          text: 'Diagnosis should be based on repeated measurements over time, not a single reading, because blood pressure changes during the day.',
        }),
        new Paragraph({ text: 'Your clinician may recommend:', spacing: { after: 40 } }),
        new Paragraph({ text: 'Home blood pressure monitoring', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Ambulatory blood pressure monitoring (24-hour monitor)', numbering: { reference: 'bullet-list', level: 0 } }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('6) Treatment')],
        }),
        new Paragraph({
          text: 'Treatment aims to lower risk of heart, brain, and kidney complications. Most adults are treated to a target below 130/80 mm Hg, based on individual risk and tolerance.',
        }),
        new Paragraph({ text: 'A) Lifestyle treatment (first step for everyone):', spacing: { after: 40 } }),

        new Table({
          width: { size: 9840, type: WidthType.DXA },
          columnWidths: [3000, 4700, 2140],
          rows: [
            new TableRow({
              children: [
                new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Lifestyle change', bold: true })] })], width: { size: 3000, type: WidthType.DXA } }),
                new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'What to do', bold: true })] })], width: { size: 4700, type: WidthType.DXA } }),
                new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: 'Typical SBP effect', bold: true })] })], width: { size: 2140, type: WidthType.DXA } }),
              ],
            }),
            new TableRow({ children: [new TableCell({ children: [new Paragraph('Weight reduction')] }), new TableCell({ children: [new Paragraph('Aim for BMI about 18.5–24.9; even moderate weight loss helps')] }), new TableCell({ children: [new Paragraph('5–20 mm Hg per 10 kg')] })] }),
            new TableRow({ children: [new TableCell({ children: [new Paragraph('DASH eating plan')] }), new TableCell({ children: [new Paragraph('More fruits, vegetables, low-fat dairy; less saturated fat')] }), new TableCell({ children: [new Paragraph('8–14 mm Hg')] })] }),
            new TableRow({ children: [new TableCell({ children: [new Paragraph('Reduce sodium')] }), new TableCell({ children: [new Paragraph('Around 2.3 g sodium/day (about 6 g salt) or lower')] }), new TableCell({ children: [new Paragraph('2–8 mm Hg')] })] }),
            new TableRow({ children: [new TableCell({ children: [new Paragraph('Regular exercise')] }), new TableCell({ children: [new Paragraph('At least 30 min brisk activity on most days')] }), new TableCell({ children: [new Paragraph('About 4–8 mm Hg')] })] }),
            new TableRow({ children: [new TableCell({ children: [new Paragraph('Limit alcohol')] }), new TableCell({ children: [new Paragraph('Men: up to 2 drinks/day; Women: up to 1 drink/day')] }), new TableCell({ children: [new Paragraph('2–4 mm Hg')] })] }),
          ],
          borders: {
            top: { style: BorderStyle.SINGLE, size: 6, color: '888888' },
            bottom: { style: BorderStyle.SINGLE, size: 6, color: '888888' },
            left: { style: BorderStyle.SINGLE, size: 6, color: '888888' },
            right: { style: BorderStyle.SINGLE, size: 6, color: '888888' },
            insideHorizontal: { style: BorderStyle.SINGLE, size: 4, color: 'BBBBBB' },
            insideVertical: { style: BorderStyle.SINGLE, size: 4, color: 'BBBBBB' },
          },
        }),

        new Paragraph({ text: 'B) Medicines (if lifestyle changes are not enough):', spacing: { before: 140, after: 40 } }),
        new Paragraph({ text: 'Common first-line medicine groups include thiazide diuretics, ACE inhibitors, ARBs, and calcium channel blockers.', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Some patients need two medicines, especially when BP is much higher than target.', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Take medicines daily as prescribed. Do not stop without discussing with your clinician.', numbering: { reference: 'bullet-list', level: 0 } }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('7) Self-care and follow-up')],
        }),
        new Paragraph({ text: 'Check your blood pressure at home (if advised) and keep a log.' }),
        new Paragraph({ text: 'Attend regular follow-up to adjust treatment and check kidney function, electrolytes, and overall cardiovascular risk.' }),
        new Paragraph({ text: 'Bring your medication list to every visit.' }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('8) When to seek immediate help')],
        }),
        new Paragraph({ text: 'Call emergency services if you have very high blood pressure with any of the following:' }),
        new Paragraph({ text: 'Chest pain', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Severe shortness of breath', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Severe headache, confusion, fainting, or seizures', numbering: { reference: 'bullet-list', level: 0 } }),
        new Paragraph({ text: 'Sudden weakness/numbness, trouble speaking, or vision loss', numbering: { reference: 'bullet-list', level: 0 } }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('Disclaimer')],
        }),
        new Paragraph({
          children: [new TextRun({ text: 'This leaflet provides general information and does not replace medical advice. Please discuss your individual care plan with your doctor.', italics: true })],
        }),

        new Paragraph({
          heading: HeadingLevel.HEADING_2,
          children: [new TextRun('Sources')],
        }),
        new Paragraph({ text: 'Comprehensive Clinical Nephrology, 7th Edition, p. 501' }),
        new Paragraph({ text: 'Morgan and Mikhail’s Clinical Anesthesiology, 7e, p. 713' }),
        new Paragraph({ text: 'National Kidneys Foundation Primer on Kidney Diseases, 8e, p. 689-690' }),
        new Paragraph({ text: 'Lippincott Illustrated Reviews: Pharmacology, p. 293-294' }),
      ],
    },
  ],
});

Packer.toBuffer(doc).then((buffer) => {
  fs.writeFileSync('/home/daytona/workspace/hypertension-leaflet/Hypertension_Patient_Information_Leaflet.docx', buffer);
  console.log('DOCX created');
});
Running Command

node /home/daytona/workspace/hypertension-leaflet/create_leaflet.js && ls -la /home/daytona/workspace/hypertension-leaflet/

Your credits are exhausted. Your daily credits reset tomorrow, or you can purchase a top-up for more.
This is a shared conversation. Sign in to Orris to start your own chat.