diff --git a/src/Components/Medicine/PrescriptionsTable.tsx b/src/Components/Medicine/PrescriptionsTable.tsx index d61275c42c1..c978ade463e 100644 --- a/src/Components/Medicine/PrescriptionsTable.tsx +++ b/src/Components/Medicine/PrescriptionsTable.tsx @@ -55,6 +55,25 @@ export default function PrescriptionsTable({ ? DISCHARGE_PRN_TKEYS : DISCHARGE_NORMAL_TKEYS; + // Implementing collapsible view for each prescription entry + const [collapsedPrescriptions, setCollapsedPrescriptions] = useState([]); + + const toggleCollapse = (id: string) => { + setCollapsedPrescriptions((prev) => { + if (prev.includes(id)) { + return prev.filter((prescriptionId) => prescriptionId !== id); + } else { + return [...prev, id]; + } + }); + }; + + // Default the view of discontinued prescriptions to collapsed + const discontinuedPrescriptions = data?.results.filter((prescription) => prescription.discontinued).map((prescription) => prescription.id) || []; + useState(() => { + setCollapsedPrescriptions(discontinuedPrescriptions); + }); + return (
{data?.results && ( @@ -205,6 +224,19 @@ export default function PrescriptionsTable({ ) : ( "never" ), + // Adding a toggle button to expand/collapse the prescription details + actions: ( + + ), })) || [] } objectKeys={Object.values(tkeys)}