@openmrs/esm-patient-chart-app 11.3.0 → 11.3.1-patch.9310

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 (231) hide show
  1. package/.turbo/turbo-build.log +27 -24
  2. package/dist/1119.js +1 -1
  3. package/dist/1197.js +1 -1
  4. package/dist/1815.js +2 -0
  5. package/dist/1815.js.map +1 -0
  6. package/dist/2146.js +1 -1
  7. package/dist/2690.js +1 -1
  8. package/dist/2761.js +1 -1
  9. package/dist/2761.js.map +1 -1
  10. package/dist/2859.js +1 -1
  11. package/dist/2859.js.map +1 -1
  12. package/dist/3099.js +1 -1
  13. package/dist/3584.js +1 -1
  14. package/dist/3697.js +1 -0
  15. package/dist/3697.js.map +1 -0
  16. package/dist/4055.js +1 -1
  17. package/dist/4132.js +1 -1
  18. package/dist/4300.js +1 -1
  19. package/dist/4335.js +1 -1
  20. package/dist/4618.js +1 -1
  21. package/dist/4632.js +1 -1
  22. package/dist/4632.js.map +1 -1
  23. package/dist/4652.js +1 -1
  24. package/dist/4718.js +1 -1
  25. package/dist/4754.js +1 -1
  26. package/dist/4944.js +1 -1
  27. package/dist/5173.js +1 -1
  28. package/dist/5205.js +1 -1
  29. package/dist/5241.js +1 -1
  30. package/dist/5442.js +1 -1
  31. package/dist/5661.js +1 -1
  32. package/dist/5670.js +1 -0
  33. package/dist/5670.js.map +1 -0
  34. package/dist/5827.js +1 -0
  35. package/dist/5827.js.map +1 -0
  36. package/dist/6022.js +1 -1
  37. package/dist/6336.js +1 -0
  38. package/dist/6336.js.map +1 -0
  39. package/dist/6411.js +1 -1
  40. package/dist/6411.js.map +1 -1
  41. package/dist/6468.js +1 -1
  42. package/dist/6529.js +1 -1
  43. package/dist/6568.js +1 -0
  44. package/dist/6568.js.map +1 -0
  45. package/dist/6679.js +1 -1
  46. package/dist/68.js +2 -0
  47. package/dist/68.js.map +1 -0
  48. package/dist/6840.js +1 -1
  49. package/dist/6859.js +1 -1
  50. package/dist/6924.js +1 -0
  51. package/dist/6924.js.map +1 -0
  52. package/dist/7097.js +1 -1
  53. package/dist/7159.js +1 -1
  54. package/dist/723.js +1 -1
  55. package/dist/7617.js +1 -1
  56. package/dist/7816.js +2 -0
  57. package/dist/7816.js.map +1 -0
  58. package/dist/7818.js +1 -0
  59. package/dist/7818.js.map +1 -0
  60. package/dist/7822.js +1 -0
  61. package/dist/7822.js.map +1 -0
  62. package/dist/795.js +1 -1
  63. package/dist/8163.js +1 -1
  64. package/dist/8260.js +1 -0
  65. package/dist/8260.js.map +1 -0
  66. package/dist/8278.js +1 -0
  67. package/dist/8278.js.map +1 -0
  68. package/dist/8349.js +1 -1
  69. package/dist/8454.js +1 -1
  70. package/dist/8454.js.map +1 -1
  71. package/dist/8618.js +1 -1
  72. package/dist/8709.js +1 -1
  73. package/dist/8709.js.map +1 -1
  74. package/dist/890.js +1 -1
  75. package/dist/9007.js +1 -1
  76. package/dist/9007.js.map +1 -1
  77. package/dist/9214.js +1 -1
  78. package/dist/{4727.js → 9294.js} +1 -1
  79. package/dist/9294.js.map +1 -0
  80. package/dist/9329.js +1 -0
  81. package/dist/9329.js.map +1 -0
  82. package/dist/9538.js +1 -1
  83. package/dist/9569.js +1 -1
  84. package/dist/986.js +1 -1
  85. package/dist/9879.js +1 -1
  86. package/dist/9895.js +1 -1
  87. package/dist/9900.js +1 -1
  88. package/dist/9913.js +1 -1
  89. package/dist/main.js +1 -1
  90. package/dist/main.js.map +1 -1
  91. package/dist/openmrs-esm-patient-chart-app.js +1 -1
  92. package/dist/openmrs-esm-patient-chart-app.js.buildmanifest.json +457 -453
  93. package/dist/openmrs-esm-patient-chart-app.js.map +1 -1
  94. package/dist/routes.json +1 -1
  95. package/package.json +5 -4
  96. package/src/actions-buttons/delete-visit.component.tsx +8 -3
  97. package/src/actions-buttons/mark-patient-deceased.component.tsx +2 -2
  98. package/src/actions-buttons/start-visit.component.tsx +10 -5
  99. package/src/actions-buttons/start-visit.test.tsx +9 -5
  100. package/src/actions-buttons/stop-visit.component.tsx +1 -1
  101. package/src/clinical-views/encounter-list/{encounter-list-tabs.component.tsx → encounter-list-tabs.extension.tsx} +10 -6
  102. package/src/clinical-views/encounter-list/tag.component.test.tsx +306 -0
  103. package/src/clinical-views/encounter-list/tag.component.tsx +27 -28
  104. package/src/clinical-views/encounter-tile/encounter-tile.component.tsx +7 -6
  105. package/src/clinical-views/encounter-tile/tile.scss +0 -1
  106. package/src/clinical-views/hooks/useEncountersByVisit.ts +13 -0
  107. package/src/clinical-views/hooks/useLastEncounter.ts +1 -1
  108. package/src/clinical-views/types.ts +2 -1
  109. package/src/clinical-views/utils/concept-utils.ts +24 -0
  110. package/src/clinical-views/utils/helpers.ts +2 -2
  111. package/src/clinical-views/utils/index.ts +4 -1
  112. package/src/config-schema.ts +42 -9
  113. package/src/dashboard.meta.ts +4 -2
  114. package/src/index.ts +21 -22
  115. package/src/mark-patient-deceased/mark-patient-deceased-form.test.tsx +22 -11
  116. package/src/mark-patient-deceased/mark-patient-deceased-form.workspace.tsx +147 -138
  117. package/src/patient-banner-tags/{visit-attribute-tags.component.tsx → visit-attribute-tags.extension.tsx} +9 -4
  118. package/src/patient-chart/chart-review/dashboard-view.component.tsx +2 -2
  119. package/src/patient-chart/patient-chart.component.tsx +19 -36
  120. package/src/patient-chart/patient-chart.resources.ts +150 -0
  121. package/src/routes.json +17 -6
  122. package/src/visit/hooks/useDeleteVisit.test.tsx +39 -42
  123. package/src/visit/hooks/useDeleteVisit.tsx +33 -17
  124. package/src/visit/start-visit-button.component.tsx +2 -2
  125. package/src/visit/start-visit-button.test.tsx +2 -2
  126. package/src/visit/visit-action-items/edit-visit-details.component.tsx +29 -8
  127. package/src/visit/visit-form/base-visit-type.component.tsx +2 -2
  128. package/src/visit/visit-form/exported-visit-form.workspace.tsx +697 -0
  129. package/src/visit/visit-form/visit-attribute-type.component.tsx +2 -1
  130. package/src/visit/visit-form/visit-form.resource.ts +2 -1
  131. package/src/visit/visit-form/visit-form.test.tsx +28 -25
  132. package/src/visit/visit-form/visit-form.workspace.tsx +63 -643
  133. package/src/visit/visit-history-table/visit-actions-cell.component.tsx +3 -2
  134. package/src/visit/visit-history-table/visit-date-cell.component.tsx +1 -0
  135. package/src/visit/visit-history-table/visit-diagnoses-cell.component.tsx +1 -0
  136. package/src/visit/visit-history-table/visit-history-table.component.tsx +3 -2
  137. package/src/visit/visit-history-table/visit-type-cell.component.tsx +1 -0
  138. package/src/visit/visit-prompt/{delete-visit-dialog.component.tsx → delete-visit-dialog.modal.tsx} +10 -4
  139. package/src/visit/visit-prompt/delete-visit-dialog.test.tsx +21 -3
  140. package/src/visit/visit-prompt/{end-visit-dialog.component.tsx → end-visit-dialog.modal.tsx} +7 -1
  141. package/src/visit/visit-prompt/end-visit-dialog.test.tsx +20 -1
  142. package/src/visit/visit-prompt/{start-visit-dialog.component.tsx → start-visit-dialog.modal.tsx} +10 -4
  143. package/src/visit/visit-prompt/start-visit-dialog.test.tsx +3 -3
  144. package/src/visit/visits-widget/active-visit-buttons/active-visit-buttons.tsx +7 -6
  145. package/src/visit/visits-widget/current-visit-summary.extension.tsx +48 -0
  146. package/src/visit/visits-widget/current-visit-summary.test.tsx +45 -25
  147. package/src/visit/visits-widget/past-visits-components/encounters-table/encounters-table.component.tsx +15 -37
  148. package/src/visit/visits-widget/past-visits-components/encounters-table/encounters-table.resource.ts +0 -1
  149. package/src/visit/visits-widget/past-visits-components/medications-summary.component.tsx +2 -3
  150. package/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx +8 -1
  151. package/src/visit/visits-widget/past-visits-components/visit-summary.scss +1 -1
  152. package/src/visit/visits-widget/single-visit-details/visit-timeline/visit-timeline.component.tsx +94 -0
  153. package/src/visit/visits-widget/single-visit-details/visit-timeline/visit-timeline.scss +60 -0
  154. package/src/visit/visits-widget/visit-context/retrospective-data-date-time-picker/retrospective-date-time-picker.component.tsx +6 -7
  155. package/src/visit/visits-widget/visit-context/{visit-context-header.component.tsx → visit-context-header.extension.tsx} +17 -15
  156. package/src/visit/visits-widget/visit-context/visit-context-header.test.tsx +35 -29
  157. package/src/visit/visits-widget/visit-context/visit-context-switcher.modal.tsx +15 -13
  158. package/src/visit/visits-widget/visit-context/visit-context-switcher.test.tsx +31 -9
  159. package/src/visit/visits-widget/visit-detail-overview.component.tsx +3 -2
  160. package/src/visit/visits-widget/visit-detail-overview.test.tsx +4 -4
  161. package/src/visit/visits-widget/visit.resource.tsx +1 -1
  162. package/translations/am.json +6 -0
  163. package/translations/ar.json +6 -0
  164. package/translations/ar_SY.json +6 -0
  165. package/translations/bn.json +6 -0
  166. package/translations/de.json +6 -0
  167. package/translations/en.json +7 -2
  168. package/translations/en_US.json +6 -0
  169. package/translations/es.json +6 -0
  170. package/translations/es_MX.json +6 -0
  171. package/translations/fr.json +15 -9
  172. package/translations/he.json +6 -0
  173. package/translations/hi.json +6 -0
  174. package/translations/hi_IN.json +6 -0
  175. package/translations/id.json +6 -0
  176. package/translations/it.json +24 -18
  177. package/translations/ka.json +6 -0
  178. package/translations/km.json +6 -0
  179. package/translations/ku.json +6 -0
  180. package/translations/ky.json +6 -0
  181. package/translations/lg.json +6 -0
  182. package/translations/ne.json +6 -0
  183. package/translations/pl.json +6 -0
  184. package/translations/pt.json +6 -0
  185. package/translations/pt_BR.json +6 -0
  186. package/translations/qu.json +6 -0
  187. package/translations/ro_RO.json +6 -0
  188. package/translations/ru_RU.json +6 -0
  189. package/translations/si.json +6 -0
  190. package/translations/sw.json +6 -0
  191. package/translations/sw_KE.json +6 -0
  192. package/translations/tr.json +6 -0
  193. package/translations/tr_TR.json +6 -0
  194. package/translations/uk.json +6 -0
  195. package/translations/uz.json +6 -0
  196. package/translations/uz@Latn.json +6 -0
  197. package/translations/uz_UZ.json +6 -0
  198. package/translations/vi.json +6 -0
  199. package/translations/zh.json +6 -0
  200. package/translations/zh_CN.json +6 -0
  201. package/dist/2537.js +0 -1
  202. package/dist/2537.js.map +0 -1
  203. package/dist/2735.js +0 -2
  204. package/dist/2735.js.map +0 -1
  205. package/dist/276.js +0 -1
  206. package/dist/276.js.map +0 -1
  207. package/dist/3042.js +0 -1
  208. package/dist/3042.js.map +0 -1
  209. package/dist/3119.js +0 -1
  210. package/dist/3119.js.map +0 -1
  211. package/dist/3184.js +0 -1
  212. package/dist/3184.js.map +0 -1
  213. package/dist/385.js +0 -2
  214. package/dist/385.js.map +0 -1
  215. package/dist/3905.js +0 -1
  216. package/dist/3905.js.map +0 -1
  217. package/dist/4713.js +0 -1
  218. package/dist/4713.js.map +0 -1
  219. package/dist/4727.js.map +0 -1
  220. package/dist/717.js +0 -1
  221. package/dist/717.js.map +0 -1
  222. package/dist/9162.js +0 -2
  223. package/dist/9162.js.map +0 -1
  224. package/dist/9206.js +0 -1
  225. package/dist/9206.js.map +0 -1
  226. package/dist/9615.js +0 -1
  227. package/dist/9615.js.map +0 -1
  228. package/src/visit/visits-widget/current-visit-summary.component.tsx +0 -55
  229. /package/dist/{9162.js.LICENSE.txt → 1815.js.LICENSE.txt} +0 -0
  230. /package/dist/{385.js.LICENSE.txt → 68.js.LICENSE.txt} +0 -0
  231. /package/dist/{2735.js.LICENSE.txt → 7816.js.LICENSE.txt} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { useSWRConfig } from 'swr';
2
2
  import { renderHook, act } from '@testing-library/react';
3
- import { showSnackbar, useVisit, type Visit, type VisitType } from '@openmrs/esm-framework';
4
- import { invalidateVisitAndEncounterData } from '@openmrs/esm-patient-common-lib';
3
+ import { showSnackbar, type Visit } from '@openmrs/esm-framework';
4
+ import { invalidateVisitAndEncounterData, usePatientChartStore } from '@openmrs/esm-patient-common-lib';
5
5
  import { useDeleteVisit } from './useDeleteVisit';
6
6
  import { deleteVisit, restoreVisit } from '../visits-widget/visit.resource';
7
7
 
@@ -20,17 +20,19 @@ jest.mock('../visits-widget/visit.resource', () => {
20
20
 
21
21
  jest.mock('@openmrs/esm-patient-common-lib', () => ({
22
22
  invalidateVisitAndEncounterData: jest.fn(),
23
+ usePatientChartStore: jest.fn(),
23
24
  }));
24
25
 
25
26
  const mockDeleteVisit = jest.mocked(deleteVisit);
26
27
  const mockRestoreVisit = jest.mocked(restoreVisit);
27
28
  const mockShowSnackbar = jest.mocked(showSnackbar);
28
29
  const mockUseSWRConfig = jest.mocked(useSWRConfig);
29
- const mockUseVisit = jest.mocked(useVisit);
30
+ const mockUsePatientChartStore = jest.mocked(usePatientChartStore);
30
31
  const mockInvalidateVisitAndEncounterData = jest.mocked(invalidateVisitAndEncounterData);
31
32
 
32
- const mockMutateCurrentVisit = jest.fn();
33
+ const mockMutateActiveVisit = jest.fn();
33
34
  const mockGlobalMutate = jest.fn();
35
+ const mockSetVisitContext = jest.fn();
34
36
 
35
37
  const mockVisitType = {
36
38
  uuid: 'visit-type-123',
@@ -54,16 +56,13 @@ const mockVisit = {
54
56
 
55
57
  describe('useDeleteVisit', () => {
56
58
  beforeEach(() => {
57
- jest.clearAllMocks();
58
-
59
- mockUseVisit.mockReturnValue({
60
- mutate: mockMutateCurrentVisit,
61
- currentVisit: null,
62
- activeVisit: null,
63
- currentVisitIsRetrospective: false,
64
- error: null,
65
- isLoading: false,
66
- isValidating: false,
59
+ mockUsePatientChartStore.mockReturnValue({
60
+ patientUuid: 'patient-123',
61
+ patient: null,
62
+ visitContext: null,
63
+ mutateVisitContext: jest.fn(),
64
+ setPatient: jest.fn(),
65
+ setVisitContext: mockSetVisitContext,
67
66
  });
68
67
 
69
68
  mockUseSWRConfig.mockReturnValue({
@@ -76,14 +75,14 @@ describe('useDeleteVisit', () => {
76
75
  mockDeleteVisit.mockResolvedValue({ data: {} } as any);
77
76
  const onVisitDelete = jest.fn();
78
77
 
79
- const { result } = renderHook(() => useDeleteVisit(mockVisit, onVisitDelete));
78
+ const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, onVisitDelete));
80
79
 
81
80
  await act(async () => {
82
81
  result.current.initiateDeletingVisit();
83
82
  });
84
83
 
85
84
  expect(mockDeleteVisit).toHaveBeenCalledWith('visit-123');
86
- expect(mockMutateCurrentVisit).toHaveBeenCalledTimes(1);
85
+ expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
87
86
  expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
88
87
 
89
88
  expect(mockShowSnackbar).toHaveBeenCalledWith(
@@ -103,13 +102,13 @@ describe('useDeleteVisit', () => {
103
102
  mockDeleteVisit.mockRejectedValue(new Error('Delete failed'));
104
103
  const onVisitDelete = jest.fn();
105
104
 
106
- const { result } = renderHook(() => useDeleteVisit(mockVisit, onVisitDelete));
105
+ const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, onVisitDelete));
107
106
 
108
107
  await act(async () => {
109
108
  result.current.initiateDeletingVisit();
110
109
  });
111
110
 
112
- expect(mockMutateCurrentVisit).toHaveBeenCalledTimes(1);
111
+ expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
113
112
  expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
114
113
 
115
114
  expect(mockShowSnackbar).toHaveBeenCalledWith({
@@ -125,7 +124,7 @@ describe('useDeleteVisit', () => {
125
124
  mockRestoreVisit.mockResolvedValue({ data: {} } as any);
126
125
  const onVisitRestore = jest.fn();
127
126
 
128
- const { result } = renderHook(() => useDeleteVisit(mockVisit, undefined, onVisitRestore));
127
+ const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, undefined, onVisitRestore));
129
128
 
130
129
  // First delete to get the restore function
131
130
  mockDeleteVisit.mockResolvedValue({ data: {} } as any);
@@ -138,14 +137,13 @@ describe('useDeleteVisit', () => {
138
137
 
139
138
  // Clear mocks to test restore independently
140
139
  jest.clearAllMocks();
141
- mockUseVisit.mockReturnValue({
142
- mutate: mockMutateCurrentVisit,
143
- currentVisit: null,
144
- activeVisit: null,
145
- currentVisitIsRetrospective: false,
146
- error: null,
147
- isLoading: false,
148
- isValidating: false,
140
+ mockUsePatientChartStore.mockReturnValue({
141
+ patientUuid: 'patient-123',
142
+ patient: null,
143
+ visitContext: null,
144
+ mutateVisitContext: jest.fn(),
145
+ setPatient: jest.fn(),
146
+ setVisitContext: mockSetVisitContext,
149
147
  });
150
148
  mockUseSWRConfig.mockReturnValue({
151
149
  mutate: mockGlobalMutate,
@@ -158,7 +156,7 @@ describe('useDeleteVisit', () => {
158
156
  });
159
157
 
160
158
  expect(mockRestoreVisit).toHaveBeenCalledWith('visit-123');
161
- expect(mockMutateCurrentVisit).toHaveBeenCalledTimes(1);
159
+ expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
162
160
  expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
163
161
 
164
162
  expect(mockShowSnackbar).toHaveBeenCalledWith({
@@ -174,7 +172,7 @@ describe('useDeleteVisit', () => {
174
172
  mockRestoreVisit.mockRejectedValue(new Error('Restore failed'));
175
173
  const onVisitRestore = jest.fn();
176
174
 
177
- const { result } = renderHook(() => useDeleteVisit(mockVisit, undefined, onVisitRestore));
175
+ const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, undefined, onVisitRestore));
178
176
 
179
177
  // First delete to get the restore function
180
178
  mockDeleteVisit.mockResolvedValue({ data: {} } as any);
@@ -186,14 +184,13 @@ describe('useDeleteVisit', () => {
186
184
 
187
185
  // Clear mocks to test restore independently
188
186
  jest.clearAllMocks();
189
- mockUseVisit.mockReturnValue({
190
- mutate: mockMutateCurrentVisit,
191
- currentVisit: null,
192
- activeVisit: null,
193
- currentVisitIsRetrospective: false,
194
- error: null,
195
- isLoading: false,
196
- isValidating: false,
187
+ mockUsePatientChartStore.mockReturnValue({
188
+ patientUuid: 'patient-123',
189
+ patient: null,
190
+ visitContext: null,
191
+ mutateVisitContext: jest.fn(),
192
+ setPatient: jest.fn(),
193
+ setVisitContext: mockSetVisitContext,
197
194
  });
198
195
  mockUseSWRConfig.mockReturnValue({
199
196
  mutate: mockGlobalMutate,
@@ -205,7 +202,7 @@ describe('useDeleteVisit', () => {
205
202
  restoreFunction();
206
203
  });
207
204
 
208
- expect(mockMutateCurrentVisit).toHaveBeenCalledTimes(1);
205
+ expect(mockMutateActiveVisit).toHaveBeenCalledTimes(1);
209
206
  expect(mockInvalidateVisitAndEncounterData).toHaveBeenCalledWith(mockGlobalMutate, 'patient-123');
210
207
 
211
208
  expect(mockShowSnackbar).toHaveBeenCalledWith({
@@ -220,7 +217,7 @@ describe('useDeleteVisit', () => {
220
217
  it('should manage loading state correctly', async () => {
221
218
  mockDeleteVisit.mockResolvedValue({ data: {} } as any);
222
219
 
223
- const { result } = renderHook(() => useDeleteVisit(mockVisit));
220
+ const { result } = renderHook(() => useDeleteVisit(mockVisit, mockMutateActiveVisit, () => {}));
224
221
 
225
222
  // Initially not deleting
226
223
  expect(result.current.isDeletingVisit).toBe(false);
@@ -238,7 +235,7 @@ describe('useDeleteVisit', () => {
238
235
  const visitWithoutPatient = { ...mockVisit, patient: null };
239
236
 
240
237
  expect(() => {
241
- renderHook(() => useDeleteVisit(visitWithoutPatient));
238
+ renderHook(() => useDeleteVisit(visitWithoutPatient, mockMutateActiveVisit, () => {}));
242
239
  }).not.toThrow();
243
240
  });
244
241
 
@@ -246,7 +243,7 @@ describe('useDeleteVisit', () => {
246
243
  const visitWithEmptyPatient = { ...mockVisit, patient: { uuid: '' } };
247
244
 
248
245
  expect(() => {
249
- renderHook(() => useDeleteVisit(visitWithEmptyPatient));
246
+ renderHook(() => useDeleteVisit(visitWithEmptyPatient, mockMutateActiveVisit, () => {}));
250
247
  }).not.toThrow();
251
248
  });
252
249
 
@@ -257,7 +254,7 @@ describe('useDeleteVisit', () => {
257
254
  };
258
255
 
259
256
  mockDeleteVisit.mockResolvedValue({ data: {} } as any);
260
- const { result } = renderHook(() => useDeleteVisit(visitWithoutDisplay));
257
+ const { result } = renderHook(() => useDeleteVisit(visitWithoutDisplay, mockMutateActiveVisit, () => {}));
261
258
 
262
259
  await act(async () => {
263
260
  result.current.initiateDeletingVisit();
@@ -1,22 +1,35 @@
1
1
  import { useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { useSWRConfig } from 'swr';
4
- import { type Visit, showSnackbar, useVisit } from '@openmrs/esm-framework';
5
- import { invalidateVisitAndEncounterData } from '@openmrs/esm-patient-common-lib';
4
+ import { type Visit, showSnackbar } from '@openmrs/esm-framework';
5
+ import {
6
+ invalidateVisitAndEncounterData,
7
+ invalidateVisitByUuid,
8
+ usePatientChartStore,
9
+ } from '@openmrs/esm-patient-common-lib';
6
10
  import { deleteVisit, restoreVisit } from '../visits-widget/visit.resource';
7
11
 
8
- export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRestore = () => {}) {
12
+ export function useDeleteVisit(
13
+ activeVisit: Visit,
14
+ mutateActiveVisit: () => void,
15
+ onVisitDelete = () => {},
16
+ onVisitRestore = () => {},
17
+ ) {
9
18
  const { t } = useTranslation();
10
19
  const { mutate: globalMutate } = useSWRConfig();
11
- const { mutate: mutateCurrentVisit } = useVisit(visit?.patient?.uuid || '');
12
20
  const [isDeletingVisit, setIsDeletingVisit] = useState(false);
13
- const patientUuid = visit?.patient?.uuid || '';
21
+ const patientUuid = activeVisit?.patient?.uuid || '';
22
+ const { visitContext, setVisitContext } = usePatientChartStore(patientUuid);
14
23
 
15
24
  const restoreDeletedVisit = () => {
16
- restoreVisit(visit?.uuid)
17
- .then(() => {
25
+ restoreVisit(activeVisit?.uuid)
26
+ .then(({ data: updatedVisit }) => {
18
27
  // Update current visit data for critical components (useVisit hook)
19
- mutateCurrentVisit();
28
+ mutateActiveVisit();
29
+ if (!updatedVisit.stopDatetime) {
30
+ const mutateSavedOrUpdatedVisit = () => invalidateVisitByUuid(globalMutate, updatedVisit.uuid);
31
+ setVisitContext(updatedVisit, mutateSavedOrUpdatedVisit);
32
+ }
20
33
 
21
34
  // Use targeted SWR invalidation instead of global mutateVisit
22
35
  invalidateVisitAndEncounterData(globalMutate, patientUuid);
@@ -24,7 +37,7 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
24
37
  showSnackbar({
25
38
  title: t('visitRestored', 'Visit restored'),
26
39
  subtitle: t('visitRestoredSuccessfully', '{{visit}} restored successfully', {
27
- visit: visit?.visitType?.display ?? t('visit', 'Visit'),
40
+ visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
28
41
  }),
29
42
  kind: 'success',
30
43
  });
@@ -32,12 +45,12 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
32
45
  })
33
46
  .catch(() => {
34
47
  // On error, revalidate to get correct state
35
- mutateCurrentVisit();
48
+ mutateActiveVisit();
36
49
  invalidateVisitAndEncounterData(globalMutate, patientUuid);
37
50
  showSnackbar({
38
51
  title: t('visitNotRestored', "Visit couldn't be restored"),
39
52
  subtitle: t('errorWhenRestoringVisit', 'Error occurred when restoring {{visit}}', {
40
- visit: visit?.visitType?.display ?? t('visit', 'Visit'),
53
+ visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
41
54
  }),
42
55
  kind: 'error',
43
56
  });
@@ -47,20 +60,23 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
47
60
  const initiateDeletingVisit = () => {
48
61
  setIsDeletingVisit(true);
49
62
 
50
- deleteVisit(visit?.uuid)
63
+ deleteVisit(activeVisit?.uuid)
51
64
  .then(() => {
52
- // Update current visit data for critical components (useVisit hook)
53
- mutateCurrentVisit();
65
+ // Update active visit data
66
+ mutateActiveVisit();
67
+ if (activeVisit.uuid == visitContext?.uuid) {
68
+ setVisitContext(null, null);
69
+ }
54
70
 
55
71
  // Use targeted SWR invalidation instead of global mutateVisit
56
72
  invalidateVisitAndEncounterData(globalMutate, patientUuid);
57
73
 
58
74
  showSnackbar({
59
75
  title: t('visitDeleted', '{{visit}} deleted', {
60
- visit: visit?.visitType?.display ?? t('visit', 'Visit'),
76
+ visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
61
77
  }),
62
78
  subtitle: t('visitDeletedSuccessfully', '{{visit}} deleted successfully', {
63
- visit: visit?.visitType?.display ?? t('visit', 'Visit'),
79
+ visit: activeVisit?.visitType?.display ?? t('visit', 'Visit'),
64
80
  }),
65
81
  kind: 'success',
66
82
  actionButtonLabel: t('undo', 'Undo'),
@@ -70,7 +86,7 @@ export function useDeleteVisit(visit: Visit, onVisitDelete = () => {}, onVisitRe
70
86
  })
71
87
  .catch(() => {
72
88
  // On error, revalidate to get correct state
73
- mutateCurrentVisit();
89
+ mutateActiveVisit();
74
90
  invalidateVisitAndEncounterData(globalMutate, patientUuid);
75
91
 
76
92
  showSnackbar({
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { Button } from '@carbon/react';
4
- import { launchWorkspace, showSnackbar } from '@openmrs/esm-framework';
4
+ import { launchWorkspace2, showSnackbar } from '@openmrs/esm-framework';
5
5
 
6
6
  interface StartVisitButtonProps {
7
7
  patientUuid: string;
@@ -20,7 +20,7 @@ const StartVisitButton = ({ patientUuid, handleReturnToSearchList, hidePatientSe
20
20
  hidePatientSearch?.();
21
21
 
22
22
  try {
23
- launchWorkspace(startVisitWorkspaceForm, {
23
+ launchWorkspace2(startVisitWorkspaceForm, {
24
24
  patientUuid,
25
25
  openedFrom: 'patient-chart-start-visit',
26
26
  handleReturnToSearchList,
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import { render, screen } from '@testing-library/react';
4
- import { launchWorkspace } from '@openmrs/esm-framework';
4
+ import { launchWorkspace2 } from '@openmrs/esm-framework';
5
5
  import { mockPatient } from 'tools';
6
6
  import StartVisitButton from './start-visit-button.component';
7
7
 
8
- const mockLaunchWorkspace = jest.mocked(launchWorkspace);
8
+ const mockLaunchWorkspace = jest.mocked(launchWorkspace2);
9
9
 
10
10
  describe('StartVisitButton', () => {
11
11
  it('renders the start visit button', () => {
@@ -6,13 +6,20 @@ import {
6
6
  UserHasAccess,
7
7
  type Visit,
8
8
  getCoreTranslation,
9
- launchWorkspace,
9
+ launchWorkspace2,
10
10
  useLayoutType,
11
11
  } from '@openmrs/esm-framework';
12
+ import { type VisitFormProps } from '../visit-form/visit-form.workspace';
13
+ import {
14
+ invalidateVisitAndEncounterData,
15
+ invalidateVisitByUuid,
16
+ type PatientWorkspaceGroupProps,
17
+ } from '@openmrs/esm-patient-common-lib';
18
+ import { useSWRConfig } from 'swr';
12
19
 
13
20
  interface EditVisitDetailsActionItemProps {
14
- patientUuid: string;
15
21
  visit: Visit;
22
+ patient: fhir.Patient;
16
23
 
17
24
  /**
18
25
  * If true, renders as IconButton instead
@@ -20,18 +27,32 @@ interface EditVisitDetailsActionItemProps {
20
27
  compact?: boolean;
21
28
  }
22
29
 
23
- const EditVisitDetailsActionItem: React.FC<EditVisitDetailsActionItemProps> = ({ visit, compact }) => {
30
+ /**
31
+ * This component
32
+ */
33
+ const EditVisitDetailsActionItem: React.FC<EditVisitDetailsActionItemProps> = ({ visit, patient, compact }) => {
24
34
  const { t } = useTranslation();
35
+ const { mutate: globalMutate } = useSWRConfig();
25
36
 
26
37
  const isTablet = useLayoutType() === 'tablet';
27
38
  const responsiveSize = isTablet ? 'lg' : 'sm';
39
+ const patientUuid = patient.id;
28
40
 
29
41
  const editVisitDetails = () => {
30
- launchWorkspace('start-visit-workspace-form', {
31
- workspaceTitle: t('editVisitDetails', 'Edit visit details'),
32
- visitToEdit: visit,
33
- openedFrom: 'patient-chart-edit-visit',
34
- });
42
+ launchWorkspace2<VisitFormProps, {}, PatientWorkspaceGroupProps>(
43
+ 'start-visit-workspace-form',
44
+ { openedFrom: 'patient-chart-edit-visit' },
45
+ {},
46
+ {
47
+ patient,
48
+ patientUuid: patientUuid,
49
+ visitContext: visit,
50
+ mutateVisitContext: () => {
51
+ invalidateVisitByUuid(globalMutate, visit.uuid);
52
+ invalidateVisitAndEncounterData(globalMutate, patientUuid);
53
+ },
54
+ },
55
+ );
35
56
  };
36
57
 
37
58
  return (
@@ -41,14 +41,14 @@ const BaseVisitType: React.FC<BaseVisitTypeProps> = ({ visitTypes }) => {
41
41
  {isTablet ? (
42
42
  <Layer>
43
43
  <Search
44
- labelText=""
44
+ labelText={t('searchForAVisitType', 'Search for a visit type')}
45
45
  onChange={handleSearchTermChange}
46
46
  placeholder={t('searchForAVisitType', 'Search for a visit type')}
47
47
  />
48
48
  </Layer>
49
49
  ) : (
50
50
  <Search
51
- labelText=""
51
+ labelText={t('searchForAVisitType', 'Search for a visit type')}
52
52
  onChange={handleSearchTermChange}
53
53
  placeholder={t('searchForAVisitType', 'Search for a visit type')}
54
54
  />