Skip to content

Commit 6c8ef6d

Browse files
(fix) Move date formatting from bill mapper to components (#650)
Move dateCreated formatting out of mapBillProperties and into the components that render dates. This lets each component choose its own format options (e.g. the printable invoice header omits time). Also format the previously-raw dateCreated in patient-bills.component.tsx and migrate its DataTable from the deprecated render prop to the children pattern.
1 parent 5526453 commit 6c8ef6d

8 files changed

Lines changed: 27 additions & 50 deletions

File tree

src/bill-history/bill-history.component.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import {
2424
CardHeader,
2525
EmptyCardIllustration,
2626
ErrorState,
27+
formatDate,
2728
launchWorkspace2,
29+
parseDate,
2830
useConfig,
2931
usePagination,
3032
usePaginationInfo,
@@ -75,7 +77,7 @@ const BillHistory: React.FC<BillHistoryProps> = ({ patientUuid }) => {
7577
id: bill.uuid,
7678
uuid: bill.uuid,
7779
billTotal: convertToCurrency(bill?.totalAmount, defaultCurrency),
78-
billDate: bill.dateCreated,
80+
billDate: formatDate(parseDate(bill.dateCreated), { mode: 'wide' }),
7981
invoiceNumber: bill.receiptNumber,
8082
billedItems: setBilledItems(bill),
8183
}));

src/billable-services/bill-waiver/patient-bills.component.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Tile,
1616
} from '@carbon/react';
1717
import { useTranslation } from 'react-i18next';
18-
import { EmptyCardIllustration, useConfig } from '@openmrs/esm-framework';
18+
import { EmptyCardIllustration, formatDate, parseDate, useConfig } from '@openmrs/esm-framework';
1919
import { type MappedBill } from '../../types';
2020
import { convertToCurrency } from '../../helpers';
2121
import PatientBillsSelections from './bill-selection.component';
@@ -44,7 +44,7 @@ const PatientBills: React.FC<PatientBillsProps> = ({ patientUuid, bills, setPati
4444

4545
const tableRows = bills.map((bill) => ({
4646
id: `${bill.uuid}`,
47-
date: bill.dateCreated,
47+
date: formatDate(parseDate(bill.dateCreated), { mode: 'wide' }),
4848
invoiceNumber: bill.receiptNumber,
4949
billableService: bill.billingService,
5050
totalAmount: convertToCurrency(bill?.totalAmount, defaultCurrency),
@@ -69,12 +69,8 @@ const PatientBills: React.FC<PatientBillsProps> = ({ patientUuid, bills, setPati
6969

7070
return (
7171
<div style={{ marginTop: '1rem' }}>
72-
<DataTable
73-
rows={tableRows}
74-
headers={tableHeaders}
75-
size="sm"
76-
useZebraStyles
77-
render={({
72+
<DataTable rows={tableRows} headers={tableHeaders} size="sm" useZebraStyles>
73+
{({
7874
rows,
7975
headers,
8076
getHeaderProps,
@@ -130,7 +126,7 @@ const PatientBills: React.FC<PatientBillsProps> = ({ patientUuid, bills, setPati
130126
</Table>
131127
</TableContainer>
132128
)}
133-
/>
129+
</DataTable>
134130
</div>
135131
);
136132
};

src/billing.resource.test.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -250,41 +250,6 @@ describe('mapBillProperties', () => {
250250
});
251251
});
252252

253-
describe('Date formatting', () => {
254-
it('Formats dateCreated when present', () => {
255-
mockFormatDate.mockReturnValue('01 January 2024');
256-
const bill = createBaseBill({
257-
dateCreated: '2024-01-01T00:00:00Z',
258-
});
259-
const result = mapBillProperties(bill);
260-
expect(result.dateCreated).toBe('01 January 2024');
261-
});
262-
263-
it('Returns "--" when dateCreated is null', () => {
264-
const bill = createBaseBill({
265-
dateCreated: null as unknown as string,
266-
});
267-
const result = mapBillProperties(bill);
268-
expect(result.dateCreated).toBe('--');
269-
});
270-
271-
it('Returns "--" when dateCreated is undefined', () => {
272-
const bill = createBaseBill({
273-
dateCreated: undefined as unknown as string,
274-
});
275-
const result = mapBillProperties(bill);
276-
expect(result.dateCreated).toBe('--');
277-
});
278-
279-
it('Returns "--" when dateCreated is empty string', () => {
280-
const bill = createBaseBill({
281-
dateCreated: '',
282-
});
283-
const result = mapBillProperties(bill);
284-
expect(result.dateCreated).toBe('--');
285-
});
286-
});
287-
288253
describe('Billing service concatenation', () => {
289254
it('Concatenates multiple line item names with double space', () => {
290255
const bill = createBaseBill({

src/billing.resource.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const mapBillProperties = (bill: PatientInvoice): MappedBill => {
3131
cashPointUuid: bill?.cashPoint?.uuid,
3232
cashPointName: bill?.cashPoint?.name,
3333
cashPointLocation: bill?.cashPoint?.location?.display,
34-
dateCreated: bill?.dateCreated ? formatDate(parseDate(bill.dateCreated), { mode: 'wide' }) : '--',
3534
lineItems: activeLineItems,
3635
billingService: activeLineItems.map((lineItem) => lineItem?.item || lineItem?.billableService || '--').join(' '),
3736
totalAmount: activeLineItems

src/bills-table/bills-table.component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import {
2424
EmptyCardIllustration,
2525
ErrorState,
2626
ConfigurableLink,
27+
formatDate,
2728
useConfig,
2829
useDebounce,
30+
parseDate,
2931
type LayoutType,
3032
} from '@openmrs/esm-framework';
3133
import { usePaginatedBills } from '../billing.resource';
@@ -108,6 +110,7 @@ const BillsTable: React.FC = () => {
108110
const object = {
109111
...bill,
110112
id: String(bill.id),
113+
dateCreated: bill.dateCreated ? formatDate(parseDate(bill.dateCreated), { mode: 'wide' }) : '--',
111114
receiptNumberDisplay: (
112115
<ConfigurableLink
113116
style={{ textDecoration: 'none' }}

src/invoice/invoice.component.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { Printer } from '@carbon/react/icons';
44
import { useParams } from 'react-router-dom';
55
import { useReactToPrint } from 'react-to-print';
66
import { useTranslation } from 'react-i18next';
7-
import { ErrorState, ExtensionSlot, showSnackbar, useConfig, usePatient } from '@openmrs/esm-framework';
7+
import {
8+
ErrorState,
9+
ExtensionSlot,
10+
formatDate,
11+
parseDate,
12+
showSnackbar,
13+
useConfig,
14+
usePatient,
15+
} from '@openmrs/esm-framework';
816
import { convertToCurrency } from '../helpers';
917
import { useBill, useDefaultFacility } from '../billing.resource';
1018
import type { BillingConfig } from '../config-schema';
@@ -76,7 +84,9 @@ const Invoice: React.FC = () => {
7684
[t('totalAmount', 'Total amount')]: convertToCurrency(bill?.totalAmount, defaultCurrency),
7785
[t('amountTendered', 'Amount tendered')]: convertToCurrency(bill?.tenderedAmount, defaultCurrency),
7886
[t('invoiceNumber', 'Invoice number')]: bill?.receiptNumber,
79-
[t('dateAndTime', 'Date and time')]: bill?.dateCreated,
87+
[t('dateAndTime', 'Date and time')]: bill?.dateCreated
88+
? formatDate(parseDate(bill.dateCreated), { mode: 'wide' })
89+
: '--',
8090
[t('invoiceStatus', 'Invoice status')]: bill?.status,
8191
};
8292

src/invoice/printable-invoice/printable-invoice-header.component.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const PrintableInvoiceHeader: React.FC<PrintableInvoiceHeaderProps> = ({ patient
1818

1919
const invoiceDetails = {
2020
[t('invoiceNumber', 'Invoice #')]: bill?.receiptNumber,
21-
[t('invoiceDate', 'Invoice date')]: bill?.dateCreated,
21+
[t('invoiceDate', 'Invoice date')]: bill?.dateCreated
22+
? formatDate(parseDate(bill.dateCreated), { mode: 'wide', noToday: true, time: false })
23+
: '--',
2224
[t('totalAmount', 'Total Amount')]: `${defaultCurrency} ${bill?.totalAmount}`,
2325
[t('totalPaid', 'Total paid')]: `${defaultCurrency} ${bill?.tenderedAmount}`,
2426
[t('amountBalance', 'Amount balance')]: `${defaultCurrency} ${bill?.totalAmount - bill?.tenderedAmount}`,

src/invoice/printable-invoice/printable-invoice-header.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const testProps = {
2424
const bill = {
2525
status: 'POSTED',
2626
receiptNumber: '0050-5',
27-
dateCreated: '01 — Nov — 2025',
27+
dateCreated: '2025-11-01T00:00:00.000Z',
2828
totalAmount: 100,
2929
tenderedAmount: 50,
3030
} as MappedBill;

0 commit comments

Comments
 (0)