From cc41b6680a363409b884706686aba45f1c2bd221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 28 Jun 2026 11:53:39 +0200 Subject: [PATCH] refactor(doctor-report): split the type-label keys out of the PDF core Move DOCTOR_REPORT_TYPE_LABEL_KEYS into a jsPDF-free module so leaf consumers can import the map without dragging jspdf + jspdf-autotable into their graph. The PDF core re-exports the map, keeping a single source of truth and its existing import surface intact. Point the clinician share view at the new module so the public share route no longer pulls the PDF renderer into its server graph. --- src/components/clinician/clinician-view.tsx | 2 +- src/lib/doctor-report-pdf-core.ts | 23 ++++++-------------- src/lib/doctor-report/type-label-keys.ts | 24 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 src/lib/doctor-report/type-label-keys.ts diff --git a/src/components/clinician/clinician-view.tsx b/src/components/clinician/clinician-view.tsx index 2b06593a2..1850a2b64 100644 --- a/src/components/clinician/clinician-view.tsx +++ b/src/components/clinician/clinician-view.tsx @@ -10,7 +10,7 @@ * a FENCED, muted wellness card carrying the load-bearing "descriptive, not a * clinical assessment / not a diagnosis" disclaimer. */ -import { DOCTOR_REPORT_TYPE_LABEL_KEYS } from "@/lib/doctor-report-pdf-core"; +import { DOCTOR_REPORT_TYPE_LABEL_KEYS } from "@/lib/doctor-report/type-label-keys"; import type { DoctorReportData } from "@/lib/doctor-report-data"; import type { DoctorReportPrefs } from "@/lib/validations/doctor-report-prefs"; diff --git a/src/lib/doctor-report-pdf-core.ts b/src/lib/doctor-report-pdf-core.ts index 79d3ade8b..54f2895bb 100644 --- a/src/lib/doctor-report-pdf-core.ts +++ b/src/lib/doctor-report-pdf-core.ts @@ -11,6 +11,7 @@ */ import { jsPDF } from "jspdf"; import autoTable from "jspdf-autotable"; +import { DOCTOR_REPORT_TYPE_LABEL_KEYS } from "./doctor-report/type-label-keys"; import { makeFormatters } from "./format-locale"; import type { Locale } from "./i18n/config"; import { convertGlucose, resolveGlucoseUnit } from "./glucose"; @@ -150,23 +151,11 @@ export interface DoctorReportRenderOptions { aiSummary?: string | null; } -/** - * Per-vital label keys. Exported for coverage tests (issue #109 / phase P0) - * so a future enum addition is caught by a unit test rather than reaching - * production as a raw enum string in the PDF. - */ -export const DOCTOR_REPORT_TYPE_LABEL_KEYS: Record = { - WEIGHT: "doctorReport.typeWeight", - BLOOD_PRESSURE_SYS: "doctorReport.typeBpSys", - BLOOD_PRESSURE_DIA: "doctorReport.typeBpDia", - PULSE: "doctorReport.typePulse", - BODY_FAT: "doctorReport.typeBodyFat", - SLEEP_DURATION: "doctorReport.typeSleep", - ACTIVITY_STEPS: "doctorReport.typeSteps", - TOTAL_BODY_WATER: "doctorReport.typeTotalBodyWater", - BONE_MASS: "doctorReport.typeBoneMass", - OXYGEN_SATURATION: "doctorReport.typeOxygenSaturation", -}; +// Per-vital label keys live in a jsPDF-free module so leaf consumers (the +// public clinician share view) can import the map without dragging the PDF +// renderer into their graph. Re-exported here so the PDF core stays the +// single import surface its existing callers already use. +export { DOCTOR_REPORT_TYPE_LABEL_KEYS }; export const DOCTOR_REPORT_TYPE_UNIT_KEYS: Record = { WEIGHT: "kg", diff --git a/src/lib/doctor-report/type-label-keys.ts b/src/lib/doctor-report/type-label-keys.ts new file mode 100644 index 000000000..9123e57b9 --- /dev/null +++ b/src/lib/doctor-report/type-label-keys.ts @@ -0,0 +1,24 @@ +/** + * Per-vital i18n label keys for the doctor report. + * + * Extracted from `doctor-report-pdf-core` so consumers that only need the + * label map (e.g. the public clinician share view, a pure server component) + * do not pull the jsPDF renderer into their module graph. The PDF core + * re-exports this map so there is a single source of truth. + * + * Exported for coverage tests (issue #109 / phase P0) so a future enum + * addition is caught by a unit test rather than reaching production as a raw + * enum string in the PDF. + */ +export const DOCTOR_REPORT_TYPE_LABEL_KEYS: Record = { + WEIGHT: "doctorReport.typeWeight", + BLOOD_PRESSURE_SYS: "doctorReport.typeBpSys", + BLOOD_PRESSURE_DIA: "doctorReport.typeBpDia", + PULSE: "doctorReport.typePulse", + BODY_FAT: "doctorReport.typeBodyFat", + SLEEP_DURATION: "doctorReport.typeSleep", + ACTIVITY_STEPS: "doctorReport.typeSteps", + TOTAL_BODY_WATER: "doctorReport.typeTotalBodyWater", + BONE_MASS: "doctorReport.typeBoneMass", + OXYGEN_SATURATION: "doctorReport.typeOxygenSaturation", +};