@openmrs/esm-bed-management-app 7.1.1-pre.3735
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 +35 -0
- package/README.md +8 -0
- package/dist/130.js +2 -0
- package/dist/130.js.LICENSE.txt +3 -0
- package/dist/130.js.map +1 -0
- package/dist/169.js +1 -0
- package/dist/169.js.map +1 -0
- package/dist/391.js +2 -0
- package/dist/391.js.LICENSE.txt +15 -0
- package/dist/391.js.map +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 -0
- package/dist/591.js +2 -0
- package/dist/591.js.LICENSE.txt +32 -0
- package/dist/591.js.map +1 -0
- package/dist/596.js +1 -0
- package/dist/596.js.map +1 -0
- package/dist/642.js +1 -0
- package/dist/642.js.map +1 -0
- package/dist/729.js +1 -0
- package/dist/729.js.map +1 -0
- package/dist/784.js +2 -0
- package/dist/784.js.LICENSE.txt +9 -0
- package/dist/784.js.map +1 -0
- package/dist/878.js +2 -0
- package/dist/878.js.LICENSE.txt +35 -0
- package/dist/878.js.map +1 -0
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -0
- package/dist/openmrs-esm-bed-management-app.js +1 -0
- package/dist/openmrs-esm-bed-management-app.js.buildmanifest.json +403 -0
- package/dist/openmrs-esm-bed-management-app.js.map +1 -0
- package/dist/routes.json +1 -0
- package/jest.config.js +3 -0
- package/package.json +55 -0
- package/src/__mocks__/react-i18next.js +50 -0
- package/src/admin-card-link.component.tsx +24 -0
- package/src/bed-administration/bed-administration-form.component.tsx +292 -0
- package/src/bed-administration/bed-administration-form.scss +0 -0
- package/src/bed-administration/bed-administration-table.component.tsx +258 -0
- package/src/bed-administration/bed-administration-table.scss +111 -0
- package/src/bed-administration/bed-administration-types.ts +20 -0
- package/src/bed-administration/bed-administration.resource.ts +57 -0
- package/src/bed-administration/edit-bed-form.component.tsx +89 -0
- package/src/bed-administration/new-bed-form.component.tsx +96 -0
- 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 +13 -0
- package/src/declarations.d.ts +7 -0
- package/src/empty-state/empty-state.component.tsx +54 -0
- package/src/empty-state/empty-state.scss +62 -0
- package/src/header/header.component.tsx +42 -0
- package/src/header/header.scss +72 -0
- package/src/header/illustration.component.tsx +13 -0
- package/src/home.component.tsx +15 -0
- package/src/home.scss +5 -0
- package/src/index.ts +51 -0
- package/src/left-panel/left-panel.component.tsx +23 -0
- package/src/left-panel/left-panel.scss +41 -0
- package/src/left-panel-link.component.tsx +39 -0
- package/src/root.component.tsx +39 -0
- package/src/root.scss +11 -0
- package/src/routes.json +56 -0
- package/src/setup-tests.ts +1 -0
- package/src/summary/summary.component.tsx +60 -0
- package/src/summary/summary.resource.ts +232 -0
- package/src/summary/summary.scss +74 -0
- package/src/types.ts +173 -0
- package/src/ward-card/ward-card.component.tsx +34 -0
- package/src/ward-card/ward-card.scss +51 -0
- package/src/ward-with-beds/ward-with-beds.component.tsx +167 -0
- package/src/ward-with-beds/ward-with-beds.scss +27 -0
- package/translations/en.json +52 -0
- package/tsconfig.json +5 -0
- package/webpack.config.js +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import useSWR from 'swr';
|
|
3
|
+
import { type FetchResponse, openmrsFetch } from '@openmrs/esm-framework';
|
|
4
|
+
import { type BedPostPayload } from '../types';
|
|
5
|
+
|
|
6
|
+
interface BedForm {
|
|
7
|
+
bedNumber: string;
|
|
8
|
+
bedType: string;
|
|
9
|
+
row: number;
|
|
10
|
+
column: number;
|
|
11
|
+
status: string;
|
|
12
|
+
locationUuid: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function saveBed({ bedPayload }: { bedPayload: BedPostPayload }): Promise<FetchResponse<BedForm>> {
|
|
16
|
+
const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed`, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: bedPayload,
|
|
20
|
+
});
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function useBedType() {
|
|
25
|
+
const locationsUrl = `/ws/rest/v1/bedtype`;
|
|
26
|
+
const { data, error, isLoading } = useSWR<{ data }>(locationsUrl, openmrsFetch);
|
|
27
|
+
|
|
28
|
+
const bedTypes = useMemo(() => {
|
|
29
|
+
const rawData = data?.data?.results ?? [];
|
|
30
|
+
const uniqueBedTypes = [];
|
|
31
|
+
|
|
32
|
+
rawData.forEach((response) => {
|
|
33
|
+
if (!uniqueBedTypes.some((bedType) => bedType.name === response.name)) {
|
|
34
|
+
uniqueBedTypes.push(response);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return uniqueBedTypes;
|
|
39
|
+
}, [data?.data?.results]);
|
|
40
|
+
|
|
41
|
+
return { bedTypes: bedTypes ? bedTypes : [], isLoading, error };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function editBed({
|
|
45
|
+
bedPayload,
|
|
46
|
+
bedId,
|
|
47
|
+
}: {
|
|
48
|
+
bedPayload: BedPostPayload;
|
|
49
|
+
bedId: string;
|
|
50
|
+
}): Promise<FetchResponse<BedForm>> {
|
|
51
|
+
const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bed/${bedId}`, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
body: bedPayload,
|
|
55
|
+
});
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
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';
|
|
8
|
+
import { type BedAdministrationData } from './bed-administration-types';
|
|
9
|
+
import { useLocationsWithAdmissionTag } from '../summary/summary.resource';
|
|
10
|
+
|
|
11
|
+
interface EditBedFormProps {
|
|
12
|
+
showModal: boolean;
|
|
13
|
+
onModalChange: (showModal: boolean) => void;
|
|
14
|
+
editData: BedFormData;
|
|
15
|
+
mutate: () => any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const EditBedForm: React.FC<EditBedFormProps> = ({ showModal, onModalChange, editData, mutate }) => {
|
|
19
|
+
const { t } = useTranslation();
|
|
20
|
+
const { data: admissionLocations } = useLocationsWithAdmissionTag();
|
|
21
|
+
|
|
22
|
+
const headerTitle = t('editBed', 'Edit bed');
|
|
23
|
+
const occupancyStatuses = ['Available', 'Occupied'];
|
|
24
|
+
const { bedTypes } = useBedType();
|
|
25
|
+
const availableBedTypes = bedTypes ? bedTypes : [];
|
|
26
|
+
const handleCreateQuestion = useCallback(
|
|
27
|
+
(formData: BedAdministrationData) => {
|
|
28
|
+
const bedUuid = editData.uuid;
|
|
29
|
+
const {
|
|
30
|
+
bedId = editData.bedNumber,
|
|
31
|
+
description = editData.description,
|
|
32
|
+
occupancyStatus = editData.status,
|
|
33
|
+
bedRow = editData.row.toString(),
|
|
34
|
+
bedColumn = editData.column.toString(),
|
|
35
|
+
location: { uuid: bedLocation = editData.location.uuid },
|
|
36
|
+
bedType = editData.bedType.name,
|
|
37
|
+
} = formData;
|
|
38
|
+
const bedPayload = {
|
|
39
|
+
bedNumber: bedId,
|
|
40
|
+
bedType,
|
|
41
|
+
description,
|
|
42
|
+
status: occupancyStatus.toUpperCase(),
|
|
43
|
+
row: parseInt(bedRow),
|
|
44
|
+
column: parseInt(bedColumn),
|
|
45
|
+
locationUuid: bedLocation,
|
|
46
|
+
};
|
|
47
|
+
editBed({ bedPayload, bedId: bedUuid })
|
|
48
|
+
.then(() => {
|
|
49
|
+
showToast({
|
|
50
|
+
title: t('formSaved', 'Bed saved'),
|
|
51
|
+
kind: 'success',
|
|
52
|
+
critical: true,
|
|
53
|
+
description: bedPayload.bedNumber + ' ' + t('saveSuccessMessage', 'was saved successfully.'),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
mutate();
|
|
57
|
+
onModalChange(false);
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
showNotification({
|
|
61
|
+
title: t('errorCreatingForm', 'Error creating bed'),
|
|
62
|
+
kind: 'error',
|
|
63
|
+
critical: true,
|
|
64
|
+
description: error?.message,
|
|
65
|
+
});
|
|
66
|
+
onModalChange(false);
|
|
67
|
+
});
|
|
68
|
+
onModalChange(false);
|
|
69
|
+
},
|
|
70
|
+
[onModalChange, mutate, editData, t],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
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
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default EditBedForm;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { showToast, showNotification } from '@openmrs/esm-framework';
|
|
4
|
+
|
|
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
|
+
|
|
11
|
+
interface NewBedFormProps {
|
|
12
|
+
showModal: boolean;
|
|
13
|
+
onModalChange: (showModal: boolean) => void;
|
|
14
|
+
mutate: () => any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const NewBedForm: React.FC<NewBedFormProps> = ({ showModal, onModalChange, mutate }) => {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const { data: admissionLocations } = useLocationsWithAdmissionTag();
|
|
20
|
+
const headerTitle = t('createNewBed', 'Create a new bed');
|
|
21
|
+
const occupancyStatuses = ['Available', 'Occupied'];
|
|
22
|
+
const { bedTypes } = useBedType();
|
|
23
|
+
const availableBedTypes = bedTypes ? bedTypes : [];
|
|
24
|
+
|
|
25
|
+
const initialData: BedFormData = {
|
|
26
|
+
id: 0,
|
|
27
|
+
uuid: '',
|
|
28
|
+
bedNumber: '',
|
|
29
|
+
status: null,
|
|
30
|
+
description: '',
|
|
31
|
+
row: 0,
|
|
32
|
+
column: 0,
|
|
33
|
+
location: {
|
|
34
|
+
display: '',
|
|
35
|
+
uuid: '',
|
|
36
|
+
},
|
|
37
|
+
bedType: null,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleCreateQuestion = useCallback(
|
|
41
|
+
(formData: BedAdministrationData) => {
|
|
42
|
+
const { bedId, description, occupancyStatus, bedRow, bedColumn, location, bedType } = formData;
|
|
43
|
+
|
|
44
|
+
const bedObject = {
|
|
45
|
+
bedNumber: bedId,
|
|
46
|
+
bedType,
|
|
47
|
+
description,
|
|
48
|
+
status: occupancyStatus.toUpperCase(),
|
|
49
|
+
row: parseInt(bedRow.toString()),
|
|
50
|
+
column: parseInt(bedColumn.toString()),
|
|
51
|
+
locationUuid: location.uuid,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
saveBed({ bedPayload: bedObject })
|
|
55
|
+
.then(() => {
|
|
56
|
+
showToast({
|
|
57
|
+
title: t('formCreated', 'New bed created'),
|
|
58
|
+
kind: 'success',
|
|
59
|
+
critical: true,
|
|
60
|
+
description: `Bed ${bedId} was created successfully.`,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
mutate();
|
|
64
|
+
onModalChange(false);
|
|
65
|
+
})
|
|
66
|
+
.catch((error) => {
|
|
67
|
+
showNotification({
|
|
68
|
+
title: t('errorCreatingForm', 'Error creating bed'),
|
|
69
|
+
kind: 'error',
|
|
70
|
+
critical: true,
|
|
71
|
+
description: error?.message,
|
|
72
|
+
});
|
|
73
|
+
onModalChange(false);
|
|
74
|
+
});
|
|
75
|
+
onModalChange(false);
|
|
76
|
+
},
|
|
77
|
+
[onModalChange, mutate, t],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<BedAdministrationForm
|
|
83
|
+
onModalChange={onModalChange}
|
|
84
|
+
allLocations={admissionLocations}
|
|
85
|
+
availableBedTypes={availableBedTypes}
|
|
86
|
+
showModal={showModal}
|
|
87
|
+
handleCreateQuestion={handleCreateQuestion}
|
|
88
|
+
headerTitle={headerTitle}
|
|
89
|
+
occupancyStatuses={occupancyStatuses}
|
|
90
|
+
initialData={initialData}
|
|
91
|
+
/>
|
|
92
|
+
</>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default NewBedForm;
|
|
@@ -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 { 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
|
+
<Form onSubmit={handleSubmit(onSubmit, onError)}>
|
|
81
|
+
<ModalBody hasScrollingContent>
|
|
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: '0rem', padding: '0rem' }}
|
|
106
|
+
role="alert"
|
|
107
|
+
kind="error"
|
|
108
|
+
subtitle={t('pleaseFillField', formStateError) + '.'}
|
|
109
|
+
onClose={() => setShowErrorNotification(false)}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</Stack>
|
|
113
|
+
</ModalBody>
|
|
114
|
+
<ModalFooter>
|
|
115
|
+
<Button onClick={() => onModalChange(false)} kind="secondary">
|
|
116
|
+
{t('cancel', 'Cancel')}
|
|
117
|
+
</Button>
|
|
118
|
+
<Button disabled={!isDirty} type="submit">
|
|
119
|
+
<span>{t('save', 'Save')}</span>
|
|
120
|
+
</Button>
|
|
121
|
+
</ModalFooter>
|
|
122
|
+
</Form>
|
|
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;
|