@kenyaemr/esm-ward-app 8.0.1-pre.95 → 8.0.2

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 (196) hide show
  1. package/.turbo/turbo-build.log +20 -24
  2. package/dist/109.js +1 -0
  3. package/dist/109.js.map +1 -0
  4. package/dist/124.js +1 -0
  5. package/dist/124.js.map +1 -0
  6. package/dist/125.js +1 -0
  7. package/dist/125.js.map +1 -0
  8. package/dist/130.js +1 -1
  9. package/dist/130.js.LICENSE.txt +2 -0
  10. package/dist/130.js.map +1 -1
  11. package/dist/146.js +1 -0
  12. package/dist/146.js.map +1 -0
  13. package/dist/15.js +1 -0
  14. package/dist/15.js.map +1 -0
  15. package/dist/153.js +1 -0
  16. package/dist/153.js.map +1 -0
  17. package/dist/303.js +2 -1
  18. package/dist/303.js.map +1 -1
  19. package/dist/325.js +1 -0
  20. package/dist/325.js.map +1 -0
  21. package/dist/372.js +2 -0
  22. package/dist/372.js.map +1 -0
  23. package/dist/471.js +1 -0
  24. package/dist/471.js.map +1 -0
  25. package/dist/481.js +1 -0
  26. package/dist/481.js.map +1 -0
  27. package/dist/53.js +1 -0
  28. package/dist/53.js.map +1 -0
  29. package/dist/{960.js → 559.js} +1 -1
  30. package/dist/559.js.map +1 -0
  31. package/dist/574.js +1 -1
  32. package/dist/576.js +1 -0
  33. package/dist/576.js.map +1 -0
  34. package/dist/577.js +1 -1
  35. package/dist/577.js.map +1 -1
  36. package/dist/{255.js → 649.js} +2 -2
  37. package/dist/649.js.LICENSE.txt +9 -0
  38. package/dist/649.js.map +1 -0
  39. package/dist/{659.js → 662.js} +1 -1
  40. package/dist/662.js.map +1 -0
  41. package/dist/920.js +1 -0
  42. package/dist/920.js.map +1 -0
  43. package/dist/921.js +1 -0
  44. package/dist/921.js.map +1 -0
  45. package/dist/922.js +1 -0
  46. package/dist/922.js.map +1 -0
  47. package/dist/969.js +1 -0
  48. package/dist/969.js.map +1 -0
  49. package/dist/kenyaemr-esm-ward-app.js +1 -1
  50. package/dist/kenyaemr-esm-ward-app.js.buildmanifest.json +304 -128
  51. package/dist/kenyaemr-esm-ward-app.js.map +1 -1
  52. package/dist/main.js +1 -1
  53. package/dist/main.js.LICENSE.txt +0 -10
  54. package/dist/main.js.map +1 -1
  55. package/dist/routes.json +1 -1
  56. package/mock.tsx +62 -0
  57. package/package-lock.json +5001 -0
  58. package/package.json +2 -3
  59. package/src/action-menu-buttons/clinical-forms-workspace-siderail.component.tsx +37 -0
  60. package/src/action-menu-buttons/discharge-workspace-siderail.component.tsx +20 -0
  61. package/src/beds/empty-bed-skeleton.tsx +4 -3
  62. package/src/beds/empty-bed.component.tsx +3 -3
  63. package/src/beds/ward-bed.component.tsx +41 -0
  64. package/src/beds/ward-bed.scss +45 -0
  65. package/src/beds/{occupied-bed.test.tsx → ward-bed.test.tsx} +42 -20
  66. package/src/config-schema.ts +203 -84
  67. package/src/constant.ts +1 -1
  68. package/src/hooks/useAdmissionLocation.ts +22 -4
  69. package/src/hooks/useAssignedBedByPatient.ts +9 -0
  70. package/src/hooks/useBeds.ts +3 -4
  71. package/src/hooks/useConcept.ts +3 -4
  72. package/src/hooks/useEmrConfiguration.ts +5 -0
  73. package/src/hooks/useInpatientAdmission.ts +9 -14
  74. package/src/hooks/useInpatientRequest.ts +4 -15
  75. package/src/hooks/useLocations.ts +8 -51
  76. package/src/hooks/useMotherAndChildren.ts +46 -0
  77. package/src/hooks/useObs.ts +3 -7
  78. package/src/hooks/usePatientPendingOrders.ts +16 -0
  79. package/src/hooks/useWardPatientGrouping.ts +32 -0
  80. package/src/index.ts +45 -17
  81. package/src/location-selector/location-selector.component.tsx +18 -21
  82. package/src/root.component.tsx +3 -0
  83. package/src/routes.json +41 -3
  84. package/src/types/index.ts +50 -1
  85. package/src/ward-patient-card/card-rows/admission-request-note-row.component.tsx +38 -0
  86. package/src/ward-patient-card/card-rows/coded-obs-tags-row.component.tsx +108 -0
  87. package/src/ward-patient-card/card-rows/mother-child-row.component.tsx +84 -0
  88. package/src/ward-patient-card/card-rows/mother-child-row.scss +22 -0
  89. package/src/ward-patient-card/card-rows/pending-items-row.component.tsx +54 -0
  90. package/src/ward-patient-card/row-elements/ward-patient-age.tsx +1 -1
  91. package/src/ward-patient-card/row-elements/ward-patient-coded-obs-tags.tsx +62 -39
  92. package/src/ward-patient-card/row-elements/ward-patient-header-address.tsx +5 -5
  93. package/src/ward-patient-card/row-elements/ward-patient-identifier.tsx +18 -41
  94. package/src/ward-patient-card/row-elements/ward-patient-location.tsx +19 -0
  95. package/src/ward-patient-card/row-elements/ward-patient-obs.resource.ts +38 -34
  96. package/src/ward-patient-card/row-elements/ward-patient-obs.tsx +26 -13
  97. package/src/ward-patient-card/row-elements/ward-patient-pending-order.component.tsx +45 -0
  98. package/src/ward-patient-card/row-elements/ward-patient-pending-transfer.tsx +38 -0
  99. package/src/ward-patient-card/row-elements/ward-patient-responsive-tooltip.tsx +32 -0
  100. package/src/ward-patient-card/row-elements/ward-patient-skeleton-text.tsx +9 -0
  101. package/src/ward-patient-card/ward-patient-card.component.tsx +14 -45
  102. package/src/ward-patient-card/ward-patient-card.scss +68 -9
  103. package/src/ward-view/default-ward/default-ward-beds.component.tsx +42 -0
  104. package/src/ward-view/default-ward/default-ward-patient-card-header.component.tsx +32 -0
  105. package/src/ward-view/default-ward/default-ward-patient-card.component.tsx +31 -0
  106. package/src/ward-view/default-ward/default-ward-pending-patients.component.tsx +52 -0
  107. package/src/ward-view/default-ward/default-ward-unassigned-patients.component.tsx +32 -0
  108. package/src/ward-view/default-ward/default-ward-view.component.tsx +31 -0
  109. package/src/ward-view/materal-ward/maternal-ward-beds.component.tsx +65 -0
  110. package/src/ward-view/materal-ward/maternal-ward-patient-card-header.component.tsx +30 -0
  111. package/src/ward-view/materal-ward/maternal-ward-patient-card.component.tsx +93 -0
  112. package/src/{beds/occupied-bed.scss → ward-view/materal-ward/maternal-ward-patient-card.scss} +4 -9
  113. package/src/ward-view/materal-ward/maternal-ward-patient-card.test.tsx +58 -0
  114. package/src/ward-view/materal-ward/maternal-ward-pending-patients.component.tsx +48 -0
  115. package/src/ward-view/materal-ward/maternal-ward-unassigned-patients.component.tsx +33 -0
  116. package/src/ward-view/materal-ward/maternal-ward-view.component.tsx +38 -0
  117. package/src/ward-view/materal-ward/maternal-ward-view.resource.ts +89 -0
  118. package/src/ward-view/ward-view.component.tsx +15 -163
  119. package/src/ward-view/ward-view.resource.ts +193 -1
  120. package/src/ward-view/ward-view.scss +17 -6
  121. package/src/ward-view/ward-view.test.tsx +43 -48
  122. package/src/ward-view/ward.component.tsx +106 -0
  123. package/src/ward-view-header/admission-requests-bar.component.tsx +14 -9
  124. package/src/ward-view-header/admission-requests-bar.test.tsx +11 -23
  125. package/src/ward-view-header/admission-requests.scss +1 -1
  126. package/src/ward-view-header/ward-metric.component.tsx +24 -0
  127. package/src/ward-view-header/ward-metric.scss +25 -0
  128. package/src/ward-view-header/ward-metrics.component.tsx +78 -0
  129. package/src/ward-view-header/ward-metrics.scss +7 -0
  130. package/src/ward-view-header/ward-metrics.test.tsx +37 -0
  131. package/src/ward-view-header/ward-view-header.component.tsx +9 -4
  132. package/src/ward-view-header/ward-view-header.scss +0 -1
  133. package/src/ward-workspace/admission-request-card/admission-request-card-actions.component.tsx +70 -6
  134. package/src/ward-workspace/admission-request-card/admission-request-card-header.component.tsx +10 -23
  135. package/src/ward-workspace/admission-request-card/admission-request-card.component.tsx +9 -3
  136. package/src/ward-workspace/admission-request-card/admission-request-card.scss +13 -4
  137. package/src/ward-workspace/admission-request-workspace/admission-requests-workspace.test.tsx +55 -33
  138. package/src/ward-workspace/admission-request-workspace/admission-requests.workspace.tsx +30 -37
  139. package/src/ward-workspace/admit-patient-form-workspace/admit-patient-form.test.tsx +98 -203
  140. package/src/ward-workspace/admit-patient-form-workspace/admit-patient-form.workspace.tsx +116 -180
  141. package/src/ward-workspace/bed-selector.component.tsx +119 -0
  142. package/src/ward-workspace/bed-selector.scss +15 -0
  143. package/src/ward-workspace/patient-banner/patient-banner.component.tsx +7 -14
  144. package/src/ward-workspace/patient-clinical-forms-workspace/patient-clinical-forms.workspace.tsx +23 -0
  145. package/src/{ward-patient-workspace → ward-workspace/patient-details}/ward-patient-action-button.extension.tsx +2 -1
  146. package/src/{ward-patient-workspace → ward-workspace/patient-details}/ward-patient.workspace.tsx +18 -9
  147. package/src/ward-workspace/patient-discharge/patient-discharge.scss +41 -0
  148. package/src/ward-workspace/patient-discharge/patient-discharge.workspace.tsx +113 -0
  149. package/src/ward-workspace/patient-transfer-bed-swap/patient-bed-swap-form.component.tsx +68 -79
  150. package/src/ward-workspace/patient-transfer-bed-swap/patient-transfer-request-form.component.tsx +24 -24
  151. package/src/ward-workspace/patient-transfer-bed-swap/patient-transfer-swap.scss +12 -2
  152. package/src/ward-workspace/patient-transfer-bed-swap/patient-transfer-swap.workspace.tsx +12 -8
  153. package/src/ward-workspace/patient-transfer-request-workspace/patient-transfer-request.workspace.tsx +11 -0
  154. package/src/ward-workspace/ward-patient-notes/form/notes-form.component.tsx +1 -1
  155. package/src/ward-workspace/ward-patient-notes/form/notes-form.test.tsx +1 -1
  156. package/src/ward-workspace/ward-patient-notes/history/notes-container.component.tsx +2 -2
  157. package/src/ward-workspace/ward-patient-notes/notes.resource.ts +5 -7
  158. package/src/ward-workspace/ward-patient-notes/notes.workspace.tsx +1 -1
  159. package/src/ward-workspace/ward-patient-notes/types.ts +0 -4
  160. package/src/ward.resource.ts +38 -2
  161. package/translations/en.json +31 -7
  162. package/dist/152.js +0 -1
  163. package/dist/152.js.map +0 -1
  164. package/dist/255.js.map +0 -1
  165. package/dist/269.js +0 -1
  166. package/dist/269.js.map +0 -1
  167. package/dist/346.js +0 -1
  168. package/dist/346.js.map +0 -1
  169. package/dist/466.js +0 -1
  170. package/dist/466.js.map +0 -1
  171. package/dist/659.js.map +0 -1
  172. package/dist/729.js +0 -1
  173. package/dist/729.js.map +0 -1
  174. package/dist/749.js +0 -1
  175. package/dist/749.js.map +0 -1
  176. package/dist/76.js +0 -1
  177. package/dist/76.js.map +0 -1
  178. package/dist/793.js +0 -2
  179. package/dist/793.js.map +0 -1
  180. package/dist/803.js +0 -1
  181. package/dist/803.js.map +0 -1
  182. package/dist/960.js.map +0 -1
  183. package/src/beds/empty-bed.scss +0 -28
  184. package/src/beds/occupied-bed.component.tsx +0 -35
  185. package/src/beds/unassigned-patient.component.tsx +0 -20
  186. package/src/beds/unassigned-patient.scss +0 -6
  187. package/src/config-schema-admission-request-note.ts +0 -9
  188. package/src/config-schema-extension-colored-obs-tags.ts +0 -91
  189. package/src/hooks/useCurrentWardCardConfig.ts +0 -32
  190. package/src/ward-patient-card/card-rows/admission-request-note.extension.tsx +0 -27
  191. package/src/ward-patient-card/card-rows/colored-obs-tags-card-row.extension.tsx +0 -13
  192. package/src/ward-patient-card/ward-patient-card-element.component.tsx +0 -65
  193. package/src/ward-view/ward-bed.component.tsx +0 -14
  194. /package/dist/{793.js.LICENSE.txt → 303.js.LICENSE.txt} +0 -0
  195. /package/dist/{255.js.LICENSE.txt → 372.js.LICENSE.txt} +0 -0
  196. /package/src/{ward-patient-workspace → ward-workspace/patient-details}/ward-patient.style.scss +0 -0
@@ -1,21 +1,16 @@
1
- import React from 'react';
1
+ import { showSnackbar, useAppContext, useFeatureFlag, useSession } from '@openmrs/esm-framework';
2
2
  import { screen } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
+ import React from 'react';
5
+ import { mockLocationInpatientWard, mockPatientAlice } from '../../../../../__mocks__';
4
6
  import { renderWithSwr } from '../../../../../tools';
7
+ import { mockWardPatientGroupDetails, mockWardViewContext } from '../../../mock';
8
+ import { useAssignedBedByPatient } from '../../hooks/useAssignedBedByPatient';
9
+ import useWardLocation from '../../hooks/useWardLocation';
10
+ import type { DispositionType, WardViewContext } from '../../types';
11
+ import { assignPatientToBed, removePatientFromBed, useAdmitPatient } from '../../ward.resource';
5
12
  import AdmitPatientFormWorkspace from './admit-patient-form.workspace';
6
- import {
7
- mockAdmissionLocation,
8
- mockInpatientRequest,
9
- mockLocationInpatientWard,
10
- mockPatientAlice,
11
- } from '../../../../../__mocks__';
12
- import type { DispositionType } from '../../types';
13
13
  import type { AdmitPatientFormWorkspaceProps } from './types';
14
- import { useAdmissionLocation } from '../../hooks/useAdmissionLocation';
15
- import { openmrsFetch, provide, showSnackbar, useFeatureFlag, useSession } from '@openmrs/esm-framework';
16
- import useEmrConfiguration from '../../hooks/useEmrConfiguration';
17
- import useWardLocation from '../../hooks/useWardLocation';
18
- import { useInpatientRequest } from '../../hooks/useInpatientRequest';
19
14
 
20
15
  jest.mock('../../hooks/useAdmissionLocation', () => ({
21
16
  useAdmissionLocation: jest.fn(),
@@ -23,20 +18,47 @@ jest.mock('../../hooks/useAdmissionLocation', () => ({
23
18
 
24
19
  jest.mock('../../hooks/useWardLocation', () => jest.fn());
25
20
 
26
- jest.mock('../../hooks/useEmrConfiguration', () => jest.fn());
27
-
28
21
  jest.mock('../../hooks/useInpatientRequest', () => ({
29
22
  useInpatientRequest: jest.fn(),
30
23
  }));
31
24
 
32
- const mockedUseInpatientRequest = jest.mocked(useInpatientRequest);
33
- const mockedUseEmrConfiguration = jest.mocked(useEmrConfiguration);
25
+ jest.mock('../../hooks/useWardPatientGrouping', () => ({
26
+ useWardPatientGrouping: jest.fn(),
27
+ }));
28
+
29
+ jest.mock('../../hooks/useInpatientAdmission', () => ({
30
+ useInpatientAdmission: jest.fn(),
31
+ }));
32
+
33
+ jest.mock('../../hooks/useAssignedBedByPatient', () => ({
34
+ useAssignedBedByPatient: jest.fn(),
35
+ }));
36
+
37
+ jest.mock('../../ward.resource', () => ({
38
+ createEncounter: jest.fn(),
39
+ useAdmitPatient: jest.fn(),
40
+ assignPatientToBed: jest.fn(),
41
+ removePatientFromBed: jest.fn(),
42
+ }));
43
+
34
44
  const mockedUseWardLocation = jest.mocked(useWardLocation);
35
- const mockedOpenmrsFetch = jest.mocked(openmrsFetch);
36
- const mockedUseAdmissionLocation = jest.mocked(useAdmissionLocation);
37
45
  const mockedUseFeatureFlag = jest.mocked(useFeatureFlag);
38
46
  const mockedShowSnackbar = jest.mocked(showSnackbar);
39
47
  const mockedUseSession = jest.mocked(useSession);
48
+ const mockedUseAssignedBedByPatient = jest.mocked(useAssignedBedByPatient);
49
+ const mockedAssignPatientToBed = jest.mocked(assignPatientToBed);
50
+ const mockedRemovePatientFromBed = jest.mocked(removePatientFromBed);
51
+ const mockedUseAdmitPatient = jest.mocked(useAdmitPatient);
52
+
53
+ jest.mocked(useAppContext<WardViewContext>).mockReturnValue(mockWardViewContext);
54
+
55
+ const mockUseAdmitPatientObj: ReturnType<typeof useAdmitPatient> = {
56
+ admitPatient: jest.fn(),
57
+ isLoadingEmrConfiguration: false,
58
+ errorFetchingEmrConfiguration: false,
59
+ };
60
+ jest.mocked(useAdmitPatient).mockReturnValue(mockUseAdmitPatientObj);
61
+ const mockedAdmitPatient = mockUseAdmitPatientObj.admitPatient;
40
62
 
41
63
  const mockWorkspaceProps: AdmitPatientFormWorkspaceProps = {
42
64
  patient: mockPatientAlice,
@@ -51,18 +73,10 @@ function renderAdmissionForm(dispositionType: DispositionType = 'ADMIT') {
51
73
  renderWithSwr(<AdmitPatientFormWorkspace {...{ ...mockWorkspaceProps, dispositionType }} />);
52
74
  }
53
75
 
54
- const mockedMutateInpatientRequest = jest.fn();
55
-
56
76
  describe('Testing AdmitPatientForm', () => {
57
77
  beforeEach(() => {
58
78
  jest.clearAllMocks();
59
- mockedUseAdmissionLocation.mockReturnValue({
60
- isLoading: false,
61
- isValidating: false,
62
- admissionLocation: mockAdmissionLocation,
63
- mutate: jest.fn(),
64
- error: undefined,
65
- });
79
+
66
80
  mockedUseSession.mockReturnValue({
67
81
  currentProvider: {
68
82
  uuid: 'current-provider-uuid',
@@ -72,38 +86,48 @@ describe('Testing AdmitPatientForm', () => {
72
86
  sessionId: 'session-id',
73
87
  });
74
88
  mockedUseFeatureFlag.mockReturnValue(true);
75
- mockedUseEmrConfiguration.mockReturnValue({
76
- isLoadingEmrConfiguration: false,
77
- errorFetchingEmrConfiguration: null,
78
- // @ts-ignore - we only need these two keys for now
79
- emrConfiguration: {
80
- admissionEncounterType: {
81
- uuid: 'admission-encounter-type-uuid',
82
- display: 'Admission Encounter',
83
- },
84
- transferWithinHospitalEncounterType: {
85
- uuid: 'transfer-within-hospital-encounter-type-uuid',
86
- display: 'Transfer Within Hospital Encounter Type',
87
- },
88
- clinicianEncounterRole: {
89
- uuid: 'clinician-encounter-role-uuid',
90
- },
91
- },
92
- mutateEmrConfiguration: jest.fn(),
93
- });
94
- mockedUseInpatientRequest.mockReturnValue({
95
- mutate: mockedMutateInpatientRequest,
96
- error: undefined,
97
- inpatientRequests: [mockInpatientRequest],
98
- isLoading: false,
99
- isValidating: false,
100
- });
89
+
101
90
  mockedUseWardLocation.mockReturnValue({
102
91
  location: mockLocationInpatientWard,
103
92
  invalidLocation: false,
104
93
  isLoadingLocation: false,
105
94
  errorFetchingLocation: null,
106
95
  });
96
+
97
+ // @ts-ignore - we don't need to mock the entire object
98
+ mockedUseAssignedBedByPatient.mockReturnValue({
99
+ data: {
100
+ data: {
101
+ results: [
102
+ {
103
+ bedId: 1,
104
+ bedNumber: 1,
105
+ bedType: null,
106
+ patients: [mockPatientAlice],
107
+ physicalLocation: mockLocationInpatientWard,
108
+ },
109
+ ],
110
+ },
111
+ },
112
+ });
113
+
114
+ // @ts-ignore - we only need these two keys for now
115
+ mockedAdmitPatient.mockResolvedValue({
116
+ ok: true,
117
+ data: {
118
+ uuid: 'encounter-uuid',
119
+ },
120
+ });
121
+
122
+ // @ts-ignore - we only need the ok key for now
123
+ mockedAssignPatientToBed.mockResolvedValue({
124
+ ok: true,
125
+ });
126
+
127
+ // @ts-ignore - we only need the ok key for now
128
+ mockedRemovePatientFromBed.mockResolvedValue({
129
+ ok: true,
130
+ });
107
131
  });
108
132
 
109
133
  it('should render admit patient form', async () => {
@@ -116,118 +140,45 @@ describe('Testing AdmitPatientForm', () => {
116
140
  });
117
141
  screen.getByText('Admit');
118
142
  expect(screen.getByText('Select a bed')).toBeInTheDocument();
119
- await user.click(
120
- screen.getByRole('combobox', {
121
- name: 'Choose an option',
122
- }),
123
- );
124
- expect(screen.getByText('bed1 · Alice Johnson')).toBeInTheDocument();
125
- expect(screen.getByText('bed2 · Empty')).toBeInTheDocument();
126
- expect(screen.getByText('bed3 · Empty')).toBeInTheDocument();
127
- expect(screen.getByText('bed4 · Empty')).toBeInTheDocument();
143
+
144
+ expect(screen.getByRole('radio', { name: 'bed1 · Alice Johnson' })).toBeInTheDocument();
145
+ expect(screen.getByRole('radio', { name: 'bed2 · Empty' })).toBeInTheDocument();
146
+ expect(screen.getByRole('radio', { name: 'bed3 · Empty' })).toBeInTheDocument();
147
+ expect(screen.getByRole('radio', { name: 'bed4 · Empty' })).toBeInTheDocument();
128
148
  });
129
149
 
130
150
  it('should block the form if emr configuration is not fetched properly', () => {
131
- mockedUseEmrConfiguration.mockReturnValue({
151
+ mockedUseAdmitPatient.mockReturnValueOnce({
152
+ admitPatient: mockedAdmitPatient,
132
153
  isLoadingEmrConfiguration: false,
133
154
  errorFetchingEmrConfiguration: true,
134
- emrConfiguration: null,
135
- mutateEmrConfiguration: jest.fn(),
136
155
  });
137
156
 
138
157
  renderAdmissionForm();
139
158
 
140
159
  const admitButton = screen.getByText('Admit');
141
160
  expect(admitButton).toBeDisabled();
142
- expect(screen.getByText("Some parts of the form didn't load")).toBeInTheDocument();
143
- expect(
144
- screen.getByText(
145
- 'Fetching EMR configuration failed. Try refreshing the page or contact your system administrator.',
146
- ),
147
- ).toBeInTheDocument();
148
- });
149
-
150
- it('should render admit patient form if bed management module is not present', () => {
151
- mockedUseFeatureFlag.mockReturnValue(false);
152
- renderAdmissionForm();
153
- expect(screen.getByText('Select a bed')).toBeInTheDocument();
154
- expect(screen.getByText('Unable to select beds')).toBeInTheDocument();
155
- expect(screen.getByText('Bed management module is not present to allow bed selection')).toBeInTheDocument();
156
161
  });
157
162
 
158
163
  it('should render admit patient form if bed management module is present, but no beds are configured', () => {
159
164
  mockedUseFeatureFlag.mockReturnValue(true);
160
- mockedUseAdmissionLocation.mockReturnValueOnce({
161
- isLoading: false,
162
- isValidating: false,
163
- admissionLocation: {
164
- ...mockAdmissionLocation,
165
- totalBeds: 0,
166
- bedLayouts: [],
167
- },
168
- mutate: jest.fn(),
169
- error: null,
170
- });
165
+ const replacedProperty = jest.replaceProperty(mockWardPatientGroupDetails(), 'bedLayouts', []);
171
166
  renderAdmissionForm();
172
167
  expect(screen.getByText('Select a bed')).toBeInTheDocument();
173
- expect(screen.getByText('No beds configured for Inpatient Ward location')).toBeInTheDocument();
168
+ expect(screen.getByText(/No beds configured/i)).toBeInTheDocument();
169
+ replacedProperty.restore();
174
170
  });
175
171
 
176
172
  it('should submit the form, create encounter and submit bed', async () => {
177
- mockedUseAdmissionLocation.mockReturnValueOnce({
178
- isLoading: false,
179
- isValidating: false,
180
- admissionLocation: mockAdmissionLocation,
181
- mutate: jest.fn(),
182
- error: null,
183
- });
184
- // @ts-ignore - we only need these two keys for now
185
- mockedOpenmrsFetch.mockResolvedValue({
186
- ok: true,
187
- data: {
188
- uuid: 'encounter-uuid',
189
- },
190
- });
191
173
  const user = userEvent.setup();
192
174
  renderAdmissionForm();
193
- const combobox = screen.getByRole('combobox', {
194
- name: 'Choose an option',
195
- });
196
- await user.click(combobox);
197
- const bedOption = screen.getByText('bed3 · Empty');
175
+ const bedOption = screen.getByRole('radio', { name: 'bed3 · Empty' });
198
176
  await user.click(bedOption);
199
177
  const admitButton = screen.getByRole('button', { name: 'Admit' });
200
178
  expect(admitButton).toBeEnabled();
201
179
  await user.click(admitButton);
202
- expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(2);
203
- expect(mockedOpenmrsFetch).toHaveBeenCalledWith('/ws/rest/v1/encounter', {
204
- method: 'POST',
205
- headers: {
206
- 'content-type': 'application/json',
207
- },
208
- body: {
209
- patient: mockPatientAlice.uuid,
210
- encounterType: 'admission-encounter-type-uuid',
211
- location: mockAdmissionLocation.ward.uuid,
212
- obs: [],
213
- encounterProviders: [
214
- {
215
- provider: 'current-provider-uuid',
216
- encounterRole: 'clinician-encounter-role-uuid',
217
- },
218
- ],
219
- },
220
- });
221
- expect(mockedOpenmrsFetch).toHaveBeenCalledWith('/ws/rest/v1/beds/3', {
222
- method: 'POST',
223
- headers: {
224
- 'content-type': 'application/json',
225
- },
226
- body: {
227
- patientUuid: mockPatientAlice.uuid,
228
- encounterUuid: 'encounter-uuid',
229
- },
230
- });
180
+ expect(mockedAdmitPatient).toHaveBeenCalledWith(mockPatientAlice, 'ADMIT');
181
+ expect(mockedAssignPatientToBed).toHaveBeenCalledWith(3, mockPatientAlice.uuid, 'encounter-uuid');
231
182
  expect(mockedShowSnackbar).toHaveBeenCalledWith({
232
183
  kind: 'success',
233
184
  subtitle: '{{patientName}} has been successfully admitted and assigned to bed bed3',
@@ -236,19 +187,14 @@ describe('Testing AdmitPatientForm', () => {
236
187
  });
237
188
 
238
189
  it('should show snackbar if there was an issue creating an encounter', async () => {
239
- mockedOpenmrsFetch.mockRejectedValue(new Error('Failed to create encounter'));
190
+ mockedAdmitPatient.mockRejectedValue(new Error('Failed to create encounter'));
240
191
  const user = userEvent.setup();
241
192
  renderAdmissionForm();
242
- const combobox = screen.getByRole('combobox', {
243
- name: 'Choose an option',
244
- });
245
- await user.click(combobox);
246
- const bedOption = screen.getByText('bed3 · Empty');
193
+ const bedOption = screen.getByRole('radio', { name: 'bed3 · Empty' });
247
194
  await user.click(bedOption);
248
195
  const admitButton = screen.getByRole('button', { name: 'Admit' });
249
196
  expect(admitButton).toBeEnabled();
250
197
  await user.click(admitButton);
251
- expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(1);
252
198
  expect(mockedShowSnackbar).toHaveBeenCalledWith({
253
199
  kind: 'error',
254
200
  title: 'Failed to admit patient',
@@ -257,31 +203,15 @@ describe('Testing AdmitPatientForm', () => {
257
203
  });
258
204
 
259
205
  it('should show warning snackbar if encounter was created and bed assignment was not successful', async () => {
260
- // @ts-ignore - matching whole FetchResponse type is not necessary
261
- mockedOpenmrsFetch.mockImplementation((url) => {
262
- if (url.startsWith('/ws/rest/v1/beds')) {
263
- return Promise.reject(new Error('Failed to assign bed'));
264
- }
265
- return Promise.resolve({
266
- ok: true,
267
- data: {
268
- uuid: 'encounter-uuid',
269
- },
270
- });
271
- });
206
+ mockedAssignPatientToBed.mockRejectedValue(new Error('Failed to assign bed'));
272
207
 
273
208
  const user = userEvent.setup();
274
209
  renderAdmissionForm();
275
- const combobox = screen.getByRole('combobox', {
276
- name: 'Choose an option',
277
- });
278
- await user.click(combobox);
279
- const bedOption = screen.getByText('bed3 · Empty');
210
+ const bedOption = screen.getByRole('radio', { name: 'bed3 · Empty' });
280
211
  await user.click(bedOption);
281
212
  const admitButton = screen.getByRole('button', { name: 'Admit' });
282
213
  expect(admitButton).toBeEnabled();
283
214
  await user.click(admitButton);
284
- expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(2);
285
215
  expect(mockedShowSnackbar).toHaveBeenCalledWith({
286
216
  kind: 'warning',
287
217
  title: 'Patient admitted successfully',
@@ -289,49 +219,14 @@ describe('Testing AdmitPatientForm', () => {
289
219
  });
290
220
  });
291
221
 
292
- it('should admit patient if no beds are configured', async () => {
293
- mockedUseAdmissionLocation.mockReturnValueOnce({
294
- isLoading: false,
295
- isValidating: false,
296
- admissionLocation: {
297
- ...mockAdmissionLocation,
298
- totalBeds: 0,
299
- bedLayouts: [],
300
- },
301
- mutate: jest.fn(),
302
- error: null,
303
- });
304
- // @ts-ignore - we only need these two keys for now
305
- mockedOpenmrsFetch.mockResolvedValue({
306
- ok: true,
307
- data: {
308
- uuid: 'encounter-uuid',
309
- },
310
- });
222
+ it('should admit patient if no bed is selected', async () => {
311
223
  const user = userEvent.setup();
312
224
  renderAdmissionForm();
313
225
  const admitButton = screen.getByRole('button', { name: 'Admit' });
314
226
  expect(admitButton).toBeEnabled();
315
227
  await user.click(admitButton);
316
- expect(mockedOpenmrsFetch).toHaveBeenCalledTimes(1);
317
- expect(mockedOpenmrsFetch).toHaveBeenCalledWith('/ws/rest/v1/encounter', {
318
- method: 'POST',
319
- headers: {
320
- 'content-type': 'application/json',
321
- },
322
- body: {
323
- patient: mockPatientAlice.uuid,
324
- encounterType: 'admission-encounter-type-uuid',
325
- location: mockAdmissionLocation.ward.uuid,
326
- obs: [],
327
- encounterProviders: [
328
- {
329
- provider: 'current-provider-uuid',
330
- encounterRole: 'clinician-encounter-role-uuid',
331
- },
332
- ],
333
- },
334
- });
228
+ expect(mockedAdmitPatient).toHaveBeenCalledWith(mockPatientAlice, 'ADMIT');
229
+ expect(mockedRemovePatientFromBed).toHaveBeenCalledWith(1, mockPatientAlice.uuid);
335
230
  expect(mockedShowSnackbar).toHaveBeenCalledWith({
336
231
  kind: 'success',
337
232
  subtitle: 'Patient admitted successfully to Inpatient Ward',