@kenyaemr/esm-bed-management-app 8.1.1-pre.129 → 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 +2 -2
  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
@@ -13,34 +13,36 @@
13
13
  border-bottom: 1px solid colors.$gray-20;
14
14
  }
15
15
 
16
- .left-justified-items {
16
+ .leftJustifiedItems {
17
17
  display: flex;
18
18
  flex-direction: row;
19
19
  align-items: center;
20
20
  cursor: pointer;
21
- }
22
21
 
23
- .right-justified-items {
24
- @include type.type-style('body-compact-02');
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
- .page-name {
31
- white-space: nowrap;
32
- @include type.type-style('heading-04');
25
+ & > p:last-child {
26
+ white-space: nowrap;
27
+ @include type.type-style('heading-04');
28
+ }
29
+ }
33
30
  }
34
31
 
35
- .page-labels {
36
- margin: layout.$spacing-05;
32
+ .inPatientPictogram {
33
+ width: 4.5rem;
34
+ height: 4.5rem;
35
+ fill: var(--brand-03);
37
36
  }
38
37
 
39
- .middot {
40
- margin: 0 layout.$spacing-03;
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
- .date-and-location {
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
- }
@@ -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 route="Summary" />
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 = '@ugandaemr/esm-bed-management-app';
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
- title: 'Ward Allocation',
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-type',
41
- title: 'Bed Type',
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-tag',
48
- title: 'Bed Tag',
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, { useEffect } from 'react';
2
- import { attach, detach, ExtensionSlot, isDesktop, useLayoutType } from '@openmrs/esm-framework';
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 aria-label="Bed management left panel" className={styles.leftPanel} expanded>
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
  )
@@ -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
+ }
@@ -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={`${window.getOpenmrsSpaBase()}bed-management`}>
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-tag" element={<BedTagAdministrationTable />} />
32
- <Route path="/bed-type" element={<BedTypeAdministrationTable />} />
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 = `/ws/rest/v1/location?tag=${admissionLocationTagName}&v=full`;
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
- return {
26
- data: data?.data?.results ?? [],
27
- error,
28
- isLoading,
29
- isValidating,
30
- mutate,
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 = `/ws/rest/v1/bed?locationUuid=${locationUuid}&v=full`;
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
- description: bed.bedType?.description,
52
+ number: bed.bedNumber,
47
53
  status: bed.status,
48
54
  uuid: bed.uuid,
49
55
  }));
50
56
 
51
- return {
52
- bedData: mappedBedData,
53
- isLoading,
54
- error,
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 { data: allLocations, isLoading } = useLocationsWithAdmissionTag();
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
- const location = allLocations.find((loc) => loc.uuid == locationUuid);
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 { data: locations, isLoading: isLoadingLocations } = useLocationsWithAdmissionTag();
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
- if (!isLoadingLocations && locations && isValidating) {
93
+ let isSubscribed = true;
94
+ if (!isLoadingAdmissionLocations && admissionLocations && isValidating) {
77
95
  const fetchData = async () => {
78
- const promises = locations.map(async (location) => {
79
- const bedsUrl = `/ws/rest/v1/bed?locationUuid=${location.uuid}`;
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
- setResult(updatedWards);
111
+ if (isSubscribed) {
112
+ setResult(updatedWards);
113
+ }
94
114
  };
95
115
  fetchData()
96
- .catch((e) => {
97
- setError(e);
116
+ .catch((error) => {
117
+ if (isSubscribed) {
118
+ setError(error);
119
+ }
98
120
  })
99
121
  .finally(() => {
100
- setIsLoading(false);
101
- setIsValidating(false);
122
+ if (isSubscribed) {
123
+ setIsLoading(false);
124
+ setIsValidating(false);
125
+ }
102
126
  });
103
127
  }
104
- }, [locations, isLoading]);
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
- return {
111
- data: result,
112
- error,
113
- isLoading: isLoading || isLoadingLocations,
114
- isValidating,
115
- mutate,
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 = `/ws/rest/v1/admissionLocation?v=full`;
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
- return {
127
- data: data?.data?.results ?? [],
128
- error,
129
- isLoading,
130
- isValidating,
131
- mutate,
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 = `/ws/rest/v1/admissionLocation/${locationUuid}?v=full`;
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
- return {
143
- data: data?.data?.bedLayouts ?? [],
144
- error,
145
- isLoading,
146
- isValidating,
147
- mutate,
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 useBedType = () => {
152
- const url = `/ws/rest/v1/bedtype/`;
153
- const { data, error, isLoading, isValidating, mutate } = useSWR<{ data }, Error>(url, openmrsFetch);
154
- const results = data?.data?.results ? data?.data?.results : [];
155
- return {
156
- bedTypeData: results,
157
- isError: error,
158
- loading: isLoading,
159
- validate: isValidating,
160
- mutate,
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 useBedTag = () => {
165
- const url = `/ws/rest/v1/bedTag/`;
166
- const { data, error, isLoading, isValidating, mutate } = useSWR<{ data }, Error>(url, openmrsFetch);
167
- const results = data?.data?.results ? data?.data?.results : [];
168
- return {
169
- bedTypeData: results,
170
- isError: error,
171
- loading: isLoading,
172
- validate: isValidating,
173
- mutate,
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
- interface BedType {
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(`/ws/rest/v1/bedtype`, {
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({ bedTagPayload }: { bedTagPayload: BedTagPayload }): Promise<FetchResponse<BedTag>> {
198
- const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bedTag/`, {
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
- const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bedtype/${bedTypeId}`, {
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
- }): Promise<FetchResponse<BedType>> {
226
- const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/bedTag/${bedTagId}`, {
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
@@ -138,9 +138,9 @@ export interface BedTypePayload {
138
138
  description: string;
139
139
  }
140
140
 
141
- export type Mutator = KeyedMutator<{
141
+ export type Mutator<T> = KeyedMutator<{
142
142
  data: {
143
- results: Array<Location>;
143
+ results: Array<T>;
144
144
  };
145
145
  }>;
146
146