@kenyaemr/esm-icu-app 5.4.5-pre.1142

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 (268) hide show
  1. package/.turbo/turbo-build.log +6 -0
  2. package/dist/1072.js +1 -0
  3. package/dist/1072.js.map +1 -0
  4. package/dist/1148.js +1 -0
  5. package/dist/1148.js.map +1 -0
  6. package/dist/1156.js +1 -0
  7. package/dist/1156.js.map +1 -0
  8. package/dist/1278.js +1 -0
  9. package/dist/1278.js.map +1 -0
  10. package/dist/1442.js +1 -0
  11. package/dist/1442.js.map +1 -0
  12. package/dist/1466.js +1 -0
  13. package/dist/1466.js.map +1 -0
  14. package/dist/15.js +1 -0
  15. package/dist/15.js.map +1 -0
  16. package/dist/1568.js +1 -0
  17. package/dist/1568.js.map +1 -0
  18. package/dist/1620.js +1 -0
  19. package/dist/1620.js.map +1 -0
  20. package/dist/1668.js +1 -0
  21. package/dist/1668.js.map +1 -0
  22. package/dist/1789.js +1 -0
  23. package/dist/1789.js.map +1 -0
  24. package/dist/1831.js +1 -0
  25. package/dist/1831.js.map +1 -0
  26. package/dist/1844.js +1 -0
  27. package/dist/1844.js.map +1 -0
  28. package/dist/1946.js +1 -0
  29. package/dist/1946.js.map +1 -0
  30. package/dist/2007.js +1 -0
  31. package/dist/2007.js.map +1 -0
  32. package/dist/2115.js +1 -0
  33. package/dist/2115.js.map +1 -0
  34. package/dist/2152.js +1 -0
  35. package/dist/2152.js.map +1 -0
  36. package/dist/2202.js +1 -0
  37. package/dist/2202.js.map +1 -0
  38. package/dist/2231.js +1 -0
  39. package/dist/2231.js.map +1 -0
  40. package/dist/2394.js +1 -0
  41. package/dist/2394.js.map +1 -0
  42. package/dist/2507.js +1 -0
  43. package/dist/2507.js.map +1 -0
  44. package/dist/2516.js +1 -0
  45. package/dist/2516.js.map +1 -0
  46. package/dist/2534.js +1 -0
  47. package/dist/2534.js.map +1 -0
  48. package/dist/2537.js +1 -0
  49. package/dist/2537.js.map +1 -0
  50. package/dist/2556.js +1 -0
  51. package/dist/2556.js.map +1 -0
  52. package/dist/2648.js +1 -0
  53. package/dist/2648.js.map +1 -0
  54. package/dist/2795.js +1 -0
  55. package/dist/2795.js.map +1 -0
  56. package/dist/2842.js +1 -0
  57. package/dist/2842.js.map +1 -0
  58. package/dist/2916.js +1 -0
  59. package/dist/2916.js.map +1 -0
  60. package/dist/2924.js +1 -0
  61. package/dist/2924.js.map +1 -0
  62. package/dist/2947.js +1 -0
  63. package/dist/2947.js.map +1 -0
  64. package/dist/3032.js +1 -0
  65. package/dist/3032.js.map +1 -0
  66. package/dist/3137.js +1 -0
  67. package/dist/3137.js.map +1 -0
  68. package/dist/3285.js +1 -0
  69. package/dist/3285.js.map +1 -0
  70. package/dist/3335.js +1 -0
  71. package/dist/3335.js.map +1 -0
  72. package/dist/3378.js +1 -0
  73. package/dist/3378.js.map +1 -0
  74. package/dist/3381.js +1 -0
  75. package/dist/3381.js.map +1 -0
  76. package/dist/3504.js +1 -0
  77. package/dist/3504.js.map +1 -0
  78. package/dist/356.js +1 -0
  79. package/dist/356.js.map +1 -0
  80. package/dist/3569.js +1 -0
  81. package/dist/3569.js.map +1 -0
  82. package/dist/3723.js +1 -0
  83. package/dist/3723.js.map +1 -0
  84. package/dist/3745.js +1 -0
  85. package/dist/3745.js.map +1 -0
  86. package/dist/3747.js +1 -0
  87. package/dist/3747.js.map +1 -0
  88. package/dist/3802.js +1 -0
  89. package/dist/3802.js.map +1 -0
  90. package/dist/3813.js +1 -0
  91. package/dist/3813.js.map +1 -0
  92. package/dist/393.js +6 -0
  93. package/dist/393.js.map +1 -0
  94. package/dist/3953.js +1 -0
  95. package/dist/3953.js.map +1 -0
  96. package/dist/3989.js +1 -0
  97. package/dist/3989.js.map +1 -0
  98. package/dist/4178.js +1 -0
  99. package/dist/4178.js.map +1 -0
  100. package/dist/4487.js +11 -0
  101. package/dist/4487.js.map +1 -0
  102. package/dist/4588.js +1 -0
  103. package/dist/4588.js.map +1 -0
  104. package/dist/4612.js +1 -0
  105. package/dist/4612.js.map +1 -0
  106. package/dist/4637.js +1 -0
  107. package/dist/4637.js.map +1 -0
  108. package/dist/466.js +1 -0
  109. package/dist/466.js.map +1 -0
  110. package/dist/4817.js +1 -0
  111. package/dist/4817.js.map +1 -0
  112. package/dist/4818.js +1 -0
  113. package/dist/4818.js.map +1 -0
  114. package/dist/500.js +1 -0
  115. package/dist/500.js.map +1 -0
  116. package/dist/5086.js +1 -0
  117. package/dist/5086.js.map +1 -0
  118. package/dist/5117.js +1 -0
  119. package/dist/5117.js.map +1 -0
  120. package/dist/5361.js +1 -0
  121. package/dist/5361.js.map +1 -0
  122. package/dist/5366.js +1 -0
  123. package/dist/5366.js.map +1 -0
  124. package/dist/5598.js +1 -0
  125. package/dist/5598.js.map +1 -0
  126. package/dist/5676.js +1 -0
  127. package/dist/5676.js.map +1 -0
  128. package/dist/5731.js +5 -0
  129. package/dist/5731.js.map +1 -0
  130. package/dist/5792.js +1 -0
  131. package/dist/5792.js.map +1 -0
  132. package/dist/5825.js +1 -0
  133. package/dist/5825.js.map +1 -0
  134. package/dist/5932.js +1 -0
  135. package/dist/5932.js.map +1 -0
  136. package/dist/5941.js +1 -0
  137. package/dist/5941.js.map +1 -0
  138. package/dist/5967.js +1 -0
  139. package/dist/5967.js.map +1 -0
  140. package/dist/6104.js +1 -0
  141. package/dist/6104.js.map +1 -0
  142. package/dist/624.js +1 -0
  143. package/dist/624.js.map +1 -0
  144. package/dist/6259.js +1 -0
  145. package/dist/6259.js.map +1 -0
  146. package/dist/6288.js +1 -0
  147. package/dist/6288.js.map +1 -0
  148. package/dist/629.js +1 -0
  149. package/dist/629.js.map +1 -0
  150. package/dist/6337.js +1 -0
  151. package/dist/6337.js.map +1 -0
  152. package/dist/6427.js +1 -0
  153. package/dist/6427.js.map +1 -0
  154. package/dist/6478.js +7 -0
  155. package/dist/6478.js.map +1 -0
  156. package/dist/6508.js +1 -0
  157. package/dist/6508.js.map +1 -0
  158. package/dist/6567.js +1 -0
  159. package/dist/6567.js.map +1 -0
  160. package/dist/6634.js +1 -0
  161. package/dist/6634.js.map +1 -0
  162. package/dist/689.js +1 -0
  163. package/dist/689.js.map +1 -0
  164. package/dist/7022.js +1 -0
  165. package/dist/7022.js.map +1 -0
  166. package/dist/7085.js +1 -0
  167. package/dist/7085.js.map +1 -0
  168. package/dist/7209.js +1 -0
  169. package/dist/7209.js.map +1 -0
  170. package/dist/7235.js +1 -0
  171. package/dist/7235.js.map +1 -0
  172. package/dist/7360.js +1 -0
  173. package/dist/7360.js.map +1 -0
  174. package/dist/7453.js +1 -0
  175. package/dist/7453.js.map +1 -0
  176. package/dist/7454.js +1 -0
  177. package/dist/7454.js.map +1 -0
  178. package/dist/7478.js +1 -0
  179. package/dist/7478.js.map +1 -0
  180. package/dist/7782.js +1 -0
  181. package/dist/7782.js.map +1 -0
  182. package/dist/7887.js +1 -0
  183. package/dist/7887.js.map +1 -0
  184. package/dist/8028.js +1 -0
  185. package/dist/8028.js.map +1 -0
  186. package/dist/8196.js +1 -0
  187. package/dist/8196.js.map +1 -0
  188. package/dist/820.js +1 -0
  189. package/dist/820.js.map +1 -0
  190. package/dist/8458.js +1 -0
  191. package/dist/8458.js.map +1 -0
  192. package/dist/8472.js +1 -0
  193. package/dist/8472.js.map +1 -0
  194. package/dist/8607.js +1 -0
  195. package/dist/8607.js.map +1 -0
  196. package/dist/8762.js +1 -0
  197. package/dist/8762.js.map +1 -0
  198. package/dist/8924.js +1 -0
  199. package/dist/8924.js.map +1 -0
  200. package/dist/8990.js +1 -0
  201. package/dist/8990.js.map +1 -0
  202. package/dist/9060.js +1 -0
  203. package/dist/9060.js.map +1 -0
  204. package/dist/9061.js +1 -0
  205. package/dist/9061.js.map +1 -0
  206. package/dist/9087.js +1 -0
  207. package/dist/9087.js.map +1 -0
  208. package/dist/9425.js +1 -0
  209. package/dist/9520.js +1 -0
  210. package/dist/9520.js.map +1 -0
  211. package/dist/9547.js +1 -0
  212. package/dist/9547.js.map +1 -0
  213. package/dist/9612.js +1 -0
  214. package/dist/9612.js.map +1 -0
  215. package/dist/9771.js +1 -0
  216. package/dist/9771.js.map +1 -0
  217. package/dist/9774.js +1 -0
  218. package/dist/9774.js.map +1 -0
  219. package/dist/9806.js +1 -0
  220. package/dist/9806.js.map +1 -0
  221. package/dist/992.js +1 -0
  222. package/dist/992.js.map +1 -0
  223. package/dist/997.js +1 -0
  224. package/dist/997.js.map +1 -0
  225. package/dist/kenyaemr-esm-icu-app.js +3 -0
  226. package/dist/kenyaemr-esm-icu-app.js.buildmanifest.json +3063 -0
  227. package/dist/kenyaemr-esm-icu-app.js.map +1 -0
  228. package/dist/main.js +3 -0
  229. package/dist/main.js.map +1 -0
  230. package/dist/routes.json +1 -0
  231. package/package.json +49 -0
  232. package/rspack.config.js +1 -0
  233. package/src/components/bed-board/icu-bed-board.component.tsx +173 -0
  234. package/src/components/bed-board/icu-bed-board.scss +228 -0
  235. package/src/components/header/header.component.tsx +25 -0
  236. package/src/components/header/header.scss +24 -0
  237. package/src/components/patient-table/icu-patient-table.component.tsx +232 -0
  238. package/src/components/patient-table/icu-patient-table.scss +91 -0
  239. package/src/components/side-menu/left-panel.component.tsx +23 -0
  240. package/src/components/side-menu/left-panel.scss +7 -0
  241. package/src/components/summary/icu-summary-tiles.component.tsx +154 -0
  242. package/src/components/summary/icu-summary-tiles.scss +116 -0
  243. package/src/config-schema.ts +33 -0
  244. package/src/context/icu-census.context.tsx +68 -0
  245. package/src/dashboard-link.component.tsx +41 -0
  246. package/src/dashboard-link.scss +6 -0
  247. package/src/declarations.d.ts +2 -0
  248. package/src/icu-dashboard.component.tsx +28 -0
  249. package/src/icu-dashboard.scss +401 -0
  250. package/src/icu-embedded-dashboard.component.tsx +15 -0
  251. package/src/index.ts +59 -0
  252. package/src/left-panel-link.component.tsx +44 -0
  253. package/src/left-panel-link.scss +11 -0
  254. package/src/resources/icu-admission.resource.ts +546 -0
  255. package/src/root.component.tsx +29 -0
  256. package/src/root.scss +11 -0
  257. package/src/routes.json +38 -0
  258. package/src/types/icu-bed.types.ts +91 -0
  259. package/src/types/icu-census-patient.types.ts +24 -0
  260. package/src/types/icu-patient.types.ts +37 -0
  261. package/src/utils/icu-census.helpers.ts +31 -0
  262. package/src/utils/icu-day-label.ts +11 -0
  263. package/translations/am.json +48 -0
  264. package/translations/en.json +48 -0
  265. package/translations/fr.json +48 -0
  266. package/translations/sw.json +48 -0
  267. package/tsconfig.json +5 -0
  268. package/webpack.config.js +1 -0
@@ -0,0 +1,154 @@
1
+ import React, { useMemo } from 'react';
2
+ import { Button, InlineLoading } from '@carbon/react';
3
+ import {
4
+ Activity,
5
+ EventSchedule,
6
+ HospitalBed,
7
+ Industry,
8
+ RainDrop,
9
+ Renew,
10
+ Security,
11
+ UserMultiple,
12
+ } from '@carbon/react/icons';
13
+ import { useTranslation } from 'react-i18next';
14
+
15
+ import { useIcuCensus } from '../../context/icu-census.context';
16
+ import { countWardFlags } from '../../types/icu-patient.types';
17
+ import styles from './icu-summary-tiles.scss';
18
+
19
+ function pct(part: number, total: number): string {
20
+ if (!total) {
21
+ return '0%';
22
+ }
23
+ return `${Math.round((part / total) * 100)}%`;
24
+ }
25
+
26
+ const IcuSummaryTiles: React.FC = () => {
27
+ const { t } = useTranslation();
28
+ const { wardSummary, patients, isLoading, isValidating, reload } = useIcuCensus();
29
+
30
+ const flags = useMemo(() => countWardFlags(patients), [patients]);
31
+
32
+ const lastUpdated = useMemo(() => {
33
+ try {
34
+ return new Intl.DateTimeFormat(undefined, {
35
+ day: '2-digit',
36
+ month: '2-digit',
37
+ year: '2-digit',
38
+ hour: '2-digit',
39
+ minute: '2-digit',
40
+ hour12: false,
41
+ }).format(new Date());
42
+ } catch {
43
+ return new Date().toLocaleString();
44
+ }
45
+ // Refresh the timestamp only when the census payload actually changes.
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [wardSummary, patients]);
48
+
49
+ const tiles = useMemo(() => {
50
+ const total = wardSummary.totalBeds || 0;
51
+ const occ = Math.max(wardSummary.occupied, 1);
52
+ return [
53
+ {
54
+ key: 'beds',
55
+ label: t('totalBeds', 'Total beds'),
56
+ value: total,
57
+ sub: t('capacity', 'Capacity'),
58
+ icon: <HospitalBed size={18} />,
59
+ iconClass: styles.iconBeds,
60
+ },
61
+ {
62
+ key: 'occupied',
63
+ label: t('occupied', 'Occupied'),
64
+ value: wardSummary.occupied,
65
+ sub: pct(wardSummary.occupied, total),
66
+ icon: <UserMultiple size={18} />,
67
+ iconClass: styles.iconOccupied,
68
+ },
69
+ {
70
+ key: 'available',
71
+ label: t('available', 'Available'),
72
+ value: wardSummary.available,
73
+ sub: pct(wardSummary.available, total),
74
+ icon: <HospitalBed size={18} />,
75
+ iconClass: styles.iconAvailable,
76
+ },
77
+ {
78
+ key: 'reserved',
79
+ label: t('reserved', 'Reserved'),
80
+ value: wardSummary.reserved,
81
+ sub: pct(wardSummary.reserved, total),
82
+ icon: <EventSchedule size={18} />,
83
+ iconClass: styles.iconReserved,
84
+ },
85
+ {
86
+ key: 'vent',
87
+ label: t('flagVentilated', 'Ventilated'),
88
+ value: flags.ventilated,
89
+ sub: pct(flags.ventilated, occ),
90
+ icon: <Activity size={18} />,
91
+ iconClass: styles.iconVent,
92
+ },
93
+ {
94
+ key: 'vaso',
95
+ label: t('flagVasopressors', 'Vasopressors'),
96
+ value: flags.vasopressors,
97
+ sub: pct(flags.vasopressors, occ),
98
+ icon: <RainDrop size={18} />,
99
+ iconClass: styles.iconVaso,
100
+ },
101
+ {
102
+ key: 'crrt',
103
+ label: t('flagCrrt', 'CRRT'),
104
+ value: flags.crrt,
105
+ sub: pct(flags.crrt, occ),
106
+ icon: <Industry size={18} />,
107
+ iconClass: styles.iconCrrt,
108
+ },
109
+ {
110
+ key: 'iso',
111
+ label: t('isolation', 'Isolation'),
112
+ value: flags.isolation,
113
+ sub: pct(flags.isolation, occ),
114
+ icon: <Security size={18} />,
115
+ iconClass: styles.iconIsolation,
116
+ },
117
+ ];
118
+ }, [wardSummary, flags, t]);
119
+
120
+ if (isLoading) {
121
+ return (
122
+ <div className={styles.homeBlock}>
123
+ <InlineLoading description={t('loadingIcuCensus', 'Loading ICU admissions…')} />
124
+ </div>
125
+ );
126
+ }
127
+
128
+ return (
129
+ <div className={styles.homeBlock}>
130
+ <div className={styles.metaRow}>
131
+ <span className={styles.updatedAt}>
132
+ {t('lastUpdated', 'Last updated')}: {lastUpdated}
133
+ </span>
134
+ <Button kind="ghost" size="sm" renderIcon={Renew} onClick={() => reload()} disabled={isValidating}>
135
+ {isValidating ? t('refreshing', 'Refreshing…') : t('refresh', 'Refresh')}
136
+ </Button>
137
+ </div>
138
+ <div className={styles.tileRow}>
139
+ {tiles.map((tile) => (
140
+ <article key={tile.key} className={styles.tile}>
141
+ <span className={`${styles.iconWrap} ${tile.iconClass}`}>{tile.icon}</span>
142
+ <p className={styles.label}>{tile.label}</p>
143
+ <div className={styles.valueRow}>
144
+ <p className={styles.value}>{tile.value}</p>
145
+ <span className={styles.pct}>{tile.sub}</span>
146
+ </div>
147
+ </article>
148
+ ))}
149
+ </div>
150
+ </div>
151
+ );
152
+ };
153
+
154
+ export default IcuSummaryTiles;
@@ -0,0 +1,116 @@
1
+ @use '@carbon/colors';
2
+ @use '@carbon/layout';
3
+ @use '@carbon/type';
4
+
5
+ .homeBlock {
6
+ margin-bottom: layout.$spacing-06;
7
+ }
8
+
9
+ .metaRow {
10
+ align-items: center;
11
+ color: colors.$gray-70;
12
+ display: flex;
13
+ flex-wrap: wrap;
14
+ gap: layout.$spacing-03;
15
+ justify-content: flex-end;
16
+ margin-bottom: layout.$spacing-04;
17
+ }
18
+
19
+ .updatedAt {
20
+ @include type.type-style('label-01');
21
+ color: colors.$gray-70;
22
+ }
23
+
24
+ .tileRow {
25
+ display: grid;
26
+ gap: layout.$spacing-04;
27
+ grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
28
+ }
29
+
30
+ .tile {
31
+ align-items: flex-start;
32
+ background: colors.$white;
33
+ border: 1px solid colors.$gray-20;
34
+ border-radius: layout.$spacing-04;
35
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
36
+ display: flex;
37
+ flex-direction: column;
38
+ gap: layout.$spacing-03;
39
+ min-height: 6rem;
40
+ padding: layout.$spacing-04;
41
+ }
42
+
43
+ .iconWrap {
44
+ align-items: center;
45
+ border-radius: layout.$spacing-03;
46
+ display: inline-flex;
47
+ height: 2.25rem;
48
+ justify-content: center;
49
+ width: 2.25rem;
50
+ }
51
+
52
+ .iconBeds {
53
+ background: colors.$blue-20;
54
+ color: colors.$blue-70;
55
+ }
56
+
57
+ .iconOccupied {
58
+ background: colors.$purple-20;
59
+ color: colors.$purple-70;
60
+ }
61
+
62
+ .iconAvailable {
63
+ background: colors.$green-20;
64
+ color: colors.$green-80;
65
+ }
66
+
67
+ .iconReserved {
68
+ background: colors.$orange-20;
69
+ color: colors.$orange-70;
70
+ }
71
+
72
+ .iconVent {
73
+ background: colors.$teal-20;
74
+ color: colors.$teal-70;
75
+ }
76
+
77
+ .iconVaso {
78
+ background: colors.$red-20;
79
+ color: colors.$red-70;
80
+ }
81
+
82
+ .iconCrrt {
83
+ background: colors.$purple-20;
84
+ color: colors.$purple-80;
85
+ }
86
+
87
+ .iconIsolation {
88
+ background: colors.$yellow-10;
89
+ color: colors.$yellow-60;
90
+ }
91
+
92
+ .label {
93
+ @include type.type-style('label-01');
94
+ color: colors.$gray-70;
95
+ font-weight: 600;
96
+ margin: 0;
97
+ }
98
+
99
+ .valueRow {
100
+ align-items: baseline;
101
+ display: flex;
102
+ flex-wrap: wrap;
103
+ gap: layout.$spacing-02;
104
+ }
105
+
106
+ .value {
107
+ @include type.type-style('heading-03');
108
+ font-weight: 700;
109
+ margin: 0;
110
+ }
111
+
112
+ .pct {
113
+ @include type.type-style('label-01');
114
+ color: colors.$gray-60;
115
+ font-weight: 600;
116
+ }
@@ -0,0 +1,33 @@
1
+ import { Type } from '@openmrs/esm-framework';
2
+
3
+ export const DEFAULT_ICU_LOCATION_TAG_UUID = '770f6a93-8e59-48ad-ba7d-98d5652db240';
4
+
5
+ export const configSchema = {
6
+ windowDurationMinutes: {
7
+ _type: Type.Number,
8
+ _default: 60,
9
+ _description: 'Used later for ICU chart hour windows. Home census day labels use calendar days from admission.',
10
+ },
11
+ facilityTimeZone: {
12
+ _type: Type.String,
13
+ _default: 'Africa/Nairobi',
14
+ _description: 'IANA timezone for the facility.',
15
+ },
16
+ icuLocationTagUuid: {
17
+ _type: Type.String,
18
+ _default: DEFAULT_ICU_LOCATION_TAG_UUID,
19
+ _description: 'location_tag.uuid for ICU Ward beds used in the ICU census.',
20
+ },
21
+ icuLocationTagName: {
22
+ _type: Type.String,
23
+ _default: 'ICU Ward',
24
+ _description: 'Location tag name for ICU wards (paired with icuLocationTagUuid).',
25
+ },
26
+ };
27
+
28
+ export type IcuConfig = {
29
+ windowDurationMinutes: number;
30
+ facilityTimeZone: string;
31
+ icuLocationTagUuid: string;
32
+ icuLocationTagName: string;
33
+ };
@@ -0,0 +1,68 @@
1
+ import React, { createContext, useCallback, useContext, useMemo } from 'react';
2
+
3
+ import { useIcuCensusData } from '../resources/icu-admission.resource';
4
+ import { type IcuCensusPatient } from '../types/icu-census-patient.types';
5
+ import { type IcuPatientSummary, type IcuWardSummary } from '../types/icu-patient.types';
6
+ import { type IcuCensusBoardState } from '../utils/icu-census.helpers';
7
+
8
+ type IcuCensusContextValue = {
9
+ boardState: IcuCensusBoardState;
10
+ patients: IcuPatientSummary[];
11
+ patientByUuid: Map<string, IcuCensusPatient>;
12
+ wardSummary: IcuWardSummary;
13
+ isLoading: boolean;
14
+ isValidating: boolean;
15
+ error: Error | undefined;
16
+ reload: () => void;
17
+ getPatient: (patientUuid: string | undefined) => IcuCensusPatient | undefined;
18
+ };
19
+
20
+ const IcuCensusContext = createContext<IcuCensusContextValue | null>(null);
21
+
22
+ export function useIcuCensus(): IcuCensusContextValue {
23
+ const ctx = useContext(IcuCensusContext);
24
+ if (!ctx) {
25
+ throw new Error('useIcuCensus must be used within IcuCensusProvider');
26
+ }
27
+ return ctx;
28
+ }
29
+
30
+ export const IcuCensusProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
31
+ const { beds, patients, wardSummary, isLoading, isValidating, error, mutate } = useIcuCensusData();
32
+
33
+ const boardState = useMemo((): IcuCensusBoardState => ({ beds }), [beds]);
34
+
35
+ const patientByUuid = useMemo(() => {
36
+ const map = new Map<string, IcuCensusPatient>();
37
+ for (const p of patients) {
38
+ map.set(p.patientUuid, p);
39
+ }
40
+ return map;
41
+ }, [patients]);
42
+
43
+ const getPatient = useCallback(
44
+ (patientUuid: string | undefined) => (patientUuid ? patientByUuid.get(patientUuid) : undefined),
45
+ [patientByUuid],
46
+ );
47
+
48
+ const reload = useCallback(() => {
49
+ mutate();
50
+ }, [mutate]);
51
+
52
+ const value = useMemo(
53
+ () => ({
54
+ boardState,
55
+ patients,
56
+ patientByUuid,
57
+ wardSummary,
58
+ isLoading,
59
+ isValidating,
60
+ error: error as Error | undefined,
61
+ reload,
62
+ getPatient,
63
+ }),
64
+ [boardState, patients, patientByUuid, wardSummary, isLoading, isValidating, error, reload, getPatient],
65
+ );
66
+
67
+ return <IcuCensusContext.Provider value={value}>{children}</IcuCensusContext.Provider>;
68
+ };
@@ -0,0 +1,41 @@
1
+ import { ConfigurableLink, MaybeIcon } from '@openmrs/esm-framework';
2
+ import last from 'lodash-es/last';
3
+ import React, { useMemo } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { BrowserRouter, useLocation } from 'react-router-dom';
6
+
7
+ import styles from './dashboard-link.scss';
8
+
9
+ export interface LinkConfig {
10
+ name: string;
11
+ title: string;
12
+ icon?: string;
13
+ basePath?: string;
14
+ }
15
+
16
+ export function LinkExtension({ config }: { readonly config: LinkConfig }) {
17
+ const { t } = useTranslation();
18
+ const { name, title, icon, basePath = 'home' } = config;
19
+ const nameSegment = name.split('/').at(-1);
20
+ const location = useLocation();
21
+ const spaBasePath = window.getOpenmrsSpaBase() + basePath;
22
+
23
+ const urlSegment = useMemo(() => decodeURIComponent(last(location.pathname.split('/')) || ''), [location.pathname]);
24
+
25
+ const url = `${spaBasePath}/${name}`.replace(/([^:]\/)\/+/g, '/');
26
+ const isActive = nameSegment === urlSegment || (!name && urlSegment === basePath);
27
+
28
+ return (
29
+ <ConfigurableLink to={url} className={`cds--side-nav__link ${isActive ? 'active-left-nav-link' : ''}`}>
30
+ {icon ? <MaybeIcon icon={icon} className={styles.icon} size={16} /> : null}
31
+ {t(title)}
32
+ </ConfigurableLink>
33
+ );
34
+ }
35
+
36
+ export const createDashboardLink = (config: LinkConfig) => () =>
37
+ (
38
+ <BrowserRouter>
39
+ <LinkExtension config={config} />
40
+ </BrowserRouter>
41
+ );
@@ -0,0 +1,6 @@
1
+ @use '@carbon/layout';
2
+
3
+ .icon {
4
+ margin-right: layout.$spacing-03;
5
+ vertical-align: middle;
6
+ }
@@ -0,0 +1,2 @@
1
+ declare module '*.css';
2
+ declare module '*.scss';
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+
3
+ import IcuSummaryTiles from './components/summary/icu-summary-tiles.component';
4
+ import IcuBedBoard from './components/bed-board/icu-bed-board.component';
5
+ import IcuPatientTable from './components/patient-table/icu-patient-table.component';
6
+ import Header from './components/header/header.component';
7
+ import { IcuCensusProvider } from './context/icu-census.context';
8
+ import styles from './icu-dashboard.scss';
9
+
10
+ interface IcuDashboardProps {
11
+ embedded?: boolean;
12
+ standalone?: boolean;
13
+ }
14
+
15
+ const IcuDashboard: React.FC<IcuDashboardProps> = ({ standalone = false }) => {
16
+ return (
17
+ <div className={styles.dashboard}>
18
+ <Header standalone={standalone} />
19
+ <IcuCensusProvider>
20
+ <IcuSummaryTiles />
21
+ <IcuBedBoard />
22
+ <IcuPatientTable />
23
+ </IcuCensusProvider>
24
+ </div>
25
+ );
26
+ };
27
+
28
+ export default IcuDashboard;