Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions src/components/Common/PrintTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,61 @@ import {
type HeaderRow = {
key: string;
width?: number;
className?: string;
};
Comment on lines 14 to 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

HeaderRow.className is never applied to header cells.

HeaderRow.className is added but not used in <TableHead>, so per-header styling won’t take effect.

🛠️ Proposed fix
-            {headers.map(({ key, width }, index) => (
+            {headers.map(({ key, width, className: headerClassName }, index) => (
               <TableHead
                 className={cn(
                   index == 0 && "first:rounded-l-md",
                   "h-auto py-1 pl-2 pr-2 text-black text-center ",
                   width && `w-${width}`,
+                  headerClassName,
                 )}
                 key={key}
               >

Also applies to: 75-81

🤖 Prompt for AI Agents
In `@src/components/Common/PrintTable.tsx` around lines 14 - 18, The
HeaderRow.className property is never applied when rendering table headers in
PrintTable; update the header-rendering code paths (where PrintTable maps over
headers in TableHead / headers.map) to add the header.className to the header
cell element (e.g., the <th> or TableCell used for header rows), merging it with
any existing classes (safely handling undefined) and keeping the existing key
and width handling; make the same change for the second header-rendering block
(the other headers.map usage) so per-header styling via HeaderRow.className
takes effect everywhere.


type TableRowType = Record<string, string | undefined>;

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<string, CellConfig>;
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 (
<div className="overflow-hidden rounded-lg border border-gray-200">
<div className="overflow-hidden rounded border border-gray-200">
<Table className="w-full">
<TableHeader>
<TableRow className="bg-transparent hover:bg-transparent divide-x divide-gray-200 border-b-gray-200">
Expand All @@ -49,14 +91,21 @@ export default function PrintTable({ headers, rows }: GenericTableProps) {
rows.map((row, index) => (
<TableRow
key={index}
className="bg-transparent hover:bg-transparent divide-x divide-gray-200"
className={cn(
"bg-transparent hover:bg-transparent divide-x divide-gray-200",
className,
)}
>
{headers.map(({ key }) => (
<TableCell
className="break-words whitespace-normal text-center"
className={cn(
"warp-break-words whitespace-normal text-center",
classNameCell,
cellConfig?.[key]?.className,
)}
key={key}
>
{row[key] || "-"}
{getCellContent(key, row[key], index)}
</TableCell>
))}
</TableRow>
Expand Down
36 changes: 25 additions & 11 deletions src/components/Prescription/PrescriptionPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const PrescriptionContent = ({ prescription }: PrescriptionContentProps) => {
return (
<div>
{/* Prescription Symbol */}
<div className="text-2xl font-semibold mb-3 flex items-end gap-4">
<div className="text-xl font-semibold mb-3 flex items-end gap-4">
<p>{t("℞")}</p>
<p className="text-sm text-gray-600 font-semibold ">
{formatDateTime(
Expand Down Expand Up @@ -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" },
}}
/>
</div>
)}
Expand Down Expand Up @@ -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" },
}}
/>
</div>
)}
{/* Doctor's Signature */}
<div className="w-full items-end mt-6 flex flex-row justify-end gap-1">
<div className="text-right">
<p className="text-sm text-gray-400">{t("prescribed_by")}</p>
<p className="text-xs text-gray-400">{t("prescribed_by")}</p>
<p className="text-sm text-gray-600 font-semibold">
{formatName(
prescription.prescription?.prescribed_by ||
Expand Down Expand Up @@ -187,12 +201,12 @@ export const PrescriptionPreview = ({
<div className="flex justify-between items-start mb-4 pb-2 border-b border-gray-200">
<div className="flex items-start gap-4">
<div className="text-left">
<h1 className="text-2xl font-medium">{facility?.name}</h1>
<h1 className="text-xl font-medium">{facility?.name}</h1>
{facility?.address && (
<div className="text-gray-500 whitespace-pre-wrap wrap-break-word text-sm">
<div className="text-gray-500 whitespace-pre-wrap wrap-break-word text-xs">
{facility.address}
{facility.phone_number && (
<p className="text-gray-500 text-sm">
<p className="text-gray-500 text-xs">
{t("phone")}: {facility.phone_number}
</p>
)}
Expand Down Expand Up @@ -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")
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date format string uses lowercase 'mm' which represents minutes, not months. This will produce incorrect dates. Use 'dd/MM/yy' instead where 'MM' represents months.

Suggested change
? 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")

Copilot uses AI. Check for mistakes.
}
isStrong
/>
Expand All @@ -264,7 +275,10 @@ export const PrescriptionPreview = ({
))}

{/* Footer */}
<PrintFooter leftContent={t("computer_generated_prescription")} />
<PrintFooter
leftContent={t("computer_generated_prescription")}
className="text-xs"
/>
</div>
</div>
</PrintPreview>
Expand Down
8 changes: 3 additions & 5 deletions src/pages/Facility/services/pharmacy/MedicationBillForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -728,7 +727,6 @@ export default function MedicationBillForm({
patientId,
prescriptionId,
}: Props) {
useShortcutSubContext("facility:general");
const { t } = useTranslation();
const queryClient = useQueryClient();
const { facilityId } = useCurrentFacility();
Expand Down
Loading