~/treatment-plan/generate.js
const {
Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
VerticalAlign, PageBreak, Header, Footer, PageNumber, NumberFormat,
TableLayoutType, convertInchesToTwip, UnderlineType
} = require('docx');
const fs = require('fs');
// ─── Colour palette ──────────────────────────────────────────────────────────
const BLUE_DARK = "1B3A6B"; // header / title
const BLUE_MID = "2E6DB4"; // section heading
const BLUE_LIGHT = "D9E6F5"; // table header background
const RED_BG = "FDECEA"; // critical row bg
const ORANGE_BG = "FFF3E0"; // warning row bg
const GREEN_BG = "E8F5E9"; // normal row bg
const GREY_LINE = "CCCCCC";
const WHITE = "FFFFFF";
// ─── Helper: horizontal rule ─────────────────────────────────────────────────
function hr() {
return new Paragraph({
border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: BLUE_MID } },
spacing: { after: 120 },
children: [],
});
}
// ─── Helper: spacer ──────────────────────────────────────────────────────────
function spacer(pts = 120) {
return new Paragraph({ spacing: { after: pts }, children: [] });
}
// ─── Helper: section heading ─────────────────────────────────────────────────
function sectionHead(text) {
return new Paragraph({
spacing: { before: 300, after: 100 },
children: [
new TextRun({
text,
bold: true,
size: 26,
color: WHITE,
font: "Calibri",
}),
],
shading: { type: ShadingType.SOLID, color: BLUE_MID },
indent: { left: 200 },
});
}
// ─── Helper: sub-heading ─────────────────────────────────────────────────────
function subHead(text, color = BLUE_DARK) {
return new Paragraph({
spacing: { before: 200, after: 60 },
children: [
new TextRun({ text, bold: true, size: 22, color, font: "Calibri" }),
],
});
}
// ─── Helper: bullet ──────────────────────────────────────────────────────────
function bullet(text, level = 0) {
return new Paragraph({
bullet: { level },
spacing: { after: 60 },
indent: { left: convertInchesToTwip(0.25 * (level + 1)), hanging: convertInchesToTwip(0.25) },
children: [new TextRun({ text, size: 20, font: "Calibri" })],
});
}
// ─── Helper: bold-label paragraph ────────────────────────────────────────────
function labelPara(label, value) {
return new Paragraph({
spacing: { after: 60 },
children: [
new TextRun({ text: label + ": ", bold: true, size: 20, font: "Calibri", color: BLUE_DARK }),
new TextRun({ text: value, size: 20, font: "Calibri" }),
],
});
}
// ─── Helper: normal paragraph ────────────────────────────────────────────────
function para(text, opts = {}) {
return new Paragraph({
spacing: { after: 80 },
children: [new TextRun({ text, size: 20, font: "Calibri", ...opts })],
});
}
// ─── Helper: alert box (coloured paragraph) ──────────────────────────────────
function alertBox(text, color, bgColor) {
return new Paragraph({
spacing: { before: 100, after: 100 },
indent: { left: 200, right: 200 },
shading: { type: ShadingType.SOLID, color: bgColor },
children: [new TextRun({ text, bold: true, size: 20, color, font: "Calibri" })],
});
}
// ─── Helper: two-column summary table ────────────────────────────────────────
function summaryTable(rows) {
// rows: [{label, value, status}] status: 'critical'|'warning'|'normal'|'info'
const bgMap = { critical: RED_BG, warning: ORANGE_BG, normal: GREEN_BG, info: WHITE };
const iconMap = { critical: "🔴", warning: "⚠️", normal: "✅", info: "" };
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
layout: TableLayoutType.FIXED,
rows: [
// header
new TableRow({
tableHeader: true,
children: [
new TableCell({
width: { size: 45, type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: "Test", bold: true, color: WHITE, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
width: { size: 20, type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: "Result", bold: true, color: WHITE, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
width: { size: 20, type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: "Reference", bold: true, color: WHITE, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
width: { size: 15, type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: "Status", bold: true, color: WHITE, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
],
}),
...rows.map(r => new TableRow({
children: [
new TableCell({
shading: { type: ShadingType.SOLID, color: bgMap[r.status] || WHITE },
children: [new Paragraph({ children: [new TextRun({ text: r.label, size: 20, font: "Calibri", bold: r.status === 'critical' })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
shading: { type: ShadingType.SOLID, color: bgMap[r.status] || WHITE },
children: [new Paragraph({ children: [new TextRun({ text: r.value, size: 20, font: "Calibri", bold: r.status === 'critical' })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
shading: { type: ShadingType.SOLID, color: bgMap[r.status] || WHITE },
children: [new Paragraph({ children: [new TextRun({ text: r.ref, size: 18, font: "Calibri", color: "555555" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
shading: { type: ShadingType.SOLID, color: bgMap[r.status] || WHITE },
children: [new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text: iconMap[r.status] || "", size: 20 })] })],
verticalAlign: VerticalAlign.CENTER,
}),
],
})),
],
});
}
// ─── Helper: 3-col plan table ─────────────────────────────────────────────────
function planTable(rows) {
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
layout: TableLayoutType.FIXED,
rows: [
new TableRow({
tableHeader: true,
children: ["Priority", "Finding", "Action"].map((h, i) => new TableCell({
width: { size: [10, 40, 50][i], type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_MID },
children: [new Paragraph({ children: [new TextRun({ text: h, bold: true, color: WHITE, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
})),
}),
...rows.map((r, idx) => new TableRow({
children: [
new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? BLUE_LIGHT : WHITE },
children: [new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text: r.priority, bold: true, size: 20, font: "Calibri", color: BLUE_DARK })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? BLUE_LIGHT : WHITE },
children: [new Paragraph({ children: [new TextRun({ text: r.finding, bold: true, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? BLUE_LIGHT : WHITE },
children: [new Paragraph({ children: [new TextRun({ text: r.action, size: 20, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
}),
],
})),
],
});
}
// ─── Helper: medication table ────────────────────────────────────────────────
function medTable(rows) {
const headers = ["Medication", "Dose", "Frequency", "Duration", "Notes"];
const widths = [22, 13, 15, 13, 37];
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
layout: TableLayoutType.FIXED,
rows: [
new TableRow({
tableHeader: true,
children: headers.map((h, i) => new TableCell({
width: { size: widths[i], type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: h, bold: true, color: WHITE, size: 19, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
})),
}),
...rows.map((r, idx) => new TableRow({
children: [r.med, r.dose, r.freq, r.dur, r.notes].map((v, ci) => new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? BLUE_LIGHT : WHITE },
children: [new Paragraph({ children: [new TextRun({ text: v, size: 19, font: "Calibri", bold: ci === 0 })] })],
verticalAlign: VerticalAlign.CENTER,
})),
})),
],
});
}
// ─── Helper: follow-up table ─────────────────────────────────────────────────
function followUpTable(rows) {
const headers = ["Timeframe", "Investigation / Action", "Target / Goal"];
const widths = [20, 45, 35];
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
layout: TableLayoutType.FIXED,
rows: [
new TableRow({
tableHeader: true,
children: headers.map((h, i) => new TableCell({
width: { size: widths[i], type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({ children: [new TextRun({ text: h, bold: true, color: WHITE, size: 19, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
})),
}),
...rows.map((r, idx) => new TableRow({
children: [r.time, r.action, r.target].map((v, ci) => new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? BLUE_LIGHT : WHITE },
children: [new Paragraph({ children: [new TextRun({ text: v, size: 19, font: "Calibri", bold: ci === 0 })] })],
verticalAlign: VerticalAlign.CENTER,
})),
})),
],
});
}
// ─── Cover page ──────────────────────────────────────────────────────────────
function coverPage() {
return [
spacer(800),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 200 },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [
new TextRun({ text: " COMPREHENSIVE TREATMENT PLAN ", bold: true, size: 48, color: WHITE, font: "Calibri" }),
],
}),
spacer(200),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 120 },
children: [new TextRun({ text: "Full Body Health Checkup Panel-3 — Lab ID: 12427690 / 12427692", size: 24, color: BLUE_MID, font: "Calibri" })],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 120 },
children: [new TextRun({ text: "Collection Date: 27 June 2026", size: 22, color: "444444", font: "Calibri" })],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 120 },
children: [new TextRun({ text: "Prepared: 02 July 2026", size: 22, color: "444444", font: "Calibri" })],
}),
spacer(400),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 80 },
children: [new TextRun({ text: "Patients", bold: true, size: 26, color: BLUE_DARK, font: "Calibri" })],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 80 },
children: [new TextRun({ text: "Mr. Subhash Chandra Jha | 60 Years | Male", size: 24, font: "Calibri" })],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 80 },
children: [new TextRun({ text: "Mrs. Deji Jha | 50 Years | Female", size: 24, font: "Calibri" })],
}),
spacer(600),
alertBox(
"DISCLAIMER: This treatment plan is for informational and clinical reference purposes only. " +
"All therapeutic decisions must be made by a qualified and licensed medical practitioner " +
"after full clinical evaluation of the patient.",
"7B0000", "FDECEA"
),
new Paragraph({ children: [new PageBreak()] }),
];
}
// ═══════════════════════════════════════════════════════════════════════════════
// PATIENT 1 — MR. SUBHASH CHANDRA JHA
// ═══════════════════════════════════════════════════════════════════════════════
function patient1() {
return [
// ── Patient banner
new Paragraph({
spacing: { before: 200, after: 160 },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [
new TextRun({ text: " PATIENT 1 | Mr. Subhash Chandra Jha | 60 Y / Male", bold: true, size: 30, color: WHITE, font: "Calibri" }),
],
}),
labelPara("Lab ID", "12427690"),
labelPara("Collection Date", "27 June 2026"),
labelPara("Referred By", "Self"),
spacer(160),
// ── Lab summary
sectionHead("1. LABORATORY RESULTS SUMMARY"),
spacer(80),
summaryTable([
{ label: "HbA1c (Glycated Haemoglobin)", value: "5.7 %", ref: "<=5.6% (Non-diabetic)", status: "warning" },
{ label: "Fasting Blood Glucose", value: "114 mg/dL", ref: "70-110 mg/dL", status: "warning" },
{ label: "Mean Plasma Glucose", value: "116.3 mg/dL", ref: "90-120 (Excellent)", status: "normal" },
{ label: "Triglycerides", value: "177 mg/dL", ref: "<150 (Normal)", status: "warning" },
{ label: "Total Cholesterol", value: "197 mg/dL", ref: "<200 (Desirable)", status: "normal" },
{ label: "HDL Cholesterol", value: "44 mg/dL", ref: ">60 (Optimal)", status: "warning" },
{ label: "LDL Cholesterol", value: "117.60 mg/dL", ref: "<130 (Desirable)", status: "normal" },
{ label: "VLDL Cholesterol", value: "35.40 mg/dL", ref: "<40", status: "normal" },
{ label: "Non-HDL Cholesterol", value: "153 mg/dL", ref: "<170", status: "normal" },
{ label: "Bilirubin Total / Direct / Indirect", value: "0.60 / 0.20 / 0.40 mg/dL", ref: "Within normal limits", status: "normal" },
{ label: "SGOT (AST)", value: "48 U/L", ref: "17-59 U/L", status: "normal" },
{ label: "SGPT (ALT)", value: "50 U/L", ref: "4-50 U/L (at upper limit)", status: "warning" },
{ label: "GGT", value: "52 U/L", ref: "15-73 U/L", status: "normal" },
{ label: "Kidney Function (Urea, Creatinine, Electrolytes)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "TSH (Thyroid Stimulating Hormone)", value: "7.79 µIU/mL", ref: "0.46-4.68 µIU/mL", status: "critical" },
{ label: "TT3 (Triiodothyronine)", value: "1.12 ng/mL", ref: "0.97-1.69 ng/mL", status: "normal" },
{ label: "TT4 (Thyroxine)", value: "7.40 µg/dL", ref: "5.53-11.0 µg/dL", status: "normal" },
{ label: "Urine - Pus Cells", value: "3-5 /HPF", ref: "0-5 /HPF", status: "warning" },
{ label: "Urine - Bacteria", value: "Nil", ref: "Nil", status: "normal" },
{ label: "Iron Profile (Iron, TIBC, Transferrin Sat.)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "Haemoglobin", value: "15.8 g/dL", ref: "13.5-18.0 g/dL", status: "normal" },
{ label: "CBC (WBC, Platelets, Differentials)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "ESR (Westergren)", value: "12 mm/hr", ref: "0-15 mm/hr", status: "normal" },
{ label: "Vitamin D (25-OH)", value: "22.50 ng/mL", ref: "30-100 (Sufficient)", status: "warning" },
{ label: "Vitamin B12", value: "285.0 pg/mL", ref: "203-792 pg/mL", status: "normal" },
]),
spacer(200),
// ── Diagnosis
sectionHead("2. CLINICAL ASSESSMENT & DIAGNOSES"),
spacer(80),
subHead("Primary Diagnoses:"),
bullet("Subclinical Hypothyroidism — TSH 7.79 µIU/mL with normal T3 and T4"),
bullet("Prediabetes (Impaired Fasting Glucose + HbA1c in risk range) — IFG with FBG 114 mg/dL and HbA1c 5.7%"),
spacer(60),
subHead("Secondary / Metabolic Concerns:"),
bullet("Borderline Hypertriglyceridemia — likely secondary to subclinical hypothyroidism and dietary factors"),
bullet("Vitamin D Insufficiency — 25-OH Vitamin D 22.5 ng/mL (target >30 ng/mL)"),
bullet("ALT at upper limit of normal — monitor for NAFLD given prediabetes and dyslipidaemia"),
bullet("HDL mildly sub-optimal at 44 mg/dL"),
spacer(60),
subHead("Reassuring Findings:"),
bullet("Normal T3 and T4 (subclinical, not overt hypothyroidism)"),
bullet("Kidney function, iron profile, CBC, ESR — all normal"),
bullet("No evidence of anaemia or significant infection"),
bullet("Vitamin B12 within normal range"),
spacer(200),
// ── Medications
sectionHead("3. PHARMACOLOGICAL TREATMENT PLAN"),
spacer(80),
subHead("3.1 Thyroid — Subclinical Hypothyroidism"),
spacer(60),
alertBox(
"ACTION REQUIRED FIRST: Repeat TSH after 3-6 months AND check Anti-TPO antibodies before initiating Levothyroxine. " +
"Treatment initiation is at physician's discretion based on symptoms and repeat values.",
BLUE_DARK, BLUE_LIGHT
),
spacer(80),
medTable([
{
med: "Levothyroxine (T4) — if symptomatic or TSH confirmed elevated on repeat",
dose: "25-50 mcg",
freq: "Once daily, morning, empty stomach",
dur: "Long-term (lifelong if autoimmune)",
notes: "Titrate by 12.5-25 mcg every 6-8 weeks. Target TSH: 1.0-2.5 µIU/mL. Take 30-60 min before breakfast. Avoid calcium/iron within 4 hours.",
},
]),
spacer(100),
subHead("3.2 Vitamin D Insufficiency"),
spacer(60),
medTable([
{
med: "Cholecalciferol (Vitamin D3)",
dose: "60,000 IU",
freq: "Once weekly",
dur: "8-12 weeks (loading)",
notes: "Take with a fatty meal for best absorption. Follow with maintenance after loading.",
},
{
med: "Cholecalciferol (Vitamin D3) — Maintenance",
dose: "1000-2000 IU",
freq: "Once daily",
dur: "Ongoing",
notes: "Start after completing loading dose. Recheck 25-OH Vitamin D at 12 weeks. Target >30 ng/mL.",
},
{
med: "Calcium (from diet or supplement, e.g. Calcium Carbonate)",
dose: "1000 mg/day total",
freq: "Divided doses with meals",
dur: "Ongoing",
notes: "Prioritise dietary calcium. Supplement only if dietary intake is insufficient. Do not take within 4h of Levothyroxine.",
},
]),
spacer(100),
subHead("3.3 Dyslipidaemia — No Pharmacotherapy at Present"),
spacer(60),
para("Triglycerides at 177 mg/dL (borderline) and LDL at 117.60 mg/dL do not currently meet thresholds for statin or fibrate therapy. Treat the underlying hypothyroidism first (which commonly normalises lipids) and reassess in 3 months. Omega-3 fatty acid supplement (1-2g EPA+DHA daily) is reasonable as a dietary adjunct."),
spacer(100),
subHead("3.4 Prediabetes — No Pharmacotherapy at Present"),
spacer(60),
para("At HbA1c 5.7% with no additional high-risk features (BMI <35, age 60), lifestyle modification is the primary intervention. Metformin may be considered at follow-up if HbA1c progresses despite lifestyle efforts."),
spacer(200),
// ── Lifestyle
sectionHead("4. LIFESTYLE & DIETARY INTERVENTIONS"),
spacer(80),
subHead("4.1 Dietary Recommendations"),
bullet("Switch from white rice and refined flour (maida) to millets (ragi, jowar, bajra) or brown rice"),
bullet("Increase dietary fibre: vegetables, legumes, whole pulses, leafy greens"),
bullet("Reduce added sugars and sweetened beverages completely"),
bullet("Limit red meat; include fish (especially fatty fish: mackerel, salmon, sardines) 2-3x/week for Omega-3s"),
bullet("Include walnuts, flaxseeds (alsi), chia seeds for Omega-3 fatty acids"),
bullet("Use olive oil or mustard oil for cooking; avoid vanaspati/trans fats"),
bullet("Limit sodium intake to <2.3 g/day (reduce pickles, papads, processed foods)"),
bullet("Bitter gourd (karela), fenugreek seeds (methi) — beneficial for glucose regulation"),
bullet("Ensure adequate calcium-rich foods: dairy, sesame seeds, dark leafy greens"),
spacer(80),
subHead("4.2 Physical Activity"),
bullet("Aerobic exercise: minimum 150 minutes per week (brisk walking, cycling, swimming)"),
bullet("Aim for 30 minutes daily, 5 days per week at moderate intensity"),
bullet("Add 2 days/week of light resistance or strength training (to preserve muscle mass at age 60)"),
bullet("Avoid prolonged sitting — break every 45-60 minutes with a short walk"),
spacer(80),
subHead("4.3 Lifestyle Modifications"),
bullet("Achieve and maintain healthy body weight — target 5-7% weight loss if overweight"),
bullet("Sun exposure: 15-20 minutes daily (10 AM-2 PM) on arms and face for Vitamin D synthesis"),
bullet("Adequate sleep: 7-8 hours per night (sleep deprivation worsens glucose metabolism and thyroid function)"),
bullet("Limit alcohol: strongly recommended — alcohol worsens triglycerides and glucose control"),
bullet("Stress management: yoga, meditation, or relaxation techniques (stress elevates cortisol and impairs thyroid)"),
spacer(200),
// ── Investigations
sectionHead("5. INVESTIGATIONS TO BE ORDERED"),
spacer(80),
subHead("Immediate (within 1-2 weeks):"),
bullet("Anti-TPO antibodies (Anti-Thyroid Peroxidase) — to determine autoimmune cause of elevated TSH"),
bullet("Repeat TSH (confirm elevation on fresh sample before treating)"),
bullet("Fasting insulin level and HOMA-IR index — to assess degree of insulin resistance"),
spacer(80),
subHead("Within 1 month:"),
bullet("Abdominal ultrasound (USG) — to assess for hepatic steatosis (fatty liver) given borderline ALT and dyslipidaemia"),
bullet("Blood pressure measurement and complete clinical examination"),
bullet("Body weight and BMI measurement"),
spacer(80),
subHead("At 3 months (follow-up):"),
bullet("Repeat Lipid Profile (fasting, confirmed 12-hour fast) — after lifestyle changes and thyroid treatment"),
bullet("Repeat HbA1c and fasting glucose"),
bullet("Repeat LFT (liver function test)"),
bullet("Repeat TSH (to monitor levothyroxine dose if started)"),
spacer(80),
subHead("At 12 weeks:"),
bullet("Repeat 25-OH Vitamin D — target >30 ng/mL after loading dose"),
spacer(200),
// ── Follow-up schedule
sectionHead("6. FOLLOW-UP SCHEDULE"),
spacer(80),
followUpTable([
{ time: "1-2 Weeks", action: "Anti-TPO antibodies + Repeat TSH; Clinical consultation for thyroid decision", target: "Confirm subclinical hypothyroidism; decide on Levothyroxine" },
{ time: "4-6 Weeks", action: "Review Vitamin D3 loading progress; dietary counselling session", target: "Compliance with supplementation and lifestyle plan" },
{ time: "3 Months", action: "Repeat HbA1c, FBG, Lipid profile, LFT, TSH; USG abdomen if not done", target: "HbA1c <5.7%, TG <150, TSH 1-2.5 µIU/mL, ALT normal" },
{ time: "12 Weeks", action: "Repeat 25-OH Vitamin D", target: "Level >30 ng/mL; switch to maintenance dose" },
{ time: "6 Months", action: "Full clinical review; repeat CBC, B12, iron profile", target: "Confirm all metabolic parameters trending to normal" },
{ time: "Annual", action: "Full body health check; DEXA scan consideration after age 65", target: "Prevent progression to diabetes, overt hypothyroidism, cardiovascular disease" },
]),
spacer(200),
// ── Priority action plan
sectionHead("7. PRIORITY ACTION PLAN"),
spacer(80),
planTable([
{ priority: "1 - Urgent", finding: "TSH 7.79 µIU/mL (Subclinical Hypothyroidism)", action: "Repeat TSH + Anti-TPO within 2 weeks. Consult endocrinologist. Start Levothyroxine 25-50 mcg if symptomatic / confirmed." },
{ priority: "2 - Important", finding: "Prediabetes (HbA1c 5.7%, FBG 114 mg/dL)", action: "Start structured lifestyle program: low-GI diet + 150 min/week aerobic exercise. Repeat HbA1c in 3 months." },
{ priority: "3 - Important", finding: "Vitamin D Insufficiency (22.5 ng/mL)", action: "Cholecalciferol 60,000 IU weekly x 8-12 weeks, then 1000-2000 IU/day maintenance + 1000 mg calcium/day." },
{ priority: "4 - Monitor", finding: "Borderline Triglycerides (177 mg/dL)", action: "Treat hypothyroidism first. Reduce dietary sugar/refined carbs. Omega-3 supplement 1-2g/day. Recheck at 3 months." },
{ priority: "5 - Monitor", finding: "ALT at upper limit (50 U/L)", action: "Abdominal USG for hepatic steatosis. Repeat LFT in 3 months after lifestyle changes." },
]),
spacer(300),
new Paragraph({ children: [new PageBreak()] }),
];
}
// ═══════════════════════════════════════════════════════════════════════════════
// PATIENT 2 — MRS. DEJI JHA
// ═══════════════════════════════════════════════════════════════════════════════
function patient2() {
return [
// ── Patient banner
new Paragraph({
spacing: { before: 200, after: 160 },
shading: { type: ShadingType.SOLID, color: "6B1B1B" },
children: [
new TextRun({ text: " PATIENT 2 | Mrs. Deji Jha | 50 Y / Female", bold: true, size: 30, color: WHITE, font: "Calibri" }),
],
}),
labelPara("Lab ID", "12427692"),
labelPara("Collection Date", "27 June 2026"),
labelPara("Referred By", "Self"),
spacer(160),
// ── Lab summary
sectionHead("1. LABORATORY RESULTS SUMMARY"),
spacer(80),
summaryTable([
{ label: "HbA1c (Glycated Haemoglobin)", value: "5.9 %", ref: "<=5.6% (Non-diabetic)", status: "warning" },
{ label: "Fasting Blood Glucose", value: "105 mg/dL", ref: "70-110 mg/dL (upper end)", status: "normal" },
{ label: "Mean Plasma Glucose", value: "122.0 mg/dL", ref: "90-120 (Excellent) / 121-150 (Good)", status: "warning" },
{ label: "Triglycerides", value: "209 mg/dL", ref: "<150 Normal / 200-499 HIGH", status: "critical" },
{ label: "Total Cholesterol", value: "182 mg/dL", ref: "<200 (Desirable)", status: "normal" },
{ label: "HDL Cholesterol", value: "46 mg/dL", ref: ">60 (Optimal)", status: "warning" },
{ label: "VLDL Cholesterol", value: "41.80 mg/dL", ref: "<40", status: "warning" },
{ label: "LDL Cholesterol", value: "94.20 mg/dL", ref: "<130 (Desirable)", status: "normal" },
{ label: "Non-HDL Cholesterol", value: "136 mg/dL", ref: "<170", status: "normal" },
{ label: "SGOT (AST)", value: "70 U/L", ref: "14-36 U/L", status: "critical" },
{ label: "SGPT (ALT)", value: "63 U/L", ref: "4-35 U/L", status: "critical" },
{ label: "GGT", value: "53 U/L", ref: "12-43 U/L", status: "critical" },
{ label: "Globulin Serum", value: "3.39 g/dL", ref: "2.0-3.5 g/dL", status: "warning" },
{ label: "A/G Ratio (Albumin/Globulin)", value: "1.06", ref: "1.20-2.10", status: "warning" },
{ label: "Albumin Serum", value: "3.60 g/dL", ref: "3.5-5.0 g/dL (lower end)", status: "normal" },
{ label: "Kidney Function (Urea, Creatinine, Electrolytes)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "TSH (Thyroid Stimulating Hormone)", value: "3.64 µIU/mL", ref: "0.46-4.68 µIU/mL", status: "normal" },
{ label: "TT3 / TT4", value: "1.32 ng/mL / 9.90 µg/dL", ref: "Normal", status: "normal" },
{ label: "Urine — Pus Cells", value: "5-6 /HPF", ref: "0-5 /HPF", status: "critical" },
{ label: "Urine — Epithelial Cells", value: "8-10 /HPF", ref: "1-4 /HPF", status: "critical" },
{ label: "Urine — Bacteria", value: "Present", ref: "Nil", status: "critical" },
{ label: "Urine — Appearance", value: "Slightly Turbid", ref: "Clear", status: "warning" },
{ label: "Iron Profile (Iron, TIBC, Transferrin Sat.)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "Haemoglobin", value: "13.3 g/dL", ref: "12.5-16.0 g/dL", status: "normal" },
{ label: "PCV (Packed Cell Volume)", value: "40.5 %", ref: "41-53 %", status: "warning" },
{ label: "CBC (WBC, Platelets, Differentials)", value: "All within range", ref: "Normal", status: "normal" },
{ label: "ESR (Westergren)", value: "14 mm/hr", ref: "0-20 mm/hr", status: "normal" },
{ label: "Vitamin D (25-OH)", value: "16.20 ng/mL", ref: "30-100 (Sufficient)", status: "critical" },
{ label: "Vitamin B12", value: "263.0 pg/mL", ref: "203-792 pg/mL (lower end)", status: "normal" },
]),
spacer(200),
// ── Diagnosis
sectionHead("2. CLINICAL ASSESSMENT & DIAGNOSES"),
spacer(80),
subHead("Primary Diagnoses:"),
bullet("Suspected Urinary Tract Infection (UTI) — Bacteria present in urine, elevated pus cells (5-6/HPF), raised epithelial cells (8-10/HPF), slightly turbid urine"),
bullet("Elevated Liver Enzymes (Hepatitis screen required) — AST 70, ALT 63, GGT 53; probable NAFLD/NASH given metabolic profile; viral hepatitis must be excluded"),
bullet("Hypertriglyceridaemia (High range) — Triglycerides 209 mg/dL, VLDL 41.80 mg/dL"),
spacer(60),
subHead("Secondary / Metabolic Concerns:"),
bullet("Prediabetes — HbA1c 5.9% (deeper in risk range than Patient 1); features of Metabolic Syndrome"),
bullet("Vitamin D Significant Insufficiency — 16.20 ng/mL; higher risk at peri-menopausal age 50"),
bullet("HDL sub-optimal at 46 mg/dL; A/G ratio mildly reduced"),
bullet("PCV borderline low at 40.5% (watch for developing anaemia)"),
spacer(60),
subHead("Metabolic Syndrome Assessment:"),
alertBox(
"Mrs. Jha presents with a cluster of: Prediabetes + High Triglycerides + Sub-optimal HDL + Elevated Liver Enzymes. " +
"This constellation is highly consistent with METABOLIC SYNDROME. Waist circumference measurement is recommended " +
"(threshold for South Asian women: >80 cm). Comprehensive metabolic intervention is required.",
"4A1700", ORANGE_BG
),
spacer(60),
subHead("Reassuring Findings:"),
bullet("Thyroid function completely normal (TSH 3.64 µIU/mL) — contrast to Patient 1"),
bullet("Kidney function, iron profile, CBC — all normal"),
bullet("No anaemia currently; Vitamin B12 within range"),
spacer(200),
// ── Medications
sectionHead("3. PHARMACOLOGICAL TREATMENT PLAN"),
spacer(80),
subHead("3.1 Urinary Tract Infection — URGENT"),
spacer(60),
alertBox(
"URGENT: Send urine for Culture & Sensitivity BEFORE or at the time of starting antibiotics. " +
"Adjust antibiotic based on sensitivity report once available.",
"7B0000", RED_BG
),
spacer(80),
medTable([
{
med: "Nitrofurantoin Monohydrate/Macrocrystalline (Macrobid) — FIRST LINE",
dose: "100 mg",
freq: "Twice daily (BD) with food",
dur: "5 days",
notes: "Take with a full meal to improve absorption and reduce nausea. Do NOT use for upper UTI/pyelonephritis. Suitable here as CrCl is normal (Creatinine 0.78 mg/dL). CAUTION: monitor LFT given elevated enzymes.",
},
{
med: "Trimethoprim-Sulfamethoxazole DS (Alternative if Nitrofurantoin not tolerated)",
dose: "160/800 mg (1 DS tablet)",
freq: "Twice daily (BD)",
dur: "3 days",
notes: "Use only if local E. coli resistance <20%. Contraindicated in G6PD deficiency. Avoid if history of sulfa allergy.",
},
{
med: "Fosfomycin Trometamol (Alternative — single dose, safest with elevated LFTs)",
dose: "3 g sachet",
freq: "Single dose",
dur: "One time",
notes: "Dissolve in water. Preferred alternative if liver enzyme concern with Nitrofurantoin. High efficacy for E. coli and Enterococcus. Take on empty stomach.",
},
]),
spacer(100),
subHead("3.2 Vitamin D Insufficiency (Priority — Peri-menopausal, Bone Risk)"),
spacer(60),
medTable([
{
med: "Cholecalciferol (Vitamin D3) — Loading",
dose: "60,000 IU",
freq: "Once weekly",
dur: "12 weeks",
notes: "Take with a fatty meal. Given lower level (16.2 ng/mL) vs Patient 1, extend loading to 12 weeks. Recheck at 12 weeks.",
},
{
med: "Cholecalciferol (Vitamin D3) — Maintenance",
dose: "1500-2000 IU",
freq: "Once daily",
dur: "Ongoing",
notes: "Start after 12-week loading. Target >30 ng/mL. Especially important for bone protection at peri-menopause.",
},
{
med: "Calcium Carbonate (with meals) or Calcium Citrate (empty stomach)",
dose: "1000-1200 mg/day total",
freq: "Divided doses",
dur: "Ongoing",
notes: "Essential with Vitamin D for bone mineralisation at age 50. Prioritise dietary calcium first (dairy, sesame, leafy greens). Supplement to bridge gap.",
},
]),
spacer(100),
subHead("3.3 Hypertriglyceridaemia — Lifestyle First, Pharmacotherapy If Persistent"),
spacer(60),
medTable([
{
med: "Omega-3 Fatty Acids (Fish Oil: EPA+DHA)",
dose: "2-4 g EPA+DHA",
freq: "Once daily with meal",
dur: "3 months, then review",
notes: "First-line supplement for elevated triglycerides. Re-assess with repeat fasting lipid profile at 3 months. If TG remains >200 mg/dL despite lifestyle change, physician to consider Fenofibrate 145 mg/day (with LFT monitoring).",
},
]),
spacer(100),
subHead("3.4 Prediabetes — No Pharmacotherapy at Present"),
spacer(60),
para("HbA1c 5.9% is in the prediabetes range and is deeper than Patient 1. Structured lifestyle intervention is the mandatory first step. Given features of metabolic syndrome, close follow-up is essential. If HbA1c reaches 6.0-6.4% or does not improve in 3-6 months, Metformin 500 mg twice daily with meals may be initiated under physician guidance."),
spacer(100),
subHead("3.5 Liver Enzymes — No Specific Drug Therapy (Investigation Required First)"),
spacer(60),
para("Pharmacotherapy for liver disease should not be started without a clear diagnosis. The priority is investigation (USG, viral hepatitis screen) and lifestyle modification. Avoid all hepatotoxic medications, including over-the-counter NSAIDs and herbal supplements. Complete alcohol avoidance is mandatory."),
spacer(200),
// ── Lifestyle
sectionHead("4. LIFESTYLE & DIETARY INTERVENTIONS"),
spacer(80),
subHead("4.1 Dietary Recommendations (Metabolic Syndrome Focus)"),
bullet("STRICT elimination of refined sugars: no soft drinks, packaged juices, sweets, mithai, desserts"),
bullet("Drastically reduce refined carbohydrates: white rice, bread, maida-based foods (biscuits, naan, puri)"),
bullet("Switch to millets (ragi, jowar, bajra), whole grain alternatives, and high-fibre foods"),
bullet("Increase non-starchy vegetables: brinjal, lauki, tinda, karela, spinach, fenugreek"),
bullet("Include legumes and dal daily for protein and fibre"),
bullet("Healthy fats: olive oil, mustard oil, nuts, seeds — avoid vanaspati, ghee in excess"),
bullet("Omega-3 rich foods: fatty fish 2-3x/week, walnuts, flaxseed (alsi powder) daily"),
bullet("Complete alcohol avoidance (critical for liver and triglyceride management)"),
bullet("Intermittent fasting (12:12 or 14:10 pattern) may be considered for weight and metabolic benefits"),
spacer(80),
subHead("4.2 Physical Activity"),
bullet("Aerobic exercise: minimum 150-200 minutes/week — brisk walking, swimming, cycling"),
bullet("Aim for 40-45 minutes daily to target both triglycerides and glucose"),
bullet("2 sessions/week of resistance training (light weights or resistance bands) for metabolic health and bone density"),
bullet("Walking after meals (10-15 minutes post-meal) is especially effective for glucose control"),
spacer(80),
subHead("4.3 Lifestyle Modifications — Peri-menopausal Considerations"),
bullet("Sun exposure: 15-20 minutes daily on arms and face (10 AM-2 PM) — Vitamin D is critical at this age"),
bullet("Weight-bearing exercise is doubly important for bone health at peri-menopause"),
bullet("Target 7-10% weight loss if overweight — this alone can significantly reduce liver enzymes, triglycerides, and HbA1c"),
bullet("Maintain adequate hydration: 2.5-3 litres of water daily (especially important during UTI treatment and prevention)"),
bullet("Urinary hygiene: void after intercourse, wipe front to back, avoid scented products in genital area — to prevent recurrent UTI"),
bullet("Sleep hygiene: 7-8 hours per night — poor sleep worsens insulin resistance and metabolic syndrome"),
bullet("Stress reduction: yoga, meditation, or pranayama — chronic stress elevates cortisol, worsening metabolic parameters"),
spacer(200),
// ── Investigations
sectionHead("5. INVESTIGATIONS TO BE ORDERED"),
spacer(80),
subHead("Immediate / Urgent (within 1 week):"),
bullet("Urine Culture & Sensitivity — URGENT (to guide antibiotic selection for UTI)"),
bullet("HBsAg (Hepatitis B surface antigen) — to rule out Hepatitis B"),
bullet("Anti-HCV (Hepatitis C antibody) — to rule out Hepatitis C"),
bullet("Abdominal Ultrasound (USG abdomen) — to assess liver (fatty liver / steatosis), size, texture; gallbladder"),
spacer(80),
subHead("Within 2-4 Weeks:"),
bullet("ANA, Anti-smooth muscle antibody (ASMA) — if viral hepatitis excluded, to rule out autoimmune hepatitis"),
bullet("Fasting insulin level and HOMA-IR — to quantify insulin resistance"),
bullet("Serum ferritin — to rule out haemochromatosis as cause of elevated liver enzymes"),
bullet("Waist circumference measurement — to confirm Metabolic Syndrome (>80 cm in South Asian women)"),
bullet("DEXA scan (bone mineral density) — strongly recommended at age 50 female with Vitamin D insufficiency to establish baseline"),
spacer(80),
subHead("At 3 Months (Follow-up):"),
bullet("Repeat LFT (AST, ALT, GGT) — assess response to lifestyle changes"),
bullet("Repeat fasting lipid profile (confirmed 12-hour fast) — assess triglycerides response"),
bullet("Repeat HbA1c and fasting glucose"),
bullet("Repeat urine routine — confirm UTI resolution"),
spacer(80),
subHead("At 12 Weeks:"),
bullet("Repeat 25-OH Vitamin D — target >30 ng/mL"),
bullet("Repeat CBC including PCV — monitor for developing anaemia"),
spacer(200),
// ── Follow-up schedule
sectionHead("6. FOLLOW-UP SCHEDULE"),
spacer(80),
followUpTable([
{ time: "3-5 Days", action: "Urine C&S result review; confirm UTI resolution or adjust antibiotic", target: "Organism identified; appropriate antibiotic confirmed; symptoms resolving" },
{ time: "1-2 Weeks", action: "HBsAg, Anti-HCV, USG abdomen; clinical review of UTI completion", target: "Viral hepatitis excluded; fatty liver confirmed or excluded; UTI cleared" },
{ time: "2-4 Weeks", action: "Autoimmune liver panel if viral screen negative; fasting insulin; waist circumference; DEXA referral", target: "Clear diagnosis for liver enzyme elevation; quantify insulin resistance; baseline bone density" },
{ time: "12 Weeks", action: "Repeat 25-OH Vitamin D; switch to maintenance dose if >30 ng/mL", target: "Vitamin D >30 ng/mL" },
{ time: "3 Months", action: "Repeat LFT, lipid profile (fasting), HbA1c, urine routine, CBC", target: "AST/ALT trending down; TG <150; HbA1c stable or improving; urine clear" },
{ time: "6 Months", action: "Full metabolic review; consider Metformin if HbA1c not improving", target: "HbA1c <5.7% or stable; TG <150; liver enzymes normalising" },
{ time: "Annual", action: "Full body health check; DEXA scan follow-up; gynaecological review", target: "Prevent progression to diabetes, NAFLD-to-NASH, osteoporosis" },
]),
spacer(200),
// ── Priority plan
sectionHead("7. PRIORITY ACTION PLAN"),
spacer(80),
planTable([
{ priority: "1 - URGENT", finding: "UTI (Bacteria + Pus Cells + Turbid urine)", action: "Urine C&S immediately. Start Nitrofurantoin 100 mg BD x 5 days with food. Review C&S at day 3-5." },
{ priority: "2 - URGENT", finding: "Elevated AST 70, ALT 63, GGT 53", action: "HBsAg + Anti-HCV + USG abdomen within 1 week. Consult gastroenterologist. Avoid alcohol and hepatotoxic drugs completely." },
{ priority: "3 - Important", finding: "High Triglycerides 209 mg/dL", action: "Eliminate dietary sugar/alcohol. Omega-3 2-4g daily. Re-check fasting lipid profile at 3 months. Consider Fenofibrate if persistent." },
{ priority: "4 - Important", finding: "Vitamin D 16.2 ng/mL (Significantly Insufficient)", action: "Cholecalciferol 60,000 IU weekly x 12 weeks + Calcium 1000-1200 mg/day. DEXA scan. Recheck D at 12 weeks." },
{ priority: "5 - Important", finding: "Prediabetes — HbA1c 5.9%", action: "Structured diet + 150-200 min/week exercise. Metformin if HbA1c progresses. Recheck HbA1c in 3 months." },
{ priority: "6 - Monitor", finding: "PCV 40.5% + B12 263 pg/mL (low-normal)", action: "Repeat CBC and B12 at 3-6 months. Supplement B12 1000 mcg/day if vegetarian." },
]),
spacer(200),
new Paragraph({ children: [new PageBreak()] }),
];
}
// ═══════════════════════════════════════════════════════════════════════════════
// COMPARATIVE SUMMARY PAGE
// ═══════════════════════════════════════════════════════════════════════════════
function comparativePage() {
return [
new Paragraph({
spacing: { before: 200, after: 160 },
shading: { type: ShadingType.SOLID, color: "2D4739" },
children: [
new TextRun({ text: " COMPARATIVE SUMMARY — Both Patients", bold: true, size: 30, color: WHITE, font: "Calibri" }),
],
}),
spacer(100),
new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
layout: TableLayoutType.FIXED,
rows: [
new TableRow({
tableHeader: true,
children: ["Parameter", "Mr. Subhash Chandra Jha (60M)", "Mrs. Deji Jha (50F)", "More Concern"].map((h, i) => new TableCell({
width: { size: [25, 25, 25, 25][i], type: WidthType.PERCENTAGE },
shading: { type: ShadingType.SOLID, color: "2D4739" },
children: [new Paragraph({ children: [new TextRun({ text: h, bold: true, color: WHITE, size: 19, font: "Calibri" })] })],
verticalAlign: VerticalAlign.CENTER,
})),
}),
...([
["TSH (Thyroid)", "7.79 µIU/mL ⚠️ HIGH", "3.64 µIU/mL ✅ Normal", "Mr. Jha"],
["HbA1c", "5.7% ⚠️ Prediabetes", "5.9% ⚠️ Prediabetes", "Mrs. Jha (higher)"],
["Fasting Glucose", "114 mg/dL ⚠️", "105 mg/dL ✅", "Mr. Jha"],
["Triglycerides", "177 mg/dL ⚠️ Borderline", "209 mg/dL 🔴 High", "Mrs. Jha"],
["AST (SGOT)", "48 U/L ✅ Normal", "70 U/L 🔴 ELEVATED", "Mrs. Jha"],
["ALT (SGPT)", "50 U/L ⚠️ At limit", "63 U/L 🔴 ELEVATED", "Mrs. Jha"],
["GGT", "52 U/L ✅ Normal", "53 U/L 🔴 Above normal", "Mrs. Jha"],
["Urine", "3-5 pus cells, no bacteria ✅", "Bacteria + 5-6 pus cells 🔴 UTI", "Mrs. Jha — Active UTI"],
["Vitamin D", "22.5 ng/mL ⚠️ Insufficient", "16.2 ng/mL 🔴 Lower", "Mrs. Jha"],
["Vitamin B12", "285 pg/mL ✅ (lower-normal)", "263 pg/mL ✅ (lower-normal)", "Both — monitor"],
["Kidney Function", "✅ Normal", "✅ Normal", "Both Normal"],
["Haemogram / CBC", "✅ Normal", "✅ Normal (PCV borderline)", "Mrs. Jha (PCV watch)"],
]).map((r, idx) => new TableRow({
children: r.map((v, ci) => new TableCell({
shading: { type: ShadingType.SOLID, color: idx % 2 === 0 ? "E8F0EB" : WHITE },
children: [new Paragraph({ children: [new TextRun({ text: v, size: 18, font: "Calibri", bold: ci === 0 })] })],
verticalAlign: VerticalAlign.CENTER,
})),
})),
],
}),
spacer(200),
sectionHead("OVERALL CLINICAL PRIORITY"),
spacer(80),
para("Mr. Subhash Chandra Jha: The dominant issue is subclinical hypothyroidism (TSH 7.79) which, if untreated, will worsen his dyslipidaemia, glucose intolerance, and cardiovascular risk over time. This requires prompt investigation (Anti-TPO, repeat TSH) and likely Levothyroxine therapy. His other findings are manageable with lifestyle changes."),
spacer(80),
para("Mrs. Deji Jha: She carries a heavier and more urgent burden with four significant abnormalities — an active UTI requiring immediate antibiotic treatment, elevated liver enzymes requiring urgent investigation to exclude hepatitis, high triglycerides, and significantly low Vitamin D. The cluster of metabolic findings (prediabetes + high TG + elevated liver enzymes) in a 50-year-old peri-menopausal woman strongly suggests Metabolic Syndrome with early NAFLD and requires a comprehensive, sustained intervention."),
spacer(200),
hr(),
spacer(100),
alertBox(
"MEDICAL DISCLAIMER: This comprehensive treatment plan has been generated based on laboratory results only. " +
"All recommendations must be reviewed and approved by a qualified, licensed medical practitioner before implementation. " +
"Drug dosages, investigation orders, and clinical decisions must be individualized based on the patient's complete history, " +
"physical examination, current medications, allergies, comorbidities, and clinical judgment. " +
"Do not initiate any treatment based solely on this document.",
"7B0000", "FDECEA"
),
spacer(80),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 60 },
children: [new TextRun({ text: "Document prepared by Orris AI Medical Assistant | 02 July 2026", size: 17, color: "888888", font: "Calibri", italics: true })],
}),
new Paragraph({
alignment: AlignmentType.CENTER,
spacing: { after: 60 },
children: [new TextRun({ text: "Laboratory: YOUR LAB | Full Body Health Checkup Panel-3", size: 17, color: "888888", font: "Calibri", italics: true })],
}),
];
}
// ═══════════════════════════════════════════════════════════════════════════════
// BUILD DOCUMENT
// ═══════════════════════════════════════════════════════════════════════════════
const doc = new Document({
creator: "Orris AI Medical Assistant",
title: "Comprehensive Treatment Plan — Jha Family",
description: "Treatment plan for Mr. Subhash Chandra Jha and Mrs. Deji Jha based on lab report dated 27 June 2026",
styles: {
default: {
document: {
run: { font: "Calibri", size: 20 },
},
},
},
sections: [
{
properties: {
page: {
margin: { top: 720, bottom: 720, left: 900, right: 900 },
},
},
headers: {
default: new Header({
children: [
new Paragraph({
border: { bottom: { style: BorderStyle.SINGLE, size: 4, color: BLUE_MID } },
children: [
new TextRun({ text: "Comprehensive Treatment Plan | Mr. Subhash Chandra Jha & Mrs. Deji Jha | 27 June 2026", size: 17, color: "666666", font: "Calibri" }),
],
}),
],
}),
},
footers: {
default: new Footer({
children: [
new Paragraph({
border: { top: { style: BorderStyle.SINGLE, size: 4, color: BLUE_MID } },
alignment: AlignmentType.CENTER,
children: [
new TextRun({ text: "Page ", size: 17, color: "666666", font: "Calibri" }),
new TextRun({ children: [PageNumber.CURRENT], size: 17, color: "666666", font: "Calibri" }),
new TextRun({ text: " of ", size: 17, color: "666666", font: "Calibri" }),
new TextRun({ children: [PageNumber.TOTAL_PAGES], size: 17, color: "666666", font: "Calibri" }),
new TextRun({ text: " | CONFIDENTIAL MEDICAL DOCUMENT", size: 17, color: "888888", font: "Calibri" }),
],
}),
],
}),
},
children: [
...coverPage(),
...patient1(),
...patient2(),
...comparativePage(),
],
},
],
});
Packer.toBuffer(doc).then(buffer => {
fs.writeFileSync("/home/daytona/workspace/treatment-plan/Treatment_Plan_Jha_Family.docx", buffer);
console.log("SUCCESS: Document created.");
}).catch(err => {
console.error("ERROR:", err);
process.exit(1);
});