@openmrs/esm-billing-app 1.1.1 → 1.1.2-pre.1

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 (193) hide show
  1. package/.turbo/cache/53e233a916ffe7d2-meta.json +1 -0
  2. package/.turbo/cache/53e233a916ffe7d2.tar.zst +0 -0
  3. package/.turbo/turbo-build.log +44 -0
  4. package/__mocks__/bills.mock.ts +6 -5
  5. package/dist/1119.js +1 -1
  6. package/dist/1197.js +1 -1
  7. package/dist/1435.js +1 -0
  8. package/dist/1435.js.map +1 -0
  9. package/dist/1807.js +1 -0
  10. package/dist/1807.js.map +1 -0
  11. package/dist/2146.js +1 -1
  12. package/dist/2177.js +1 -1
  13. package/dist/2177.js.map +1 -1
  14. package/dist/2690.js +1 -1
  15. package/dist/2704.js +1 -0
  16. package/dist/2704.js.map +1 -0
  17. package/dist/3002.js +1 -0
  18. package/dist/3002.js.map +1 -0
  19. package/dist/3041.js +1 -1
  20. package/dist/3041.js.map +1 -1
  21. package/dist/3099.js +1 -1
  22. package/dist/3184.js +1 -1
  23. package/dist/3184.js.map +1 -1
  24. package/dist/3584.js +1 -1
  25. package/dist/4055.js +1 -1
  26. package/dist/4132.js +1 -1
  27. package/dist/4225.js +1 -1
  28. package/dist/4225.js.map +1 -1
  29. package/dist/4300.js +1 -1
  30. package/dist/4335.js +1 -1
  31. package/dist/439.js +1 -1
  32. package/dist/4618.js +1 -1
  33. package/dist/4652.js +1 -1
  34. package/dist/4944.js +1 -1
  35. package/dist/5173.js +1 -1
  36. package/dist/5241.js +1 -1
  37. package/dist/5422.js +1 -1
  38. package/dist/5422.js.map +1 -1
  39. package/dist/5442.js +1 -1
  40. package/dist/5661.js +1 -1
  41. package/dist/6022.js +1 -1
  42. package/dist/6404.js +1 -0
  43. package/dist/6404.js.map +1 -0
  44. package/dist/6468.js +1 -1
  45. package/dist/6540.js +1 -1
  46. package/dist/6540.js.map +1 -1
  47. package/dist/6589.js +1 -1
  48. package/dist/6606.js +1 -1
  49. package/dist/6606.js.map +1 -1
  50. package/dist/6679.js +1 -1
  51. package/dist/6792.js +1 -0
  52. package/dist/6792.js.map +1 -0
  53. package/dist/6840.js +1 -1
  54. package/dist/6859.js +1 -1
  55. package/dist/7097.js +1 -1
  56. package/dist/7159.js +1 -1
  57. package/dist/723.js +1 -1
  58. package/dist/7255.js +1 -1
  59. package/dist/7255.js.map +1 -1
  60. package/dist/7617.js +1 -1
  61. package/dist/795.js +1 -1
  62. package/dist/8163.js +1 -1
  63. package/dist/8341.js +2 -0
  64. package/dist/{1907.js.LICENSE.txt → 8341.js.LICENSE.txt} +0 -15
  65. package/dist/8341.js.map +1 -0
  66. package/dist/8349.js +1 -1
  67. package/dist/8371.js +1 -1
  68. package/dist/8421.js +1 -0
  69. package/dist/8421.js.map +1 -0
  70. package/dist/8618.js +1 -1
  71. package/dist/890.js +1 -1
  72. package/dist/9214.js +1 -1
  73. package/dist/9538.js +1 -1
  74. package/dist/9569.js +1 -1
  75. package/dist/961.js +1 -1
  76. package/dist/961.js.map +1 -1
  77. package/dist/986.js +1 -1
  78. package/dist/9879.js +1 -1
  79. package/dist/9895.js +1 -1
  80. package/dist/9900.js +1 -1
  81. package/dist/9913.js +1 -1
  82. package/dist/main.js +1 -1
  83. package/dist/main.js.LICENSE.txt +0 -15
  84. package/dist/main.js.map +1 -1
  85. package/dist/openmrs-esm-billing-app.js +1 -1
  86. package/dist/openmrs-esm-billing-app.js.buildmanifest.json +284 -259
  87. package/dist/openmrs-esm-billing-app.js.map +1 -1
  88. package/dist/routes.json +1 -1
  89. package/e2e/commands/patient-operations.ts +1 -1
  90. package/e2e/pages/billing-dashboard-page.ts +3 -1
  91. package/e2e/pages/billing-form-page.ts +5 -0
  92. package/e2e/pages/invoice-page.ts +10 -0
  93. package/e2e/specs/billing-dashboard.spec.ts +126 -3
  94. package/e2e/specs/billing-patient-chart.spec.ts +95 -9
  95. package/package.json +3 -6
  96. package/src/bill-history/bill-action-menu.component.tsx +41 -0
  97. package/src/bill-history/bill-action-menu.scss +3 -0
  98. package/src/bill-history/bill-history.component.tsx +15 -5
  99. package/src/bill-history/bill-history.scss +0 -1
  100. package/src/bill-history/bill-history.test.tsx +78 -1
  101. package/src/bill-item-actions/edit-bill-item.modal.tsx +1 -1
  102. package/src/bill-item-actions/edit-bill-item.test.tsx +40 -0
  103. package/src/billable-services/bill-waiver/bill-waiver.component.tsx +3 -1
  104. package/src/billing-dashboard/billing-dashboard.component.tsx +3 -16
  105. package/src/billing-form/billing-checkin-form.component.tsx +116 -57
  106. package/src/billing-form/billing-checkin-form.scss +26 -2
  107. package/src/billing-form/billing-checkin-form.test.tsx +51 -1
  108. package/src/billing-form/billing-form.resource.test.ts +87 -0
  109. package/src/billing-form/billing-form.resource.ts +33 -0
  110. package/src/billing-form/billing-form.scss +54 -7
  111. package/src/billing-form/billing-form.test.tsx +547 -0
  112. package/src/billing-form/billing-form.workspace.tsx +150 -45
  113. package/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +25 -2
  114. package/src/billing-form/visit-attributes/visit-attributes-form.scss +29 -0
  115. package/src/billing-header/billing-header.component.tsx +1 -34
  116. package/src/billing-header/billing-header.scss +0 -50
  117. package/src/billing.resource.test.ts +11 -11
  118. package/src/billing.resource.ts +42 -12
  119. package/src/bills-table/bills-table.component.tsx +16 -12
  120. package/src/bills-table/bills-table.test.tsx +84 -7
  121. package/src/index.ts +5 -0
  122. package/src/invoice/invoice.component.tsx +46 -16
  123. package/src/invoice/invoice.scss +9 -8
  124. package/src/invoice/invoice.test.tsx +128 -7
  125. package/src/invoice/line-item-action-menu.component.tsx +2 -2
  126. package/src/invoice/payments/payments.component.tsx +2 -2
  127. package/src/invoice/payments/payments.test.tsx +31 -2
  128. package/src/metrics-cards/metrics.resource.ts +3 -4
  129. package/src/modal/finalize-bill-confirmation.modal.test.tsx +209 -0
  130. package/src/modal/finalize-bill-confirmation.modal.tsx +86 -0
  131. package/src/modal/require-payment.modal.tsx +2 -1
  132. package/src/routes.json +4 -0
  133. package/src/types/index.ts +10 -1
  134. package/tools/setup-tests.ts +7 -6
  135. package/translations/am.json +28 -0
  136. package/translations/ar.json +28 -0
  137. package/translations/ar_SY.json +28 -0
  138. package/translations/bn.json +28 -0
  139. package/translations/cs.json +28 -0
  140. package/translations/de.json +266 -238
  141. package/translations/en.json +29 -0
  142. package/translations/en_US.json +28 -0
  143. package/translations/es.json +28 -0
  144. package/translations/es_MX.json +28 -0
  145. package/translations/fr.json +28 -0
  146. package/translations/he.json +28 -0
  147. package/translations/hi.json +28 -0
  148. package/translations/hi_IN.json +28 -0
  149. package/translations/id.json +28 -0
  150. package/translations/it.json +28 -0
  151. package/translations/ka.json +28 -0
  152. package/translations/km.json +28 -0
  153. package/translations/ku.json +28 -0
  154. package/translations/ky.json +28 -0
  155. package/translations/lg.json +28 -0
  156. package/translations/ne.json +28 -0
  157. package/translations/pl.json +28 -0
  158. package/translations/pt.json +28 -0
  159. package/translations/pt_BR.json +28 -0
  160. package/translations/qu.json +28 -0
  161. package/translations/ro_RO.json +28 -0
  162. package/translations/ru_RU.json +28 -0
  163. package/translations/si.json +28 -0
  164. package/translations/sq.json +28 -0
  165. package/translations/sw.json +28 -0
  166. package/translations/sw_KE.json +28 -0
  167. package/translations/tr.json +28 -0
  168. package/translations/tr_TR.json +28 -0
  169. package/translations/uk.json +28 -0
  170. package/translations/uz.json +28 -0
  171. package/translations/uz@Latn.json +28 -0
  172. package/translations/uz_UZ.json +28 -0
  173. package/translations/vi.json +28 -0
  174. package/translations/zh.json +268 -240
  175. package/translations/zh_CN.json +30 -2
  176. package/translations/zh_TW.json +28 -0
  177. package/turbo.json +29 -0
  178. package/dist/1537.js +0 -1
  179. package/dist/1537.js.map +0 -1
  180. package/dist/1907.js +0 -2
  181. package/dist/1907.js.map +0 -1
  182. package/dist/1981.js +0 -1
  183. package/dist/1981.js.map +0 -1
  184. package/dist/2820.js +0 -1
  185. package/dist/2820.js.map +0 -1
  186. package/dist/8025.js +0 -1
  187. package/dist/8025.js.map +0 -1
  188. package/dist/9727.js +0 -2
  189. package/dist/9727.js.LICENSE.txt +0 -14
  190. package/dist/9727.js.map +0 -1
  191. package/dist/9756.js +0 -1
  192. package/dist/9756.js.map +0 -1
  193. package/src/hooks/selectedDateContext.ts +0 -10
@@ -0,0 +1,87 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import useSWR from 'swr';
3
+ import { useLastVisitInfo } from './billing-form.resource';
4
+
5
+ jest.mock('swr');
6
+ const mockUseSWR = jest.mocked(useSWR);
7
+
8
+ // Pin "now" so diffDays calculations are deterministic
9
+ const FIXED_NOW = new Date('2026-01-10T12:00:00Z').getTime();
10
+
11
+ describe('useLastVisitInfo', () => {
12
+ beforeAll(() => {
13
+ jest.useFakeTimers();
14
+ jest.setSystemTime(FIXED_NOW);
15
+ });
16
+
17
+ afterAll(() => {
18
+ jest.useRealTimers();
19
+ });
20
+
21
+ it('returns null lastVisitInfo when there is no visit data yet', () => {
22
+ mockUseSWR.mockReturnValue({ data: undefined, isLoading: false, error: undefined } as any);
23
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
24
+ expect(result.current.lastVisitInfo).toBeNull();
25
+ });
26
+
27
+ it('returns null lastVisitInfo when the visits list is empty', () => {
28
+ mockUseSWR.mockReturnValue({ data: { data: { results: [] } }, isLoading: false, error: undefined } as any);
29
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
30
+ expect(result.current.lastVisitInfo).toBeNull();
31
+ });
32
+
33
+ it('forwards isLoading and error from SWR', () => {
34
+ const error = new Error('Network error');
35
+ mockUseSWR.mockReturnValue({ data: undefined, isLoading: true, error } as any);
36
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
37
+ expect(result.current.isLoading).toBe(true);
38
+ expect(result.current.error).toBe(error);
39
+ });
40
+
41
+ it('returns correct visit info for a visit 2 days ago', () => {
42
+ const twoDaysAgo = new Date(FIXED_NOW - 2 * 24 * 60 * 60 * 1000).toISOString();
43
+ mockUseSWR.mockReturnValue({
44
+ data: {
45
+ data: {
46
+ results: [
47
+ {
48
+ startDatetime: twoDaysAgo,
49
+ visitType: { display: 'Outpatient' },
50
+ location: { display: 'Main Clinic' },
51
+ },
52
+ ],
53
+ },
54
+ },
55
+ isLoading: false,
56
+ error: undefined,
57
+ } as any);
58
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
59
+ expect(result.current.lastVisitInfo).toEqual({ diffDays: 2, type: 'Outpatient', location: 'Main Clinic' });
60
+ });
61
+
62
+ it('returns diffDays of 1 for a visit exactly 1 day ago', () => {
63
+ const oneDayAgo = new Date(FIXED_NOW - 1 * 24 * 60 * 60 * 1000).toISOString();
64
+ mockUseSWR.mockReturnValue({
65
+ data: {
66
+ data: {
67
+ results: [{ startDatetime: oneDayAgo, visitType: { display: 'Inpatient' }, location: { display: 'Ward A' } }],
68
+ },
69
+ },
70
+ isLoading: false,
71
+ error: undefined,
72
+ } as any);
73
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
74
+ expect(result.current.lastVisitInfo?.diffDays).toBe(1);
75
+ });
76
+
77
+ it('falls back to empty strings when visitType and location are absent', () => {
78
+ const oneDayAgo = new Date(FIXED_NOW - 1 * 24 * 60 * 60 * 1000).toISOString();
79
+ mockUseSWR.mockReturnValue({
80
+ data: { data: { results: [{ startDatetime: oneDayAgo, visitType: null, location: null }] } },
81
+ isLoading: false,
82
+ error: undefined,
83
+ } as any);
84
+ const { result } = renderHook(() => useLastVisitInfo('patient-uuid'));
85
+ expect(result.current.lastVisitInfo).toEqual({ diffDays: 1, type: '', location: '' });
86
+ });
87
+ });
@@ -1,7 +1,40 @@
1
+ import { useMemo } from 'react';
1
2
  import useSWR from 'swr';
2
3
  import { type OpenmrsResource, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
3
4
  import { apiBasePath } from '../constants';
4
5
 
6
+ type LastVisitInfo = {
7
+ diffDays: number;
8
+ type: string;
9
+ location: string;
10
+ };
11
+
12
+ export const useLastVisitInfo = (
13
+ patientUuid: string,
14
+ ): { lastVisitInfo: LastVisitInfo | null; isLoading: boolean; error: any } => {
15
+ const url = `${restBaseUrl}/visit?patient=${patientUuid}&v=default&limit=1&sort=desc:startDatetime`;
16
+ const { data, isLoading, error } = useSWR<{ data: { results: Array<any> } }>(patientUuid ? url : null, openmrsFetch);
17
+
18
+ const lastVisitInfo = useMemo((): LastVisitInfo | null => {
19
+ const results = data?.data?.results;
20
+ if (!results?.length) return null;
21
+
22
+ const visit = results[0];
23
+ const visitDate = new Date(visit.startDatetime);
24
+ if (isNaN(visitDate.getTime())) return null;
25
+ const diffTime = Math.abs(Date.now() - visitDate.getTime());
26
+ const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
27
+
28
+ return {
29
+ diffDays,
30
+ type: visit.visitType?.display ?? '',
31
+ location: visit.location?.display ?? '',
32
+ };
33
+ }, [data]);
34
+
35
+ return { lastVisitInfo, isLoading, error };
36
+ };
37
+
5
38
  export const useBillableItems = () => {
6
39
  const url = `${apiBasePath}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`;
7
40
  const { data, isLoading, error } = useSWR<{ data: { results: Array<OpenmrsResource> } }>(url, openmrsFetch);
@@ -1,4 +1,5 @@
1
1
  @use '@carbon/layout';
2
+ @use '@carbon/type';
2
3
  @use '@openmrs/esm-styleguide/src/vars' as *;
3
4
 
4
5
  .tablet {
@@ -89,15 +90,61 @@
89
90
  margin-top: layout.$spacing-05;
90
91
  }
91
92
 
92
- .selectedItemsContainer {
93
- margin-top: layout.$spacing-05;
94
-
95
- h4 {
96
- margin-bottom: layout.$spacing-05;
93
+ .existingItemsContainer {
94
+ padding: layout.$spacing-05;
95
+ background-color: $ui-01;
96
+ border: 1px solid $ui-03;
97
+ border-radius: layout.$spacing-02;
98
+
99
+ .existingItemRow {
100
+ display: flex;
101
+ justify-content: space-between;
102
+ align-items: center;
103
+ padding: layout.$spacing-03 0;
104
+ border-bottom: 1px solid $ui-03;
105
+
106
+ &:last-of-type {
107
+ border-bottom: none;
108
+ }
109
+
110
+ .existingItemName {
111
+ @include type.type-style('body-compact-01');
112
+ flex: 1;
113
+ color: $text-02;
114
+ }
115
+
116
+ .existingItemDetail {
117
+ @include type.type-style('body-compact-01');
118
+ flex: 0 0 auto;
119
+ color: $text-02;
120
+ margin: 0 layout.$spacing-05;
121
+ }
122
+
123
+ .existingItemTotal {
124
+ @include type.type-style('heading-compact-01');
125
+ flex: 0 0 auto;
126
+ color: $text-02;
127
+ }
128
+ }
129
+
130
+ .existingItemsSubtotal {
131
+ @include type.type-style('body-compact-01');
132
+ text-align: right;
133
+ padding-top: layout.$spacing-04;
134
+ border-top: 1px solid $ui-03;
135
+ margin-top: layout.$spacing-03;
97
136
  color: $text-02;
98
- font-size: 1rem;
99
- font-weight: 600;
100
137
  }
138
+ }
139
+
140
+ .sectionHeading {
141
+ @include type.type-style('heading-compact-02');
142
+ margin-bottom: layout.$spacing-04;
143
+ color: $text-02;
144
+ }
145
+
146
+ .selectedItemsContainer {
147
+ margin-top: layout.$spacing-05;
101
148
 
102
149
  .itemCard {
103
150
  border: 1px solid $ui-03;