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

O3-2879 Add billing form and billing history to patient chart #8

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
171 changes: 98 additions & 73 deletions src/bill-history/bill-history.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -42,6 +44,8 @@ const BillHistory: React.FC<BillHistoryProps> = ({ patientUuid }) => {
const { paginated, goTo, results, currentPage } = usePagination(bills, PAGE_SIZE);
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense

const { pageSizes } = usePaginationInfo(PAGE_SIZE, bills?.length, currentPage, results?.length);

const { defaultCurrency } = useConfig();

const headerData = [
{
header: t('visitTime', 'Visit time'),
Expand All @@ -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) => {
Copy link
Member

Choose a reason for hiding this comment

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

Extract this utility to a utils file so it can be reused

Copy link
Member Author

Choose a reason for hiding this comment

The 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';

Copy link
Member

Choose a reason for hiding this comment

The 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),
Expand Down Expand Up @@ -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>
</>
);
};

Expand Down
Loading
Loading