@kenyaemr/esm-bed-management-app 8.1.1-pre.129 → 8.1.2-pre.154
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 +26 -25
- package/dist/130.js +1 -1
- package/dist/130.js.map +1 -1
- package/dist/148.js +1 -1
- package/dist/148.js.map +1 -1
- package/dist/236.js +1 -0
- package/dist/240.js +1 -0
- package/dist/261.js +1 -0
- package/dist/271.js +1 -1
- package/dist/272.js +1 -0
- package/dist/288.js +1 -0
- package/dist/288.js.map +1 -0
- package/dist/319.js +1 -1
- package/dist/336.js +1 -0
- package/dist/378.js +1 -0
- package/dist/443.js +1 -0
- package/dist/443.js.map +1 -0
- package/dist/460.js +1 -1
- package/dist/539.js +1 -0
- package/dist/542.js +1 -1
- package/dist/542.js.map +1 -1
- package/dist/566.js +1 -0
- package/dist/574.js +1 -1
- package/dist/644.js +1 -1
- package/dist/652.js +1 -0
- package/dist/673.js +1 -0
- package/dist/705.js +1 -0
- package/dist/711.js +1 -0
- package/dist/727.js +1 -0
- package/dist/737.js +1 -0
- package/dist/744.js +1 -0
- package/dist/746.js +2 -0
- package/dist/746.js.map +1 -0
- package/dist/757.js +1 -1
- package/dist/768.js +2 -0
- package/dist/{455.js.LICENSE.txt → 768.js.LICENSE.txt} +0 -6
- package/dist/768.js.map +1 -0
- package/dist/788.js +1 -1
- package/dist/807.js +1 -1
- package/dist/833.js +1 -1
- package/dist/899.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 -1
- package/dist/openmrs-esm-bed-management-app.js.buildmanifest.json +414 -83
- package/dist/openmrs-esm-bed-management-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package-lock.json +2 -2
- package/package.json +4 -4
- package/src/admin-card-link.component.tsx +3 -2
- package/src/bed-administration/bed-administration-form.component.tsx +53 -54
- package/src/bed-administration/bed-administration-table.component.tsx +27 -23
- package/src/bed-administration/bed-administration-table.scss +1 -1
- package/src/bed-administration/bed-administration-types.ts +7 -5
- package/src/bed-administration/bed-administration.resource.ts +5 -7
- package/src/bed-administration/edit-bed-form.component.tsx +43 -43
- package/src/bed-administration/new-bed-form.component.tsx +34 -38
- package/src/bed-tag/bed-tag-administration-table.component.tsx +23 -23
- package/src/bed-tag/bed-tags-admin-form.component.tsx +12 -11
- package/src/bed-tag/edit-tag-form.component.tsx +27 -29
- package/src/bed-tag/new-tag-form.component.tsx +29 -34
- package/src/bed-type/bed-type-admin-form.component.tsx +32 -35
- package/src/bed-type/bed-type-administration-table.component.tsx +49 -49
- package/src/bed-type/edit-bed-type.component.tsx +24 -23
- package/src/bed-type/new-bed-type-form.component.tsx +32 -37
- package/src/card-header/card-header.component.tsx +3 -1
- package/src/header/header.component.tsx +23 -18
- package/src/header/header.scss +18 -32
- package/src/home.component.tsx +4 -1
- package/src/index.ts +12 -7
- package/src/left-panel/left-panel.component.tsx +10 -8
- package/src/modals.scss +29 -0
- package/src/root.component.tsx +8 -7
- package/src/routes.json +0 -15
- package/src/summary/summary.resource.ts +154 -100
- package/src/types.ts +2 -2
- package/src/ward-with-beds/ward-with-beds.component.tsx +7 -8
- package/translations/am.json +34 -18
- package/translations/ar.json +35 -19
- package/translations/de.json +67 -0
- package/translations/en.json +34 -18
- package/translations/es.json +38 -22
- package/translations/fr.json +34 -18
- package/translations/he.json +34 -18
- package/translations/hi.json +67 -0
- package/translations/hi_IN.json +67 -0
- package/translations/id.json +67 -0
- package/translations/it.json +67 -0
- package/translations/km.json +34 -18
- package/translations/ne.json +67 -0
- package/translations/pt.json +67 -0
- package/translations/pt_BR.json +67 -0
- package/translations/qu.json +67 -0
- package/translations/si.json +67 -0
- package/translations/sw.json +67 -0
- package/translations/sw_KE.json +67 -0
- package/translations/tr.json +67 -0
- package/translations/tr_TR.json +67 -0
- package/translations/uk.json +67 -0
- package/translations/vi.json +67 -0
- package/translations/zh.json +34 -18
- package/translations/zh_CN.json +34 -18
- package/tsconfig.json +0 -1
- package/dist/169.js +0 -1
- package/dist/169.js.map +0 -1
- package/dist/339.js +0 -1
- package/dist/339.js.map +0 -1
- package/dist/455.js +0 -2
- package/dist/455.js.map +0 -1
- package/dist/501.js +0 -1
- package/dist/501.js.map +0 -1
- package/dist/766.js +0 -2
- package/dist/766.js.map +0 -1
- package/src/bed-administration/bed-administration-form.scss +0 -0
- package/src/header/illustration.component.tsx +0 -13
- package/src/setup-tests.ts +0 -1
- /package/dist/{766.js.LICENSE.txt → 746.js.LICENSE.txt} +0 -0
package/src/header/header.scss
CHANGED
|
@@ -13,34 +13,36 @@
|
|
|
13
13
|
border-bottom: 1px solid colors.$gray-20;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
.
|
|
16
|
+
.leftJustifiedItems {
|
|
17
17
|
display: flex;
|
|
18
18
|
flex-direction: row;
|
|
19
19
|
align-items: center;
|
|
20
20
|
cursor: pointer;
|
|
21
|
-
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
color: colors.$gray-70;
|
|
26
|
-
margin: layout.$spacing-03;
|
|
27
|
-
padding-top: layout.$spacing-04;
|
|
28
|
-
}
|
|
22
|
+
& > div:nth-child(2) {
|
|
23
|
+
margin: layout.$spacing-05;
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
& > p:last-child {
|
|
26
|
+
white-space: nowrap;
|
|
27
|
+
@include type.type-style('heading-04');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
.
|
|
36
|
-
|
|
32
|
+
.inPatientPictogram {
|
|
33
|
+
width: 4.5rem;
|
|
34
|
+
height: 4.5rem;
|
|
35
|
+
fill: var(--brand-03);
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
.
|
|
40
|
-
|
|
38
|
+
.rightJustifiedItems {
|
|
39
|
+
@include type.type-style('body-compact-02');
|
|
40
|
+
color: colors.$gray-70;
|
|
41
|
+
margin: layout.$spacing-03;
|
|
42
|
+
padding-top: layout.$spacing-04;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
.
|
|
45
|
+
.dateAndLocation {
|
|
44
46
|
display: flex;
|
|
45
47
|
justify-content: flex-end;
|
|
46
48
|
align-items: center;
|
|
@@ -54,19 +56,3 @@
|
|
|
54
56
|
.middot {
|
|
55
57
|
margin: 0 layout.$spacing-03;
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
.view {
|
|
59
|
-
@include type.type-style('label-01');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
svg.iconOverrides {
|
|
63
|
-
width: 72 !important;
|
|
64
|
-
height: 72 !important;
|
|
65
|
-
fill: var(--brand-03);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.svgContainer svg {
|
|
69
|
-
width: 4.5rem;
|
|
70
|
-
height: 4.5rem;
|
|
71
|
-
fill: var(--brand-03);
|
|
72
|
-
}
|
package/src/home.component.tsx
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
2
3
|
import BedManagementSummary from './summary/summary.component';
|
|
3
4
|
import Header from './header/header.component';
|
|
4
5
|
import styles from './home.scss';
|
|
5
6
|
|
|
6
7
|
const Home: React.FC = () => {
|
|
8
|
+
const { t } = useTranslation();
|
|
9
|
+
|
|
7
10
|
return (
|
|
8
11
|
<section className={styles.section}>
|
|
9
|
-
<Header
|
|
12
|
+
<Header title={t('bedManagement', 'Bed management')} />
|
|
10
13
|
<BedManagementSummary />
|
|
11
14
|
</section>
|
|
12
15
|
);
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { getAsyncLifecycle, defineConfigSchema, getSyncLifecycle } from '@openmr
|
|
|
2
2
|
import { configSchema } from './config-schema';
|
|
3
3
|
import { createLeftPanelLink } from './left-panel-link.component';
|
|
4
4
|
|
|
5
|
-
const moduleName = '@
|
|
5
|
+
const moduleName = '@openmrs/esm-bed-management-app';
|
|
6
6
|
|
|
7
7
|
const options = {
|
|
8
8
|
featureName: 'bed-management',
|
|
@@ -22,6 +22,7 @@ export const adminCardLink = getAsyncLifecycle(() => import('./admin-card-link.c
|
|
|
22
22
|
export const summaryLeftPanelLink = getSyncLifecycle(
|
|
23
23
|
createLeftPanelLink({
|
|
24
24
|
name: 'bed-management',
|
|
25
|
+
// t('summary', 'Summary')
|
|
25
26
|
title: 'Summary',
|
|
26
27
|
}),
|
|
27
28
|
options,
|
|
@@ -29,23 +30,27 @@ export const summaryLeftPanelLink = getSyncLifecycle(
|
|
|
29
30
|
|
|
30
31
|
export const adminLeftPanelLink = getSyncLifecycle(
|
|
31
32
|
createLeftPanelLink({
|
|
32
|
-
name: 'administration',
|
|
33
|
-
|
|
33
|
+
name: 'bed-administration',
|
|
34
|
+
// t('wardAllocation', 'Ward allocation')
|
|
35
|
+
title: 'Ward allocation',
|
|
34
36
|
}),
|
|
35
37
|
options,
|
|
36
38
|
);
|
|
37
39
|
|
|
38
40
|
export const bedTypeLeftPanelLink = getSyncLifecycle(
|
|
39
41
|
createLeftPanelLink({
|
|
40
|
-
name: 'bed-
|
|
41
|
-
|
|
42
|
+
name: 'bed-types',
|
|
43
|
+
// t('bedTypes', 'Bed types')
|
|
44
|
+
title: 'Bed types',
|
|
42
45
|
}),
|
|
43
46
|
options,
|
|
44
47
|
);
|
|
48
|
+
|
|
45
49
|
export const bedTagLeftPanelLink = getSyncLifecycle(
|
|
46
50
|
createLeftPanelLink({
|
|
47
|
-
name: 'bed-
|
|
48
|
-
|
|
51
|
+
name: 'bed-tags',
|
|
52
|
+
// t('bedTags', 'Bed tags')
|
|
53
|
+
title: 'Bed tags',
|
|
49
54
|
}),
|
|
50
55
|
options,
|
|
51
56
|
);
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { SideNav } from '@carbon/react';
|
|
4
|
+
import { attach, ExtensionSlot, isDesktop, useLayoutType } from '@openmrs/esm-framework';
|
|
4
5
|
import styles from './left-panel.scss';
|
|
5
6
|
|
|
7
|
+
attach('nav-menu-slot', 'bed-management-left-panel');
|
|
8
|
+
|
|
6
9
|
const LeftPanel: React.FC = () => {
|
|
10
|
+
const { t } = useTranslation();
|
|
7
11
|
const layout = useLayoutType();
|
|
8
12
|
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
attach('nav-menu-slot', 'bed-management-left-panel');
|
|
11
|
-
return () => detach('nav-menu-slot', 'bed-management-left-panel');
|
|
12
|
-
}, []);
|
|
13
|
-
|
|
14
13
|
return (
|
|
15
14
|
isDesktop(layout) && (
|
|
16
|
-
<SideNav
|
|
15
|
+
<SideNav
|
|
16
|
+
aria-label={t('bedManagementLeftPanel', 'Bed management left panel')}
|
|
17
|
+
className={styles.leftPanel}
|
|
18
|
+
expanded>
|
|
17
19
|
<ExtensionSlot name="bed-management-left-panel-slot" />
|
|
18
20
|
</SideNav>
|
|
19
21
|
)
|
package/src/modals.scss
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@use '@carbon/layout';
|
|
2
|
+
|
|
3
|
+
.modalHeader {
|
|
4
|
+
:global {
|
|
5
|
+
.cds--modal-close-button {
|
|
6
|
+
position: absolute;
|
|
7
|
+
inset-block-start: 0;
|
|
8
|
+
inset-inline-end: 0;
|
|
9
|
+
margin: 0;
|
|
10
|
+
margin-top: calc(-1 * #{layout.$spacing-05});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.cds--modal-close {
|
|
14
|
+
background-color: rgba(0, 0, 0, 0);
|
|
15
|
+
|
|
16
|
+
&:hover {
|
|
17
|
+
background-color: var(--cds-layer-hover);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.cds--popover--left > .cds--popover > .cds--popover-content {
|
|
22
|
+
transform: translate(-4rem, 0.85rem);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.cds--popover--left > .cds--popover > .cds--popover-caret {
|
|
26
|
+
transform: translate(-3.75rem, 1.25rem);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/root.component.tsx
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import { BrowserRouter, Route, Routes } from 'react-router-dom';
|
|
3
3
|
import { setLeftNav, unsetLeftNav } from '@openmrs/esm-framework';
|
|
4
|
-
import Home from './home.component';
|
|
5
|
-
import LeftPanel from './left-panel/left-panel.component';
|
|
6
|
-
import WardWithBeds from './ward-with-beds/ward-with-beds.component';
|
|
7
4
|
import BedAdministrationTable from './bed-administration/bed-administration-table.component';
|
|
8
5
|
import BedTagAdministrationTable from './bed-tag/bed-tag-administration-table.component';
|
|
9
6
|
import BedTypeAdministrationTable from './bed-type/bed-type-administration-table.component';
|
|
7
|
+
import Home from './home.component';
|
|
8
|
+
import LeftPanel from './left-panel/left-panel.component';
|
|
9
|
+
import WardWithBeds from './ward-with-beds/ward-with-beds.component';
|
|
10
10
|
import styles from './root.scss';
|
|
11
11
|
|
|
12
12
|
const Root: React.FC = () => {
|
|
13
13
|
const spaBasePath = window.spaBase;
|
|
14
|
+
const bedManagementBasename = window.getOpenmrsSpaBase() + 'bed-management';
|
|
14
15
|
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
setLeftNav({
|
|
@@ -21,15 +22,15 @@ const Root: React.FC = () => {
|
|
|
21
22
|
}, [spaBasePath]);
|
|
22
23
|
|
|
23
24
|
return (
|
|
24
|
-
<BrowserRouter basename={
|
|
25
|
+
<BrowserRouter basename={bedManagementBasename}>
|
|
25
26
|
<LeftPanel />
|
|
26
27
|
<main className={styles.container}>
|
|
27
28
|
<Routes>
|
|
28
29
|
<Route path="/" element={<Home />} />
|
|
29
30
|
<Route path="/location/:location" element={<WardWithBeds />} />
|
|
30
|
-
<Route path="/administration" element={<BedAdministrationTable />} />
|
|
31
|
-
<Route path="/bed-
|
|
32
|
-
<Route path="/bed-
|
|
31
|
+
<Route path="/bed-administration" element={<BedAdministrationTable />} />
|
|
32
|
+
<Route path="/bed-tags" element={<BedTagAdministrationTable />} />
|
|
33
|
+
<Route path="/bed-types" element={<BedTypeAdministrationTable />} />
|
|
33
34
|
</Routes>
|
|
34
35
|
</main>
|
|
35
36
|
</BrowserRouter>
|
package/src/routes.json
CHANGED
|
@@ -36,21 +36,6 @@
|
|
|
36
36
|
"name": "bed-management-home-dashboard-link",
|
|
37
37
|
"slot": "bed-management-left-panel-slot",
|
|
38
38
|
"order": 0
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"component": "bedAdmission",
|
|
42
|
-
"name": "bed-admission-dashboard",
|
|
43
|
-
"slot": "bed-admission-dashboard-slot"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"name": "bed-admission-dashboard-link",
|
|
47
|
-
"component": "bedAdmissionDashboardLink",
|
|
48
|
-
"slot": "homepage-dashboard-slot",
|
|
49
|
-
"meta": {
|
|
50
|
-
"name": "bed-admission",
|
|
51
|
-
"slot": "bed-admission-dashboard-slot",
|
|
52
|
-
"title": "Bed-admission"
|
|
53
|
-
}
|
|
54
39
|
}
|
|
55
40
|
]
|
|
56
41
|
}
|
|
@@ -1,38 +1,44 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
1
2
|
import useSWR from 'swr';
|
|
2
|
-
import { type FetchResponse, openmrsFetch, useConfig } from '@openmrs/esm-framework';
|
|
3
|
+
import { type FetchResponse, openmrsFetch, restBaseUrl, useConfig } from '@openmrs/esm-framework';
|
|
3
4
|
import type {
|
|
4
5
|
AdmissionLocation,
|
|
5
6
|
Bed,
|
|
6
7
|
BedFetchResponse,
|
|
8
|
+
BedTagData,
|
|
7
9
|
BedTagPayload,
|
|
10
|
+
BedType,
|
|
8
11
|
BedTypePayload,
|
|
9
12
|
LocationFetchResponse,
|
|
10
13
|
MappedBedData,
|
|
11
|
-
Mutator,
|
|
12
14
|
} from '../types';
|
|
13
15
|
import { type BedManagementConfig } from '../config-schema';
|
|
14
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
15
16
|
|
|
16
17
|
export const useLocationsWithAdmissionTag = () => {
|
|
17
18
|
const { admissionLocationTagName } = useConfig<BedManagementConfig>();
|
|
18
|
-
const locationsUrl =
|
|
19
|
+
const locationsUrl = `${restBaseUrl}/location?tag=${admissionLocationTagName}&v=full`;
|
|
19
20
|
|
|
20
21
|
const { data, error, isLoading, isValidating, mutate } = useSWR<LocationFetchResponse, Error>(
|
|
21
22
|
admissionLocationTagName ? locationsUrl : null,
|
|
22
23
|
openmrsFetch,
|
|
23
24
|
);
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const results = useMemo(
|
|
27
|
+
() => ({
|
|
28
|
+
admissionLocations: data?.data?.results ?? [],
|
|
29
|
+
errorLoadingAdmissionLocations: error,
|
|
30
|
+
isLoadingAdmissionLocations: isLoading,
|
|
31
|
+
isValidatingAdmissionLocations: isValidating,
|
|
32
|
+
mutateAdmissionLocations: mutate,
|
|
33
|
+
}),
|
|
34
|
+
[data, error, isLoading, isValidating, mutate],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return results;
|
|
32
38
|
};
|
|
33
39
|
|
|
34
40
|
export const useBedsForLocation = (locationUuid: string) => {
|
|
35
|
-
const apiUrl =
|
|
41
|
+
const apiUrl = `${restBaseUrl}/bed?locationUuid=${locationUuid}&v=full`;
|
|
36
42
|
|
|
37
43
|
const { data, isLoading, error } = useSWR<{ data: { results: Array<Bed> } }, Error>(
|
|
38
44
|
locationUuid ? apiUrl : null,
|
|
@@ -40,43 +46,55 @@ export const useBedsForLocation = (locationUuid: string) => {
|
|
|
40
46
|
);
|
|
41
47
|
|
|
42
48
|
const mappedBedData: MappedBedData = (data?.data?.results ?? []).map((bed) => ({
|
|
49
|
+
description: bed.bedType?.description,
|
|
43
50
|
id: bed.id,
|
|
44
|
-
number: bed.bedNumber,
|
|
45
51
|
name: bed.bedType?.displayName,
|
|
46
|
-
|
|
52
|
+
number: bed.bedNumber,
|
|
47
53
|
status: bed.status,
|
|
48
54
|
uuid: bed.uuid,
|
|
49
55
|
}));
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
const results = useMemo(
|
|
58
|
+
() => ({
|
|
59
|
+
bedsData: mappedBedData,
|
|
60
|
+
errorLoadingBeds: error,
|
|
61
|
+
isLoadingBeds: isLoading,
|
|
62
|
+
}),
|
|
63
|
+
[mappedBedData, isLoading, error],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return results;
|
|
56
67
|
};
|
|
57
68
|
|
|
58
69
|
export const useLocationName = (locationUuid: string) => {
|
|
59
|
-
const {
|
|
70
|
+
const { admissionLocations, isLoadingAdmissionLocations } = useLocationsWithAdmissionTag();
|
|
71
|
+
const matchingLocation = admissionLocations.find((location) => location.uuid === locationUuid);
|
|
72
|
+
|
|
73
|
+
const results = useMemo(
|
|
74
|
+
() => ({
|
|
75
|
+
name: matchingLocation?.display ?? null,
|
|
76
|
+
isLoadingLocationData: isLoadingAdmissionLocations,
|
|
77
|
+
}),
|
|
78
|
+
[matchingLocation, isLoadingAdmissionLocations],
|
|
79
|
+
);
|
|
60
80
|
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
name: location?.display ?? null,
|
|
64
|
-
isLoadingLocationData: isLoading,
|
|
65
|
-
};
|
|
81
|
+
return results;
|
|
66
82
|
};
|
|
67
83
|
|
|
68
84
|
export function useBedsGroupedByLocation() {
|
|
69
|
-
const {
|
|
85
|
+
const { admissionLocations, isLoadingAdmissionLocations } = useLocationsWithAdmissionTag();
|
|
86
|
+
|
|
87
|
+
const [error, setError] = useState<Error | null>(null);
|
|
70
88
|
const [isLoading, setIsLoading] = useState(true);
|
|
71
89
|
const [isValidating, setIsValidating] = useState(true);
|
|
72
|
-
const [error, setError] = useState(null);
|
|
73
90
|
const [result, setResult] = useState([]);
|
|
74
91
|
|
|
75
92
|
useEffect(() => {
|
|
76
|
-
|
|
93
|
+
let isSubscribed = true;
|
|
94
|
+
if (!isLoadingAdmissionLocations && admissionLocations && isValidating) {
|
|
77
95
|
const fetchData = async () => {
|
|
78
|
-
const promises =
|
|
79
|
-
const bedsUrl =
|
|
96
|
+
const promises = admissionLocations.map(async (location) => {
|
|
97
|
+
const bedsUrl = `${restBaseUrl}/bed?locationUuid=${location.uuid}`;
|
|
80
98
|
const bedsFetchResult = await openmrsFetch<BedFetchResponse>(bedsUrl, {
|
|
81
99
|
method: 'GET',
|
|
82
100
|
});
|
|
@@ -90,103 +108,136 @@ export function useBedsGroupedByLocation() {
|
|
|
90
108
|
});
|
|
91
109
|
|
|
92
110
|
const updatedWards = (await Promise.all(promises)).filter(Boolean);
|
|
93
|
-
|
|
111
|
+
if (isSubscribed) {
|
|
112
|
+
setResult(updatedWards);
|
|
113
|
+
}
|
|
94
114
|
};
|
|
95
115
|
fetchData()
|
|
96
|
-
.catch((
|
|
97
|
-
|
|
116
|
+
.catch((error) => {
|
|
117
|
+
if (isSubscribed) {
|
|
118
|
+
setError(error);
|
|
119
|
+
}
|
|
98
120
|
})
|
|
99
121
|
.finally(() => {
|
|
100
|
-
|
|
101
|
-
|
|
122
|
+
if (isSubscribed) {
|
|
123
|
+
setIsLoading(false);
|
|
124
|
+
setIsValidating(false);
|
|
125
|
+
}
|
|
102
126
|
});
|
|
103
127
|
}
|
|
104
|
-
|
|
128
|
+
return () => {
|
|
129
|
+
isSubscribed = false;
|
|
130
|
+
};
|
|
131
|
+
}, [admissionLocations, isLoadingAdmissionLocations, isValidating]);
|
|
105
132
|
|
|
106
133
|
const mutate = useCallback(() => {
|
|
107
134
|
setIsValidating(true);
|
|
108
135
|
}, []);
|
|
109
136
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
137
|
+
const results = useMemo(
|
|
138
|
+
() => ({
|
|
139
|
+
bedsGroupedByLocation: result,
|
|
140
|
+
errorFetchingBedsGroupedByLocation: error,
|
|
141
|
+
isLoadingBedsGroupedByLocation: isLoading || isLoadingAdmissionLocations,
|
|
142
|
+
isValidatingBedsGroupedByLocation: isValidating,
|
|
143
|
+
mutateBedsGroupedByLocation: mutate,
|
|
144
|
+
}),
|
|
145
|
+
[error, isLoading, isLoadingAdmissionLocations, isValidating, mutate, result],
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return results;
|
|
117
149
|
}
|
|
118
150
|
|
|
119
151
|
export const useAdmissionLocations = () => {
|
|
120
|
-
const locationsUrl =
|
|
152
|
+
const locationsUrl = `${restBaseUrl}/admissionLocation?v=full`;
|
|
121
153
|
const { data, error, isLoading, isValidating, mutate } = useSWR<
|
|
122
154
|
{ data: { results: Array<AdmissionLocation> } },
|
|
123
155
|
Error
|
|
124
156
|
>(locationsUrl, openmrsFetch);
|
|
125
157
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
158
|
+
const results = useMemo(
|
|
159
|
+
() => ({
|
|
160
|
+
data: data?.data?.results ?? [],
|
|
161
|
+
error,
|
|
162
|
+
isLoading,
|
|
163
|
+
isValidating,
|
|
164
|
+
mutate,
|
|
165
|
+
}),
|
|
166
|
+
[data, error, isLoading, isValidating, mutate],
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return results;
|
|
133
170
|
};
|
|
134
171
|
|
|
135
172
|
export const useAdmissionLocationBedLayout = (locationUuid: string) => {
|
|
136
|
-
const locationsUrl =
|
|
173
|
+
const locationsUrl = `${restBaseUrl}/admissionLocation/${locationUuid}?v=full`;
|
|
137
174
|
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: AdmissionLocation }, Error>(
|
|
138
175
|
locationsUrl,
|
|
139
176
|
openmrsFetch,
|
|
140
177
|
);
|
|
141
178
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
179
|
+
const results = useMemo(
|
|
180
|
+
() => ({
|
|
181
|
+
data: data?.data?.bedLayouts ?? [],
|
|
182
|
+
error,
|
|
183
|
+
isLoading,
|
|
184
|
+
isValidating,
|
|
185
|
+
mutate,
|
|
186
|
+
}),
|
|
187
|
+
[data, error, isLoading, isValidating, mutate],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return results;
|
|
149
191
|
};
|
|
150
192
|
|
|
151
|
-
export const
|
|
152
|
-
const url =
|
|
153
|
-
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data }, Error>(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
193
|
+
export const useBedTypes = () => {
|
|
194
|
+
const url = `${restBaseUrl}/bedtype/`;
|
|
195
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: { results: Array<BedType> } }, Error>(
|
|
196
|
+
url,
|
|
197
|
+
openmrsFetch,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const results = useMemo(
|
|
201
|
+
() => ({
|
|
202
|
+
bedTypes: data?.data?.results ?? [],
|
|
203
|
+
errorLoadingBedTypes: error,
|
|
204
|
+
isLoadingBedTypes: isLoading,
|
|
205
|
+
isValidatingBedTypes: isValidating,
|
|
206
|
+
mutateBedTypes: mutate,
|
|
207
|
+
}),
|
|
208
|
+
[data, error, isLoading, isValidating, mutate],
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
return results;
|
|
162
212
|
};
|
|
163
213
|
|
|
164
|
-
export const
|
|
165
|
-
const url =
|
|
166
|
-
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data }, Error>(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
214
|
+
export const useBedTags = () => {
|
|
215
|
+
const url = `${restBaseUrl}/bedTag/`;
|
|
216
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: { results: Array<BedTagData> } }, Error>(
|
|
217
|
+
url,
|
|
218
|
+
openmrsFetch,
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const results = useMemo(
|
|
222
|
+
() => ({
|
|
223
|
+
bedTags: data?.data?.results ?? [],
|
|
224
|
+
errorLoadingBedTags: error,
|
|
225
|
+
isLoadingBedTags: isLoading,
|
|
226
|
+
isValidatingBedTags: isValidating,
|
|
227
|
+
mutateBedTags: mutate,
|
|
228
|
+
}),
|
|
229
|
+
[data, error, isLoading, isValidating, mutate],
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
return results;
|
|
175
233
|
};
|
|
176
|
-
|
|
177
|
-
name: string;
|
|
178
|
-
displayName: string;
|
|
179
|
-
description: string;
|
|
180
|
-
}
|
|
181
|
-
interface BedTag {
|
|
182
|
-
name: string;
|
|
183
|
-
}
|
|
234
|
+
|
|
184
235
|
export async function saveBedType({
|
|
185
236
|
bedTypePayload,
|
|
186
237
|
}: {
|
|
187
238
|
bedTypePayload: BedTypePayload;
|
|
188
239
|
}): Promise<FetchResponse<BedType>> {
|
|
189
|
-
const response: FetchResponse = await openmrsFetch(
|
|
240
|
+
const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/bedtype`, {
|
|
190
241
|
method: 'POST',
|
|
191
242
|
headers: { 'Content-Type': 'application/json' },
|
|
192
243
|
body: bedTypePayload,
|
|
@@ -194,39 +245,42 @@ export async function saveBedType({
|
|
|
194
245
|
return response;
|
|
195
246
|
}
|
|
196
247
|
|
|
197
|
-
export async function saveBedTag({
|
|
198
|
-
|
|
248
|
+
export async function saveBedTag({
|
|
249
|
+
bedTagPayload,
|
|
250
|
+
}: {
|
|
251
|
+
bedTagPayload: BedTagPayload;
|
|
252
|
+
}): Promise<FetchResponse<BedTagData>> {
|
|
253
|
+
return await openmrsFetch(`${restBaseUrl}/bedTag/`, {
|
|
199
254
|
method: 'POST',
|
|
200
255
|
headers: { 'Content-Type': 'application/json' },
|
|
201
256
|
body: bedTagPayload,
|
|
202
257
|
});
|
|
203
|
-
return response;
|
|
204
258
|
}
|
|
259
|
+
|
|
205
260
|
export async function editBedType({
|
|
206
261
|
bedTypePayload,
|
|
207
262
|
bedTypeId,
|
|
208
263
|
}: {
|
|
209
|
-
bedTypePayload: BedTypePayload;
|
|
210
264
|
bedTypeId: string;
|
|
265
|
+
bedTypePayload: BedTypePayload;
|
|
211
266
|
}): Promise<FetchResponse<BedType>> {
|
|
212
|
-
|
|
267
|
+
return await openmrsFetch(`${restBaseUrl}/bedtype/${bedTypeId}`, {
|
|
213
268
|
method: 'POST',
|
|
214
269
|
headers: { 'Content-Type': 'application/json' },
|
|
215
270
|
body: bedTypePayload,
|
|
216
271
|
});
|
|
217
|
-
return response;
|
|
218
272
|
}
|
|
273
|
+
|
|
219
274
|
export async function editBedTag({
|
|
220
275
|
bedTagPayload,
|
|
221
276
|
bedTagId,
|
|
222
277
|
}: {
|
|
223
|
-
bedTagPayload: BedTagPayload;
|
|
224
278
|
bedTagId: string;
|
|
225
|
-
|
|
226
|
-
|
|
279
|
+
bedTagPayload: BedTagPayload;
|
|
280
|
+
}): Promise<FetchResponse<BedTagData>> {
|
|
281
|
+
return await openmrsFetch(`${restBaseUrl}/bedTag/${bedTagId}`, {
|
|
227
282
|
method: 'POST',
|
|
228
283
|
headers: { 'Content-Type': 'application/json' },
|
|
229
284
|
body: bedTagPayload,
|
|
230
285
|
});
|
|
231
|
-
return response;
|
|
232
286
|
}
|
package/src/types.ts
CHANGED