-
Notifications
You must be signed in to change notification settings - Fork 14
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
O3-2879 Add billing form and billing history to patient chart #8
Changes from 3 commits
c6be57d
22927c8
4f6fd77
f2c8111
b3d1c5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,9 @@ import { | |
TableRow, | ||
Tile, | ||
} from '@carbon/react'; | ||
import { isDesktop, useLayoutType, usePagination } from '@openmrs/esm-framework'; | ||
import { isDesktop, useConfig, useLayoutType, usePagination } from '@openmrs/esm-framework'; | ||
import { | ||
CardHeader, | ||
EmptyDataIllustration, | ||
ErrorState, | ||
launchPatientWorkspace, | ||
|
@@ -28,6 +29,7 @@ import { | |
import { useBills } from '../billing.resource'; | ||
import InvoiceTable from '../invoice/invoice-table.component'; | ||
import styles from './bill-history.scss'; | ||
import { Add } from '@carbon/react/icons'; | ||
|
||
interface BillHistoryProps { | ||
patientUuid: string; | ||
|
@@ -42,6 +44,8 @@ const BillHistory: React.FC<BillHistoryProps> = ({ patientUuid }) => { | |
const { paginated, goTo, results, currentPage } = usePagination(bills, PAGE_SIZE); | ||
const { pageSizes } = usePaginationInfo(PAGE_SIZE, bills?.length, currentPage, results?.length); | ||
|
||
const { defaultCurrency } = useConfig(); | ||
|
||
const headerData = [ | ||
{ | ||
header: t('visitTime', 'Visit time'), | ||
|
@@ -64,10 +68,21 @@ const BillHistory: React.FC<BillHistoryProps> = ({ patientUuid }) => { | |
const setBilledItems = (bill) => | ||
bill.lineItems.reduce((acc, item) => acc + (acc ? ' & ' : '') + (item.billableService || item.item || ''), ''); | ||
|
||
const formatCurrency = (amount) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract this utility to a utils file so it can be reused There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be duplication actually, using the function Cynthia adjusted |
||
const currencyCode = defaultCurrency._default || 'UGX'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need this? there's a PR from Cynthia that was merged and resolves this |
||
return new Intl.NumberFormat(undefined, { | ||
style: 'currency', | ||
currency: currencyCode, | ||
minimumFractionDigits: 0, | ||
maximumFractionDigits: 0, | ||
}).format(amount); | ||
}; | ||
|
||
const rowData = results?.map((bill) => ({ | ||
id: bill.uuid, | ||
uuid: bill.uuid, | ||
billTotal: bill.totalAmount, | ||
billTotal: formatCurrency(bill.totalAmount), | ||
visitTime: bill.dateCreated, | ||
identifier: bill.identifier, | ||
billedItems: setBilledItems(bill), | ||
|
@@ -108,79 +123,89 @@ const BillHistory: React.FC<BillHistoryProps> = ({ patientUuid }) => { | |
} | ||
|
||
return ( | ||
<div className={styles.billHistoryContainer}> | ||
<DataTable isSortable rows={rowData} headers={headerData} size={responsiveSize} useZebraStyles> | ||
{({ | ||
rows, | ||
headers, | ||
getExpandHeaderProps, | ||
getTableProps, | ||
getTableContainerProps, | ||
getHeaderProps, | ||
getRowProps, | ||
}) => ( | ||
<TableContainer {...getTableContainerProps}> | ||
<Table className={styles.table} {...getTableProps()} aria-label="Bill list"> | ||
<TableHead> | ||
<TableRow> | ||
<TableExpandHeader enableToggle {...getExpandHeaderProps()} /> | ||
{headers.map((header, i) => ( | ||
<TableHeader | ||
key={i} | ||
{...getHeaderProps({ | ||
header, | ||
})}> | ||
{header.header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, i) => { | ||
const currentBill = bills?.find((bill) => bill.uuid === row.id); | ||
<> | ||
<CardHeader title={t('billingHistory', 'Billing History')}> | ||
<Button | ||
renderIcon={Add} | ||
onClick={() => launchPatientWorkspace('billing-form', { workspaceTitle: 'Billing Form' })} | ||
kind="ghost"> | ||
{t('addBill', 'Add bill item(s)')} | ||
</Button> | ||
</CardHeader> | ||
<div className={styles.billHistoryContainer}> | ||
<DataTable isSortable rows={rowData} headers={headerData} size={responsiveSize} useZebraStyles> | ||
{({ | ||
rows, | ||
headers, | ||
getExpandHeaderProps, | ||
getTableProps, | ||
getTableContainerProps, | ||
getHeaderProps, | ||
getRowProps, | ||
}) => ( | ||
<TableContainer {...getTableContainerProps}> | ||
<Table className={styles.table} {...getTableProps()} aria-label="Bill list"> | ||
<TableHead> | ||
<TableRow> | ||
<TableExpandHeader enableToggle {...getExpandHeaderProps()} /> | ||
{headers.map((header, i) => ( | ||
<TableHeader | ||
key={i} | ||
{...getHeaderProps({ | ||
header, | ||
})}> | ||
{header.header} | ||
</TableHeader> | ||
))} | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, i) => { | ||
const currentBill = bills?.find((bill) => bill.uuid === row.id); | ||
|
||
return ( | ||
<React.Fragment key={row.id}> | ||
<TableExpandRow {...getRowProps({ row })}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell.id}>{cell.value}</TableCell> | ||
))} | ||
</TableExpandRow> | ||
{row.isExpanded ? ( | ||
<TableExpandedRow className={styles.expandedRow} colSpan={headers.length + 1}> | ||
<div className={styles.container} key={i}> | ||
<InvoiceTable bill={currentBill} isSelectable={false} /> | ||
</div> | ||
</TableExpandedRow> | ||
) : ( | ||
<TableExpandedRow className={styles.hiddenRow} colSpan={headers.length + 2} /> | ||
)} | ||
</React.Fragment> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
return ( | ||
<React.Fragment key={row.id}> | ||
<TableExpandRow {...getRowProps({ row })}> | ||
{row.cells.map((cell) => ( | ||
<TableCell key={cell.id}>{cell.value}</TableCell> | ||
))} | ||
</TableExpandRow> | ||
{row.isExpanded ? ( | ||
<TableExpandedRow className={styles.expandedRow} colSpan={headers.length + 1}> | ||
<div className={styles.container} key={i}> | ||
<InvoiceTable bill={currentBill} isSelectable={false} /> | ||
</div> | ||
</TableExpandedRow> | ||
) : ( | ||
<TableExpandedRow className={styles.hiddenRow} colSpan={headers.length + 2} /> | ||
)} | ||
</React.Fragment> | ||
); | ||
})} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
)} | ||
</DataTable> | ||
{paginated && ( | ||
<Pagination | ||
forwardText={t('nextPage', 'Next page')} | ||
backwardText={t('previousPage', 'Previous page')} | ||
page={currentPage} | ||
pageSize={PAGE_SIZE} | ||
pageSizes={pageSizes} | ||
totalItems={bills.length} | ||
className={styles.pagination} | ||
size={responsiveSize} | ||
onChange={({ page: newPage }) => { | ||
if (newPage !== currentPage) { | ||
goTo(newPage); | ||
} | ||
}} | ||
/> | ||
)} | ||
</DataTable> | ||
{paginated && ( | ||
<Pagination | ||
forwardText={t('nextPage', 'Next page')} | ||
backwardText={t('previousPage', 'Previous page')} | ||
page={currentPage} | ||
pageSize={PAGE_SIZE} | ||
pageSizes={pageSizes} | ||
totalItems={bills.length} | ||
className={styles.pagination} | ||
size={responsiveSize} | ||
onChange={({ page: newPage }) => { | ||
if (newPage !== currentPage) { | ||
goTo(newPage); | ||
} | ||
}} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
|
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.
You can add the page sizes to the config
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.
Makes sense