Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing pagination for Active Tests and Past Order Results Data Tables under routine tests tab on patient chart #50

Merged
merged 4 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ErrorState,
showModal,
useConfig,
usePagination,
} from "@openmrs/esm-framework";
import { mutate } from "swr";
import {
Expand Down Expand Up @@ -85,22 +86,14 @@ const LaboratoryActiveTestOrderResults: React.FC<
"Active Laboratory Tests"
);

const {
items,
tableHeaders,
currentPage,
pageSizes,
totalItems,
goTo,
currentPageSize,
setPageSize,
isLoading,
isError,
} = useLaboratoryOrderResultsPages({
v: ResourceRepresentation.Full,
totalCount: true,
patientUuid: patientUuid,
});
const { items, tableHeaders, isLoading, isError } =
useLaboratoryOrderResultsPages({
v: ResourceRepresentation.Full,
totalCount: true,
patientUuid: patientUuid,
});
const pageSizes = [10, 20, 30, 40, 50];
const [currentPageSize, setPageSize] = useState(10);

const sortedLabRequests = useMemo(() => {
return [...items].sort((a, b) => {
Expand Down Expand Up @@ -226,69 +219,77 @@ const LaboratoryActiveTestOrderResults: React.FC<
const currentDateTime = new Date().getTime();
const twentyFourHoursAgo = currentDateTime - 24 * 60 * 60 * 1000;

const tableRows = useMemo(() => {
return laboratoryOrders
?.filter((entry) => {
const entryDate = new Date(entry.encounterDatetime).getTime();
return entryDate >= twentyFourHoursAgo && entryDate <= currentDateTime;
})
?.map((entry, index) => ({
...entry,
id: entry.uuid,
orderDate: {
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: true,
mode: "standard",
})}
</span>
),
},
orders: {
content: (
<>
{entry?.orders
?.filter(
(order) =>
order?.type === "testorder" && order?.action === "NEW"
)
.map((order) => (
<Tag
style={{
background: `${getOrderColor(
order.dateActivated,
order.dateStopped
)}`,
color: "white",
}}
role="tooltip"
key={order.uuid} // Add a unique key for each Tag
>
{order?.concept?.display}
</Tag>
))}
</>
),
},

location: {
content: <span>{entry.location.display}</span>,
},
status: {
content: <span>--</span>,
},
actions: {
content: (
<div style={{ display: "flex" }}>
<PrintButtonAction encounter={entry} />
{enableSendingLabTestsByEmail && <EmailButtonAction />}
</div>
),
},
}));
const filteredActiveTestOrderResults = useMemo(() => {
return laboratoryOrders?.filter((entry) => {
const entryDate = new Date(entry.encounterDatetime).getTime();
return entryDate >= twentyFourHoursAgo && entryDate <= currentDateTime;
});
}, [currentDateTime, laboratoryOrders, twentyFourHoursAgo]);

const {
goTo,
results: paginatedActiveTestOrderResults,
currentPage,
} = usePagination(filteredActiveTestOrderResults, currentPageSize);

const tableRows = useMemo(() => {
return paginatedActiveTestOrderResults?.map((entry, index) => ({
...entry,
id: entry.uuid,
orderDate: {
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: true,
mode: "standard",
})}
</span>
),
},
orders: {
content: (
<>
{entry?.orders
?.filter(
(order) =>
order?.type === "testorder" && order?.action === "NEW"
)
.map((order) => (
<Tag
style={{
background: `${getOrderColor(
order.dateActivated,
order.dateStopped
)}`,
color: "white",
}}
role="tooltip"
key={order.uuid} // Add a unique key for each Tag
>
{order?.concept?.display}
</Tag>
))}
</>
),
},

location: {
content: <span>{entry.location.display}</span>,
},
status: {
content: <span>--</span>,
},
actions: {
content: (
<div style={{ display: "flex" }}>
<PrintButtonAction encounter={entry} />
{enableSendingLabTestsByEmail && <EmailButtonAction />}
</div>
),
},
}));
}, [enableSendingLabTestsByEmail, paginatedActiveTestOrderResults]);

if (isLoading) {
return <DataTableSkeleton role="progressbar" />;
}
Expand All @@ -297,7 +298,7 @@ const LaboratoryActiveTestOrderResults: React.FC<
return <ErrorState error={isError} headerTitle={"Error"} />;
}

if (items?.length >= 0) {
if (filteredActiveTestOrderResults?.length >= 0) {
return (
<div className={styles.widgetCard}>
<CardHeader title={displayText}>
Expand Down Expand Up @@ -451,7 +452,7 @@ const LaboratoryActiveTestOrderResults: React.FC<
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={totalItems}
totalItems={filteredActiveTestOrderResults?.length}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
setPageSize(pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const LaboratoryOrderReferalResults: React.FC<
),
},
}));
}, [laboratoryOrders]);
}, [enableSendingLabTestsByEmail, laboratoryOrders]);

if (isLoading) {
return <DataTableSkeleton role="progressbar" />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ErrorState,
showModal,
useConfig,
usePagination,
} from "@openmrs/esm-framework";

import {
Expand Down Expand Up @@ -81,22 +82,14 @@ const LaboratoryPastTestOrderResults: React.FC<
"pastLaboratoryTestsDisplayTextTitle",
"Past Laboratory Tests"
);
const {
items,
tableHeaders,
currentPage,
pageSizes,
totalItems,
goTo,
currentPageSize,
setPageSize,
isLoading,
isError,
} = useLaboratoryOrderResultsPages({
v: ResourceRepresentation.Full,
totalCount: true,
patientUuid: patientUuid,
});
const { items, tableHeaders, isLoading, isError } =
useLaboratoryOrderResultsPages({
v: ResourceRepresentation.Full,
totalCount: true,
patientUuid: patientUuid,
});
const pageSizes = [10, 20, 30, 40, 50];
const [currentPageSize, setPageSize] = useState(10);

const sortedLabRequests = useMemo(() => {
return [...items].sort((a, b) => {
Expand Down Expand Up @@ -210,67 +203,74 @@ const LaboratoryPastTestOrderResults: React.FC<
const currentDateTime = new Date().getTime();
const twentyFourHoursAgo = currentDateTime - 24 * 60 * 60 * 1000;

const filteredPastTestOrderResults = useMemo(() => {
return laboratoryOrders?.filter((entry) => {
const entryDate = new Date(entry.encounterDatetime).getTime();
return entryDate < twentyFourHoursAgo;
});
}, [laboratoryOrders, twentyFourHoursAgo]);
const {
goTo,
results: paginatedPastTestOrderResults,
currentPage,
} = usePagination(filteredPastTestOrderResults, currentPageSize);

const tableRows = useMemo(() => {
return laboratoryOrders
?.filter((entry) => {
const entryDate = new Date(entry.encounterDatetime).getTime();
return entryDate < twentyFourHoursAgo;
})
?.map((entry, index) => ({
...entry,
id: entry.uuid,
orderDate: {
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: true,
mode: "standard",
})}
</span>
),
},
orders: {
content: (
<>
{entry?.orders
?.filter(
(order) =>
order?.type === "testorder" && order?.action === "NEW"
)
.map((order) => (
<Tag
style={{
background: `${getOrderColor(
order.dateActivated,
order.dateStopped
)}`,
color: "white",
}}
role="tooltip"
key={order.uuid} // Add a unique key for each Tag
>
{order?.concept?.display}
</Tag>
))}
</>
),
},
location: {
content: <span>{entry.location.display}</span>,
},
status: {
content: <span>--</span>,
},
actions: {
content: (
<div style={{ display: "flex" }}>
<PrintButtonAction encounter={entry} />
{enableSendingLabTestsByEmail && <EmailButtonAction />}
</div>
),
},
}));
}, [enableSendingLabTestsByEmail, laboratoryOrders, twentyFourHoursAgo]);
return paginatedPastTestOrderResults?.map((entry, index) => ({
...entry,
id: entry.uuid,
orderDate: {
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: true,
mode: "standard",
})}
</span>
),
},
orders: {
content: (
<>
{entry?.orders
?.filter(
(order) =>
order?.type === "testorder" && order?.action === "NEW"
)
.map((order) => (
<Tag
style={{
background: `${getOrderColor(
order.dateActivated,
order.dateStopped
)}`,
color: "white",
}}
role="tooltip"
key={order.uuid} // Add a unique key for each Tag
>
{order?.concept?.display}
</Tag>
))}
</>
),
},
location: {
content: <span>{entry.location.display}</span>,
},
status: {
content: <span>--</span>,
},
actions: {
content: (
<div style={{ display: "flex" }}>
<PrintButtonAction encounter={entry} />
{enableSendingLabTestsByEmail && <EmailButtonAction />}
</div>
),
},
}));
}, [enableSendingLabTestsByEmail, paginatedPastTestOrderResults]);

if (isLoading) {
return <DataTableSkeleton role="progressbar" />;
Expand All @@ -280,7 +280,7 @@ const LaboratoryPastTestOrderResults: React.FC<
return <ErrorState error={isError} headerTitle={"Error"} />;
}

if (items?.length >= 0) {
if (filteredPastTestOrderResults?.length >= 0) {
return (
<div className={styles.widgetCard}>
<CardHeader title={displayText}>
Expand Down Expand Up @@ -423,7 +423,7 @@ const LaboratoryPastTestOrderResults: React.FC<
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={totalItems}
totalItems={filteredPastTestOrderResults?.length}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
setPageSize(pageSize);
Expand Down
Loading
Loading