From 191ed129d823214462e325f6dcbd09332683e20e Mon Sep 17 00:00:00 2001 From: Gitead Date: Fri, 3 Jul 2026 21:06:44 -0400 Subject: [PATCH] feat: replace DOB with Age in Lab RX form, auto-calculated from patient DOB Age is pre-filled when opening the RX popup by calculating from patient.dateOfBirth. The field is editable in case of override. Both preview card and print output now show Age instead of DOB. Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/chart/lab-rx-modal.jsx | 22 ++++++++++++++---- .../src/components/chart/lab-rx-modal.tsx | 23 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/apps/Frontend/src/components/chart/lab-rx-modal.jsx b/apps/Frontend/src/components/chart/lab-rx-modal.jsx index 91cd17a1..338e81cf 100644 --- a/apps/Frontend/src/components/chart/lab-rx-modal.jsx +++ b/apps/Frontend/src/components/chart/lab-rx-modal.jsx @@ -27,7 +27,17 @@ const EMPTY_TEMPLATE = { name: "", labName: "", labPhone: "", labFax: "", labAddress: "", labAccount: "", caseType: "", material: "", instructions: "Please make\nThank you!", }; -const EMPTY_RX = { toothNumbers: "", shade: "", dueDate: "", doctorName: "", additionalNotes: "Please make\nThank you!" }; +const EMPTY_RX = { toothNumbers: "", shade: "", dueDate: "", doctorName: "", age: "", additionalNotes: "Please make\nThank you!" }; + +const calcAge = (dob) => { + if (!dob) return ""; + const birth = new Date(dob); + const today = new Date(); + let age = today.getFullYear() - birth.getFullYear(); + const m = today.getMonth() - birth.getMonth(); + if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) age--; + return String(age); +}; const CASE_TYPES = ["Crown", "Bridge", "Veneer", "Inlay/Onlay", "Full Denture", "Partial Denture", "Night Guard", "Retainer", "Implant Crown", "Other"]; const MATERIALS = ["Zirconia", "PFM (Porcelain-Fused-to-Metal)", "E-Max", "Acrylic", "Cast Metal", "Composite", "PMMA", "Other"]; @@ -131,7 +141,7 @@ export function LabRxModal({ open, onClose, patient }) { const openRx = (t) => { if (renamingId !== null) return; setRxTemplate(t); - setRx({ ...EMPTY_RX, doctorName: providers[0]?.providerName ?? "" }); + setRx({ ...EMPTY_RX, doctorName: providers[0]?.providerName ?? "", age: calcAge(patient.dateOfBirth) }); }; const startRename = (e, t) => { @@ -451,6 +461,10 @@ export function LabRxModal({ open, onClose, patient }) { setRx((r) => ({ ...r, shade: e.target.value }))} className="h-9 text-sm" /> +
+ + setRx((r) => ({ ...r, age: e.target.value }))} className="h-9 text-sm" /> +
setRx((r) => ({ ...r, dueDate: e.target.value }))} className="h-9 text-sm" /> @@ -499,7 +513,7 @@ export function LabRxModal({ open, onClose, patient }) {
Patient

{patientName}

-
DOB

{patient.dateOfBirth ? new Date(patient.dateOfBirth).toLocaleDateString("en-US") : "—"}

+
Age

{rx.age || "—"}

Lab

{rxTemplate.labName || "—"}

Phone

{rxTemplate.labPhone || "—"}

{rxTemplate.labFax &&
Fax

{rxTemplate.labFax}

} @@ -537,7 +551,7 @@ export function LabRxModal({ open, onClose, patient }) {
Patient Information
{patientName}
-
{patient.dateOfBirth ? new Date(patient.dateOfBirth).toLocaleDateString("en-US") : ""}
+
{rx.age}
diff --git a/apps/Frontend/src/components/chart/lab-rx-modal.tsx b/apps/Frontend/src/components/chart/lab-rx-modal.tsx index e293dcf7..5b6c7153 100644 --- a/apps/Frontend/src/components/chart/lab-rx-modal.tsx +++ b/apps/Frontend/src/components/chart/lab-rx-modal.tsx @@ -55,6 +55,7 @@ type RxFields = { shade: string; dueDate: string; doctorName: string; + age: string; additionalNotes: string; }; @@ -62,7 +63,17 @@ const EMPTY_TEMPLATE: TemplateFormState = { name: "", labName: "", labPhone: "", labFax: "", labAddress: "", labAccount: "", caseType: "", material: "", instructions: "Please make\nThank you!", }; -const EMPTY_RX: RxFields = { toothNumbers: "", shade: "", dueDate: "", doctorName: "", additionalNotes: "Please make\nThank you!" }; +const EMPTY_RX: RxFields = { toothNumbers: "", shade: "", dueDate: "", doctorName: "", age: "", additionalNotes: "Please make\nThank you!" }; + +const calcAge = (dob: string | Date | null | undefined): string => { + if (!dob) return ""; + const birth = new Date(dob); + const today = new Date(); + let age = today.getFullYear() - birth.getFullYear(); + const m = today.getMonth() - birth.getMonth(); + if (m < 0 || (m === 0 && today.getDate() < birth.getDate())) age--; + return String(age); +}; const CASE_TYPES = ["Crown", "Bridge", "Veneer", "Inlay/Onlay", "Full Denture", "Partial Denture", "Night Guard", "Retainer", "Implant Crown", "Other"]; const MATERIALS = ["Zirconia", "PFM (Porcelain-Fused-to-Metal)", "E-Max", "Acrylic", "Cast Metal", "Composite", "PMMA", "Other"]; @@ -175,7 +186,7 @@ export function LabRxModal({ open, onClose, patient }: Props) { const openRx = (t: LabRxTemplate) => { if (renamingId !== null) return; setRxTemplate(t); - setRx({ ...EMPTY_RX, doctorName: providers[0]?.providerName ?? "" }); + setRx({ ...EMPTY_RX, doctorName: providers[0]?.providerName ?? "", age: calcAge(patient.dateOfBirth) }); }; const startRename = (e: React.MouseEvent, t: LabRxTemplate) => { @@ -495,6 +506,10 @@ export function LabRxModal({ open, onClose, patient }: Props) { setRx((r) => ({ ...r, shade: e.target.value }))} className="h-9 text-sm" />
+
+ + setRx((r) => ({ ...r, age: e.target.value }))} className="h-9 text-sm" /> +
setRx((r) => ({ ...r, dueDate: e.target.value }))} className="h-9 text-sm" /> @@ -543,7 +558,7 @@ export function LabRxModal({ open, onClose, patient }: Props) {
Patient

{patientName}

-
DOB

{patient.dateOfBirth ? new Date(patient.dateOfBirth).toLocaleDateString("en-US") : "—"}

+
Age

{rx.age || "—"}

Lab

{rxTemplate.labName || "—"}

Phone

{rxTemplate.labPhone || "—"}

{rxTemplate.labFax &&
Fax

{rxTemplate.labFax}

} @@ -581,7 +596,7 @@ export function LabRxModal({ open, onClose, patient }: Props) {
Patient Information
{patientName}
-
{patient.dateOfBirth ? new Date(patient.dateOfBirth).toLocaleDateString("en-US") : ""}
+
{rx.age}