@kenyaemr/esm-bed-management-app 1.0.1-pre.4 → 8.1.1-pre.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +36 -0
- package/README.md +6 -38
- package/dist/130.js +2 -0
- package/dist/{800.js.LICENSE.txt → 130.js.LICENSE.txt} +2 -0
- package/dist/130.js.map +1 -0
- package/dist/148.js +1 -0
- package/dist/148.js.map +1 -0
- package/dist/169.js +1 -0
- package/dist/169.js.map +1 -0
- package/dist/271.js +1 -0
- package/dist/319.js +1 -0
- package/dist/325.js +1 -0
- package/dist/325.js.map +1 -0
- package/dist/339.js +1 -0
- package/dist/339.js.map +1 -0
- package/dist/455.js +1 -1
- package/dist/455.js.LICENSE.txt +6 -0
- package/dist/455.js.map +1 -1
- package/dist/460.js +1 -0
- package/dist/501.js +1 -0
- package/dist/501.js.map +1 -0
- package/dist/542.js +1 -0
- package/dist/542.js.map +1 -0
- package/dist/574.js +1 -1
- package/dist/591.js +2 -0
- package/dist/{26.js.LICENSE.txt → 591.js.LICENSE.txt} +3 -3
- package/dist/591.js.map +1 -0
- package/dist/644.js +1 -0
- package/dist/757.js +1 -0
- package/dist/766.js +2 -0
- package/dist/{330.js.LICENSE.txt → 766.js.LICENSE.txt} +0 -9
- package/dist/766.js.map +1 -0
- package/dist/{294.js → 784.js} +2 -2
- package/dist/{294.js.map → 784.js.map} +1 -1
- package/dist/788.js +1 -0
- package/dist/807.js +1 -0
- package/dist/833.js +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-bed-management-app.js +1 -0
- package/dist/{esm-kenyaemr-bed-management-app.js.buildmanifest.json → openmrs-esm-bed-management-app.js.buildmanifest.json} +202 -155
- package/dist/openmrs-esm-bed-management-app.js.map +1 -0
- package/dist/routes.json +1 -1
- package/jest.config.js +3 -0
- package/package.json +25 -82
- package/src/__mocks__/react-i18next.js +18 -14
- package/src/admin-card-link.component.tsx +7 -10
- package/src/bed-administration/bed-administration-form.component.tsx +65 -99
- package/src/bed-administration/bed-administration-table.component.tsx +68 -127
- package/src/bed-administration/bed-administration-table.scss +12 -16
- package/src/bed-administration/bed-administration-types.ts +8 -0
- package/src/bed-administration/bed-administration.resource.ts +16 -18
- package/src/bed-administration/edit-bed-form.component.tsx +20 -31
- package/src/bed-administration/new-bed-form.component.tsx +28 -44
- package/src/bed-tag/bed-tag-administration-table.component.tsx +192 -0
- package/src/bed-tag/bed-tags-admin-form.component.tsx +127 -0
- package/src/bed-tag/edit-tag-form.component.tsx +72 -0
- package/src/bed-tag/new-tag-form.component.tsx +76 -0
- package/src/bed-type/bed-type-admin-form.component.tsx +166 -0
- package/src/bed-type/bed-type-administration-table.component.tsx +198 -0
- package/src/bed-type/edit-bed-type.component.tsx +72 -0
- package/src/bed-type/new-bed-type-form.component.tsx +80 -0
- package/src/card-header/card-header.component.tsx +20 -0
- package/src/card-header/card-header.scss +45 -0
- package/src/config-schema.ts +9 -17
- package/src/declarations.d.ts +5 -5
- package/src/empty-state/empty-state.component.tsx +6 -21
- package/src/empty-state/empty-state.scss +10 -10
- package/src/header/header.component.tsx +14 -23
- package/src/header/header.scss +11 -11
- package/src/header/illustration.component.tsx +3 -3
- package/src/home.component.tsx +4 -4
- package/src/index.ts +26 -40
- package/src/left-panel/left-panel.component.tsx +7 -17
- package/src/left-panel/left-panel.scss +8 -7
- package/src/left-panel-link.component.tsx +14 -24
- package/src/root.component.tsx +14 -10
- package/src/root.scss +2 -2
- package/src/routes.json +12 -2
- package/src/setup-tests.ts +1 -1
- package/src/summary/summary.component.tsx +16 -30
- package/src/summary/summary.resource.ts +169 -60
- package/src/summary/summary.scss +31 -29
- package/src/types.ts +50 -29
- package/src/ward-card/ward-card.component.tsx +5 -12
- package/src/ward-card/ward-card.scss +2 -2
- package/src/ward-with-beds/ward-with-beds.component.tsx +28 -47
- package/src/ward-with-beds/ward-with-beds.scss +5 -5
- package/translations/am.json +51 -0
- package/translations/ar.json +51 -0
- package/translations/en.json +48 -4
- package/translations/es.json +51 -0
- package/translations/fr.json +51 -0
- package/translations/he.json +51 -0
- package/translations/km.json +51 -0
- package/translations/zh.json +51 -0
- package/translations/zh_CN.json +51 -0
- package/tsconfig.json +3 -21
- package/webpack.config.js +1 -1
- package/.editorconfig +0 -12
- package/.eslintignore +0 -2
- package/.eslintrc +0 -37
- package/.husky/pre-commit +0 -4
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.prettierignore +0 -14
- package/.turbo.json +0 -18
- package/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs +0 -541
- package/.yarn/plugins/@yarnpkg/plugin-version.cjs +0 -550
- package/.yarn/versions/6816f0d4.yml +0 -0
- package/LICENSE +0 -373
- package/dist/187.js +0 -1
- package/dist/187.js.map +0 -1
- package/dist/207.js +0 -1
- package/dist/207.js.map +0 -1
- package/dist/26.js +0 -2
- package/dist/26.js.map +0 -1
- package/dist/283.js +0 -1
- package/dist/283.js.map +0 -1
- package/dist/330.js +0 -2
- package/dist/330.js.map +0 -1
- package/dist/352.js +0 -1
- package/dist/352.js.map +0 -1
- package/dist/404.js +0 -1
- package/dist/404.js.map +0 -1
- package/dist/558.js +0 -2
- package/dist/558.js.LICENSE.txt +0 -14
- package/dist/558.js.map +0 -1
- package/dist/629.js +0 -1
- package/dist/629.js.map +0 -1
- package/dist/707.js +0 -1
- package/dist/707.js.map +0 -1
- package/dist/800.js +0 -2
- package/dist/800.js.map +0 -1
- package/dist/884.js +0 -1
- package/dist/884.js.map +0 -1
- package/dist/933.js +0 -1
- package/dist/933.js.map +0 -1
- package/dist/959.js +0 -1
- package/dist/959.js.map +0 -1
- package/dist/esm-kenyaemr-bed-management-app.js +0 -1
- package/dist/esm-kenyaemr-bed-management-app.js.map +0 -1
- package/i18next-parser.config.js +0 -89
- package/src/assets/landing-page.png +0 -0
- package/src/assets/logo.svg +0 -1
- package/src/bed-admission/active-patients/active-patients-table.component.tsx +0 -299
- package/src/bed-admission/active-patients/active-visits.resource.ts +0 -171
- package/src/bed-admission/active-patients/admission-action-button-styles.scss +0 -0
- package/src/bed-admission/active-patients/admission-action-button.component.tsx +0 -26
- package/src/bed-admission/active-patients/index.tsx +0 -15
- package/src/bed-admission/active-patients/patient-queues.resource.ts +0 -136
- package/src/bed-admission/active-patients/styles.scss +0 -284
- package/src/bed-admission/active-patients/view-action-menu.component.tsx +0 -33
- package/src/bed-admission/admitted-patients/active-admissions.resource.ts +0 -121
- package/src/bed-admission/admitted-patients/admitted-patients-table.component.tsx +0 -280
- package/src/bed-admission/admitted-patients/admitted-patients.component.tsx +0 -22
- package/src/bed-admission/admitted-patients/location-combo-box.component.tsx +0 -55
- package/src/bed-admission/admitted-patients/styles.scss +0 -284
- package/src/bed-admission/bed-admission-tabs-styles.scss +0 -30
- package/src/bed-admission/bed-admission-tabs.component.tsx +0 -69
- package/src/bed-admission/bed-admission.component.tsx +0 -15
- package/src/bed-admission/bed-admission.resource.ts +0 -35
- package/src/bed-admission/bed-layout/bed-layout-list.component.tsx +0 -101
- package/src/bed-admission/bed-layout/bed-layout.component.tsx +0 -64
- package/src/bed-admission/bed-layout/bed-layout.scss +0 -118
- package/src/bed-admission/bed-layout/min-bed-layout.component.tsx +0 -26
- package/src/bed-admission/createDashboardLink.tsx +0 -47
- package/src/bed-admission/discharged-patients/discharged-patients.componet.tsx +0 -19
- package/src/bed-admission/helpers/functions.ts +0 -102
- package/src/bed-admission/types.ts +0 -133
- package/src/workspace/allocate-bed-workspace.component.tsx +0 -141
- package/src/workspace/allocate-bed.scss +0 -117
- package/src/workspace/overlay.component.tsx +0 -55
- package/src/workspace/overlay.scss +0 -96
- /package/dist/{294.js.LICENSE.txt → 784.js.LICENSE.txt} +0 -0
|
@@ -1,61 +1,45 @@
|
|
|
1
|
-
import React, { useCallback } from
|
|
2
|
-
import { useTranslation } from
|
|
3
|
-
import { showToast, showNotification
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { showToast, showNotification } from '@openmrs/esm-framework';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import { useBedType, saveBed } from
|
|
7
|
-
import BedAdministrationForm from
|
|
8
|
-
import {
|
|
9
|
-
import { BedAdministrationData } from
|
|
5
|
+
import type { BedFormData } from '../types';
|
|
6
|
+
import { useBedType, saveBed } from './bed-administration.resource';
|
|
7
|
+
import BedAdministrationForm from './bed-administration-form.component';
|
|
8
|
+
import { useLocationsWithAdmissionTag } from '../summary/summary.resource';
|
|
9
|
+
import { type BedAdministrationData } from './bed-administration-types';
|
|
10
10
|
|
|
11
11
|
interface NewBedFormProps {
|
|
12
12
|
showModal: boolean;
|
|
13
13
|
onModalChange: (showModal: boolean) => void;
|
|
14
|
-
mutate:
|
|
14
|
+
mutate: () => any;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const NewBedForm: React.FC<NewBedFormProps> = ({
|
|
18
|
-
showModal,
|
|
19
|
-
onModalChange,
|
|
20
|
-
mutate,
|
|
21
|
-
}) => {
|
|
17
|
+
const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutate }) => {
|
|
22
18
|
const { t } = useTranslation();
|
|
23
|
-
const {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
);
|
|
27
|
-
const headerTitle = t("createNewBed", "Create a new bed");
|
|
28
|
-
const occupancyStatuses = ["Available", "Occupied"];
|
|
19
|
+
const { data: admissionLocations } = useLocationsWithAdmissionTag();
|
|
20
|
+
const headerTitle = t('createNewBed', 'Create a new bed');
|
|
21
|
+
const occupancyStatuses = ['Available', 'Occupied'];
|
|
29
22
|
const { bedTypes } = useBedType();
|
|
30
23
|
const availableBedTypes = bedTypes ? bedTypes : [];
|
|
31
24
|
|
|
32
|
-
const initialData:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
const initialData: BedFormData = {
|
|
26
|
+
id: 0,
|
|
27
|
+
uuid: '',
|
|
28
|
+
bedNumber: '',
|
|
29
|
+
status: null,
|
|
30
|
+
description: '',
|
|
37
31
|
row: 0,
|
|
38
32
|
column: 0,
|
|
39
33
|
location: {
|
|
40
|
-
display:
|
|
41
|
-
uuid:
|
|
42
|
-
},
|
|
43
|
-
bedType: {
|
|
44
|
-
name: "",
|
|
34
|
+
display: '',
|
|
35
|
+
uuid: '',
|
|
45
36
|
},
|
|
37
|
+
bedType: null,
|
|
46
38
|
};
|
|
47
39
|
|
|
48
40
|
const handleCreateQuestion = useCallback(
|
|
49
41
|
(formData: BedAdministrationData) => {
|
|
50
|
-
const {
|
|
51
|
-
bedId,
|
|
52
|
-
description,
|
|
53
|
-
occupancyStatus,
|
|
54
|
-
bedRow,
|
|
55
|
-
bedColumn,
|
|
56
|
-
location,
|
|
57
|
-
bedType,
|
|
58
|
-
} = formData;
|
|
42
|
+
const { bedId, description, occupancyStatus, bedRow, bedColumn, location, bedType } = formData;
|
|
59
43
|
|
|
60
44
|
const bedObject = {
|
|
61
45
|
bedNumber: bedId,
|
|
@@ -70,8 +54,8 @@ const NewBedForm: React.FC<NewBedFormProps> = ({
|
|
|
70
54
|
saveBed({ bedPayload: bedObject })
|
|
71
55
|
.then(() => {
|
|
72
56
|
showToast({
|
|
73
|
-
title: t(
|
|
74
|
-
kind:
|
|
57
|
+
title: t('formCreated', 'New bed created'),
|
|
58
|
+
kind: 'success',
|
|
75
59
|
critical: true,
|
|
76
60
|
description: `Bed ${bedId} was created successfully.`,
|
|
77
61
|
});
|
|
@@ -81,8 +65,8 @@ const NewBedForm: React.FC<NewBedFormProps> = ({
|
|
|
81
65
|
})
|
|
82
66
|
.catch((error) => {
|
|
83
67
|
showNotification({
|
|
84
|
-
title: t(
|
|
85
|
-
kind:
|
|
68
|
+
title: t('errorCreatingForm', 'Error creating bed'),
|
|
69
|
+
kind: 'error',
|
|
86
70
|
critical: true,
|
|
87
71
|
description: error?.message,
|
|
88
72
|
});
|
|
@@ -90,7 +74,7 @@ const NewBedForm: React.FC<NewBedFormProps> = ({
|
|
|
90
74
|
});
|
|
91
75
|
onModalChange(false);
|
|
92
76
|
},
|
|
93
|
-
[onModalChange, mutate, t]
|
|
77
|
+
[onModalChange, mutate, t],
|
|
94
78
|
);
|
|
95
79
|
|
|
96
80
|
return (
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
DataTable,
|
|
6
|
+
DataTableSkeleton,
|
|
7
|
+
InlineLoading,
|
|
8
|
+
Pagination,
|
|
9
|
+
Table,
|
|
10
|
+
TableBody,
|
|
11
|
+
TableCell,
|
|
12
|
+
TableContainer,
|
|
13
|
+
TableHead,
|
|
14
|
+
TableHeader,
|
|
15
|
+
TableRow,
|
|
16
|
+
Tile,
|
|
17
|
+
} from '@carbon/react';
|
|
18
|
+
import { Add, Edit } from '@carbon/react/icons';
|
|
19
|
+
import { ErrorState, isDesktop as desktopLayout, useLayoutType } from '@openmrs/esm-framework';
|
|
20
|
+
import type { BedTagData } from '../types';
|
|
21
|
+
import { useBedTag } from '../summary/summary.resource';
|
|
22
|
+
import Header from '../header/header.component';
|
|
23
|
+
import styles from '../bed-administration/bed-administration-table.scss';
|
|
24
|
+
import { CardHeader } from '../card-header/card-header.component';
|
|
25
|
+
import BedTagForm from './new-tag-form.component';
|
|
26
|
+
import EditBedTagForm from './edit-tag-form.component';
|
|
27
|
+
|
|
28
|
+
const BedTagAdministrationTable: React.FC = () => {
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
const headerTitle = t('bedTag', 'Bed Tag');
|
|
31
|
+
const layout = useLayoutType();
|
|
32
|
+
const isTablet = layout === 'tablet';
|
|
33
|
+
const responsiveSize = isTablet ? 'lg' : 'sm';
|
|
34
|
+
const isDesktop = desktopLayout(layout);
|
|
35
|
+
const [isBedDataLoading] = useState(false);
|
|
36
|
+
const [showBedTagsModal, setAddBedTagsModal] = useState(false);
|
|
37
|
+
const [showEditBedModal, setShowEditBedModal] = useState(false);
|
|
38
|
+
const [editData, setEditData] = useState<BedTagData>();
|
|
39
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
40
|
+
const { bedTypeData, isError, loading, validate, mutate } = useBedTag();
|
|
41
|
+
const [pageSize, setPageSize] = useState(10);
|
|
42
|
+
|
|
43
|
+
const tableHeaders = [
|
|
44
|
+
{
|
|
45
|
+
header: t('ids', 'Id'),
|
|
46
|
+
key: 'ids',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
header: t('name', 'Name'),
|
|
50
|
+
key: 'name',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
header: t('actions', 'Actions'),
|
|
54
|
+
key: 'actions',
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const tableRows = useMemo(() => {
|
|
59
|
+
return bedTypeData?.map((entry) => ({
|
|
60
|
+
id: entry.uuid,
|
|
61
|
+
ids: entry.id,
|
|
62
|
+
name: entry?.name,
|
|
63
|
+
actions: (
|
|
64
|
+
<>
|
|
65
|
+
<Button
|
|
66
|
+
enterDelayMs={300}
|
|
67
|
+
renderIcon={Edit}
|
|
68
|
+
onClick={(e) => {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
setEditData(entry);
|
|
71
|
+
setShowEditBedModal(true);
|
|
72
|
+
setAddBedTagsModal(false);
|
|
73
|
+
}}
|
|
74
|
+
kind={'ghost'}
|
|
75
|
+
iconDescription={t('editBedTag', 'Edit Bed Tag')}
|
|
76
|
+
hasIconOnly
|
|
77
|
+
size={responsiveSize}
|
|
78
|
+
tooltipAlignment="start"
|
|
79
|
+
/>
|
|
80
|
+
</>
|
|
81
|
+
),
|
|
82
|
+
}));
|
|
83
|
+
}, [responsiveSize, bedTypeData, t]);
|
|
84
|
+
|
|
85
|
+
if (isBedDataLoading || loading) {
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<Header route="Bed Tag" />
|
|
89
|
+
<div className={styles.widgetCard}>
|
|
90
|
+
<DataTableSkeleton role="progressbar" compact={isDesktop} zebra />
|
|
91
|
+
</div>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (isError) {
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<Header route="Bed Tag" />
|
|
100
|
+
<div className={styles.widgetCard}>
|
|
101
|
+
<ErrorState error={isError} headerTitle={headerTitle} />
|
|
102
|
+
</div>
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<Header route="Bed Tag" />
|
|
110
|
+
|
|
111
|
+
<div className={styles.widgetCard}>
|
|
112
|
+
{showBedTagsModal ? (
|
|
113
|
+
<BedTagForm onModalChange={setAddBedTagsModal} showModal={showBedTagsModal} mutate={mutate} />
|
|
114
|
+
) : null}
|
|
115
|
+
{showEditBedModal ? (
|
|
116
|
+
<EditBedTagForm
|
|
117
|
+
onModalChange={setShowEditBedModal}
|
|
118
|
+
showModal={showEditBedModal}
|
|
119
|
+
editData={editData}
|
|
120
|
+
mutate={mutate}
|
|
121
|
+
/>
|
|
122
|
+
) : null}
|
|
123
|
+
<CardHeader title={headerTitle}>
|
|
124
|
+
<span className={styles.backgroundDataFetchingIndicator}>
|
|
125
|
+
<span>{validate ? <InlineLoading /> : null}</span>
|
|
126
|
+
</span>
|
|
127
|
+
{bedTypeData?.length ? (
|
|
128
|
+
<Button
|
|
129
|
+
kind="ghost"
|
|
130
|
+
renderIcon={(props) => <Add size={16} {...props} />}
|
|
131
|
+
onClick={() => setAddBedTagsModal(true)}>
|
|
132
|
+
{t('addBedTag', 'Add Bed Tag')}
|
|
133
|
+
</Button>
|
|
134
|
+
) : null}
|
|
135
|
+
</CardHeader>
|
|
136
|
+
<DataTable rows={tableRows} headers={tableHeaders} isSortable size={isTablet ? 'lg' : 'sm'} useZebraStyles>
|
|
137
|
+
{({ rows, headers, getTableProps }) => (
|
|
138
|
+
<TableContainer>
|
|
139
|
+
<Table {...getTableProps()}>
|
|
140
|
+
<TableHead>
|
|
141
|
+
<TableRow>
|
|
142
|
+
{headers.map((header) => (
|
|
143
|
+
<TableHeader>{header.header?.content ?? header.header}</TableHeader>
|
|
144
|
+
))}
|
|
145
|
+
</TableRow>
|
|
146
|
+
</TableHead>
|
|
147
|
+
<TableBody>
|
|
148
|
+
{rows.map((row) => (
|
|
149
|
+
<TableRow key={row.id}>
|
|
150
|
+
{row.cells.map((cell) => (
|
|
151
|
+
<TableCell key={cell.id}>{cell.value?.content ?? cell.value}</TableCell>
|
|
152
|
+
))}
|
|
153
|
+
</TableRow>
|
|
154
|
+
))}
|
|
155
|
+
</TableBody>
|
|
156
|
+
</Table>
|
|
157
|
+
{rows.length === 0 ? (
|
|
158
|
+
<div className={styles.tileContainer}>
|
|
159
|
+
<Tile className={styles.tile}>
|
|
160
|
+
<div className={styles.tileContent}>
|
|
161
|
+
<p className={styles.content}>{t('No data', 'No data to display')}</p>
|
|
162
|
+
<p className={styles.helper}>{t('checkFilters', 'Check the filters above')}</p>
|
|
163
|
+
</div>
|
|
164
|
+
<p className={styles.separator}>{t('or', 'or')}</p>
|
|
165
|
+
<Button
|
|
166
|
+
kind="ghost"
|
|
167
|
+
size="sm"
|
|
168
|
+
renderIcon={(props) => <Add size={16} {...props} />}
|
|
169
|
+
onClick={() => setAddBedTagsModal(true)}>
|
|
170
|
+
{t('bedTag', 'Add Bed Tag')}
|
|
171
|
+
</Button>
|
|
172
|
+
</Tile>
|
|
173
|
+
</div>
|
|
174
|
+
) : null}
|
|
175
|
+
<Pagination
|
|
176
|
+
page={currentPage}
|
|
177
|
+
pageSize={pageSize}
|
|
178
|
+
pageSizes={[10, 20, 30, 40, 50]}
|
|
179
|
+
totalItems={bedTypeData.length}
|
|
180
|
+
onChange={({ page, pageSize }) => {
|
|
181
|
+
setCurrentPage(page);
|
|
182
|
+
setPageSize(pageSize);
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
</TableContainer>
|
|
186
|
+
)}
|
|
187
|
+
</DataTable>
|
|
188
|
+
</div>
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
export default BedTagAdministrationTable;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { useForm, Controller } from 'react-hook-form';
|
|
4
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
ComposedModal,
|
|
8
|
+
Form,
|
|
9
|
+
FormGroup,
|
|
10
|
+
ModalBody,
|
|
11
|
+
ModalFooter,
|
|
12
|
+
ModalHeader,
|
|
13
|
+
Stack,
|
|
14
|
+
TextInput,
|
|
15
|
+
InlineNotification,
|
|
16
|
+
} from '@carbon/react';
|
|
17
|
+
import { useTranslation } from 'react-i18next';
|
|
18
|
+
import { getCoreTranslation, type Location } from '@openmrs/esm-framework';
|
|
19
|
+
import type { BedTagData } from '../types';
|
|
20
|
+
|
|
21
|
+
const BedTagAdministrationSchema = z.object({
|
|
22
|
+
name: z.string().max(255),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
interface BedTagAdministrationFormProps {
|
|
26
|
+
showModal: boolean;
|
|
27
|
+
onModalChange: (showModal: boolean) => void;
|
|
28
|
+
availableBedTypes: Array<BedTagData>;
|
|
29
|
+
allLocations: Location[];
|
|
30
|
+
handleCreateQuestion?: (formData: BedTagData) => void;
|
|
31
|
+
handleDeleteBedTag?: () => void;
|
|
32
|
+
headerTitle: string;
|
|
33
|
+
initialData: BedTagData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ErrorType {
|
|
37
|
+
message: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const BedTagsAdministrationForm: React.FC<BedTagAdministrationFormProps> = ({
|
|
41
|
+
showModal,
|
|
42
|
+
onModalChange,
|
|
43
|
+
handleCreateQuestion,
|
|
44
|
+
headerTitle,
|
|
45
|
+
initialData,
|
|
46
|
+
}) => {
|
|
47
|
+
const { t } = useTranslation();
|
|
48
|
+
|
|
49
|
+
const [showErrorNotification, setShowErrorNotification] = useState(false);
|
|
50
|
+
const [formStateError, setFormStateError] = useState('');
|
|
51
|
+
|
|
52
|
+
const {
|
|
53
|
+
handleSubmit,
|
|
54
|
+
control,
|
|
55
|
+
formState: { isDirty },
|
|
56
|
+
} = useForm<BedTagData>({
|
|
57
|
+
mode: 'all',
|
|
58
|
+
resolver: zodResolver(BedTagAdministrationSchema),
|
|
59
|
+
defaultValues: {
|
|
60
|
+
name: initialData.name || '',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const onSubmit = (formData: BedTagData) => {
|
|
65
|
+
const result = BedTagAdministrationSchema.safeParse(formData);
|
|
66
|
+
if (result.success) {
|
|
67
|
+
setShowErrorNotification(false);
|
|
68
|
+
handleCreateQuestion(formData);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const onError = (error: { [key: string]: ErrorType }) => {
|
|
73
|
+
setFormStateError(Object.entries(error)[0][1].message);
|
|
74
|
+
setShowErrorNotification(true);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
|
|
79
|
+
<ModalHeader title={headerTitle} />
|
|
80
|
+
<ModalBody hasScrollingContent>
|
|
81
|
+
<Form>
|
|
82
|
+
<Stack gap={3}>
|
|
83
|
+
<FormGroup legendText={''}>
|
|
84
|
+
<Controller
|
|
85
|
+
name="name"
|
|
86
|
+
control={control}
|
|
87
|
+
render={({ field, fieldState }) => (
|
|
88
|
+
<>
|
|
89
|
+
<TextInput
|
|
90
|
+
id="bedTag"
|
|
91
|
+
labelText={t('bedTag', 'Bed Tag Name')}
|
|
92
|
+
placeholder={t('bedTagPlaceholder', '')}
|
|
93
|
+
invalidText={fieldState.error?.message}
|
|
94
|
+
{...field}
|
|
95
|
+
/>
|
|
96
|
+
</>
|
|
97
|
+
)}
|
|
98
|
+
/>
|
|
99
|
+
</FormGroup>
|
|
100
|
+
|
|
101
|
+
{showErrorNotification && (
|
|
102
|
+
<InlineNotification
|
|
103
|
+
lowContrast
|
|
104
|
+
title={t('error', 'Error')}
|
|
105
|
+
style={{ minWidth: '100%', margin: '0', padding: '0' }}
|
|
106
|
+
role="alert"
|
|
107
|
+
kind="error"
|
|
108
|
+
subtitle={t('pleaseFillField', formStateError) + '.'}
|
|
109
|
+
onClose={() => setShowErrorNotification(false)}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</Stack>
|
|
113
|
+
</Form>
|
|
114
|
+
</ModalBody>
|
|
115
|
+
<ModalFooter>
|
|
116
|
+
<Button onClick={() => onModalChange(false)} kind="secondary">
|
|
117
|
+
{getCoreTranslation('cancel', 'Cancel')}
|
|
118
|
+
</Button>
|
|
119
|
+
<Button disabled={!isDirty} onClick={handleSubmit(onSubmit, onError)}>
|
|
120
|
+
<span>{t('save', 'Save')}</span>
|
|
121
|
+
</Button>
|
|
122
|
+
</ModalFooter>
|
|
123
|
+
</ComposedModal>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default BedTagsAdministrationForm;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { showToast, showNotification, useConfig } from '@openmrs/esm-framework';
|
|
4
|
+
|
|
5
|
+
import { editBedTag, useBedTag } from '../summary/summary.resource';
|
|
6
|
+
import { type BedTagDataAdministration } from '../bed-administration/bed-administration-types';
|
|
7
|
+
import BedTagsAdministrationForm from './bed-tags-admin-form.component';
|
|
8
|
+
import { type BedTagData, type Mutator } from '../types';
|
|
9
|
+
|
|
10
|
+
interface EditBedTagFormProps {
|
|
11
|
+
showModal: boolean;
|
|
12
|
+
onModalChange: (showModal: boolean) => void;
|
|
13
|
+
editData: BedTagData;
|
|
14
|
+
mutate: Mutator;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const EditBedTagForm: React.FC<EditBedTagFormProps> = ({ showModal, onModalChange, editData, mutate }) => {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
|
|
20
|
+
const headerTitle = t('editBed', 'Edit Tag');
|
|
21
|
+
const { bedTypeData } = useBedTag();
|
|
22
|
+
const availableBedTypes = bedTypeData ? bedTypeData : [];
|
|
23
|
+
|
|
24
|
+
const handleCreateQuestion = useCallback(
|
|
25
|
+
(formData: BedTagDataAdministration) => {
|
|
26
|
+
const bedUuid = editData.uuid;
|
|
27
|
+
const { name } = formData;
|
|
28
|
+
const bedTagPayload = {
|
|
29
|
+
name,
|
|
30
|
+
};
|
|
31
|
+
editBedTag({ bedTagPayload, bedTagId: bedUuid })
|
|
32
|
+
.then(() => {
|
|
33
|
+
showToast({
|
|
34
|
+
title: t('formSaved', 'Bed Tag'),
|
|
35
|
+
kind: 'success',
|
|
36
|
+
critical: true,
|
|
37
|
+
description: bedTagPayload.name + ' ' + t('saveSuccessMessage', 'was saved successfully.'),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
mutate();
|
|
41
|
+
onModalChange(false);
|
|
42
|
+
})
|
|
43
|
+
.catch((error) => {
|
|
44
|
+
showNotification({
|
|
45
|
+
title: t('errorCreatingForm', 'Error creating bed'),
|
|
46
|
+
kind: 'error',
|
|
47
|
+
critical: true,
|
|
48
|
+
description: error?.message,
|
|
49
|
+
});
|
|
50
|
+
onModalChange(false);
|
|
51
|
+
});
|
|
52
|
+
onModalChange(false);
|
|
53
|
+
},
|
|
54
|
+
[onModalChange, mutate, editData, t],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
<BedTagsAdministrationForm
|
|
60
|
+
onModalChange={onModalChange}
|
|
61
|
+
availableBedTypes={availableBedTypes}
|
|
62
|
+
showModal={showModal}
|
|
63
|
+
handleCreateQuestion={handleCreateQuestion}
|
|
64
|
+
headerTitle={headerTitle}
|
|
65
|
+
initialData={editData}
|
|
66
|
+
allLocations={[]}
|
|
67
|
+
/>
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default EditBedTagForm;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { showToast, showNotification, useConfig } from '@openmrs/esm-framework';
|
|
4
|
+
import { useBedType } from '../bed-administration/bed-administration.resource';
|
|
5
|
+
import BedTagsAdministrationForm from './bed-tags-admin-form.component';
|
|
6
|
+
import { saveBedTag, useLocationsWithAdmissionTag } from '../summary/summary.resource';
|
|
7
|
+
import { type BedTagData, type Mutator } from '../types';
|
|
8
|
+
|
|
9
|
+
interface BedTagFormProps {
|
|
10
|
+
showModal: boolean;
|
|
11
|
+
onModalChange: (showModal: boolean) => void;
|
|
12
|
+
mutate: () => any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const NewTagForm: React.FC<BedTagFormProps> = ({ showModal, onModalChange, mutate }) => {
|
|
16
|
+
const { t } = useTranslation();
|
|
17
|
+
const { data: admissionLocations } = useLocationsWithAdmissionTag();
|
|
18
|
+
const headerTitle = t('addBedTag', 'Create Bed Tag');
|
|
19
|
+
const { bedTypes } = useBedType();
|
|
20
|
+
const availableBedTypes = bedTypes ? bedTypes : [];
|
|
21
|
+
|
|
22
|
+
const initialData: BedTagData = {
|
|
23
|
+
uuid: '',
|
|
24
|
+
name: '',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const handleCreateQuestion = useCallback(
|
|
28
|
+
(formData: BedTagData) => {
|
|
29
|
+
const { name } = formData;
|
|
30
|
+
|
|
31
|
+
const bedTagPayload = {
|
|
32
|
+
name,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
saveBedTag({ bedTagPayload })
|
|
36
|
+
.then(() => {
|
|
37
|
+
showToast({
|
|
38
|
+
title: t('formCreated', 'Add Bed Tag'),
|
|
39
|
+
kind: 'success',
|
|
40
|
+
critical: true,
|
|
41
|
+
description: `Tag ${name} was created successfully.`,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
mutate();
|
|
45
|
+
onModalChange(false);
|
|
46
|
+
})
|
|
47
|
+
.catch((error) => {
|
|
48
|
+
showNotification({
|
|
49
|
+
title: t('errorCreatingForm', 'Error creating bed'),
|
|
50
|
+
kind: 'error',
|
|
51
|
+
critical: true,
|
|
52
|
+
description: error?.message,
|
|
53
|
+
});
|
|
54
|
+
onModalChange(false);
|
|
55
|
+
});
|
|
56
|
+
onModalChange(false);
|
|
57
|
+
},
|
|
58
|
+
[onModalChange, mutate, t],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<BedTagsAdministrationForm
|
|
64
|
+
onModalChange={onModalChange}
|
|
65
|
+
allLocations={admissionLocations}
|
|
66
|
+
availableBedTypes={availableBedTypes}
|
|
67
|
+
showModal={showModal}
|
|
68
|
+
handleCreateQuestion={handleCreateQuestion}
|
|
69
|
+
headerTitle={headerTitle}
|
|
70
|
+
initialData={initialData}
|
|
71
|
+
/>
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default NewTagForm;
|