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 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "src/index.ts",
"source": true,
"scripts": {
"start": "openmrs develop",
"start": "openmrs develop --backend http://194.163.171.253:8282",
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this url

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove this url

Hey @jabahum this has been removed

"serve": "webpack serve --mode=development",
"build": "webpack --mode production",
"analyze": "webpack --mode=production --env analyze=true",
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 { 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,78 +219,90 @@ 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" />;
}

if (isError) {
return <ErrorState error={isError} headerTitle={"Error"} />;
}
// If no active test order results hide table
if (filteredActiveTestOrderResults.length === 0) {
return null;
}

if (items?.length >= 0) {
if (filteredActiveTestOrderResults?.length >= 0) {
return (
<div className={styles.widgetCard}>
<CardHeader title={displayText}>
Expand Down Expand Up @@ -451,7 +456,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
Loading
Loading