From bf0ec6a045fc2c77426d8a60a5d46f6ff67c2a52 Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Wed, 21 Jan 2026 15:14:29 +0530 Subject: [PATCH 1/3] Refactor PrintTable and PrescriptionPreview components for improved cell rendering and styling --- src/components/Common/PrintTable.tsx | 59 +++++++++++++++++-- .../Prescription/PrescriptionPreview.tsx | 36 +++++++---- .../services/pharmacy/MedicationBillForm.tsx | 8 +-- 3 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/components/Common/PrintTable.tsx b/src/components/Common/PrintTable.tsx index a411f44bfb3..45782af8cf7 100644 --- a/src/components/Common/PrintTable.tsx +++ b/src/components/Common/PrintTable.tsx @@ -14,19 +14,61 @@ import { type HeaderRow = { key: string; width?: number; + className?: string; }; type TableRowType = Record; + +type CellConfig = { + value?: string; + className?: string; + render?: (value: string | undefined) => React.ReactNode; +}; + interface GenericTableProps { headers: HeaderRow[]; rows: TableRowType[] | undefined; + className?: string; + classNameCell?: string; + cellConfig?: Record; + renderCell?: ( + key: string, + value: string | undefined, + rowIndex: number, + ) => React.ReactNode; } -export default function PrintTable({ headers, rows }: GenericTableProps) { +export default function PrintTable({ + headers, + rows, + className, + classNameCell, + cellConfig, + renderCell, +}: GenericTableProps) { const { t } = useTranslation(); + const getCellContent = ( + key: string, + value: string | undefined, + rowIndex: number, + ) => { + // Priority 1: Custom renderCell function + if (renderCell) { + return renderCell(key, value, rowIndex); + } + + // Priority 2: Cell-specific render function from cellConfig + if (cellConfig?.[key]?.render) { + return cellConfig[key].render(value); + } + + // Priority 3: Default value or "-" + return value || "-"; + }; + return ( -
+
@@ -49,14 +91,21 @@ export default function PrintTable({ headers, rows }: GenericTableProps) { rows.map((row, index) => ( {headers.map(({ key }) => ( - {row[key] || "-"} + {getCellContent(key, row[key], index)} ))} diff --git a/src/components/Prescription/PrescriptionPreview.tsx b/src/components/Prescription/PrescriptionPreview.tsx index 2a344b1fce4..31c998deda8 100644 --- a/src/components/Prescription/PrescriptionPreview.tsx +++ b/src/components/Prescription/PrescriptionPreview.tsx @@ -44,7 +44,7 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => { return (
{/* Prescription Symbol */} -
+

{t("℞")}

{formatDateTime( @@ -87,6 +87,13 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => { instructions: `${remarks || "-"}${notes ? ` (${t("note")}: ${notes})` : ""}`, }; })} + className="text-xs whitespace-break-spaces text-gray-950" + cellConfig={{ + medicine: { className: "text-left font-semibold" }, + instructions: { className: "text-[10px] font-normal" }, + frequency: { className: "text-[10px] font-normal" }, + duration: { className: "text-[10px] font-normal" }, + }} />

)} @@ -123,13 +130,20 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => { instructions: `${remarks || "-"}${notes ? ` (${t("note")}: ${notes})` : ""}`, }; })} + className="text-xs whitespace-break-spaces text-gray-950" + cellConfig={{ + medicine: { className: "text-left font-semibold" }, + instructions: { className: "text-[10px] font-normal" }, + frequency: { className: "text-[10px] font-normal" }, + duration: { className: "text-[10px] font-normal" }, + }} />
)} {/* Doctor's Signature */}
-

{t("prescribed_by")}

+

{t("prescribed_by")}

{formatName( prescription.prescription?.prescribed_by || @@ -187,12 +201,12 @@ export const PrescriptionPreview = ({

-

{facility?.name}

+

{facility?.name}

{facility?.address && ( -
+
{facility.address} {facility.phone_number && ( -

+

{t("phone")}: {facility.phone_number}

)} @@ -240,11 +254,8 @@ export const PrescriptionPreview = ({ label={t("date")} value={ encounter?.period?.start - ? format( - new Date(encounter.period.start), - "dd MMM yyyy, EEEE", - ) - : format(new Date(), "dd MMM yyyy, EEEE") + ? format(new Date(encounter.period.start), "dd/mm/yy") + : format(new Date(), "dd/mm/yy") } isStrong /> @@ -264,7 +275,10 @@ export const PrescriptionPreview = ({ ))} {/* Footer */} - +
diff --git a/src/pages/Facility/services/pharmacy/MedicationBillForm.tsx b/src/pages/Facility/services/pharmacy/MedicationBillForm.tsx index 64836132fb1..e5355bcbcb9 100644 --- a/src/pages/Facility/services/pharmacy/MedicationBillForm.tsx +++ b/src/pages/Facility/services/pharmacy/MedicationBillForm.tsx @@ -243,10 +243,9 @@ const AddMedicationSheet = ({ const isConsumable = selectedProduct?.product_type === "consumable"; - // TODO: bring this back, after debugging what's causing it. B, P, E, T (and more?) can't be typed. - // useShortcutSubContext("patient:search:-global", { - // ignoreInputFields: true, - // }); + useShortcutSubContext("patient:search:-global", { + ignoreInputFields: true, + }); // Update local state when the sheet opens or when editing a different item useEffect(() => { @@ -728,7 +727,6 @@ export default function MedicationBillForm({ patientId, prescriptionId, }: Props) { - useShortcutSubContext("facility:general"); const { t } = useTranslation(); const queryClient = useQueryClient(); const { facilityId } = useCurrentFacility(); From 6c880a7caba87f3c6ee3ea0549edf716beb51ea5 Mon Sep 17 00:00:00 2001 From: Abhimanyu Rajeesh <63541653+abhimanyurajeesh@users.noreply.github.com> Date: Wed, 21 Jan 2026 23:15:11 +0530 Subject: [PATCH 2/3] Update src/components/Common/PrintTable.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/components/Common/PrintTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Common/PrintTable.tsx b/src/components/Common/PrintTable.tsx index 45782af8cf7..4f6128dd9f7 100644 --- a/src/components/Common/PrintTable.tsx +++ b/src/components/Common/PrintTable.tsx @@ -99,7 +99,7 @@ export default function PrintTable({ {headers.map(({ key }) => ( Date: Wed, 21 Jan 2026 23:32:54 +0530 Subject: [PATCH 3/3] Enhance styling in PrescriptionPreview component for improved readability --- .../Prescription/PrescriptionPreview.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/components/Prescription/PrescriptionPreview.tsx b/src/components/Prescription/PrescriptionPreview.tsx index 31c998deda8..aeae3fada8f 100644 --- a/src/components/Prescription/PrescriptionPreview.tsx +++ b/src/components/Prescription/PrescriptionPreview.tsx @@ -87,12 +87,9 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => { instructions: `${remarks || "-"}${notes ? ` (${t("note")}: ${notes})` : ""}`, }; })} - className="text-xs whitespace-break-spaces text-gray-950" + className="text-xs font-semibold whitespace-break-spaces text-gray-950" cellConfig={{ medicine: { className: "text-left font-semibold" }, - instructions: { className: "text-[10px] font-normal" }, - frequency: { className: "text-[10px] font-normal" }, - duration: { className: "text-[10px] font-normal" }, }} />
@@ -130,12 +127,9 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => { instructions: `${remarks || "-"}${notes ? ` (${t("note")}: ${notes})` : ""}`, }; })} - className="text-xs whitespace-break-spaces text-gray-950" + className="text-xs font-semibold whitespace-break-spaces text-gray-950" cellConfig={{ medicine: { className: "text-left font-semibold" }, - instructions: { className: "text-[10px] font-normal" }, - frequency: { className: "text-[10px] font-normal" }, - duration: { className: "text-[10px] font-normal" }, }} />
@@ -254,8 +248,8 @@ export const PrescriptionPreview = ({ label={t("date")} value={ encounter?.period?.start - ? format(new Date(encounter.period.start), "dd/mm/yy") - : format(new Date(), "dd/mm/yy") + ? format(new Date(encounter.period.start), "dd/MM/yy") + : format(new Date(), "dd/MM/yy") } isStrong />