-
Notifications
You must be signed in to change notification settings - Fork 15
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
grouped radiology orders by patient #88
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
072d70a
grouped radiology orders by patient
FelixKiprotich350 7a61e91
fix lint issues
FelixKiprotich350 7bd7bab
fix lint issues
FelixKiprotich350 1fba2e3
fix lint issues
FelixKiprotich350 f743e55
code improvement and formatting
FelixKiprotich350 ee3dac5
reorganized styles in common folder
FelixKiprotich350 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useMemo } from "react"; | ||
import { GroupedOrders } from "../radiology-tabs/common/radiologyProps.resource"; | ||
|
||
export function useSearchGroupedResults( | ||
data: Array<GroupedOrders>, | ||
searchString: string | ||
) { | ||
const searchResults = useMemo(() => { | ||
if (searchString && searchString.trim() !== "") { | ||
// Normalize the search string to lowercase | ||
const lowerSearchString = searchString.toLowerCase(); | ||
return data.filter((orderGroup) => | ||
orderGroup.orders.some( | ||
(order) => | ||
order.orderNumber.toLowerCase().includes(lowerSearchString) || | ||
order.patient.display.toLowerCase().includes(lowerSearchString) | ||
) | ||
); | ||
} | ||
|
||
return data; | ||
}, [searchString, data]); | ||
|
||
return searchResults; | ||
} |
135 changes: 14 additions & 121 deletions
135
src/radiology-tabs/approved/approved-orders.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,27 @@ | ||
import React, { useMemo, useState } from "react"; | ||
Check warning on line 1 in src/radiology-tabs/approved/approved-orders.component.tsx GitHub Actions / build
|
||
import { useTranslation } from "react-i18next"; | ||
import { | ||
Table, | ||
TableHead, | ||
TableRow, | ||
TableHeader, | ||
TableBody, | ||
TableCell, | ||
DataTable, | ||
Pagination, | ||
DataTableSkeleton, | ||
TableContainer, | ||
TableToolbar, | ||
TableToolbarContent, | ||
TableToolbarSearch, | ||
} from "@carbon/react"; | ||
import { DataTableSkeleton } from "@carbon/react"; | ||
import { useOrdersWorklist } from "../../hooks/useOrdersWorklist"; | ||
import { formatDate, parseDate, usePagination } from "@openmrs/esm-framework"; | ||
import { useSearchResults } from "../../hooks/useSearchResults"; | ||
import styles from "../test-ordered/tests-ordered.scss"; | ||
import GroupedOrdersTable from "../common/groupedOrdersTable.component"; | ||
|
||
export const ApprovedOrders: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const [currentPageSize, setCurrentPageSize] = useState<number>(10); | ||
const { workListEntries, isLoading } = useOrdersWorklist("", "ON_HOLD"); | ||
const [searchString, setSearchString] = useState<string>(""); | ||
|
||
const searchResults = useSearchResults(workListEntries, searchString); | ||
if (isLoading) { | ||
return <DataTableSkeleton />; | ||
} | ||
|
||
const { | ||
goTo, | ||
results: paginatedResults, | ||
currentPage, | ||
} = usePagination(searchResults, currentPageSize); | ||
|
||
const pageSizes = [10, 20, 30, 40, 50]; | ||
|
||
const rows = useMemo(() => { | ||
return paginatedResults | ||
?.filter((item) => item.action === "NEW") | ||
.map((entry) => ({ | ||
...entry, | ||
date: ( | ||
<span className={styles["single-line-display"]}> | ||
{formatDate(parseDate(entry?.dateActivated))} | ||
</span> | ||
), | ||
})); | ||
}, [paginatedResults]); | ||
|
||
const tableColums = [ | ||
{ id: 0, header: t("date", "Date"), key: "date" }, | ||
{ id: 1, header: t("orderNumber", "Order Number"), key: "orderNumber" }, | ||
{ id: 2, header: t("patient", "Patient"), key: "patient" }, | ||
{ id: 4, header: t("procedure", "Procedure"), key: "procedure" }, | ||
{ id: 5, header: t("orderType", "Order type"), key: "action" }, | ||
{ id: 6, header: t("status", "Status"), key: "status" }, | ||
{ id: 8, header: t("orderer", "Orderer"), key: "orderer" }, | ||
{ id: 9, header: t("urgency", "Urgency"), key: "urgency" }, | ||
]; | ||
|
||
return isLoading ? ( | ||
<DataTableSkeleton /> | ||
) : ( | ||
return ( | ||
<div> | ||
<DataTable | ||
rows={rows} | ||
headers={tableColums} | ||
useZebraStyles | ||
overflowMenuOnHover={true} | ||
> | ||
{({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => ( | ||
<> | ||
<TableContainer> | ||
<TableToolbar | ||
style={{ | ||
position: "static", | ||
height: "3rem", | ||
overflow: "visible", | ||
margin: 0, | ||
// TODO: add background color to the toolbar | ||
}} | ||
> | ||
<TableToolbarContent style={{ margin: 0 }}> | ||
<TableToolbarSearch | ||
style={{ backgroundColor: "#f4f4f4" }} | ||
onChange={(event) => setSearchString(event.target.value)} | ||
/> | ||
</TableToolbarContent> | ||
</TableToolbar> | ||
<Table {...getTableProps()}> | ||
<TableHead> | ||
<TableRow> | ||
{headers.map((header) => ( | ||
<TableHeader {...getHeaderProps({ header })}> | ||
{header.header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row) => ( | ||
<TableRow {...getRowProps({ row })}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell.id}>{cell.value}</TableCell> | ||
))} | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
<Pagination | ||
forwardText="Next page" | ||
backwardText="Previous page" | ||
page={currentPage} | ||
pageSize={currentPageSize} | ||
pageSizes={pageSizes} | ||
totalItems={workListEntries?.length} | ||
onChange={({ pageSize, page }) => { | ||
if (pageSize !== currentPageSize) { | ||
setCurrentPageSize(pageSize); | ||
} | ||
if (page !== currentPage) { | ||
goTo(page); | ||
} | ||
}} | ||
/> | ||
</TableContainer> | ||
</> | ||
)} | ||
</DataTable> | ||
<GroupedOrdersTable | ||
orders={workListEntries} | ||
showStatus={false} | ||
showStartButton={false} | ||
showActions={false} | ||
showOrderType={true} | ||
actions={[]} | ||
/> | ||
</div> | ||
); | ||
}; |
171 changes: 171 additions & 0 deletions
171
src/radiology-tabs/common/groupedOrdersTable.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import styles from "./groupedOrdersTable.scss"; | ||
import { useTranslation } from "react-i18next"; | ||
import { formatDate, parseDate, usePagination } from "@openmrs/esm-framework"; | ||
import { GroupedOrdersTableProps } from "./radiologyProps.resource"; | ||
import { useSearchGroupedResults } from "../../hooks/useSearchGroupedResults"; | ||
import { | ||
Table, | ||
TableHead, | ||
TableRow, | ||
TableHeader, | ||
TableBody, | ||
TableExpandRow, | ||
TableExpandedRow, | ||
TableExpandHeader, | ||
TableCell, | ||
DataTable, | ||
Pagination, | ||
TableContainer, | ||
TableToolbar, | ||
TableToolbarContent, | ||
TableToolbarSearch, | ||
} from "@carbon/react"; | ||
import ListOrderDetails from "./listOrderDetails.component"; | ||
|
||
// render Grouped by patient Orders in radiology module | ||
const GroupedOrdersTable: React.FC<GroupedOrdersTableProps> = (props) => { | ||
const workListEntries = props.orders; | ||
const { t } = useTranslation(); | ||
const [currentPageSize, setCurrentPageSize] = useState<number>(10); | ||
const [searchString, setSearchString] = useState<string>(""); | ||
|
||
function groupOrdersById(orders) { | ||
if (orders && orders.length > 0) { | ||
const groupedOrders = orders.reduce((acc, item) => { | ||
if (!acc[item.patient.uuid]) { | ||
acc[item.patient.uuid] = []; | ||
} | ||
acc[item.patient.uuid].push(item); | ||
return acc; | ||
}, {}); | ||
|
||
// Convert the result to an array of objects with patientId and orders | ||
return Object.keys(groupedOrders).map((patientId) => ({ | ||
patientId: patientId, | ||
orders: groupedOrders[patientId], | ||
})); | ||
} else { | ||
return []; | ||
} | ||
} | ||
const groupedOrdersByPatient = groupOrdersById(workListEntries); | ||
const searchResults = useSearchGroupedResults( | ||
groupedOrdersByPatient, | ||
searchString | ||
); | ||
const { | ||
goTo, | ||
results: paginatedResults, | ||
currentPage, | ||
} = usePagination(searchResults, currentPageSize); | ||
|
||
const pageSizes = [10, 20, 30, 40, 50]; | ||
|
||
const rowsdata = useMemo(() => { | ||
return paginatedResults.map((patient) => ({ | ||
id: patient.patientId, | ||
patientname: patient.orders[0].patient?.display?.split("-")[1], | ||
orders: patient.orders, | ||
totalorders: patient.orders?.length, | ||
})); | ||
}, [paginatedResults]); | ||
|
||
const tableColumns = [ | ||
{ id: 0, header: t("patient", "Patient"), key: "patientname" }, | ||
{ id: 1, header: t("totalorders", "Total Orders"), key: "totalorders" }, | ||
]; | ||
return ( | ||
<div> | ||
<DataTable | ||
rows={rowsdata} | ||
headers={tableColumns} | ||
overflowMenuOnHover={true} | ||
> | ||
{({ rows, headers, getTableProps, getHeaderProps, getRowProps }) => ( | ||
<> | ||
<TableContainer> | ||
<TableToolbar className={styles.ordersTableToolbar}> | ||
<TableToolbarContent style={{ margin: 0 }}> | ||
<TableToolbarSearch | ||
className={styles.ordersToolbarSearchBar} | ||
onChange={(event) => setSearchString(event.target.value)} | ||
/> | ||
</TableToolbarContent> | ||
</TableToolbar> | ||
<Table {...getTableProps()}> | ||
<TableHead> | ||
<TableRow> | ||
<TableExpandHeader /> | ||
{headers.map((header) => ( | ||
<TableHeader {...getHeaderProps({ header })}> | ||
{header.header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.length > 0 ? ( | ||
rows.map((row) => ( | ||
<React.Fragment key={row.id}> | ||
<TableExpandRow {...getRowProps({ row })}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell.id}> | ||
{cell.id.endsWith("created") | ||
? formatDate(parseDate(cell.value)) | ||
: cell.value} | ||
</TableCell> | ||
))} | ||
</TableExpandRow> | ||
<TableExpandedRow colSpan={headers.length + 1}> | ||
<ListOrderDetails | ||
actions={props.actions} | ||
groupedOrders={groupedOrdersByPatient.find( | ||
(item) => item.patientId === row.id | ||
)} | ||
showActions={props.showActions} | ||
showOrderType={props.showOrderType} | ||
showStartButton={props.showStartButton} | ||
showStatus={props.showStatus} | ||
/> | ||
</TableExpandedRow> | ||
</React.Fragment> | ||
)) | ||
) : ( | ||
<TableRow> | ||
<TableCell | ||
colSpan={headers.length + 1} | ||
style={{ textAlign: "center" }} | ||
className={styles.noOrdersDiv} | ||
> | ||
{t("noOrderAvailable", "No Orders Availalble")} | ||
</TableCell> | ||
</TableRow> | ||
)} | ||
</TableBody> | ||
</Table> | ||
<Pagination | ||
forwardText="Next page" | ||
backwardText="Previous page" | ||
page={currentPage} | ||
pageSize={currentPageSize} | ||
pageSizes={pageSizes} | ||
totalItems={workListEntries?.length} | ||
onChange={({ pageSize, page }) => { | ||
if (pageSize !== currentPageSize) { | ||
setCurrentPageSize(pageSize); | ||
} | ||
if (page !== currentPage) { | ||
goTo(page); | ||
} | ||
}} | ||
/> | ||
</TableContainer> | ||
</> | ||
)} | ||
</DataTable> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GroupedOrdersTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@use '@carbon/layout'; | ||
@use '@carbon/colors'; | ||
@use '@openmrs/esm-styleguide/src/vars' as *; | ||
|
||
.noOrdersDiv{ | ||
background-color: #fff; | ||
text-align: center; | ||
font-weight:bold; | ||
width: 100%; | ||
} | ||
|
||
.ordersTableToolbar{ | ||
position: static; | ||
height: 3rem; | ||
overflow: visible; | ||
margin: 0; | ||
} | ||
|
||
.ordersToolbarSearchBar{ | ||
background-color:#f4f4f4 ; | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have a hook to generate page sizes
usePaginationInfo
from@openmrs/esm-framework
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@donaldkibet i am done with your comments but this seem unclear to me. any help on implementing this usePaginationInfo, the parameters are kinda confusing to me and cant find a similar implementation. Thanks