@ampath/esm-dha-workflow-app 4.0.0-next.451 → 4.0.0-next.453

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/1100.js +1 -1
  2. package/dist/1435.js +1 -1
  3. package/dist/1435.js.map +1 -1
  4. package/dist/2257.js +2 -0
  5. package/dist/2257.js.map +1 -0
  6. package/dist/2535.js +1 -1
  7. package/dist/2592.js +1 -1
  8. package/dist/2663.js +1 -1
  9. package/dist/2687.js +1 -1
  10. package/dist/2808.js +1 -1
  11. package/dist/2848.js +1 -1
  12. package/dist/2904.js +1 -0
  13. package/dist/2904.js.map +1 -0
  14. package/dist/3.js +1 -1
  15. package/dist/3016.js +1 -1
  16. package/dist/3182.js +1 -1
  17. package/dist/3196.js +1 -1
  18. package/dist/3242.js +1 -1
  19. package/dist/3288.js +1 -1
  20. package/dist/3612.js +1 -1
  21. package/dist/3794.js +1 -1
  22. package/dist/3897.js +1 -1
  23. package/dist/3949.js +1 -1
  24. package/dist/3949.js.map +1 -1
  25. package/dist/408.js +1 -1
  26. package/dist/409.js +1 -1
  27. package/dist/4300.js +1 -1
  28. package/dist/4399.js +1 -1
  29. package/dist/{7269.js → 4457.js} +1 -1
  30. package/dist/4457.js.map +1 -0
  31. package/dist/4535.js +1 -0
  32. package/dist/4535.js.map +1 -0
  33. package/dist/4569.js +1 -1
  34. package/dist/474.js +1 -1
  35. package/dist/5119.js +1 -1
  36. package/dist/5138.js +1 -1
  37. package/dist/5179.js +1 -1
  38. package/dist/5244.js +1 -1
  39. package/dist/5353.js +1 -1
  40. package/dist/5377.js +1 -1
  41. package/dist/5377.js.map +1 -1
  42. package/dist/5500.js +1 -1
  43. package/dist/5771.js +1 -0
  44. package/dist/5771.js.map +1 -0
  45. package/dist/5805.js +1 -1
  46. package/dist/6048.js +1 -1
  47. package/dist/6055.js +1 -1
  48. package/dist/6206.js +1 -1
  49. package/dist/6279.js +1 -1
  50. package/dist/6682.js +1 -1
  51. package/dist/6802.js +1 -1
  52. package/dist/72.js +1 -1
  53. package/dist/7694.js +1 -1
  54. package/dist/7698.js +1 -1
  55. package/dist/7734.js +1 -1
  56. package/dist/8137.js +1 -1
  57. package/dist/8167.js +1 -1
  58. package/dist/818.js +1 -1
  59. package/dist/8735.js +1 -1
  60. package/dist/8961.js +1 -1
  61. package/dist/902.js +1 -1
  62. package/dist/9134.js +1 -1
  63. package/dist/9429.js +1 -1
  64. package/dist/9442.js +1 -1
  65. package/dist/968.js +1 -1
  66. package/dist/9770.js +1 -1
  67. package/dist/9879.js +1 -1
  68. package/dist/9974.js +1 -1
  69. package/dist/esm-dha-workflow-app.js +1 -1
  70. package/dist/esm-dha-workflow-app.js.buildmanifest.json +214 -166
  71. package/dist/main.js +1 -1
  72. package/dist/main.js.map +1 -1
  73. package/dist/routes.json +1 -1
  74. package/package.json +1 -1
  75. package/src/billing/dashboard/v3/finalize-bill/bill-line-items/bill-line-items.component.tsx +101 -0
  76. package/src/billing/dashboard/v3/finalize-bill/bill-line-items/bill-line-items.scss +69 -0
  77. package/src/billing/dashboard/v3/finalize-bill/finalize-bill-confirmation.modal.scss +11 -0
  78. package/src/billing/dashboard/v3/finalize-bill/finalize-bill-confirmation.modal.tsx +72 -0
  79. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.component.scss +68 -0
  80. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.component.tsx +261 -0
  81. package/src/billing/dashboard/v3/finalize-bill/finalize-bill.resource.ts +68 -0
  82. package/src/billing/dashboard/v3/finalize-bill/helpers/functions.ts +85 -0
  83. package/src/billing/dashboard/v3/finalize-bill/helpers/index.ts +1 -0
  84. package/src/billing/dashboard/v3/finalize-bill/payments/invoice-breakdown/invoice-breakdown.component.tsx +17 -0
  85. package/src/billing/dashboard/v3/finalize-bill/payments/invoice-breakdown/invoice-breakdown.scss +29 -0
  86. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.component.tsx +60 -0
  87. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.scss +53 -0
  88. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.test.tsx +211 -0
  89. package/src/billing/dashboard/v3/finalize-bill/payments/payment-form/payment-form.utils.ts +87 -0
  90. package/src/billing/dashboard/v3/finalize-bill/payments/payment-history/payment-history.component.tsx +77 -0
  91. package/src/billing/dashboard/v3/finalize-bill/payments/payment-history/payment-history.test.tsx +158 -0
  92. package/src/billing/dashboard/v3/finalize-bill/payments/payments.component.tsx +238 -0
  93. package/src/billing/dashboard/v3/finalize-bill/payments/payments.scss +77 -0
  94. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.component.tsx +43 -0
  95. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.scss +14 -0
  96. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/print-receipt.test.tsx +133 -0
  97. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.component.tsx +19 -0
  98. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.scss +17 -0
  99. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-footer.test.tsx +22 -0
  100. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.component.tsx +109 -0
  101. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.scss +62 -0
  102. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice-header.test.tsx +159 -0
  103. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice.component.tsx +221 -0
  104. package/src/billing/dashboard/v3/finalize-bill/payments/printable-invoice/printable-invoice.scss +55 -0
  105. package/src/billing/dashboard/v3/finalize-bill/types.ts +248 -0
  106. package/src/billing/dashboard/v3/patient-bill-details/patient-visit-details.tsx +43 -8
  107. package/src/billing/dashboard/v3/patient-bill-details/patient-visit.scss +7 -0
  108. package/src/config-schema.ts +33 -3
  109. package/src/index.ts +12 -9
  110. package/src/routes.json +8 -0
  111. package/translations/en.json +1 -0
  112. package/dist/7269.js.map +0 -1
  113. package/dist/7949.js +0 -2
  114. package/dist/7949.js.map +0 -1
  115. package/dist/7958.js +0 -1
  116. package/dist/7958.js.map +0 -1
  117. /package/dist/{7949.js.LICENSE.txt → 2257.js.LICENSE.txt} +0 -0
@@ -0,0 +1,17 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+
5
+ .container {
6
+ display: flex;
7
+ flex-direction: column;
8
+ position: fixed;
9
+ width: 100%;
10
+ bottom: 0;
11
+ }
12
+
13
+ .itemFooter {
14
+ padding: 1rem;
15
+ @include type.type-style('body-compact-02');
16
+ color: colors.$cool-gray-90;
17
+ }
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+ import { screen, render } from '@testing-library/react';
4
+ import { useDefaultFacility } from '../../billing.resource';
5
+ import PrintableFooter from './printable-footer.component';
6
+
7
+ const mockUseDefaultFacility = vi.mocked<typeof useDefaultFacility>(useDefaultFacility);
8
+
9
+ vi.mock('../../billing.resource', () => ({
10
+ useDefaultFacility: vi.fn(),
11
+ }));
12
+
13
+ describe('PrintableFooter', () => {
14
+ it('should render PrintableFooter component', () => {
15
+ mockUseDefaultFacility.mockReturnValue({
16
+ data: { display: 'MTRH', uuid: 'mtrh-uuid', links: [] },
17
+ });
18
+ render(<PrintableFooter />);
19
+ const footer = screen.getByText('MTRH');
20
+ expect(footer).toBeInTheDocument();
21
+ });
22
+ });
@@ -0,0 +1,109 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import isEmpty from 'lodash/isEmpty';
4
+ import {
5
+ formatDate,
6
+ formatPartialDate,
7
+ interpolateUrl,
8
+ parseDate,
9
+ type SessionLocation,
10
+ useConfig,
11
+ } from '@openmrs/esm-framework';
12
+ import type { MappedBill, PatientDetails } from '../../types';
13
+ import styles from './printable-invoice-header.scss';
14
+ import { ConfigObject } from 'src/config-schema';
15
+
16
+ interface PrintableInvoiceHeaderProps {
17
+ patientDetails: PatientDetails;
18
+ defaultFacility: SessionLocation | null;
19
+ bill: MappedBill;
20
+ }
21
+
22
+ const PrintableInvoiceHeader: React.FC<PrintableInvoiceHeaderProps> = ({ patientDetails, defaultFacility, bill }) => {
23
+ const { t } = useTranslation();
24
+ const { logo, country, defaultCurrency } = useConfig<ConfigObject>();
25
+
26
+ const invoiceDetails = {
27
+ [t('invoiceNo', 'Invoice #')]: bill?.receiptNumber,
28
+ [t('invoiceDate', 'Invoice date')]: bill?.dateCreated
29
+ ? formatDate(parseDate(bill.dateCreated), { mode: 'wide', noToday: true, time: false })
30
+ : '--',
31
+ [t('totalAmount', 'Total amount')]: `${defaultCurrency} ${bill?.totalAmount}`,
32
+ [t('totalPaid', 'Total paid')]: `${defaultCurrency} ${bill?.tenderedAmount}`,
33
+ [t('amountBalance', 'Amount balance')]: `${defaultCurrency} ${bill?.netAmount - bill?.tenderedAmount}`,
34
+ ...(bill?.status && { [t('invoiceStatus', 'Invoice status')]: bill.status }),
35
+ };
36
+
37
+ const patientInformation = {
38
+ [t('name', 'Name')]: patientDetails?.name,
39
+ ...(patientDetails.gender && { [t('gender', 'Gender')]: patientDetails.gender }),
40
+ ...(patientDetails.birthDate && {
41
+ [t('birthDate', 'Date of birth')]: formatPartialDate(patientDetails.birthDate, {
42
+ time: false,
43
+ noToday: true,
44
+ }),
45
+ }),
46
+ ...(patientDetails.address && { [t('address', 'Address')]: patientDetails.address }),
47
+ };
48
+
49
+ return (
50
+ <div className={styles.container}>
51
+ <div className={styles.printableHeader}>
52
+ <div className={styles.logo}>
53
+ {logo?.src && !isEmpty(logo.src) ? (
54
+ <img className={styles.img} src={interpolateUrl(logo.src)} alt={logo.alt} />
55
+ ) : logo?.alt && !isEmpty(logo.alt) ? (
56
+ logo.alt
57
+ ) : (
58
+ // OpenMRS Logo
59
+ <svg
60
+ className={styles.img}
61
+ role="img"
62
+ width={110}
63
+ height={40}
64
+ viewBox="0 0 380 119"
65
+ xmlns="http://www.w3.org/2000/svg">
66
+ <path
67
+ fillRule="evenodd"
68
+ clipRule="evenodd"
69
+ d="M40.29 40.328a27.755 27.755 0 0 1 19.688-8.154c7.669 0 14.613 3.102 19.647 8.116l.02-18.54A42.835 42.835 0 0 0 59.978 17c-7.089 0-13.813 1.93-19.709 4.968l.021 18.36ZM79.645 79.671a27.744 27.744 0 0 1-19.684 8.154c-7.67 0-14.614-3.101-19.651-8.116l-.02 18.54A42.857 42.857 0 0 0 59.96 103a42.833 42.833 0 0 0 19.672-4.751l.013-18.578ZM40.328 79.696c-5.038-5.037-8.154-11.995-8.154-19.685 0-7.669 3.102-14.612 8.116-19.65l-18.54-.02A42.85 42.85 0 0 0 17 60.012a42.819 42.819 0 0 0 4.752 19.672l18.576.013ZM79.634 40.289a27.753 27.753 0 0 1 8.154 19.688 27.744 27.744 0 0 1-8.117 19.646l18.542.02a42.842 42.842 0 0 0 4.749-19.666c0-7.09-1.714-13.779-4.751-19.675l-18.577-.013ZM156.184 60.002c0-8.748-6.118-15.776-15.025-15.776-8.909 0-15.025 7.028-15.025 15.776 0 8.749 6.116 15.78 15.025 15.78 8.907 0 15.025-7.031 15.025-15.78Zm-34.881 0c0-11.482 8.318-19.958 19.856-19.958 11.536 0 19.855 8.477 19.855 19.959 0 11.484-8.319 19.964-19.855 19.964-11.538 0-19.856-8.48-19.856-19.965ZM179.514 75.54c5.507 0 9.05-4.14 9.05-9.482 0-5.341-3.543-9.483-9.05-9.483-5.505 0-9.046 4.142-9.046 9.483 0 5.342 3.541 9.482 9.046 9.482ZM166.22 53.306h4.248v3.704h.11c2.344-2.725 5.449-4.36 9.154-4.36 8.014 0 13.408 5.67 13.408 13.408 0 7.63-5.613 13.406-12.752 13.406-4.58 0-8.231-2.29-9.81-5.178h-.11V90.87h-4.248V53.306ZM217.773 63.768c-.163-4.305-3-7.193-7.686-7.193-4.685 0-7.79 2.888-8.335 7.193h16.021Zm3.653 10.412c-3.001 3.868-6.596 5.284-11.339 5.284-8.01 0-12.914-5.993-12.914-13.406 0-7.901 5.559-13.407 13.08-13.407 7.196 0 12.096 4.906 12.096 13.354v1.362h-20.597c.325 4.413 3.704 8.173 8.335 8.173 3.65 0 6.105-1.307 8.12-3.868l3.219 2.508ZM227.854 59.356c0-2.346-.216-4.36-.216-6.05h4.031c0 1.363.11 2.777.11 4.195h.11c1.144-2.505 4.306-4.85 8.5-4.85 6.705 0 9.699 4.252 9.699 10.41v15.748h-4.248v-15.31c0-4.253-1.856-6.924-5.833-6.924-5.503 0-7.903 3.979-7.903 9.811V78.81h-4.25V59.356ZM259.211 41.008h6.708L278.8 70.791h.107l12.982-29.782h6.549v37.99h-4.506V47.124h-.106L280.192 79h-2.738l-13.629-31.875h-.107V79h-4.507V41.01ZM312.392 57.752h4.023c4.992 0 11.487 0 11.487-6.282 0-5.47-4.776-6.276-9.177-6.276h-6.333v12.558Zm-4.506-16.744h9.711c7.352 0 15.132 1.072 15.132 10.462 0 5.527-3.594 9.125-9.495 10.037L334.018 79h-5.525l-10.304-17.063h-5.797V79h-4.506V41.01ZM358.123 47.712c-1.506-2.413-4.187-3.486-6.926-3.486-3.973 0-8.1 1.88-8.1 6.385 0 3.49 1.931 5.047 7.994 6.98 5.903 1.878 11.377 3.809 11.377 11.267 0 7.567-6.495 11.11-13.36 11.11-4.402 0-9.125-1.45-11.7-5.262l3.862-3.165c1.61 2.794 4.83 4.24 8.105 4.24 3.862 0 8.263-2.253 8.263-6.601 0-4.669-3.165-5.474-9.928-7.728-5.366-1.771-9.442-4.134-9.442-10.463 0-7.298 6.277-10.945 12.929-10.945 4.241 0 7.836 1.178 10.625 4.45l-3.699 3.218Z"
70
+ />
71
+ </svg>
72
+ )}
73
+ </div>
74
+ <div className={styles.facilityDetails}>
75
+ <p className={styles.facilityName}>{defaultFacility?.display}</p>
76
+ <p className={styles.itemLabel}>{country}</p>
77
+ </div>
78
+ </div>
79
+ <h1 className={styles.invoiceHeading}>{t('invoice', 'Invoice')}</h1>
80
+
81
+ <div className={styles.printableBody}>
82
+ <div className={styles.detailsContainer}>
83
+ <div>
84
+ <h2 className={styles.sectionHeading}>{t('patientInformation', 'Patient information')}</h2>
85
+
86
+ {Object.entries(patientInformation).map(([key, val]) => (
87
+ <p className={styles.itemLabel} key={key}>
88
+ <strong>{key}</strong>
89
+ <span>: {val}</span>
90
+ </p>
91
+ ))}
92
+ </div>
93
+
94
+ <div>
95
+ <h2 className={styles.sectionHeading}>{t('invoiceSummary', 'Invoice summary')}</h2>
96
+ {Object.entries(invoiceDetails).map(([key, val]) => (
97
+ <p className={styles.itemLabel} key={key}>
98
+ <strong>{key}</strong>
99
+ <span>: {val}</span>
100
+ </p>
101
+ ))}
102
+ </div>
103
+ </div>
104
+ </div>
105
+ </div>
106
+ );
107
+ };
108
+
109
+ export default PrintableInvoiceHeader;
@@ -0,0 +1,62 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+
5
+ .container {
6
+ padding: layout.$spacing-07;
7
+ }
8
+
9
+ .printableBody {
10
+ .detailsContainer {
11
+ display: flex;
12
+ justify-content: space-between;
13
+ gap: layout.$spacing-07;
14
+ }
15
+ border-bottom: solid 0.1pt colors.$cool-gray-30;
16
+ padding: layout.$spacing-02;
17
+ }
18
+
19
+ .printableHeader {
20
+ display: flex;
21
+ justify-content: space-between;
22
+ align-items: flex-start;
23
+ padding-bottom: layout.$spacing-02;
24
+ margin-bottom: layout.$spacing-02;
25
+ }
26
+
27
+ .logo {
28
+ flex: 1;
29
+ }
30
+
31
+ .img {
32
+ height: auto;
33
+ }
34
+
35
+ .facilityDetails {
36
+ flex: 1;
37
+ text-align: right;
38
+ }
39
+
40
+ .invoiceHeading {
41
+ @include type.type-style('heading-04');
42
+ text-transform: uppercase;
43
+ text-align: center;
44
+ font-size: 40px;
45
+ }
46
+
47
+ .facilityName {
48
+ @include type.type-style('heading-compact-02');
49
+ font-weight: bold;
50
+ color: colors.$green-70;
51
+ }
52
+
53
+ .sectionHeading {
54
+ @include type.type-style('heading-compact-02');
55
+ margin-bottom: layout.$spacing-04;
56
+ padding-bottom: layout.$spacing-03;
57
+ }
58
+
59
+ .itemLabel {
60
+ @include type.type-style('body-compact-01');
61
+ margin-bottom: layout.$spacing-01;
62
+ }
@@ -0,0 +1,159 @@
1
+ import React from 'react';
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
+ import { screen, render } from '@testing-library/react';
4
+ import { useConfig } from '@openmrs/esm-framework';
5
+ import { type BillingConfig } from '../../config-schema';
6
+ import { useDefaultFacility } from '../../billing.resource';
7
+ import { type MappedBill } from '../../types';
8
+ import PrintableInvoiceHeader from './printable-invoice-header.component';
9
+
10
+ const mockUseDefaultFacility = vi.mocked(useDefaultFacility);
11
+ const mockUseConfig = vi.mocked(useConfig<BillingConfig>);
12
+
13
+ vi.mock('../../billing.resource', () => ({
14
+ useDefaultFacility: vi.fn(),
15
+ }));
16
+
17
+ const testProps = {
18
+ patientDetails: {
19
+ name: 'John Doe',
20
+ address: 'Rongai, Nairobi, Westlands',
21
+ birthDate: '1980-05-15',
22
+ gender: 'Male',
23
+ },
24
+ };
25
+ const bill = {
26
+ status: 'POSTED',
27
+ receiptNumber: '0050-5',
28
+ dateCreated: '2025-11-01T00:00:00.000Z',
29
+ totalAmount: 100,
30
+ tenderedAmount: 50,
31
+ } as MappedBill;
32
+
33
+ const defaultFacility = { display: 'MTRH', uuid: 'mtrh-uuid', links: [] };
34
+
35
+ describe('PrintableInvoiceHeader', () => {
36
+ beforeEach(() => {
37
+ mockUseConfig.mockReturnValue({
38
+ logo: { src: 'logo.png', alt: 'logo' },
39
+ country: 'Kenya',
40
+ defaultCurrency: 'KES',
41
+ } as unknown as BillingConfig);
42
+ mockUseDefaultFacility.mockReturnValue({ data: { display: 'MTRH', uuid: 'mtrh-uuid', links: [] } });
43
+ });
44
+
45
+ afterEach(() => {
46
+ vi.useRealTimers();
47
+ });
48
+
49
+ it('should render PrintableInvoiceHeader component', () => {
50
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={defaultFacility} bill={bill} />);
51
+ const header = screen.getByText('Invoice');
52
+ expect(header).toBeInTheDocument();
53
+
54
+ expect(screen.getByText(/john Doe/i)).toBeInTheDocument();
55
+ expect(screen.getByText(/mtrh/i)).toBeInTheDocument();
56
+ expect(screen.getByText(/Rongai, Nairobi, Westlands/i)).toBeInTheDocument();
57
+ expect(screen.getByText(/kenya/i)).toBeInTheDocument();
58
+ expect(screen.getByText(/male/i)).toBeInTheDocument();
59
+ expect(screen.getByText(/15-May-1980/i)).toBeInTheDocument();
60
+ });
61
+
62
+ it('should display the logo when logo is provided', () => {
63
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={defaultFacility} bill={bill} />);
64
+ const logo = screen.getByAltText('logo');
65
+ expect(logo).toBeInTheDocument();
66
+ });
67
+
68
+ it('should display the default OpenMRS SVG logo when logo src is not provided', () => {
69
+ mockUseConfig.mockReturnValue({
70
+ logo: { src: '', alt: '' },
71
+ country: 'Kenya',
72
+ defaultCurrency: 'KES',
73
+ } as unknown as BillingConfig);
74
+
75
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={defaultFacility} bill={bill} />);
76
+ const logo = screen.getByRole('img');
77
+ expect(logo).toBeInTheDocument();
78
+ expect(logo.tagName).toBe('svg');
79
+ });
80
+
81
+ it('should display logo alt text when src is empty but alt is provided', () => {
82
+ mockUseConfig.mockReturnValue({
83
+ logo: { src: '', alt: 'Test Facility Logo' },
84
+ country: 'Kenya',
85
+ defaultCurrency: 'KES',
86
+ } as unknown as BillingConfig);
87
+
88
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={defaultFacility} bill={bill} />);
89
+ expect(screen.getByText('Test Facility Logo')).toBeInTheDocument();
90
+ });
91
+
92
+ it.each([
93
+ { birthDate: '1995-12-25', formattedBirthDate: '25-Dec-1995' },
94
+ { birthDate: '1993', formattedBirthDate: '1993' },
95
+ { birthDate: '2024-03', formattedBirthDate: 'Mar 2024' },
96
+ ])('should format birthDate $birthDate without inventing missing precision', ({ birthDate, formattedBirthDate }) => {
97
+ const propsWithDifferentDate = {
98
+ patientDetails: {
99
+ ...testProps.patientDetails,
100
+ birthDate,
101
+ gender: 'Female',
102
+ },
103
+ };
104
+ render(<PrintableInvoiceHeader {...propsWithDifferentDate} defaultFacility={defaultFacility} bill={bill} />);
105
+ expect(screen.getByText(`: ${formattedBirthDate}`)).toBeInTheDocument();
106
+ });
107
+
108
+ it('should print a newborn date of birth as a calendar date', () => {
109
+ vi.useFakeTimers({ toFake: ['Date'] });
110
+ vi.setSystemTime(new Date(2026, 2, 15, 12));
111
+
112
+ render(
113
+ <PrintableInvoiceHeader
114
+ patientDetails={{ ...testProps.patientDetails, birthDate: '2026-03-15' }}
115
+ defaultFacility={defaultFacility}
116
+ bill={bill}
117
+ />,
118
+ );
119
+
120
+ expect(screen.getByText(': 15-Mar-2026')).toBeInTheDocument();
121
+ expect(screen.queryByText(/Today/i)).not.toBeInTheDocument();
122
+ });
123
+
124
+ it('should not render birthDate and gender when not provided', () => {
125
+ const propsWithoutBirthDateAndGender = {
126
+ patientDetails: {
127
+ ...testProps.patientDetails,
128
+ birthDate: null,
129
+ gender: '',
130
+ },
131
+ };
132
+ render(
133
+ <PrintableInvoiceHeader {...propsWithoutBirthDateAndGender} defaultFacility={defaultFacility} bill={bill} />,
134
+ );
135
+
136
+ expect(screen.queryByText(/Date of birth:/i)).not.toBeInTheDocument();
137
+ expect(screen.queryByText(/Gender:/i)).not.toBeInTheDocument();
138
+ });
139
+
140
+ it('should handle null defaultFacility gracefully', () => {
141
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={null} bill={bill} />);
142
+ expect(screen.getByRole('heading', { name: /Invoice/i, level: 1 })).toBeInTheDocument();
143
+ expect(screen.getByText(/john Doe/i)).toBeInTheDocument();
144
+ });
145
+
146
+ it('should use netAmount to calculate amount balance when a discount is applied', () => {
147
+ const discountedBill = {
148
+ ...bill,
149
+ totalAmount: 100,
150
+ netAmount: 80,
151
+ tenderedAmount: 20,
152
+ } as MappedBill;
153
+
154
+ render(<PrintableInvoiceHeader {...testProps} defaultFacility={defaultFacility} bill={discountedBill} />);
155
+
156
+ expect(screen.getByText(': KES 60')).toBeInTheDocument();
157
+ expect(screen.queryByText(': KES 80')).not.toBeInTheDocument();
158
+ });
159
+ });
@@ -0,0 +1,221 @@
1
+ import React, { useMemo } from 'react';
2
+ import {
3
+ DataTable,
4
+ Table,
5
+ TableContainer,
6
+ TableHead,
7
+ TableRow,
8
+ TableBody,
9
+ TableHeader,
10
+ TableCell,
11
+ } from '@carbon/react';
12
+ import {formatDate, isDesktop, type SessionLocation, useConfig, useLayoutType } from '@openmrs/esm-framework';
13
+ import { getGender } from '../../helpers';
14
+ import { type MappedBill } from '../../types';
15
+ import { useTranslation } from 'react-i18next';
16
+ import PrintableFooter from './printable-footer.component';
17
+ import PrintableInvoiceHeader from './printable-invoice-header.component';
18
+ import styles from './printable-invoice.scss';
19
+ import { type ConfigObject } from '../../../../../../config-schema';
20
+
21
+ type PrintableInvoiceProps = {
22
+ bill: MappedBill;
23
+ patient: fhir.Patient;
24
+ componentRef: React.RefObject<HTMLDivElement>;
25
+ defaultFacility: SessionLocation;
26
+ };
27
+
28
+ const PrintableInvoice: React.FC<PrintableInvoiceProps> = ({ bill, patient, componentRef, defaultFacility }) => {
29
+ const { t } = useTranslation();
30
+ const layout = useLayoutType();
31
+ const { defaultCurrency } = useConfig<ConfigObject>();
32
+ const responsiveSize = isDesktop(layout) ? 'sm' : 'lg';
33
+ const headerData = [
34
+ { header: t('inventoryItem', 'Inventory item'), key: 'billItem' },
35
+ { header: t('quantity', 'Quantity'), key: 'quantity' },
36
+ { header: t('unitPrice', 'Unit price'), key: 'price' },
37
+ { header: t('total', 'Total'), key: 'total' },
38
+ ];
39
+
40
+ const rowData =
41
+ bill?.lineItems?.map((item) => {
42
+ return {
43
+ id: `${item.uuid}`,
44
+ billItem: item.billableService ? item.billableService : item.item,
45
+ quantity: item.quantity,
46
+ price: `${defaultCurrency} ${item.price}`,
47
+ total: `${defaultCurrency} ${item.price * item.quantity}`,
48
+ };
49
+ }) ?? [];
50
+
51
+ const paymentHistoryHeaders = [
52
+ {
53
+ key: 'no',
54
+ header: t('no', 'No'),
55
+ },
56
+ {
57
+ key: 'paymentMethod',
58
+ header: t('paymentMethod', 'Payment method'),
59
+ },
60
+
61
+ {
62
+ key: 'amountPaid',
63
+ header: t('amountPaid', 'Amount paid'),
64
+ },
65
+ {
66
+ key: 'dateCreated',
67
+ header: t('dateOfPayment', 'Date of payment'),
68
+ },
69
+ ];
70
+
71
+ const paymentHistoryRows = useMemo(() => {
72
+ if (bill) {
73
+ return bill.payments?.map((payment, index) => {
74
+ return {
75
+ no: index + 1,
76
+ id: `${payment.uuid}-${index}`,
77
+ paymentMethod: payment.instanceType.name,
78
+ amountPaid: `${defaultCurrency} ${payment.amountTendered.toFixed(2)}`,
79
+ dateCreated: formatDate(new Date(payment.dateCreated)),
80
+ };
81
+ });
82
+ }
83
+ return [];
84
+ }, [bill, defaultCurrency]);
85
+
86
+ const patientDetails = useMemo(() => {
87
+ const address = patient?.address?.[0];
88
+ const addressParts = [address?.line?.join(' '), address?.city, address?.district, address?.state].filter(Boolean);
89
+ const formattedAddress = addressParts.join(', ');
90
+
91
+ return {
92
+ name: `${patient?.name?.[0]?.given?.join(' ')} ${patient?.name?.[0].family}`,
93
+ birthDate: patient?.birthDate,
94
+ gender: getGender(patient?.gender, t),
95
+ address: formattedAddress,
96
+ };
97
+ }, [patient, t]);
98
+
99
+ return (
100
+ <div className={styles.container} ref={componentRef}>
101
+ <PrintableInvoiceHeader patientDetails={patientDetails} defaultFacility={defaultFacility} bill={bill} />
102
+
103
+ <div className={styles.itemsContainer}>
104
+ <div className={styles.tableContainer}>
105
+ <DataTable rows={rowData} headers={headerData} size={responsiveSize} useZebraStyles={false}>
106
+ {({ rows, headers, getRowProps, getTableProps }) => (
107
+ <TableContainer>
108
+ <Table {...getTableProps()} aria-label={t('invoiceLineItems', 'Invoice line items')}>
109
+ <TableHead>
110
+ <TableRow>
111
+ {headers.map((header) => (
112
+ <TableHeader key={header.key}>{header.header}</TableHeader>
113
+ ))}
114
+ </TableRow>
115
+ </TableHead>
116
+ <TableBody>
117
+ {rows.map((row) => (
118
+ <TableRow
119
+ key={row.id}
120
+ {...getRowProps({
121
+ row,
122
+ })}>
123
+ {row.cells.map((cell) => (
124
+ <TableCell key={cell.id}>{cell.value}</TableCell>
125
+ ))}
126
+ </TableRow>
127
+ ))}
128
+ </TableBody>
129
+ </Table>
130
+ </TableContainer>
131
+ )}
132
+ </DataTable>
133
+ {bill?.netAmount != null && bill.totalAmount !== bill.netAmount ? (
134
+ <>
135
+ <div className={styles.balanceContainer}>
136
+ <span className={styles.itemHeading}>{t('subtotal', 'Subtotal')}:</span>{' '}
137
+ <span className={styles.itemLabel}>
138
+ <strong>
139
+ {defaultCurrency} {bill?.totalAmount}
140
+ </strong>
141
+ </span>
142
+ </div>
143
+ <div className={styles.balanceContainer}>
144
+ <span className={styles.itemHeading}>{t('discount', 'Discount')}:</span>{' '}
145
+ <span className={styles.itemLabel}>
146
+ <strong>
147
+ - {defaultCurrency} {(bill?.totalAmount ?? 0) - (bill?.netAmount ?? 0)}
148
+ </strong>
149
+ </span>
150
+ </div>
151
+ <div className={styles.balanceContainer}>
152
+ <span className={styles.itemHeading}>{t('totalAmount', 'Total amount')}:</span>{' '}
153
+ <span className={styles.itemLabel}>
154
+ <strong>
155
+ {defaultCurrency} {bill?.netAmount}
156
+ </strong>
157
+ </span>
158
+ </div>
159
+ </>
160
+ ) : (
161
+ <div className={styles.balanceContainer}>
162
+ <span className={styles.itemHeading}>{t('totalAmount', 'Total amount')}:</span>{' '}
163
+ <span className={styles.itemLabel}>
164
+ <strong>
165
+ {defaultCurrency} {bill?.totalAmount}
166
+ </strong>
167
+ </span>
168
+ </div>
169
+ )}
170
+ {bill?.payments?.length > 0 && (
171
+ <div className={styles.paymentHistoryContainer}>
172
+ <DataTable rows={paymentHistoryRows} headers={paymentHistoryHeaders} size={responsiveSize}>
173
+ {({ rows, headers, getRowProps, getTableProps }) => (
174
+ <TableContainer>
175
+ <Table {...getTableProps()} aria-label={t('paymentHistory', 'Payment History')}>
176
+ <TableHead>
177
+ <TableRow>
178
+ {headers.map((header) => (
179
+ <TableHeader key={header.key}>{header.header}</TableHeader>
180
+ ))}
181
+ </TableRow>
182
+ </TableHead>
183
+ <TableBody>
184
+ {rows.map((row) => (
185
+ <TableRow key={row.id} {...getRowProps({ row })}>
186
+ {row.cells.map((cell) => (
187
+ <TableCell key={cell.id}>{cell.value}</TableCell>
188
+ ))}
189
+ </TableRow>
190
+ ))}
191
+ </TableBody>
192
+ </Table>
193
+ </TableContainer>
194
+ )}
195
+ </DataTable>
196
+ </div>
197
+ )}
198
+ <div className={styles.balanceContainer}>
199
+ <span className={styles.itemHeading}>{t('totalTendered', 'Total tendered')}:</span>
200
+ <span className={styles.itemLabel}>
201
+ <strong>
202
+ {defaultCurrency} {bill?.tenderedAmount}
203
+ </strong>
204
+ </span>
205
+ </div>
206
+ <div className={styles.balanceContainer}>
207
+ <span className={styles.itemHeading}>{t('balance', 'Balance')}:</span>
208
+ <span className={styles.itemLabel}>
209
+ <strong>
210
+ {defaultCurrency} {bill?.netAmount - bill?.tenderedAmount}
211
+ </strong>
212
+ </span>
213
+ </div>
214
+ </div>
215
+ </div>
216
+ <PrintableFooter />
217
+ </div>
218
+ );
219
+ };
220
+
221
+ export default PrintableInvoice;
@@ -0,0 +1,55 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+
5
+
6
+ .itemsContainer {
7
+ display: flex;
8
+ flex-direction: column;
9
+ padding: layout.$spacing-05;
10
+ margin: layout.$spacing-05;
11
+ }
12
+
13
+ .tableContainer {
14
+ min-height: 50vh;
15
+ }
16
+
17
+ .totalContainer {
18
+ display: flex;
19
+ flex-direction: column;
20
+ }
21
+
22
+ .item {
23
+ margin: layout.$spacing-04;
24
+ }
25
+
26
+ .itemHeading {
27
+ @include type.type-style('body-compact-02');
28
+ font-weight: bold;
29
+ color: colors.$cool-gray-90;
30
+ margin-bottom: layout.$spacing-02;
31
+ }
32
+
33
+ .itemTotal {
34
+ border-top: solid 0.1pt colors.$cool-gray-30;
35
+ padding: layout.$spacing-02;
36
+ }
37
+
38
+ .itemLabel {
39
+ float: right;
40
+ }
41
+
42
+ .summaryContainer {
43
+ margin-top: layout.$spacing-05;
44
+ }
45
+
46
+ .paymentHistoryContainer{
47
+ margin-top: layout.$spacing-05;
48
+ }
49
+
50
+ .balanceContainer{
51
+ padding: layout.$spacing-02;
52
+ margin-top: layout.$spacing-05;
53
+ border-top: solid 0.1pt colors.$cool-gray-30;
54
+ border-bottom: solid 0.1pt colors.$cool-gray-30;
55
+ }