@openmrs/esm-billing-app 1.0.2-pre.82 → 1.0.2-pre.820
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.
- package/.eslintrc +16 -2
- package/README.md +54 -9
- package/__mocks__/bills.mock.ts +12 -0
- package/__mocks__/react-i18next.js +6 -5
- package/dist/1119.js +1 -1
- package/dist/1146.js +1 -2
- package/dist/1146.js.map +1 -1
- package/dist/1197.js +1 -1
- package/dist/1856.js +1 -0
- package/dist/1856.js.map +1 -0
- package/dist/2146.js +1 -1
- package/dist/2177.js +2 -0
- package/dist/2177.js.LICENSE.txt +9 -0
- package/dist/2177.js.map +1 -0
- package/dist/2524.js +1 -0
- package/dist/2524.js.map +1 -0
- package/dist/2690.js +1 -1
- package/dist/3041.js +1 -0
- package/dist/3041.js.map +1 -0
- package/dist/3099.js +1 -1
- package/dist/3584.js +1 -1
- package/dist/4055.js +1 -1
- package/dist/4132.js +1 -1
- package/dist/4225.js +1 -0
- package/dist/4225.js.map +1 -0
- package/dist/4300.js +1 -1
- package/dist/4335.js +1 -1
- package/dist/4344.js +1 -0
- package/dist/4344.js.map +1 -0
- package/dist/4618.js +1 -1
- package/dist/4652.js +1 -1
- package/dist/4724.js +1 -0
- package/dist/4724.js.map +1 -0
- package/dist/4739.js +1 -1
- package/dist/4739.js.map +1 -1
- package/dist/4944.js +1 -1
- package/dist/5173.js +1 -1
- package/dist/5241.js +1 -1
- package/dist/5422.js +1 -0
- package/dist/5422.js.map +1 -0
- package/dist/5442.js +1 -1
- package/dist/5661.js +1 -1
- package/dist/6022.js +1 -1
- package/dist/6468.js +1 -1
- package/dist/6540.js +1 -1
- package/dist/6540.js.map +1 -1
- package/dist/6606.js +1 -0
- package/dist/6606.js.map +1 -0
- package/dist/6679.js +1 -1
- package/dist/6840.js +1 -1
- package/dist/6859.js +1 -1
- package/dist/7097.js +1 -1
- package/dist/7159.js +1 -1
- package/dist/723.js +1 -1
- package/dist/7452.js +2 -0
- package/dist/7452.js.map +1 -0
- package/dist/7617.js +1 -1
- package/dist/795.js +1 -1
- package/dist/8163.js +1 -1
- package/dist/8349.js +1 -1
- package/dist/8618.js +1 -1
- package/dist/890.js +1 -1
- package/dist/8930.js +2 -0
- package/dist/{6525.js.LICENSE.txt → 8930.js.LICENSE.txt} +16 -4
- package/dist/8930.js.map +1 -0
- package/dist/9214.js +1 -1
- package/dist/9538.js +1 -1
- package/dist/9569.js +1 -1
- package/dist/961.js +1 -1
- package/dist/961.js.map +1 -1
- package/dist/986.js +1 -1
- package/dist/9879.js +1 -1
- package/dist/9895.js +1 -1
- package/dist/9900.js +1 -1
- package/dist/9913.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-billing-app.js +1 -1
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +371 -265
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/e2e/README.md +19 -18
- package/e2e/core/test.ts +1 -1
- package/e2e/fixtures/api.ts +1 -1
- package/e2e/specs/sample-test.spec.ts +0 -1
- package/e2e/support/github/Dockerfile +1 -1
- package/package.json +13 -10
- package/src/bill-history/bill-history.component.tsx +17 -25
- package/src/bill-history/bill-history.scss +4 -94
- package/src/bill-history/bill-history.test.tsx +37 -78
- package/src/bill-item-actions/bill-item-actions.scss +0 -4
- package/src/bill-item-actions/{edit-bill-item.component.tsx → edit-bill-item.modal.tsx} +100 -78
- package/src/bill-item-actions/edit-bill-item.test.tsx +116 -31
- package/src/billable-services/bill-waiver/bill-selection.component.tsx +2 -2
- package/src/billable-services/bill-waiver/bill-waiver-form.component.tsx +2 -3
- package/src/billable-services/bill-waiver/patient-bills.component.tsx +3 -3
- package/src/billable-services/bill-waiver/utils.ts +13 -3
- package/src/billable-services/billable-service.resource.ts +28 -12
- package/src/billable-services/billable-services-home.component.tsx +1 -1
- package/src/billable-services/billable-services.component.tsx +142 -145
- package/src/billable-services/billable-services.scss +3 -0
- package/src/billable-services/billable-services.test.tsx +2 -45
- package/src/billable-services/cash-point/add-cash-point.modal.tsx +168 -0
- package/src/billable-services/cash-point/cash-point-configuration.component.tsx +18 -192
- package/src/billable-services/cash-point/cash-point-configuration.scss +1 -5
- package/src/billable-services/create-edit/add-billable-service.component.tsx +358 -300
- package/src/billable-services/create-edit/add-billable-service.scss +6 -65
- package/src/billable-services/create-edit/add-billable-service.test.tsx +166 -80
- package/src/billable-services/create-edit/edit-billable-service.modal.tsx +51 -0
- package/src/billable-services/payment-modes/add-payment-mode.modal.tsx +121 -0
- package/src/billable-services/payment-modes/delete-payment-mode.modal.tsx +72 -0
- package/src/billable-services/payment-modes/payment-modes-config.component.tsx +125 -0
- package/src/billable-services/{payyment-modes → payment-modes}/payment-modes-config.scss +5 -4
- package/src/billing-form/billing-checkin-form.component.tsx +2 -3
- package/src/billing-form/billing-checkin-form.test.tsx +97 -24
- package/src/billing-form/billing-form.component.tsx +216 -269
- package/src/billing-form/billing-form.scss +143 -0
- package/src/billing.resource.ts +52 -68
- package/src/bills-table/bills-table.test.tsx +98 -54
- package/src/config-schema.ts +52 -24
- package/src/dashboard.meta.ts +4 -2
- package/src/helpers/functions.ts +5 -4
- package/src/index.ts +17 -6
- package/src/invoice/invoice-table.component.tsx +34 -68
- package/src/invoice/invoice-table.scss +8 -5
- package/src/invoice/invoice-table.test.tsx +273 -62
- package/src/invoice/invoice.component.tsx +38 -29
- package/src/invoice/invoice.scss +11 -4
- package/src/invoice/invoice.test.tsx +324 -120
- package/src/invoice/payments/invoice-breakdown/invoice-breakdown.scss +9 -9
- package/src/invoice/payments/payment-form/payment-form.component.tsx +43 -34
- package/src/invoice/payments/payment-form/payment-form.scss +5 -6
- package/src/invoice/payments/payment-form/payment-form.test.tsx +216 -66
- package/src/invoice/payments/payment-history/payment-history.component.tsx +6 -4
- package/src/invoice/payments/payment-history/payment-history.test.tsx +9 -14
- package/src/invoice/payments/payments.component.tsx +53 -65
- package/src/invoice/payments/payments.scss +4 -3
- package/src/invoice/payments/payments.test.tsx +282 -0
- package/src/invoice/payments/utils.ts +15 -27
- package/src/invoice/printable-invoice/print-receipt.component.tsx +3 -2
- package/src/invoice/printable-invoice/print-receipt.test.tsx +14 -25
- package/src/invoice/printable-invoice/printable-footer.component.tsx +2 -2
- package/src/invoice/printable-invoice/printable-footer.test.tsx +4 -13
- package/src/invoice/printable-invoice/printable-invoice-header.component.tsx +12 -11
- package/src/invoice/printable-invoice/printable-invoice-header.test.tsx +16 -14
- package/src/invoice/printable-invoice/printable-invoice.component.tsx +19 -33
- package/src/left-panel-link.test.tsx +1 -4
- package/src/metrics-cards/metrics-cards.test.tsx +18 -5
- package/src/modal/require-payment-modal.test.tsx +27 -22
- package/src/modal/{require-payment-modal.component.tsx → require-payment.modal.tsx} +17 -18
- package/src/routes.json +22 -2
- package/src/types/index.ts +80 -18
- package/translations/am.json +69 -21
- package/translations/ar.json +69 -21
- package/translations/ar_SY.json +69 -21
- package/translations/bn.json +74 -26
- package/translations/de.json +69 -21
- package/translations/en.json +69 -21
- package/translations/en_US.json +69 -21
- package/translations/es.json +69 -21
- package/translations/es_MX.json +69 -21
- package/translations/fr.json +82 -34
- package/translations/he.json +69 -21
- package/translations/hi.json +69 -21
- package/translations/hi_IN.json +69 -21
- package/translations/id.json +69 -21
- package/translations/it.json +104 -56
- package/translations/ka.json +69 -21
- package/translations/km.json +69 -21
- package/translations/ku.json +69 -21
- package/translations/ky.json +69 -21
- package/translations/lg.json +69 -21
- package/translations/ne.json +69 -21
- package/translations/pl.json +69 -21
- package/translations/pt.json +69 -21
- package/translations/pt_BR.json +69 -21
- package/translations/qu.json +69 -21
- package/translations/ro_RO.json +213 -165
- package/translations/ru_RU.json +69 -21
- package/translations/si.json +69 -21
- package/translations/sw.json +69 -21
- package/translations/sw_KE.json +69 -21
- package/translations/tr.json +69 -21
- package/translations/tr_TR.json +69 -21
- package/translations/uk.json +69 -21
- package/translations/uz.json +69 -21
- package/translations/uz@Latn.json +69 -21
- package/translations/uz_UZ.json +69 -21
- package/translations/vi.json +69 -21
- package/translations/zh.json +69 -21
- package/translations/zh_CN.json +124 -76
- package/dist/1146.js.LICENSE.txt +0 -21
- package/dist/2352.js +0 -1
- package/dist/2352.js.map +0 -1
- package/dist/246.js +0 -1
- package/dist/246.js.map +0 -1
- package/dist/6525.js +0 -2
- package/dist/6525.js.map +0 -1
- package/dist/8556.js +0 -2
- package/dist/8556.js.map +0 -1
- package/dist/8638.js +0 -1
- package/dist/8638.js.map +0 -1
- package/dist/9968.js +0 -1
- package/dist/9968.js.map +0 -1
- package/src/billable-services/payyment-modes/payment-modes-config.component.tsx +0 -280
- package/src/invoice/payments/payments.component.test.tsx +0 -121
- /package/dist/{8556.js.LICENSE.txt → 7452.js.LICENSE.txt} +0 -0
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
DataTable,
|
|
7
7
|
InlineLoading,
|
|
8
8
|
Layer,
|
|
9
|
-
Modal,
|
|
10
9
|
OverflowMenu,
|
|
11
10
|
OverflowMenuItem,
|
|
12
11
|
Pagination,
|
|
@@ -21,25 +20,40 @@ import {
|
|
|
21
20
|
Tile,
|
|
22
21
|
} from '@carbon/react';
|
|
23
22
|
import { ArrowRight } from '@carbon/react/icons';
|
|
24
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
ErrorState,
|
|
25
|
+
getCoreTranslation,
|
|
26
|
+
isDesktop,
|
|
27
|
+
navigate,
|
|
28
|
+
showModal,
|
|
29
|
+
useConfig,
|
|
30
|
+
useLayoutType,
|
|
31
|
+
usePagination,
|
|
32
|
+
type LayoutType,
|
|
33
|
+
} from '@openmrs/esm-framework';
|
|
25
34
|
import { EmptyState } from '@openmrs/esm-patient-common-lib';
|
|
26
35
|
import { type BillableService } from '../types/index';
|
|
27
36
|
import { useBillableServices } from './billable-service.resource';
|
|
28
|
-
import
|
|
37
|
+
import type { BillingConfig } from '../config-schema';
|
|
29
38
|
import styles from './billable-services.scss';
|
|
30
39
|
|
|
40
|
+
interface FilterableTableHeaderProps {
|
|
41
|
+
layout: LayoutType;
|
|
42
|
+
handleSearch: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
43
|
+
isValidating: boolean;
|
|
44
|
+
responsiveSize: 'sm' | 'md' | 'lg';
|
|
45
|
+
t: (key: string, fallback: string) => string;
|
|
46
|
+
}
|
|
47
|
+
|
|
31
48
|
const BillableServices = () => {
|
|
32
49
|
const { t } = useTranslation();
|
|
33
50
|
const { billableServices, isLoading, isValidating, error, mutate } = useBillableServices();
|
|
34
51
|
const layout = useLayoutType();
|
|
35
|
-
const
|
|
52
|
+
const { pageSize: configuredPageSize } = useConfig<BillingConfig>();
|
|
36
53
|
const [searchString, setSearchString] = useState('');
|
|
37
54
|
const responsiveSize = isDesktop(layout) ? 'lg' : 'sm';
|
|
38
|
-
const pageSizes =
|
|
39
|
-
const [pageSize, setPageSize] = useState(
|
|
40
|
-
|
|
41
|
-
const [showOverlay, setShowOverlay] = useState(false);
|
|
42
|
-
const [editingService, setEditingService] = useState(null);
|
|
55
|
+
const pageSizes = [10, 20, 30, 40, 50];
|
|
56
|
+
const [pageSize, setPageSize] = useState(configuredPageSize ?? 10);
|
|
43
57
|
|
|
44
58
|
const headerData = [
|
|
45
59
|
{
|
|
@@ -55,31 +69,26 @@ const BillableServices = () => {
|
|
|
55
69
|
key: 'serviceType',
|
|
56
70
|
},
|
|
57
71
|
{
|
|
58
|
-
header: t('
|
|
72
|
+
header: t('serviceStatus', 'Service Status'),
|
|
59
73
|
key: 'status',
|
|
60
74
|
},
|
|
61
75
|
{
|
|
62
76
|
header: t('prices', 'Prices'),
|
|
63
77
|
key: 'prices',
|
|
64
78
|
},
|
|
65
|
-
{
|
|
66
|
-
header: t('actions', 'Actions'),
|
|
67
|
-
key: 'actions',
|
|
68
|
-
},
|
|
69
79
|
];
|
|
70
80
|
|
|
71
81
|
const launchBillableServiceForm = useCallback(() => {
|
|
72
82
|
navigate({ to: window.getOpenmrsSpaBase() + 'billable-services/add-service' });
|
|
73
|
-
setEditingService(null);
|
|
74
|
-
setShowOverlay(true);
|
|
75
83
|
}, []);
|
|
76
84
|
|
|
77
85
|
const searchResults: BillableService[] = useMemo(() => {
|
|
78
86
|
const flatBillableServices = Array.isArray(billableServices) ? billableServices.flat() : billableServices;
|
|
79
87
|
|
|
80
88
|
if (flatBillableServices !== undefined && flatBillableServices.length > 0) {
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
const trimmedSearch = searchString.trim();
|
|
90
|
+
if (trimmedSearch) {
|
|
91
|
+
const search = trimmedSearch.toLowerCase();
|
|
83
92
|
return flatBillableServices.filter((service: BillableService) =>
|
|
84
93
|
Object.entries(service).some(([header, value]) => {
|
|
85
94
|
return header === 'uuid' ? false : `${value}`.toLowerCase().includes(search);
|
|
@@ -94,31 +103,16 @@ const BillableServices = () => {
|
|
|
94
103
|
const rowData = [];
|
|
95
104
|
|
|
96
105
|
if (results) {
|
|
97
|
-
results.forEach((service
|
|
106
|
+
results.forEach((service) => {
|
|
98
107
|
const s = {
|
|
99
|
-
id:
|
|
108
|
+
id: service.uuid,
|
|
100
109
|
uuid: service.uuid,
|
|
101
110
|
serviceName: service.name,
|
|
102
111
|
shortName: service.shortName,
|
|
103
112
|
serviceType: service?.serviceType?.display,
|
|
104
113
|
status: service.serviceStatus,
|
|
105
|
-
prices: '--',
|
|
106
|
-
actions: (
|
|
107
|
-
<TableCell>
|
|
108
|
-
<OverflowMenu size="sm" flipped>
|
|
109
|
-
<OverflowMenuItem
|
|
110
|
-
itemText={t('editBillableService', 'Edit Billable Service')}
|
|
111
|
-
onClick={() => handleEditService(service)}
|
|
112
|
-
/>
|
|
113
|
-
</OverflowMenu>
|
|
114
|
-
</TableCell>
|
|
115
|
-
),
|
|
114
|
+
prices: service.servicePrices.map((price) => `${price.name} (${price.price})`).join(', ') || '--',
|
|
116
115
|
};
|
|
117
|
-
let cost = '';
|
|
118
|
-
service.servicePrices.forEach((price) => {
|
|
119
|
-
cost += `${price.name} (${price.price}) `;
|
|
120
|
-
});
|
|
121
|
-
s.prices = cost;
|
|
122
116
|
rowData.push(s);
|
|
123
117
|
});
|
|
124
118
|
}
|
|
@@ -130,132 +124,134 @@ const BillableServices = () => {
|
|
|
130
124
|
},
|
|
131
125
|
[goTo, setSearchString],
|
|
132
126
|
);
|
|
133
|
-
const handleEditService = useCallback((service) => {
|
|
134
|
-
setEditingService(service);
|
|
135
|
-
setShowOverlay(true);
|
|
136
|
-
}, []);
|
|
137
127
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
128
|
+
const handleEditService = useCallback(
|
|
129
|
+
(service: BillableService) => {
|
|
130
|
+
const dispose = showModal('edit-billable-service-modal', {
|
|
131
|
+
serviceToEdit: service,
|
|
132
|
+
onServiceUpdated: mutate,
|
|
133
|
+
closeModal: () => dispose(),
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
[mutate],
|
|
137
|
+
);
|
|
142
138
|
|
|
143
139
|
if (isLoading) {
|
|
144
|
-
|
|
140
|
+
return (
|
|
141
|
+
<InlineLoading status="active" iconDescription={getCoreTranslation('loading')} description="Loading data..." />
|
|
142
|
+
);
|
|
145
143
|
}
|
|
144
|
+
|
|
146
145
|
if (error) {
|
|
147
|
-
<ErrorState headerTitle={t('billableService', 'Billable
|
|
146
|
+
return <ErrorState headerTitle={t('billableService', 'Billable service')} error={error} />;
|
|
148
147
|
}
|
|
148
|
+
|
|
149
149
|
if (billableServices.length === 0) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
return (
|
|
151
|
+
<EmptyState
|
|
152
|
+
displayText={t('billableServices__lower', 'billable services')}
|
|
153
|
+
headerTitle={t('billableService', 'Billable service')}
|
|
154
|
+
launchForm={launchBillableServiceForm}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
return (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
160
|
+
<div className={styles.serviceContainer}>
|
|
161
|
+
<FilterableTableHeader
|
|
162
|
+
handleSearch={handleSearch}
|
|
163
|
+
isValidating={isValidating}
|
|
164
|
+
layout={layout}
|
|
165
|
+
responsiveSize={responsiveSize}
|
|
166
|
+
t={t}
|
|
167
|
+
/>
|
|
168
|
+
<DataTable
|
|
169
|
+
isSortable
|
|
170
|
+
rows={rowData}
|
|
171
|
+
headers={headerData}
|
|
172
|
+
overflowMenuOnHover={isDesktop(layout)}
|
|
173
|
+
size={responsiveSize}
|
|
174
|
+
useZebraStyles={rowData?.length > 1}>
|
|
175
|
+
{({ rows, headers, getHeaderProps, getRowProps, getTableProps }) => (
|
|
176
|
+
<TableContainer>
|
|
177
|
+
<Table {...getTableProps()} aria-label="service list">
|
|
178
|
+
<TableHead>
|
|
179
|
+
<TableRow>
|
|
180
|
+
{headers.map((header) => (
|
|
181
|
+
<TableHeader
|
|
182
|
+
{...getHeaderProps({
|
|
183
|
+
header,
|
|
184
|
+
})}
|
|
185
|
+
key={header.key}>
|
|
186
|
+
{header.header}
|
|
187
|
+
</TableHeader>
|
|
188
|
+
))}
|
|
189
|
+
<TableHeader aria-label={getCoreTranslation('actions')} />
|
|
190
|
+
</TableRow>
|
|
191
|
+
</TableHead>
|
|
192
|
+
<TableBody>
|
|
193
|
+
{rows.map((row) => (
|
|
194
|
+
<TableRow
|
|
195
|
+
key={row.id}
|
|
196
|
+
{...getRowProps({
|
|
197
|
+
row,
|
|
198
|
+
})}>
|
|
199
|
+
{row.cells.map((cell) => (
|
|
200
|
+
<TableCell key={cell.id}>{cell.value}</TableCell>
|
|
195
201
|
))}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
size={responsiveSize}
|
|
223
|
-
onChange={({ pageSize: newPageSize, page: newPage }) => {
|
|
224
|
-
if (newPageSize !== pageSize) {
|
|
225
|
-
setPageSize(newPageSize);
|
|
226
|
-
}
|
|
227
|
-
if (newPage !== currentPage) {
|
|
228
|
-
goTo(newPage);
|
|
229
|
-
}
|
|
230
|
-
}}
|
|
231
|
-
/>
|
|
232
|
-
)}
|
|
202
|
+
<TableCell className="cds--table-column-menu">
|
|
203
|
+
<OverflowMenu size="lg" flipped>
|
|
204
|
+
<OverflowMenuItem
|
|
205
|
+
className={styles.menuItem}
|
|
206
|
+
itemText={t('editBillableService', 'Edit billable service')}
|
|
207
|
+
onClick={() => handleEditService(results.find((service) => service.uuid === row.id))}
|
|
208
|
+
/>
|
|
209
|
+
</OverflowMenu>
|
|
210
|
+
</TableCell>
|
|
211
|
+
</TableRow>
|
|
212
|
+
))}
|
|
213
|
+
</TableBody>
|
|
214
|
+
</Table>
|
|
215
|
+
</TableContainer>
|
|
216
|
+
)}
|
|
217
|
+
</DataTable>
|
|
218
|
+
{searchResults?.length === 0 && (
|
|
219
|
+
<div className={styles.filterEmptyState}>
|
|
220
|
+
<Layer level={0}>
|
|
221
|
+
<Tile className={styles.filterEmptyStateTile}>
|
|
222
|
+
<p className={styles.filterEmptyStateContent}>
|
|
223
|
+
{t('noMatchingServicesToDisplay', 'No matching services to display')}
|
|
224
|
+
</p>
|
|
225
|
+
<p className={styles.filterEmptyStateHelper}>{t('checkFilters', 'Check the filters above')}</p>
|
|
226
|
+
</Tile>
|
|
227
|
+
</Layer>
|
|
233
228
|
</div>
|
|
234
|
-
) : (
|
|
235
|
-
<EmptyState
|
|
236
|
-
launchForm={launchBillableServiceForm}
|
|
237
|
-
displayText={t('noServicesToDisplay', 'There are no services to display')}
|
|
238
|
-
headerTitle={t('billableService', 'Billable service')}
|
|
239
|
-
/>
|
|
240
229
|
)}
|
|
241
|
-
{
|
|
242
|
-
<
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
230
|
+
{paginated && (
|
|
231
|
+
<Pagination
|
|
232
|
+
forwardText={t('nextPage', 'Next page')}
|
|
233
|
+
backwardText={t('previousPage', 'Previous page')}
|
|
234
|
+
page={currentPage}
|
|
235
|
+
pageSize={pageSize}
|
|
236
|
+
pageSizes={pageSizes}
|
|
237
|
+
totalItems={searchResults?.length}
|
|
238
|
+
className={styles.pagination}
|
|
239
|
+
size={responsiveSize}
|
|
240
|
+
onChange={({ pageSize: newPageSize, page: newPage }) => {
|
|
241
|
+
if (newPageSize !== pageSize) {
|
|
242
|
+
setPageSize(newPageSize);
|
|
243
|
+
}
|
|
244
|
+
if (newPage !== currentPage) {
|
|
245
|
+
goTo(newPage);
|
|
246
|
+
}
|
|
247
|
+
}}
|
|
248
|
+
/>
|
|
253
249
|
)}
|
|
254
|
-
|
|
250
|
+
</div>
|
|
255
251
|
);
|
|
256
252
|
};
|
|
257
253
|
|
|
258
|
-
function FilterableTableHeader({ layout, handleSearch, isValidating, responsiveSize, t }) {
|
|
254
|
+
function FilterableTableHeader({ layout, handleSearch, isValidating, responsiveSize, t }: FilterableTableHeaderProps) {
|
|
259
255
|
return (
|
|
260
256
|
<>
|
|
261
257
|
<div className={styles.headerContainer}>
|
|
@@ -291,4 +287,5 @@ function FilterableTableHeader({ layout, handleSearch, isValidating, responsiveS
|
|
|
291
287
|
</>
|
|
292
288
|
);
|
|
293
289
|
}
|
|
290
|
+
|
|
294
291
|
export default BillableServices;
|
|
@@ -4,55 +4,13 @@ import userEvent from '@testing-library/user-event';
|
|
|
4
4
|
import BillableServices from './billable-services.component';
|
|
5
5
|
import { useBillableServices } from './billable-service.resource';
|
|
6
6
|
|
|
7
|
-
// Mock the resource
|
|
8
7
|
jest.mock('./billable-service.resource', () => ({
|
|
9
8
|
useBillableServices: jest.fn(),
|
|
10
9
|
}));
|
|
11
10
|
|
|
12
|
-
// Mock the empty state component
|
|
13
|
-
jest.mock('@openmrs/esm-patient-common-lib', () => ({
|
|
14
|
-
EmptyState: jest.fn(({ displayText, headerTitle }) => (
|
|
15
|
-
<div data-testid="empty-state">
|
|
16
|
-
<h1>{headerTitle}</h1>
|
|
17
|
-
<p>{displayText}</p>
|
|
18
|
-
</div>
|
|
19
|
-
)),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// Mock navigation
|
|
23
|
-
jest.mock('@openmrs/esm-framework', () => ({
|
|
24
|
-
useLayoutType: jest.fn(() => 'desktop'),
|
|
25
|
-
isDesktop: jest.fn(() => true),
|
|
26
|
-
useConfig: jest.fn(() => ({
|
|
27
|
-
billableServices: {
|
|
28
|
-
pageSizes: [10, 20, 30, 40, 50],
|
|
29
|
-
pageSize: 10,
|
|
30
|
-
},
|
|
31
|
-
})),
|
|
32
|
-
usePagination: jest.fn().mockImplementation((data) => ({
|
|
33
|
-
currentPage: 1,
|
|
34
|
-
goTo: jest.fn(),
|
|
35
|
-
results: data,
|
|
36
|
-
paginated: true,
|
|
37
|
-
})),
|
|
38
|
-
navigate: jest.fn(),
|
|
39
|
-
ErrorState: jest.fn(({ error }) => <div>Error: {error?.message || error}</div>),
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
// Mock i18next
|
|
43
|
-
jest.mock('react-i18next', () => ({
|
|
44
|
-
useTranslation: () => ({
|
|
45
|
-
t: (key: string, fallback: string) => fallback || key,
|
|
46
|
-
}),
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
11
|
describe('BillableService', () => {
|
|
50
12
|
const mockedUseBillableServices = useBillableServices as jest.Mock;
|
|
51
13
|
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
jest.clearAllMocks();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
14
|
it('renders an empty state when there are no billable services', () => {
|
|
57
15
|
mockedUseBillableServices.mockReturnValue({
|
|
58
16
|
billableServices: [],
|
|
@@ -64,9 +22,8 @@ describe('BillableService', () => {
|
|
|
64
22
|
|
|
65
23
|
render(<BillableServices />);
|
|
66
24
|
|
|
67
|
-
expect(screen.
|
|
68
|
-
expect(screen.
|
|
69
|
-
expect(screen.getByText('There are no services to display')).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByRole('button', { name: /record.*billable services/i })).toBeInTheDocument();
|
|
26
|
+
expect(screen.queryByRole('table')).not.toBeInTheDocument();
|
|
70
27
|
});
|
|
71
28
|
|
|
72
29
|
it('renders billable services table correctly', () => {
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { useForm, Controller } from 'react-hook-form';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
6
|
+
import { Button, Dropdown, Form, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react';
|
|
7
|
+
import { showSnackbar, openmrsFetch, restBaseUrl, getCoreTranslation } from '@openmrs/esm-framework';
|
|
8
|
+
|
|
9
|
+
type CashPointFormValues = {
|
|
10
|
+
name: string;
|
|
11
|
+
uuid: string;
|
|
12
|
+
location: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
interface AddCashPointModalProps {
|
|
16
|
+
closeModal: () => void;
|
|
17
|
+
onCashPointAdded: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const AddCashPointModal: React.FC<AddCashPointModalProps> = ({ closeModal, onCashPointAdded }) => {
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
const [locations, setLocations] = useState([]);
|
|
23
|
+
|
|
24
|
+
const cashPointSchema = z.object({
|
|
25
|
+
name: z.string().min(1, t('cashPointNameRequired', 'Cash Point Name is required')),
|
|
26
|
+
uuid: z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1, t('uuidRequired', 'UUID is required'))
|
|
29
|
+
.regex(
|
|
30
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
31
|
+
t('invalidUuidFormat', 'Invalid UUID format'),
|
|
32
|
+
),
|
|
33
|
+
location: z.string().min(1, t('locationRequired', 'Location is required')),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
control,
|
|
38
|
+
handleSubmit,
|
|
39
|
+
reset,
|
|
40
|
+
formState: { errors, isSubmitting },
|
|
41
|
+
} = useForm<CashPointFormValues>({
|
|
42
|
+
resolver: zodResolver(cashPointSchema),
|
|
43
|
+
defaultValues: {
|
|
44
|
+
name: '',
|
|
45
|
+
uuid: '',
|
|
46
|
+
location: '',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const fetchLocations = useCallback(async () => {
|
|
51
|
+
try {
|
|
52
|
+
const response = await openmrsFetch(`${restBaseUrl}/location?v=default`);
|
|
53
|
+
const allLocations = response.data.results.map((loc: any) => ({
|
|
54
|
+
id: loc.uuid,
|
|
55
|
+
label: loc.display,
|
|
56
|
+
}));
|
|
57
|
+
setLocations(allLocations);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
showSnackbar({
|
|
60
|
+
title: getCoreTranslation('error'),
|
|
61
|
+
subtitle: t('errorFetchingLocations', 'An error occurred while fetching locations.'),
|
|
62
|
+
kind: 'error',
|
|
63
|
+
isLowContrast: false,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}, [t]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
fetchLocations();
|
|
70
|
+
}, [fetchLocations]);
|
|
71
|
+
|
|
72
|
+
const onSubmit = async (data: CashPointFormValues) => {
|
|
73
|
+
try {
|
|
74
|
+
await openmrsFetch(`${restBaseUrl}/billing/cashPoint`, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/json',
|
|
78
|
+
},
|
|
79
|
+
body: {
|
|
80
|
+
name: data.name,
|
|
81
|
+
uuid: data.uuid,
|
|
82
|
+
location: { uuid: data.location },
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
showSnackbar({
|
|
87
|
+
title: t('success', 'Success'),
|
|
88
|
+
subtitle: t('cashPointSaved', 'Cash point was successfully saved.'),
|
|
89
|
+
kind: 'success',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
closeModal();
|
|
93
|
+
reset({ name: '', uuid: '', location: '' });
|
|
94
|
+
onCashPointAdded();
|
|
95
|
+
} catch (err) {
|
|
96
|
+
showSnackbar({
|
|
97
|
+
title: getCoreTranslation('error'),
|
|
98
|
+
subtitle: err?.message || t('errorSavingCashPoint', 'An error occurred while saving the cash point.'),
|
|
99
|
+
kind: 'error',
|
|
100
|
+
isLowContrast: false,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<>
|
|
107
|
+
<ModalHeader closeModal={closeModal} title={t('addCashPoint', 'Add Cash Point')} />
|
|
108
|
+
<Form onSubmit={handleSubmit(onSubmit)}>
|
|
109
|
+
<ModalBody>
|
|
110
|
+
<Controller
|
|
111
|
+
name="name"
|
|
112
|
+
control={control}
|
|
113
|
+
render={({ field }) => (
|
|
114
|
+
<TextInput
|
|
115
|
+
id="cash-point-name"
|
|
116
|
+
labelText={t('cashPointName', 'Cash Point Name')}
|
|
117
|
+
placeholder={t('cashPointNamePlaceholder', 'e.g., Pharmacy Cash Point')}
|
|
118
|
+
invalid={!!errors.name}
|
|
119
|
+
invalidText={errors.name?.message}
|
|
120
|
+
{...field}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
/>
|
|
124
|
+
<Controller
|
|
125
|
+
name="uuid"
|
|
126
|
+
control={control}
|
|
127
|
+
render={({ field }) => (
|
|
128
|
+
<TextInput
|
|
129
|
+
id="cash-point-uuid"
|
|
130
|
+
labelText={t('cashPointUuid', 'Cash Point UUID')}
|
|
131
|
+
placeholder={t('cashPointUuidPlaceholder', 'Enter UUID')}
|
|
132
|
+
invalid={!!errors.uuid}
|
|
133
|
+
invalidText={errors.uuid?.message}
|
|
134
|
+
{...field}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
/>
|
|
138
|
+
<Controller
|
|
139
|
+
name="location"
|
|
140
|
+
control={control}
|
|
141
|
+
render={({ field }) => (
|
|
142
|
+
<Dropdown
|
|
143
|
+
id="cash-point-location"
|
|
144
|
+
label={t('selectLocation', 'Select Location')}
|
|
145
|
+
titleText={t('cashPointLocation', 'Cash Point Location')}
|
|
146
|
+
items={locations}
|
|
147
|
+
selectedItem={locations.find((loc) => loc.id === field.value)}
|
|
148
|
+
onChange={({ selectedItem }) => field.onChange(selectedItem?.id)}
|
|
149
|
+
invalid={!!errors.location}
|
|
150
|
+
invalidText={errors.location?.message}
|
|
151
|
+
/>
|
|
152
|
+
)}
|
|
153
|
+
/>
|
|
154
|
+
</ModalBody>
|
|
155
|
+
<ModalFooter>
|
|
156
|
+
<Button kind="secondary" onClick={closeModal}>
|
|
157
|
+
{getCoreTranslation('cancel')}
|
|
158
|
+
</Button>
|
|
159
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
160
|
+
{isSubmitting ? t('saving', 'Saving') + '...' : getCoreTranslation('save')}
|
|
161
|
+
</Button>
|
|
162
|
+
</ModalFooter>
|
|
163
|
+
</Form>
|
|
164
|
+
</>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export default AddCashPointModal;
|