@kenyaemr/esm-bed-management-app 8.1.1-pre.124 → 8.1.2-pre.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/.turbo/turbo-build.log +26 -25
  2. package/dist/130.js +1 -1
  3. package/dist/130.js.map +1 -1
  4. package/dist/148.js +1 -1
  5. package/dist/148.js.map +1 -1
  6. package/dist/236.js +1 -0
  7. package/dist/240.js +1 -0
  8. package/dist/261.js +1 -0
  9. package/dist/271.js +1 -1
  10. package/dist/272.js +1 -0
  11. package/dist/288.js +1 -0
  12. package/dist/288.js.map +1 -0
  13. package/dist/319.js +1 -1
  14. package/dist/336.js +1 -0
  15. package/dist/378.js +1 -0
  16. package/dist/443.js +1 -0
  17. package/dist/443.js.map +1 -0
  18. package/dist/460.js +1 -1
  19. package/dist/539.js +1 -0
  20. package/dist/542.js +1 -1
  21. package/dist/542.js.map +1 -1
  22. package/dist/566.js +1 -0
  23. package/dist/574.js +1 -1
  24. package/dist/644.js +1 -1
  25. package/dist/652.js +1 -0
  26. package/dist/673.js +1 -0
  27. package/dist/705.js +1 -0
  28. package/dist/711.js +1 -0
  29. package/dist/727.js +1 -0
  30. package/dist/737.js +1 -0
  31. package/dist/744.js +1 -0
  32. package/dist/746.js +2 -0
  33. package/dist/746.js.map +1 -0
  34. package/dist/757.js +1 -1
  35. package/dist/768.js +2 -0
  36. package/dist/{455.js.LICENSE.txt → 768.js.LICENSE.txt} +0 -6
  37. package/dist/768.js.map +1 -0
  38. package/dist/788.js +1 -1
  39. package/dist/807.js +1 -1
  40. package/dist/833.js +1 -1
  41. package/dist/899.js +1 -0
  42. package/dist/main.js +1 -1
  43. package/dist/main.js.map +1 -1
  44. package/dist/openmrs-esm-bed-management-app.js +1 -1
  45. package/dist/openmrs-esm-bed-management-app.js.buildmanifest.json +414 -83
  46. package/dist/openmrs-esm-bed-management-app.js.map +1 -1
  47. package/dist/routes.json +1 -1
  48. package/package-lock.json +5893 -0
  49. package/package.json +4 -4
  50. package/src/admin-card-link.component.tsx +3 -2
  51. package/src/bed-administration/bed-administration-form.component.tsx +53 -54
  52. package/src/bed-administration/bed-administration-table.component.tsx +27 -23
  53. package/src/bed-administration/bed-administration-table.scss +1 -1
  54. package/src/bed-administration/bed-administration-types.ts +7 -5
  55. package/src/bed-administration/bed-administration.resource.ts +5 -7
  56. package/src/bed-administration/edit-bed-form.component.tsx +43 -43
  57. package/src/bed-administration/new-bed-form.component.tsx +34 -38
  58. package/src/bed-tag/bed-tag-administration-table.component.tsx +23 -23
  59. package/src/bed-tag/bed-tags-admin-form.component.tsx +12 -11
  60. package/src/bed-tag/edit-tag-form.component.tsx +27 -29
  61. package/src/bed-tag/new-tag-form.component.tsx +29 -34
  62. package/src/bed-type/bed-type-admin-form.component.tsx +32 -35
  63. package/src/bed-type/bed-type-administration-table.component.tsx +49 -49
  64. package/src/bed-type/edit-bed-type.component.tsx +24 -23
  65. package/src/bed-type/new-bed-type-form.component.tsx +32 -37
  66. package/src/card-header/card-header.component.tsx +3 -1
  67. package/src/header/header.component.tsx +23 -18
  68. package/src/header/header.scss +18 -32
  69. package/src/home.component.tsx +4 -1
  70. package/src/index.ts +12 -7
  71. package/src/left-panel/left-panel.component.tsx +10 -8
  72. package/src/modals.scss +29 -0
  73. package/src/root.component.tsx +8 -7
  74. package/src/routes.json +0 -15
  75. package/src/summary/summary.resource.ts +154 -100
  76. package/src/types.ts +2 -2
  77. package/src/ward-with-beds/ward-with-beds.component.tsx +7 -8
  78. package/translations/am.json +34 -18
  79. package/translations/ar.json +35 -19
  80. package/translations/de.json +67 -0
  81. package/translations/en.json +34 -18
  82. package/translations/es.json +38 -22
  83. package/translations/fr.json +34 -18
  84. package/translations/he.json +34 -18
  85. package/translations/hi.json +67 -0
  86. package/translations/hi_IN.json +67 -0
  87. package/translations/id.json +67 -0
  88. package/translations/it.json +67 -0
  89. package/translations/km.json +34 -18
  90. package/translations/ne.json +67 -0
  91. package/translations/pt.json +67 -0
  92. package/translations/pt_BR.json +67 -0
  93. package/translations/qu.json +67 -0
  94. package/translations/si.json +67 -0
  95. package/translations/sw.json +67 -0
  96. package/translations/sw_KE.json +67 -0
  97. package/translations/tr.json +67 -0
  98. package/translations/tr_TR.json +67 -0
  99. package/translations/uk.json +67 -0
  100. package/translations/vi.json +67 -0
  101. package/translations/zh.json +34 -18
  102. package/translations/zh_CN.json +34 -18
  103. package/tsconfig.json +0 -1
  104. package/dist/169.js +0 -1
  105. package/dist/169.js.map +0 -1
  106. package/dist/339.js +0 -1
  107. package/dist/339.js.map +0 -1
  108. package/dist/455.js +0 -2
  109. package/dist/455.js.map +0 -1
  110. package/dist/501.js +0 -1
  111. package/dist/501.js.map +0 -1
  112. package/dist/766.js +0 -2
  113. package/dist/766.js.map +0 -1
  114. package/src/bed-administration/bed-administration-form.scss +0 -0
  115. package/src/header/illustration.component.tsx +0 -13
  116. package/src/setup-tests.ts +0 -1
  117. /package/dist/{766.js.LICENSE.txt → 746.js.LICENSE.txt} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kenyaemr/esm-bed-management-app",
3
- "version": "8.1.1-pre.124",
3
+ "version": "8.1.2-pre.152",
4
4
  "description": "Bed management app for OpenMRS 3",
5
5
  "browser": "dist/openmrs-esm-bed-management-app.js",
6
6
  "main": "src/index.ts",
@@ -37,11 +37,11 @@
37
37
  "url": "https://github.com/openmrs/openmrs-esm-patient-management/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@carbon/react": "~1.37.0",
40
+ "@carbon/react": "^1.71.0",
41
41
  "lodash-es": "^4.17.15"
42
42
  },
43
43
  "peerDependencies": {
44
- "@openmrs/esm-framework": "5.x",
44
+ "@openmrs/esm-framework": "6.x",
45
45
  "dayjs": "1.x",
46
46
  "react": "18.x",
47
47
  "react-i18next": "11.x",
@@ -51,5 +51,5 @@
51
51
  "devDependencies": {
52
52
  "webpack": "^5.74.0"
53
53
  },
54
- "stableVersion": "8.1.0"
54
+ "stableVersion": "8.0.2"
55
55
  }
@@ -5,13 +5,14 @@ import { ArrowRight } from '@carbon/react/icons';
5
5
 
6
6
  const BedManagementAdminCardLink: React.FC = () => {
7
7
  const { t } = useTranslation();
8
- const header = t('manageBeds', 'Manage Beds');
8
+ const header = t('manageBeds', 'Manage beds');
9
+
9
10
  return (
10
11
  <Layer>
11
12
  <ClickableTile href={window.getOpenmrsSpaBase() + 'bed-management'} rel="noopener noreferrer">
12
13
  <div>
13
14
  <div className="heading">{header}</div>
14
- <div className="content">{t('bedManagement', 'Bed Management')}</div>
15
+ <div className="content">{t('bedManagement', 'Bed management')}</div>
15
16
  </div>
16
17
  <div className="iconWrapper">
17
18
  <ArrowRight size={16} />
@@ -9,6 +9,7 @@ import {
9
9
  ComposedModal,
10
10
  Form,
11
11
  FormGroup,
12
+ InlineNotification,
12
13
  ModalBody,
13
14
  ModalFooter,
14
15
  ModalHeader,
@@ -18,18 +19,34 @@ import {
18
19
  Stack,
19
20
  TextArea,
20
21
  TextInput,
21
- InlineNotification,
22
22
  } from '@carbon/react';
23
23
  import { useTranslation } from 'react-i18next';
24
24
  import { getCoreTranslation, type Location } from '@openmrs/esm-framework';
25
- import type { BedType, BedFormData } from '../types';
26
25
  import { type BedAdministrationData } from './bed-administration-types';
26
+ import { type BedType, type BedFormData } from '../types';
27
+ import styles from '../modals.scss';
28
+
29
+ interface BedAdministrationFormProps {
30
+ allLocations: Location[];
31
+ availableBedTypes: Array<BedType>;
32
+ handleCreateBed?: (formData: BedAdministrationData) => void;
33
+ headerTitle: string;
34
+ initialData: BedFormData;
35
+ occupancyStatuses: string[];
36
+ onModalChange: (showModal: boolean) => void;
37
+ showModal: boolean;
38
+ }
39
+
40
+ interface ErrorType {
41
+ message: string;
42
+ }
27
43
 
28
44
  const numberInString = z.string().transform((val, ctx) => {
29
45
  const parsed = parseInt(val);
30
46
  if (isNaN(parsed) || parsed < 1) {
31
47
  ctx.addIssue({
32
48
  code: z.ZodIssueCode.custom,
49
+ // TODO: Translate this message
33
50
  message: 'Please enter a valid number',
34
51
  });
35
52
  return z.NEVER;
@@ -38,41 +55,26 @@ const numberInString = z.string().transform((val, ctx) => {
38
55
  });
39
56
 
40
57
  const BedAdministrationSchema = z.object({
58
+ bedColumn: numberInString,
41
59
  bedId: z.string().max(255),
42
- description: z.string().max(255),
43
60
  bedRow: numberInString,
44
- bedColumn: numberInString,
61
+ bedType: z.string().refine((value) => value != '', 'Please select a valid bed type'),
62
+ description: z.string().max(255),
45
63
  location: z
46
64
  .object({ display: z.string(), uuid: z.string() })
47
65
  .refine((value) => value.display != '', 'Please select a valid location'),
48
66
  occupancyStatus: z.string().refine((value) => value != '', 'Please select a valid occupied status'),
49
- bedType: z.string().refine((value) => value != '', 'Please select a valid bed type'),
50
67
  });
51
68
 
52
- interface BedAdministrationFormProps {
53
- showModal: boolean;
54
- onModalChange: (showModal: boolean) => void;
55
- availableBedTypes: Array<BedType>;
56
- allLocations: Location[];
57
- handleCreateQuestion?: (formData: BedAdministrationData) => void;
58
- headerTitle: string;
59
- occupancyStatuses: string[];
60
- initialData: BedFormData;
61
- }
62
-
63
- interface ErrorType {
64
- message: string;
65
- }
66
-
67
69
  const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
68
- showModal,
69
- onModalChange,
70
- availableBedTypes,
71
70
  allLocations,
72
- handleCreateQuestion,
71
+ availableBedTypes,
72
+ handleCreateBed,
73
73
  headerTitle,
74
- occupancyStatuses,
75
74
  initialData,
75
+ occupancyStatuses,
76
+ onModalChange,
77
+ showModal,
76
78
  }) => {
77
79
  const { t } = useTranslation();
78
80
  const [occupancyStatus, setOccupancyStatus] = useState(capitalize(initialData.status));
@@ -80,10 +82,6 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
80
82
  const [showErrorNotification, setShowErrorNotification] = useState(false);
81
83
  const [formStateError, setFormStateError] = useState('');
82
84
 
83
- const filterLocationNames = (location) => {
84
- return location.item.display?.toLowerCase().includes(location?.inputValue?.toLowerCase()) ?? [];
85
- };
86
-
87
85
  const {
88
86
  handleSubmit,
89
87
  control,
@@ -92,13 +90,13 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
92
90
  mode: 'all',
93
91
  resolver: zodResolver(BedAdministrationSchema),
94
92
  defaultValues: {
93
+ bedColumn: initialData.column.toString() ?? '0',
95
94
  bedId: initialData.bedNumber ?? '',
96
- description: initialData.bedType?.description ?? '',
97
95
  bedRow: initialData.row.toString() ?? '0',
98
- bedColumn: initialData.column.toString() ?? '0',
96
+ bedType: initialData.bedType?.name ?? '',
97
+ description: initialData.bedType?.description ?? '',
99
98
  location: initialData.location ?? {},
100
99
  occupancyStatus: capitalize(initialData.status) ?? occupancyStatus,
101
- bedType: initialData.bedType?.name ?? '',
102
100
  },
103
101
  });
104
102
 
@@ -106,7 +104,7 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
106
104
  const result = BedAdministrationSchema.safeParse(formData);
107
105
  if (result.success) {
108
106
  setShowErrorNotification(false);
109
- handleCreateQuestion(formData);
107
+ handleCreateBed(formData);
110
108
  }
111
109
  };
112
110
 
@@ -116,8 +114,9 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
116
114
  };
117
115
 
118
116
  return (
117
+ // TODO: Port this over to the modal system or create individual modals for each form
119
118
  <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
120
- <ModalHeader title={headerTitle} />
119
+ <ModalHeader className={styles.modalHeader} title={headerTitle} />
121
120
  <ModalBody hasScrollingContent>
122
121
  <Form>
123
122
  <Stack gap={3}>
@@ -129,9 +128,9 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
129
128
  <>
130
129
  <TextInput
131
130
  id="bedId"
132
- labelText={t('bedId', 'Bed number')}
133
- placeholder={t('bedIdPlaceholder', 'e.g. BMW-201')}
134
131
  invalidText={fieldState.error?.message}
132
+ labelText={t('bedNumber', 'Bed number')}
133
+ placeholder={t('enterBedNumber', 'e.g. BMW-201')}
135
134
  {...field}
136
135
  />
137
136
  </>
@@ -146,12 +145,12 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
146
145
  render={({ field, fieldState }) => (
147
146
  <>
148
147
  <TextArea
149
- rows={2}
150
148
  id="description"
151
149
  invalidText={fieldState?.error?.message}
152
- labelText={t('description', 'Bed description')}
150
+ labelText={t('bedDescription', 'Bed description')}
151
+ placeholder={t('enterBedDescription', 'Enter the bed description')}
152
+ rows={2}
153
153
  {...field}
154
- placeholder={t('description', 'Enter the bed description')}
155
154
  />
156
155
  </>
157
156
  )}
@@ -166,9 +165,9 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
166
165
  <NumberInput
167
166
  hideSteppers
168
167
  id="bedRow"
168
+ invalidText={fieldState?.error?.message}
169
169
  label="Bed row"
170
170
  labelText="Bed row"
171
- invalidText={fieldState?.error?.message}
172
171
  {...field}
173
172
  />
174
173
  )}
@@ -199,18 +198,18 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
199
198
  render={({ fieldState, field: { onChange, onBlur, value, ref } }) => (
200
199
  <ComboBox
201
200
  aria-label={t('location', 'Location')}
202
- shouldFilterItem={filterLocationNames}
203
201
  id="location"
204
- label={t('location', 'Location')}
205
202
  invalidText={fieldState?.error?.message}
206
203
  items={allLocations}
204
+ itemToString={(location) => location?.display ?? ''}
205
+ label={t('location', 'Location')}
207
206
  onBlur={onBlur}
208
- ref={ref}
209
- selectedItem={value}
210
207
  onChange={({ selectedItem }) => onChange(selectedItem)}
211
- itemToString={(location) => location?.display ?? ''}
212
208
  placeholder={t('selectBedLocation', 'Select a bed location')}
209
+ ref={ref}
210
+ selectedItem={value}
213
211
  titleText={t('bedLocation', 'Location')}
212
+ typeahead
214
213
  />
215
214
  )}
216
215
  />
@@ -222,19 +221,19 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
222
221
  control={control}
223
222
  render={({ field, fieldState }) => (
224
223
  <Select
224
+ defaultValue={occupancyStatus}
225
225
  id="occupancyStatus"
226
- labelText={t('occupancyStatus', 'Occupied Status')}
227
226
  invalidText={fieldState.error?.message}
228
- defaultValue={occupancyStatus}
227
+ labelText={t('occupancyStatus', 'Occupancy status')}
229
228
  onChange={(event) => setOccupancyStatus(event.target.value)}
230
229
  value={occupancyStatus}
231
230
  {...field}>
232
231
  <SelectItem text={t('chooseOccupiedStatus', 'Choose occupied status')} value="" />
233
232
  {occupancyStatuses.map((occupancyStatus, index) => (
234
233
  <SelectItem
234
+ key={`occupancyStatus-${index}`}
235
235
  text={t('occupancyStatus', `${occupancyStatus}`)}
236
236
  value={t('occupancyStatus', `${occupancyStatus}`)}
237
- key={`occupancyStatus-${index}`}
238
237
  />
239
238
  ))}
240
239
  </Select>
@@ -248,10 +247,10 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
248
247
  control={control}
249
248
  render={({ field }) => (
250
249
  <Select
250
+ defaultValue={selectedBedType}
251
251
  id="bedType"
252
- labelText={t('bedType', 'Bed type')}
253
252
  invalidText={t('required', 'Required')}
254
- defaultValue={selectedBedType}
253
+ labelText={t('bedTypes', 'Bed types')}
255
254
  {...field}>
256
255
  <SelectItem text={t('chooseBedtype', 'Choose a bed type')} />
257
256
  {availableBedTypes.map((bedType, index) => (
@@ -265,13 +264,13 @@ const BedAdministrationForm: React.FC<BedAdministrationFormProps> = ({
265
264
  </FormGroup>
266
265
  {showErrorNotification && (
267
266
  <InlineNotification
267
+ kind="error"
268
268
  lowContrast
269
- title={t('error', 'Error')}
270
- style={{ minWidth: '100%', margin: '0', padding: '0' }}
269
+ onClose={() => setShowErrorNotification(false)}
271
270
  role="alert"
272
- kind="error"
271
+ style={{ minWidth: '100%', margin: '0', padding: '0' }}
273
272
  subtitle={t('pleaseFillField', formStateError) + '.'}
274
- onClose={() => setShowErrorNotification(false)}
273
+ title={t('error', 'Error')}
275
274
  />
276
275
  )}
277
276
  </Stack>
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useMemo, useState } from 'react';
1
+ import React, { useMemo, useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import {
4
4
  Button,
@@ -21,26 +21,26 @@ import { Add, Edit } from '@carbon/react/icons';
21
21
  import { ErrorState, isDesktop as desktopLayout, useLayoutType, usePagination } from '@openmrs/esm-framework';
22
22
  import type { BedFormData } from '../types';
23
23
  import { useBedsGroupedByLocation } from '../summary/summary.resource';
24
+ import CardHeader from '../card-header/card-header.component';
24
25
  import EditBedForm from './edit-bed-form.component';
25
26
  import Header from '../header/header.component';
26
27
  import NewBedForm from './new-bed-form.component';
27
28
  import styles from './bed-administration-table.scss';
28
- import { CardHeader } from '../card-header/card-header.component';
29
29
 
30
30
  const BedAdministrationTable: React.FC = () => {
31
31
  const { t } = useTranslation();
32
- const headerTitle = t('wardAllocation', 'Ward Allocation');
32
+ const headerTitle = t('wardAllocation', 'Ward allocation');
33
33
  const layout = useLayoutType();
34
34
  const isTablet = layout === 'tablet';
35
35
  const responsiveSize = isTablet ? 'lg' : 'sm';
36
36
  const isDesktop = desktopLayout(layout);
37
37
 
38
38
  const {
39
- data: wardsGroupedByLocations,
40
- isLoading: isLoadingBeds,
41
- isValidating,
42
- mutate,
43
- error,
39
+ bedsGroupedByLocation,
40
+ isLoadingBedsGroupedByLocation,
41
+ isValidatingBedsGroupedByLocation,
42
+ mutateBedsGroupedByLocation,
43
+ errorFetchingBedsGroupedByLocation,
44
44
  } = useBedsGroupedByLocation();
45
45
  const [showAddBedModal, setShowAddBedModal] = useState(false);
46
46
  const [showEditBedModal, setShowEditBedModal] = useState(false);
@@ -71,8 +71,8 @@ const BedAdministrationTable: React.FC = () => {
71
71
  const [pageSize, setPageSize] = useState(10);
72
72
  const { results, currentPage, totalPages, goTo } = usePagination(
73
73
  filterOption === 'ALL'
74
- ? wardsGroupedByLocations
75
- : wardsGroupedByLocations.filter((bed) => bed.status === filterOption) ?? [],
74
+ ? bedsGroupedByLocation
75
+ : bedsGroupedByLocation.flat().filter((bed) => bed.status === filterOption) ?? [],
76
76
  pageSize,
77
77
  );
78
78
 
@@ -87,7 +87,7 @@ const BedAdministrationTable: React.FC = () => {
87
87
  },
88
88
  {
89
89
  key: 'occupancyStatus',
90
- header: t('occupancyStatus', 'Occupied'),
90
+ header: t('occupancyStatus', 'Occupancy status'),
91
91
  },
92
92
  {
93
93
  key: 'allocationStatus',
@@ -118,7 +118,7 @@ const BedAdministrationTable: React.FC = () => {
118
118
  setShowAddBedModal(false);
119
119
  }}
120
120
  kind={'ghost'}
121
- iconDescription={t('editBed', 'Edit Bed')}
121
+ iconDescription={t('editBed', 'Edit bed')}
122
122
  hasIconOnly
123
123
  size={responsiveSize}
124
124
  tooltipAlignment="start"
@@ -128,10 +128,10 @@ const BedAdministrationTable: React.FC = () => {
128
128
  }));
129
129
  }, [responsiveSize, results, t]);
130
130
 
131
- if (isLoadingBeds && !wardsGroupedByLocations.length) {
131
+ if (isLoadingBedsGroupedByLocation && !bedsGroupedByLocation.length) {
132
132
  return (
133
133
  <>
134
- <Header route="Ward Allocation" />
134
+ <Header title={t('wardAllocation', 'Ward allocation')} />
135
135
  <div className={styles.widgetCard}>
136
136
  <DataTableSkeleton role="progressbar" compact={isDesktop} zebra />
137
137
  </div>
@@ -139,12 +139,12 @@ const BedAdministrationTable: React.FC = () => {
139
139
  );
140
140
  }
141
141
 
142
- if (error) {
142
+ if (errorFetchingBedsGroupedByLocation) {
143
143
  return (
144
144
  <>
145
- <Header route="Ward Allocation" />
145
+ <Header title={t('wardAllocation', 'Ward allocation')} />
146
146
  <div className={styles.widgetCard}>
147
- <ErrorState error={error} headerTitle={headerTitle} />
147
+ <ErrorState error={errorFetchingBedsGroupedByLocation} headerTitle={headerTitle} />
148
148
  </div>
149
149
  </>
150
150
  );
@@ -152,7 +152,7 @@ const BedAdministrationTable: React.FC = () => {
152
152
 
153
153
  return (
154
154
  <>
155
- <Header route="Ward Allocation" />
155
+ <Header title={t('wardAllocation', 'Ward allocation')} />
156
156
  <div className={styles.flexContainer}>
157
157
  {results?.length ? (
158
158
  <div className={styles.filterContainer}>
@@ -170,19 +170,23 @@ const BedAdministrationTable: React.FC = () => {
170
170
  </div>
171
171
  <div className={styles.widgetCard}>
172
172
  {showAddBedModal ? (
173
- <NewBedForm onModalChange={setShowAddBedModal} showModal={showAddBedModal} mutate={mutate} />
173
+ <NewBedForm
174
+ mutate={mutateBedsGroupedByLocation}
175
+ onModalChange={setShowAddBedModal}
176
+ showModal={showAddBedModal}
177
+ />
174
178
  ) : null}
175
179
  {showEditBedModal ? (
176
180
  <EditBedForm
181
+ editData={editData}
182
+ mutate={mutateBedsGroupedByLocation}
177
183
  onModalChange={setShowEditBedModal}
178
184
  showModal={showEditBedModal}
179
- editData={editData}
180
- mutate={mutate}
181
185
  />
182
186
  ) : null}
183
187
  <CardHeader title={headerTitle}>
184
188
  <span className={styles.backgroundDataFetchingIndicator}>
185
- <span>{isValidating ? <InlineLoading /> : null}</span>
189
+ <span>{isValidatingBedsGroupedByLocation ? <InlineLoading /> : null}</span>
186
190
  </span>
187
191
  {results?.length ? (
188
192
  <Button
@@ -239,7 +243,7 @@ const BedAdministrationTable: React.FC = () => {
239
243
  pageNumberText="Page Number"
240
244
  pageSize={totalPages}
241
245
  pageSizes={[10, 20, 30, 40, 50]}
242
- totalItems={wardsGroupedByLocations.length}
246
+ totalItems={bedsGroupedByLocation.length}
243
247
  onChange={({ pageSize, page }) => {
244
248
  setPageSize(pageSize);
245
249
  if (page !== currentPage) {
@@ -43,7 +43,7 @@
43
43
  .backgroundDataFetchingIndicator {
44
44
  align-items: center;
45
45
  display: flex;
46
- justify-content: end;
46
+ justify-content: flex-end;
47
47
  }
48
48
 
49
49
  .tileContainer {
@@ -1,20 +1,22 @@
1
1
  export interface BedAdministrationData {
2
+ bedColumn: string;
2
3
  bedId: string;
3
- description: string;
4
4
  bedRow: string;
5
- bedColumn: string;
5
+ bedType: string;
6
+ description: string;
6
7
  location: {
7
8
  display: string;
8
9
  uuid: string;
9
10
  };
10
11
  occupancyStatus: string;
11
- bedType: string;
12
12
  }
13
+
13
14
  export interface BedTypeDataAdministration {
14
- name: string;
15
- displayName: string;
16
15
  description: string;
16
+ displayName: string;
17
+ name: string;
17
18
  }
19
+
18
20
  export interface BedTagDataAdministration {
19
21
  name: string;
20
22
  }
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react';
2
2
  import useSWR from 'swr';
3
- import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
3
+ import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
4
4
  import { type BedPostPayload } from '../types';
5
5
 
6
6
  interface BedForm {
@@ -13,16 +13,15 @@ interface BedForm {
13
13
  }
14
14
 
15
15
  export async function saveBed({ bedPayload }: { bedPayload: BedPostPayload }): Promise<FetchResponse<BedForm>> {
16
- const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed`, {
16
+ return await openmrsFetch(`${restBaseUrl}/bed`, {
17
17
  method: 'POST',
18
18
  headers: { 'Content-Type': 'application/json' },
19
19
  body: bedPayload,
20
20
  });
21
- return response;
22
21
  }
23
22
 
24
23
  export function useBedType() {
25
- const locationsUrl = `/ws/rest/v1/bedtype`;
24
+ const locationsUrl = `${restBaseUrl}/bedtype`;
26
25
  const { data, error, isLoading } = useSWR<{ data }>(locationsUrl, openmrsFetch);
27
26
 
28
27
  const bedTypes = useMemo(() => {
@@ -38,7 +37,7 @@ export function useBedType() {
38
37
  return uniqueBedTypes;
39
38
  }, [data?.data?.results]);
40
39
 
41
- return { bedTypes: bedTypes ? bedTypes : [], isLoading, error };
40
+ return { bedTypes: bedTypes ?? [], isLoading, error };
42
41
  }
43
42
 
44
43
  export async function editBed({
@@ -48,10 +47,9 @@ export async function editBed({
48
47
  bedPayload: BedPostPayload;
49
48
  bedId: string;
50
49
  }): Promise<FetchResponse<BedForm>> {
51
- const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed/${bedId}`, {
50
+ return await openmrsFetch(`${restBaseUrl}/bed/${bedId}`, {
52
51
  method: 'POST',
53
52
  headers: { 'Content-Type': 'application/json' },
54
53
  body: bedPayload,
55
54
  });
56
- return response;
57
55
  }
@@ -1,88 +1,88 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
- import { showToast, showNotification } from '@openmrs/esm-framework';
4
-
5
- import type { BedFormData } from '../types';
6
- import { useBedType, editBed } from './bed-administration.resource';
7
- import BedAdministrationForm from './bed-administration-form.component';
3
+ import { showSnackbar } from '@openmrs/esm-framework';
8
4
  import { type BedAdministrationData } from './bed-administration-types';
5
+ import { type BedFormData } from '../types';
6
+ import { editBed, useBedType } from './bed-administration.resource';
9
7
  import { useLocationsWithAdmissionTag } from '../summary/summary.resource';
8
+ import BedAdministrationForm from './bed-administration-form.component';
10
9
 
11
10
  interface EditBedFormProps {
12
- showModal: boolean;
13
- onModalChange: (showModal: boolean) => void;
14
11
  editData: BedFormData;
15
- mutate: () => any;
12
+ mutate: () => void;
13
+ onModalChange: (showModal: boolean) => void;
14
+ showModal: boolean;
16
15
  }
17
16
 
18
17
  const EditBedForm: React.FC<EditBedFormProps> = ({ showModal, onModalChange, editData, mutate }) => {
19
18
  const { t } = useTranslation();
20
- const { data: admissionLocations } = useLocationsWithAdmissionTag();
21
-
22
- const headerTitle = t('editBed', 'Edit bed');
23
- const occupancyStatuses = ['Available', 'Occupied'];
19
+ const { admissionLocations } = useLocationsWithAdmissionTag();
24
20
  const { bedTypes } = useBedType();
25
21
  const availableBedTypes = bedTypes ? bedTypes : [];
26
- const handleCreateQuestion = useCallback(
22
+ const headerTitle = t('editBed', 'Edit bed');
23
+ const occupancyStatuses = ['Available', 'Occupied'];
24
+
25
+ const handleCreateBed = useCallback(
27
26
  (formData: BedAdministrationData) => {
28
27
  const bedUuid = editData.uuid;
28
+
29
29
  const {
30
+ bedColumn = editData.column.toString(),
30
31
  bedId = editData.bedNumber,
31
- description = editData.description,
32
- occupancyStatus = editData.status,
33
32
  bedRow = editData.row.toString(),
34
- bedColumn = editData.column.toString(),
35
- location: { uuid: bedLocation = editData.location.uuid },
36
33
  bedType = editData.bedType.name,
34
+ description = editData.description,
35
+ location: { uuid: bedLocation = editData.location.uuid },
36
+ occupancyStatus = editData.status,
37
37
  } = formData;
38
+
38
39
  const bedPayload = {
39
40
  bedNumber: bedId,
40
41
  bedType,
41
- description,
42
- status: occupancyStatus.toUpperCase(),
43
- row: parseInt(bedRow),
44
42
  column: parseInt(bedColumn),
43
+ description,
45
44
  locationUuid: bedLocation,
45
+ row: parseInt(bedRow),
46
+ status: occupancyStatus.toUpperCase(),
46
47
  };
48
+
47
49
  editBed({ bedPayload, bedId: bedUuid })
48
50
  .then(() => {
49
- showToast({
50
- title: t('formSaved', 'Bed saved'),
51
+ showSnackbar({
51
52
  kind: 'success',
52
- critical: true,
53
- description: bedPayload.bedNumber + ' ' + t('saveSuccessMessage', 'was saved successfully.'),
53
+ title: t('bedUpdated', 'Bed updated'),
54
+ subtitle: t('bedUpdatedSuccessfully', `${bedPayload.bedNumber} updated successfully`, {
55
+ bedNumber: bedPayload.bedNumber,
56
+ }),
54
57
  });
55
58
 
56
59
  mutate();
57
- onModalChange(false);
58
60
  })
59
61
  .catch((error) => {
60
- showNotification({
61
- title: t('errorCreatingForm', 'Error creating bed'),
62
+ showSnackbar({
62
63
  kind: 'error',
63
- critical: true,
64
- description: error?.message,
64
+ title: t('errorCreatingForm', 'Error creating bed'),
65
+ subtitle: error?.message,
65
66
  });
67
+ })
68
+ .finally(() => {
66
69
  onModalChange(false);
67
70
  });
68
- onModalChange(false);
69
71
  },
70
- [onModalChange, mutate, editData, t],
72
+ [editData, mutate, onModalChange, t],
71
73
  );
72
74
 
73
75
  return (
74
- <>
75
- <BedAdministrationForm
76
- onModalChange={onModalChange}
77
- allLocations={admissionLocations}
78
- availableBedTypes={availableBedTypes}
79
- showModal={showModal}
80
- handleCreateQuestion={handleCreateQuestion}
81
- headerTitle={headerTitle}
82
- occupancyStatuses={occupancyStatuses}
83
- initialData={editData}
84
- />
85
- </>
76
+ <BedAdministrationForm
77
+ allLocations={admissionLocations}
78
+ availableBedTypes={availableBedTypes}
79
+ handleCreateBed={handleCreateBed}
80
+ headerTitle={headerTitle}
81
+ initialData={editData}
82
+ occupancyStatuses={occupancyStatuses}
83
+ onModalChange={onModalChange}
84
+ showModal={showModal}
85
+ />
86
86
  );
87
87
  };
88
88