@openmrs/esm-service-queues-app 5.0.1-pre.2087

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 (254) hide show
  1. package/.turbo/turbo-build.log +40 -0
  2. package/LICENSE.md +401 -0
  3. package/README.md +23 -0
  4. package/__mocks__/active-visits.mock.ts +97 -0
  5. package/__mocks__/appointments-data.mock.ts +283 -0
  6. package/__mocks__/search.mock.ts +35 -0
  7. package/__mocks__/visits.mock.ts +42 -0
  8. package/dist/121.js +1 -0
  9. package/dist/121.js.map +1 -0
  10. package/dist/130.js +2 -0
  11. package/dist/130.js.LICENSE.txt +5 -0
  12. package/dist/130.js.map +1 -0
  13. package/dist/176.js +1 -0
  14. package/dist/176.js.map +1 -0
  15. package/dist/227.js +1 -0
  16. package/dist/227.js.map +1 -0
  17. package/dist/242.js +1 -0
  18. package/dist/242.js.map +1 -0
  19. package/dist/252.js +1 -0
  20. package/dist/252.js.map +1 -0
  21. package/dist/286.js +1 -0
  22. package/dist/286.js.map +1 -0
  23. package/dist/308.js +1 -0
  24. package/dist/308.js.map +1 -0
  25. package/dist/319.js +1 -0
  26. package/dist/328.js +1 -0
  27. package/dist/328.js.map +1 -0
  28. package/dist/330.js +1 -0
  29. package/dist/330.js.map +1 -0
  30. package/dist/364.js +1 -0
  31. package/dist/364.js.map +1 -0
  32. package/dist/425.js +1 -0
  33. package/dist/425.js.map +1 -0
  34. package/dist/457.js +1 -0
  35. package/dist/457.js.map +1 -0
  36. package/dist/469.js +1 -0
  37. package/dist/469.js.map +1 -0
  38. package/dist/521.js +1 -0
  39. package/dist/521.js.map +1 -0
  40. package/dist/53.js +1 -0
  41. package/dist/53.js.map +1 -0
  42. package/dist/574.js +1 -0
  43. package/dist/591.js +2 -0
  44. package/dist/591.js.LICENSE.txt +32 -0
  45. package/dist/591.js.map +1 -0
  46. package/dist/610.js +1 -0
  47. package/dist/610.js.map +1 -0
  48. package/dist/611.js +1 -0
  49. package/dist/611.js.map +1 -0
  50. package/dist/616.js +1 -0
  51. package/dist/616.js.map +1 -0
  52. package/dist/644.js +1 -0
  53. package/dist/644.js.map +1 -0
  54. package/dist/670.js +2 -0
  55. package/dist/670.js.LICENSE.txt +57 -0
  56. package/dist/670.js.map +1 -0
  57. package/dist/733.js +1 -0
  58. package/dist/733.js.map +1 -0
  59. package/dist/757.js +1 -0
  60. package/dist/764.js +1 -0
  61. package/dist/764.js.map +1 -0
  62. package/dist/766.js +1 -0
  63. package/dist/766.js.map +1 -0
  64. package/dist/784.js +2 -0
  65. package/dist/784.js.LICENSE.txt +9 -0
  66. package/dist/784.js.map +1 -0
  67. package/dist/788.js +1 -0
  68. package/dist/807.js +1 -0
  69. package/dist/833.js +1 -0
  70. package/dist/86.js +1 -0
  71. package/dist/86.js.map +1 -0
  72. package/dist/981.js +1 -0
  73. package/dist/981.js.map +1 -0
  74. package/dist/main.js +1 -0
  75. package/dist/main.js.map +1 -0
  76. package/dist/openmrs-esm-service-queues-app.js +1 -0
  77. package/dist/openmrs-esm-service-queues-app.js.buildmanifest.json +930 -0
  78. package/dist/openmrs-esm-service-queues-app.js.map +1 -0
  79. package/dist/routes.json +1 -0
  80. package/jest.config.js +3 -0
  81. package/package.json +53 -0
  82. package/src/active-visits/active-visits-tab.component.tsx +71 -0
  83. package/src/active-visits/active-visits-tab.test.tsx +19 -0
  84. package/src/active-visits/active-visits-table.component.tsx +543 -0
  85. package/src/active-visits/active-visits-table.resource.ts +443 -0
  86. package/src/active-visits/active-visits-table.scss +271 -0
  87. package/src/active-visits/active-visits-table.test.tsx +131 -0
  88. package/src/active-visits/change-status-dialog.component.tsx +233 -0
  89. package/src/active-visits/change-status-dialog.scss +32 -0
  90. package/src/active-visits/change-status-dialog.test.tsx +107 -0
  91. package/src/add-patient-toqueue/add-patient-toqueue-dialog.component.tsx +218 -0
  92. package/src/add-patient-toqueue/add-patient-toqueue-dialog.scss +32 -0
  93. package/src/add-provider-queue-room/add-provider-queue-room.component.tsx +236 -0
  94. package/src/add-provider-queue-room/add-provider-queue-room.resource.tsx +76 -0
  95. package/src/add-provider-queue-room/add-provider-queue-room.scss +17 -0
  96. package/src/add-provider-queue-room/add-provider-queue-room.test.tsx +98 -0
  97. package/src/clear-queue-entries-dialog/clear-queue-entries-dialog.component.tsx +74 -0
  98. package/src/clear-queue-entries-dialog/clear-queue-entries-dialog.resource.tsx +46 -0
  99. package/src/clear-queue-entries-dialog/clear-queue-entries-dialog.scss +15 -0
  100. package/src/clear-queue-entries-dialog/clear-queue-entries-dialog.test.tsx +42 -0
  101. package/src/clear-queue-entries-dialog/clear-queue-entries.component.tsx +36 -0
  102. package/src/config-schema.ts +177 -0
  103. package/src/constants.ts +7 -0
  104. package/src/createDashboardLink.tsx +35 -0
  105. package/src/current-visit/current-visit-summary.component.tsx +38 -0
  106. package/src/current-visit/current-visit-summary.test.tsx +47 -0
  107. package/src/current-visit/current-visit.resource.ts +84 -0
  108. package/src/current-visit/current-visit.scss +34 -0
  109. package/src/current-visit/hooks/useVitalsConceptMetadata.tsx +101 -0
  110. package/src/current-visit/visit-details/biometrics-config-schema.ts +14 -0
  111. package/src/current-visit/visit-details/current-visit-details.component.tsx +96 -0
  112. package/src/current-visit/visit-details/triage-note.component.tsx +53 -0
  113. package/src/current-visit/visit-details/triage-note.scss +89 -0
  114. package/src/current-visit/visit-details/vitals-config-schema.ts +17 -0
  115. package/src/current-visit/visit-details/vitals.component.tsx +164 -0
  116. package/src/dashboard.meta.ts +5 -0
  117. package/src/declarations.d.ts +2 -0
  118. package/src/helpers/functions.ts +67 -0
  119. package/src/helpers/helpers.ts +170 -0
  120. package/src/helpers/time-helpers.ts +15 -0
  121. package/src/home.component.tsx +29 -0
  122. package/src/home.test.tsx +58 -0
  123. package/src/index.ts +100 -0
  124. package/src/overlay.component.tsx +46 -0
  125. package/src/overlay.scss +96 -0
  126. package/src/overlay.test.tsx +49 -0
  127. package/src/past-visit/past-visit-details/encounter-list.component.tsx +51 -0
  128. package/src/past-visit/past-visit-details/medications-list.component.tsx +95 -0
  129. package/src/past-visit/past-visit-details/notes-list.component.tsx +40 -0
  130. package/src/past-visit/past-visit-details/past-visit-summary.component.tsx +172 -0
  131. package/src/past-visit/past-visit-details/past-visit-summary.scss +58 -0
  132. package/src/past-visit/past-visit.component.tsx +37 -0
  133. package/src/past-visit/past-visit.resource.ts +83 -0
  134. package/src/past-visit/past-visit.scss +126 -0
  135. package/src/past-visit/past-visit.test.tsx +41 -0
  136. package/src/patient-info/appointment-details.component.tsx +98 -0
  137. package/src/patient-info/appointment-details.scss +34 -0
  138. package/src/patient-info/appointment-details.test.tsx +36 -0
  139. package/src/patient-info/appointments.resource.tsx +43 -0
  140. package/src/patient-info/contact-details.component.tsx +71 -0
  141. package/src/patient-info/contact-details.scss +31 -0
  142. package/src/patient-info/contact-details.test.tsx +94 -0
  143. package/src/patient-info/hooks/usePatientAttributes.tsx +42 -0
  144. package/src/patient-info/patient-info.component.tsx +78 -0
  145. package/src/patient-info/patient-info.scss +60 -0
  146. package/src/patient-info/patient-info.test.tsx +45 -0
  147. package/src/patient-queue-header/patient-queue-header.component.tsx +64 -0
  148. package/src/patient-queue-header/patient-queue-header.scss +88 -0
  149. package/src/patient-queue-header/patient-queue-illustration.component.tsx +22 -0
  150. package/src/patient-queue-metrics/clinic-metrics.component.tsx +93 -0
  151. package/src/patient-queue-metrics/clinic-metrics.resource.tsx +51 -0
  152. package/src/patient-queue-metrics/clinic-metrics.scss +11 -0
  153. package/src/patient-queue-metrics/clinic-metrics.test.tsx +87 -0
  154. package/src/patient-queue-metrics/metrics-card.component.tsx +64 -0
  155. package/src/patient-queue-metrics/metrics-card.scss +80 -0
  156. package/src/patient-queue-metrics/metrics-header.component.tsx +74 -0
  157. package/src/patient-queue-metrics/metrics-header.scss +22 -0
  158. package/src/patient-queue-metrics/queue-metrics.resource.ts +54 -0
  159. package/src/patient-search/advanced-search.component.tsx +190 -0
  160. package/src/patient-search/advanced-search.scss +154 -0
  161. package/src/patient-search/advanced-search.test.tsx +29 -0
  162. package/src/patient-search/basic-search.component.tsx +112 -0
  163. package/src/patient-search/basic-search.scss +139 -0
  164. package/src/patient-search/basic-search.test.tsx +23 -0
  165. package/src/patient-search/empty-data-illustration.component.tsx +41 -0
  166. package/src/patient-search/hooks/useActivePatientEnrollment.tsx +29 -0
  167. package/src/patient-search/hooks/useDefaultLocation.tsx +14 -0
  168. package/src/patient-search/hooks/usePatients.tsx +25 -0
  169. package/src/patient-search/hooks/useQueueLocations.tsx +20 -0
  170. package/src/patient-search/hooks/useRecommendedVisitTypes.tsx +36 -0
  171. package/src/patient-search/hooks/useScheduledVisits.tsx +50 -0
  172. package/src/patient-search/patient-scheduled-visits.component.tsx +350 -0
  173. package/src/patient-search/patient-scheduled-visits.scss +131 -0
  174. package/src/patient-search/patient-scheduled-visits.test.tsx +55 -0
  175. package/src/patient-search/patient-search.component.tsx +64 -0
  176. package/src/patient-search/search-illustration.component.tsx +27 -0
  177. package/src/patient-search/search-results.component.tsx +75 -0
  178. package/src/patient-search/search-results.scss +80 -0
  179. package/src/patient-search/search-results.test.tsx +77 -0
  180. package/src/patient-search/search.resource.ts +10 -0
  181. package/src/patient-search/visit-form/base-visit-type.component.tsx +82 -0
  182. package/src/patient-search/visit-form/base-visit-type.scss +100 -0
  183. package/src/patient-search/visit-form/base-visit-type.test.tsx +41 -0
  184. package/src/patient-search/visit-form/queue.resource.ts +73 -0
  185. package/src/patient-search/visit-form/recommended-visit-type.component.tsx +38 -0
  186. package/src/patient-search/visit-form/visit-form.component.tsx +366 -0
  187. package/src/patient-search/visit-form/visit-form.scss +96 -0
  188. package/src/patient-search/visit-form-queue-fields/visit-form-queue-fields.component.tsx +160 -0
  189. package/src/patient-search/visit-form-queue-fields/visit-form-queue-fields.scss +21 -0
  190. package/src/patient-search/visit-form-queue-fields/visit-form-queue-fields.test.tsx +67 -0
  191. package/src/queue-entry-table-components/actions-menu.component.tsx +51 -0
  192. package/src/queue-entry-table-components/actions-menu.scss +3 -0
  193. package/src/queue-entry-table-components/edit-entry.component.tsx +28 -0
  194. package/src/queue-entry-table-components/edit-entry.scss +14 -0
  195. package/src/queue-entry-table-components/open-chart.component.tsx +33 -0
  196. package/src/queue-entry-table-components/open-chart.resource.tsx +14 -0
  197. package/src/queue-entry-table-components/open-chart.scss +14 -0
  198. package/src/queue-entry-table-components/status-icon.component.tsx +17 -0
  199. package/src/queue-entry-table-components/transition-entry.component.tsx +53 -0
  200. package/src/queue-entry-table-components/transition-entry.scss +22 -0
  201. package/src/queue-patient-linelists/queue-linelist-base-table.component.tsx +230 -0
  202. package/src/queue-patient-linelists/queue-linelist-base-table.scss +110 -0
  203. package/src/queue-patient-linelists/queue-linelist-base-table.test.tsx +118 -0
  204. package/src/queue-patient-linelists/queue-linelist-filter.component.tsx +172 -0
  205. package/src/queue-patient-linelists/queue-linelist-filter.scss +63 -0
  206. package/src/queue-patient-linelists/queue-linelist-filter.test.tsx +76 -0
  207. package/src/queue-patient-linelists/queue-linelist.component.tsx +29 -0
  208. package/src/queue-patient-linelists/queue-linelist.resource.tsx +84 -0
  209. package/src/queue-patient-linelists/queue-linelist.test.tsx +22 -0
  210. package/src/queue-patient-linelists/queue-services-table.component.tsx +63 -0
  211. package/src/queue-patient-linelists/scheduled-appointments-table.component.tsx +300 -0
  212. package/src/queue-patient-linelists/scheduled-appointments-table.test.tsx +42 -0
  213. package/src/queue-rooms/queue-room-form.component.tsx +168 -0
  214. package/src/queue-rooms/queue-room-form.test.tsx +65 -0
  215. package/src/queue-rooms/queue-room.resource.tsx +20 -0
  216. package/src/queue-rooms/queue-room.scss +58 -0
  217. package/src/queue-screen/queue-screen.component.tsx +47 -0
  218. package/src/queue-screen/queue-screen.scss +39 -0
  219. package/src/queue-screen/queue-screen.test.tsx +47 -0
  220. package/src/queue-screen/useActiveTickets.tsx +13 -0
  221. package/src/queue-services/queue-service-form.component.tsx +183 -0
  222. package/src/queue-services/queue-service-form.test.tsx +56 -0
  223. package/src/queue-services/queue-service.resource.tsx +38 -0
  224. package/src/queue-services/queue-service.scss +54 -0
  225. package/src/remove-queue-entry-dialog/remove-queue-entry.component.tsx +95 -0
  226. package/src/remove-queue-entry-dialog/remove-queue-entry.resource.tsx +93 -0
  227. package/src/remove-queue-entry-dialog/remove-queue-entry.scss +8 -0
  228. package/src/remove-queue-entry-dialog/remove-queue-entry.test.tsx +44 -0
  229. package/src/root.component.tsx +28 -0
  230. package/src/root.scss +15 -0
  231. package/src/root.test.tsx +28 -0
  232. package/src/routes.json +91 -0
  233. package/src/side-menu/nav-group/createNavGroup.tsx +17 -0
  234. package/src/side-menu/nav-group/nav-group.component.tsx +24 -0
  235. package/src/side-menu/nav-group/nav-group.test.tsx +32 -0
  236. package/src/side-menu/nav-group/nav-group.ts +10 -0
  237. package/src/side-menu/side-menu.component.tsx +6 -0
  238. package/src/side-menu/side-menu.test.tsx +17 -0
  239. package/src/transition-queue-entry/transition-queue-entry-dialog.component.tsx +174 -0
  240. package/src/transition-queue-entry/transition-queue-entry-dialog.scss +12 -0
  241. package/src/transition-queue-entry/transition-queue-entry-dialog.test.tsx +95 -0
  242. package/src/transition-queue-entry/transition-queue-entry.resource.ts +16 -0
  243. package/src/types/index.ts +434 -0
  244. package/src/visits-missing-inqueue/visits-missing-inqueue.component.tsx +298 -0
  245. package/src/visits-missing-inqueue/visits-missing-inqueue.resource.ts +93 -0
  246. package/src/visits-missing-inqueue/visits-missing-inqueue.scss +108 -0
  247. package/translations/am.json +258 -0
  248. package/translations/en.json +258 -0
  249. package/translations/es.json +258 -0
  250. package/translations/fr.json +258 -0
  251. package/translations/he.json +262 -0
  252. package/translations/km.json +258 -0
  253. package/tsconfig.json +5 -0
  254. package/webpack.config.js +1 -0
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+
3
+ const EmptyDataIllustration = ({ width = '61', height = '59' }) => {
4
+ return (
5
+ <svg width={width} height={height} viewBox="0 0 61 59">
6
+ <title>Empty data illustration</title>
7
+ <g fill="none" fillRule="evenodd">
8
+ <path
9
+ d="M38.133 13.186H21.947c-.768.001-1.39.623-1.39 1.391V50.55l-.186.057-3.97 1.216a.743.743 0 01-.927-.493L3.664 12.751a.742.742 0 01.492-.926l6.118-1.874 17.738-5.43 6.119-1.873a.741.741 0 01.926.492L38.076 13l.057.186z"
10
+ fill="#E0E0E0"
11
+ />
12
+ <path
13
+ d="M41.664 13L38.026 1.117A1.576 1.576 0 0036.056.07l-8.601 2.633-17.737 5.43-8.603 2.634a1.578 1.578 0 00-1.046 1.97l12.436 40.616a1.58 1.58 0 001.969 1.046l5.897-1.805.185-.057v-.194l-.185.057-5.952 1.822a1.393 1.393 0 01-1.737-.923L.247 12.682a1.39 1.39 0 01.923-1.738L9.772 8.31 27.51 2.881 36.112.247a1.393 1.393 0 011.737.923L41.47 13l.057.186h.193l-.057-.185z"
14
+ fill="#8D8D8D"
15
+ />
16
+ <path
17
+ d="M11.378 11.855a.836.836 0 01-.798-.59L9.385 7.361a.835.835 0 01.554-1.042l16.318-4.996a.836.836 0 011.042.554l1.195 3.902a.836.836 0 01-.554 1.043l-16.318 4.995a.831.831 0 01-.244.037z"
18
+ fill="#C6C6C6"
19
+ />
20
+ <circle fill="#C6C6C6" cx={17.636} cy={2.314} r={1.855} />
21
+ <circle fill="#FFF" fillRule="nonzero" cx={17.636} cy={2.314} r={1.175} />
22
+ <path
23
+ d="M55.893 53.995H24.544a.79.79 0 01-.788-.789V15.644a.79.79 0 01.788-.788h31.349a.79.79 0 01.788.788v37.562a.79.79 0 01-.788.789z"
24
+ fill="#E0E0E0"
25
+ />
26
+ <path
27
+ d="M41.47 13H21.948a1.579 1.579 0 00-1.576 1.577V52.4l.185-.057V14.577c.001-.768.623-1.39 1.391-1.39h19.581L41.471 13zm17.02 0H21.947a1.579 1.579 0 00-1.576 1.577v42.478c0 .87.706 1.576 1.576 1.577H58.49a1.579 1.579 0 001.576-1.577V14.577a1.579 1.579 0 00-1.576-1.576zm1.39 44.055c0 .768-.622 1.39-1.39 1.392H21.947c-.768-.001-1.39-.624-1.39-1.392V14.577c0-.768.622-1.39 1.39-1.39H58.49c.768 0 1.39.622 1.39 1.39v42.478z"
28
+ fill="#8D8D8D"
29
+ />
30
+ <path
31
+ d="M48.751 17.082H31.686a.836.836 0 01-.835-.835v-4.081c0-.46.374-.834.835-.835H48.75c.461 0 .834.374.835.835v4.08c0 .462-.374.835-.835.836z"
32
+ fill="#C6C6C6"
33
+ />
34
+ <circle fill="#C6C6C6" cx={40.218} cy={9.755} r={1.855} />
35
+ <circle fill="#FFF" fillRule="nonzero" cx={40.218} cy={9.755} r={1.13} />
36
+ </g>
37
+ </svg>
38
+ );
39
+ };
40
+
41
+ export default EmptyDataIllustration;
@@ -0,0 +1,29 @@
1
+ import useSWR from 'swr';
2
+ import { openmrsFetch } from '@openmrs/esm-framework';
3
+ import { useMemo } from 'react';
4
+ import { PatientProgram } from '../../types';
5
+ import uniqBy from 'lodash-es/uniqBy';
6
+ const customRepresentation = `custom:(uuid,display,program,dateEnrolled,dateCompleted,location:(uuid,display))`;
7
+
8
+ export const useActivePatientEnrollment = (patientUuid: string) => {
9
+ const apiUrl = `/ws/rest/v1/programenrollment?patient=${patientUuid}&v=${customRepresentation}`;
10
+
11
+ const { data, error, isLoading } = useSWR<{ data: { results: Array<PatientProgram> } }>(
12
+ patientUuid ? apiUrl : null,
13
+ openmrsFetch,
14
+ );
15
+
16
+ const activePatientEnrollment = useMemo(
17
+ () =>
18
+ data?.data.results
19
+ .sort((a, b) => (b.dateEnrolled > a.dateEnrolled ? 1 : -1))
20
+ .filter((enrollment) => enrollment.dateCompleted === null) ?? [],
21
+ [data?.data.results],
22
+ );
23
+
24
+ return {
25
+ activePatientEnrollment: uniqBy(activePatientEnrollment, (program) => program?.program?.uuid),
26
+ error,
27
+ isLoading,
28
+ };
29
+ };
@@ -0,0 +1,14 @@
1
+ import { FetchResponse, openmrsFetch, useConfig } from '@openmrs/esm-framework';
2
+ import useSWRImmutable from 'swr/immutable';
3
+
4
+ export const useDefaultLoginLocation = () => {
5
+ const config = useConfig();
6
+ const apiUrl = config.defaultFacilityUrl;
7
+ const { data, error, isLoading } = useSWRImmutable<FetchResponse>(apiUrl, openmrsFetch);
8
+
9
+ return {
10
+ defaultFacility: data ? data?.data : null,
11
+ isLoading: isLoading,
12
+ isError: error,
13
+ };
14
+ };
@@ -0,0 +1,25 @@
1
+ import useSWR from 'swr';
2
+ import { fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
3
+ import { useMemo } from 'react';
4
+
5
+ interface FHIRResponse {
6
+ entry: Array<{ resource: fhir.Patient }>;
7
+ total: number;
8
+ type: string;
9
+ resourceType: string;
10
+ }
11
+
12
+ const usePatients = (searchTerm: string) => {
13
+ const apiUrl = `${fhirBaseUrl}/Patient?name=${searchTerm}&_summary=data`;
14
+
15
+ const { data, error, isLoading } = useSWR<{ data: FHIRResponse }>(searchTerm !== null ? apiUrl : null, openmrsFetch);
16
+
17
+ const searchedPatients = useMemo(
18
+ () => data?.data?.entry?.map((response) => response.resource) ?? [],
19
+ [data?.data?.entry],
20
+ );
21
+
22
+ return { patients: searchedPatients, isLoading: isLoading && searchTerm !== null, error };
23
+ };
24
+
25
+ export default usePatients;
@@ -0,0 +1,20 @@
1
+ import useSWR from 'swr';
2
+ import { fhirBaseUrl, openmrsFetch } from '@openmrs/esm-framework';
3
+ import { useMemo } from 'react';
4
+
5
+ interface FHIRResponse {
6
+ entry: Array<{ resource: fhir.Location }>;
7
+ total: number;
8
+ type: string;
9
+ resourceType: string;
10
+ }
11
+ export function useQueueLocations() {
12
+ const apiUrl = `${fhirBaseUrl}/Location?_summary=data&_tag=queue location`;
13
+ const { data, error, isLoading } = useSWR<{ data: FHIRResponse }>(apiUrl, openmrsFetch);
14
+
15
+ const queueLocations = useMemo(
16
+ () => data?.data?.entry?.map((response) => response.resource) ?? [],
17
+ [data?.data?.entry],
18
+ );
19
+ return { queueLocations: queueLocations ? queueLocations : [], isLoading, error };
20
+ }
@@ -0,0 +1,36 @@
1
+ import useSWR from 'swr';
2
+ import { openmrsFetch, useConfig } from '@openmrs/esm-framework';
3
+ import { ConfigObject, OutpatientConfig } from '../../config-schema';
4
+ import { useMemo } from 'react';
5
+
6
+ interface EnrollmentVisitType {
7
+ dataDependencies: Array<string>;
8
+ enrollmentOptions: object;
9
+ incompatibleWith: Array<string>;
10
+ name: string;
11
+ visitTypes: { allowed: Array<EnrollmentVisitType>; disallowed: Array<EnrollmentVisitType> };
12
+ }
13
+
14
+ export const useRecommendedVisitTypes = (
15
+ patientUuid: string,
16
+ enrollmentUuid: string,
17
+ programUuid: string,
18
+ locationUuid: string,
19
+ ) => {
20
+ const { visitTypeResourceUrl } = useConfig() as OutpatientConfig;
21
+ const { showRecommendedVisitTypeTab } = useConfig() as ConfigObject;
22
+
23
+ const apiUrl = `${visitTypeResourceUrl}${patientUuid}/program/${programUuid}/enrollment/${enrollmentUuid}?intendedLocationUuid=${locationUuid}`;
24
+
25
+ const { data, error, isLoading } = useSWR<{ data: EnrollmentVisitType }>(
26
+ showRecommendedVisitTypeTab && patientUuid && enrollmentUuid && programUuid ? apiUrl : null,
27
+ openmrsFetch,
28
+ );
29
+
30
+ const recommendedVisitTypes = useMemo(() => data?.data?.visitTypes?.allowed.map(mapToVisitType) ?? [], [data]);
31
+ return { recommendedVisitTypes, error, isLoading };
32
+ };
33
+
34
+ const mapToVisitType = (visitType) => {
35
+ return { ...visitType, display: visitType.name };
36
+ };
@@ -0,0 +1,50 @@
1
+ import useSWR from 'swr';
2
+ import { openmrsFetch } from '@openmrs/esm-framework';
3
+ import dayjs from 'dayjs';
4
+ import { AppointmentsFetchResponse } from '../../types';
5
+
6
+ export function useScheduledVisits(patientUuid: string) {
7
+ const abortController = new AbortController();
8
+ let startDate = dayjs(new Date().toISOString()).subtract(6, 'month').toISOString();
9
+ const appointmentsSearchUrl = `/ws/rest/v1/appointments/search`;
10
+
11
+ const fetcher = () =>
12
+ openmrsFetch(appointmentsSearchUrl, {
13
+ method: 'POST',
14
+ signal: abortController.signal,
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ body: {
19
+ patientUuid: patientUuid,
20
+ startDate: startDate,
21
+ },
22
+ });
23
+
24
+ const { data, error, isLoading } = useSWR<AppointmentsFetchResponse, Error>(
25
+ patientUuid ? appointmentsSearchUrl : null,
26
+ fetcher,
27
+ );
28
+
29
+ const appointments = data?.data?.length
30
+ ? data.data.sort((a, b) => (b.startDateTime > a.startDateTime ? 1 : -1))
31
+ : null;
32
+
33
+ // visits + or - 7 days before visit date
34
+ const recentVisits = appointments?.filter(
35
+ (appointment) =>
36
+ dayjs((appointment.startDateTime / 1000) * 1000).isBefore(dayjs().add(7, 'day')) ||
37
+ dayjs((appointment.startDateTime / 1000) * 1000).isBefore(dayjs().subtract(7, 'day')),
38
+ );
39
+
40
+ // visits past 7 days
41
+ const futureVisits = appointments?.filter((appointment) =>
42
+ dayjs((appointment.startDateTime / 1000) * 1000).isAfter(dayjs().add(7, 'day')),
43
+ );
44
+
45
+ return {
46
+ appointments: data ? { recentVisits, futureVisits } : null,
47
+ isError: error,
48
+ isLoading,
49
+ };
50
+ }
@@ -0,0 +1,350 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import {
4
+ Button,
5
+ ButtonSet,
6
+ Switch,
7
+ ContentSwitcher,
8
+ RadioTile,
9
+ TileGroup,
10
+ DataTableSkeleton,
11
+ InlineLoading,
12
+ InlineNotification,
13
+ } from '@carbon/react';
14
+ import {
15
+ formatDatetime,
16
+ useLayoutType,
17
+ parseDate,
18
+ ErrorState,
19
+ toOmrsIsoString,
20
+ toDateObjectStrict,
21
+ showNotification,
22
+ showToast,
23
+ useSession,
24
+ useLocations,
25
+ NewVisitPayload,
26
+ saveVisit,
27
+ useVisitTypes,
28
+ useVisit,
29
+ useConfig,
30
+ ConfigObject,
31
+ } from '@openmrs/esm-framework';
32
+ import { Appointment, SearchTypes } from '../types';
33
+ import styles from './patient-scheduled-visits.scss';
34
+ import { useScheduledVisits } from './hooks/useScheduledVisits';
35
+ import isNil from 'lodash-es/isNil';
36
+ import {
37
+ usePriority,
38
+ useServices,
39
+ useStatus,
40
+ useVisitQueueEntries,
41
+ } from '../active-visits/active-visits-table.resource';
42
+ import { addQueueEntry } from './visit-form/queue.resource';
43
+ import { first } from 'rxjs/operators';
44
+ import { convertTime12to24, amPm } from '../helpers/time-helpers';
45
+ import dayjs from 'dayjs';
46
+ import head from 'lodash-es/head';
47
+ import { useQueueLocations } from './hooks/useQueueLocations';
48
+ interface PatientScheduledVisitsProps {
49
+ toggleSearchType: (searchMode: SearchTypes, patientUuid, mode) => void;
50
+ patientUuid: string;
51
+ closePanel: () => void;
52
+ }
53
+
54
+ enum visitType {
55
+ RECENT = 'Recent',
56
+ FUTURE = 'Future',
57
+ }
58
+
59
+ const ScheduledVisits: React.FC<{
60
+ visits;
61
+ visitType;
62
+ scheduledVisitHeader;
63
+ patientUuid;
64
+ closePanel: () => void;
65
+ }> = ({ visits, scheduledVisitHeader, patientUuid, closePanel }) => {
66
+ const { t } = useTranslation();
67
+ const [visitsIndex, setVisitsIndex] = useState(0);
68
+ const [hasPriority, setHasPriority] = useState(false);
69
+ const [priority, setPriority] = useState('');
70
+ const { priorities, isLoading } = usePriority();
71
+ const { statuses } = useStatus();
72
+ const [userLocation, setUserLocation] = useState('');
73
+ const locations = useLocations();
74
+ const session = useSession();
75
+ const { services } = useServices(userLocation);
76
+ const { mutate } = useVisitQueueEntries('', '');
77
+ const [isSubmitting, setIsSubmitting] = useState(false);
78
+ const [timeFormat, setTimeFormat] = useState<amPm>(new Date().getHours() >= 12 ? 'PM' : 'AM');
79
+ const [visitDate, setVisitDate] = useState(new Date());
80
+ const [visitTime, setVisitTime] = useState(dayjs(new Date()).format('hh:mm'));
81
+ const [appointment, setAppointment] = useState<Appointment>();
82
+ const [patientId, setPatientId] = useState('');
83
+ const allVisitTypes = useVisitTypes();
84
+ const { currentVisit } = useVisit(patientUuid);
85
+ const config = useConfig() as ConfigObject;
86
+ const visitQueueNumberAttributeUuid = config.concepts.visitQueueNumberAttributeUuid;
87
+ const { queueLocations } = useQueueLocations();
88
+ const [selectedQueueLocation, setSelectedQueueLocation] = useState(queueLocations[0]?.id);
89
+
90
+ useEffect(() => {
91
+ if (!userLocation && session?.sessionLocation !== null) {
92
+ setUserLocation(session?.sessionLocation?.uuid);
93
+ } else if (!userLocation && locations) {
94
+ setUserLocation(head(locations)?.uuid);
95
+ }
96
+ }, [session, locations, userLocation]);
97
+
98
+ const handleSubmit = useCallback(
99
+ (event) => {
100
+ setIsSubmitting(true);
101
+
102
+ const [hours, minutes] = convertTime12to24(visitTime, timeFormat);
103
+ const visitType = [...allVisitTypes].shift().uuid;
104
+
105
+ const payload: NewVisitPayload = {
106
+ patient: patientId,
107
+ startDatetime: toDateObjectStrict(
108
+ toOmrsIsoString(
109
+ new Date(dayjs(visitDate).year(), dayjs(visitDate).month(), dayjs(visitDate).date(), hours, minutes),
110
+ ),
111
+ ),
112
+ visitType: visitType,
113
+ location: userLocation,
114
+ };
115
+
116
+ const service = head(services)?.uuid;
117
+ const defaultStatus = config.concepts.defaultStatusConceptUuid;
118
+ const defaultPriority = config.concepts.defaultPriorityConceptUuid;
119
+
120
+ const abortController = new AbortController();
121
+ if (currentVisit) {
122
+ showNotification({
123
+ title: t('startVisitError', 'Error starting visit'),
124
+ kind: 'error',
125
+ critical: true,
126
+ description: t('patientHasActiveVisit', 'The patient already has an active visit'),
127
+ });
128
+ setIsSubmitting(false);
129
+ } else {
130
+ const abortController = new AbortController();
131
+
132
+ saveVisit(payload, abortController)
133
+ .pipe(first())
134
+ .subscribe(
135
+ (response) => {
136
+ if (response.status === 201) {
137
+ addQueueEntry(
138
+ response.data.uuid,
139
+ patientId,
140
+ priority ? priority : defaultPriority,
141
+ defaultStatus,
142
+ service,
143
+ appointment,
144
+ selectedQueueLocation,
145
+ visitQueueNumberAttributeUuid,
146
+ ).then(
147
+ ({ status }) => {
148
+ if (status === 201) {
149
+ showToast({
150
+ kind: 'success',
151
+ title: t('startVisit', 'Start a visit'),
152
+ description: t(
153
+ 'startVisitQueueSuccessfully',
154
+ 'Patient has been added to active visits list and queue.',
155
+ `${hours} : ${minutes}`,
156
+ ),
157
+ });
158
+ closePanel();
159
+ setIsSubmitting(false);
160
+ mutate();
161
+ }
162
+ },
163
+ (error) => {
164
+ showNotification({
165
+ title: t('queueEntryError', 'Error adding patient to the queue'),
166
+ kind: 'error',
167
+ critical: true,
168
+ description: error?.message,
169
+ });
170
+ setIsSubmitting(false);
171
+ },
172
+ );
173
+ }
174
+ },
175
+ (error) => {
176
+ showNotification({
177
+ title: t('startVisitError', 'Error starting visit'),
178
+ kind: 'error',
179
+ critical: true,
180
+ description: error?.message,
181
+ });
182
+ setIsSubmitting(false);
183
+ },
184
+ );
185
+ }
186
+ },
187
+ [
188
+ visitTime,
189
+ timeFormat,
190
+ allVisitTypes,
191
+ patientId,
192
+ visitDate,
193
+ userLocation,
194
+ services,
195
+ config.concepts.defaultStatusConceptUuid,
196
+ config.concepts.defaultPriorityConceptUuid,
197
+ currentVisit,
198
+ t,
199
+ priority,
200
+ appointment,
201
+ selectedQueueLocation,
202
+ visitQueueNumberAttributeUuid,
203
+ closePanel,
204
+ mutate,
205
+ ],
206
+ );
207
+
208
+ if (visits) {
209
+ return (
210
+ <div className={styles.row}>
211
+ <p className={styles.heading}>{scheduledVisitHeader} </p>
212
+ {visits?.length > 0 ? (
213
+ <TileGroup name="tile-group" defaultSelected="default-selected">
214
+ {visits?.map((visit, ind) => {
215
+ return (
216
+ <RadioTile
217
+ value={visit.uuid}
218
+ key={visit.uuid}
219
+ className={styles.visitTile}
220
+ onClick={(e) => {
221
+ setHasPriority(true);
222
+ setVisitsIndex(ind);
223
+ setPatientId(visit?.patient?.uuid);
224
+ setAppointment(visit);
225
+ }}>
226
+ <div className={styles.helperText}>
227
+ <p className={styles.primaryText}>{visit.service?.name}</p>
228
+ <p className={styles.secondaryText}>
229
+ {' '}
230
+ {formatDatetime(parseDate(visit?.startDateTime))} · {visit.location?.name}{' '}
231
+ </p>
232
+
233
+ {isLoading ? (
234
+ <DataTableSkeleton />
235
+ ) : !priorities?.length ? (
236
+ <InlineNotification
237
+ className={styles.inlineNotification}
238
+ kind={'error'}
239
+ lowContrast
240
+ subtitle={t('configurePriorities', 'Please configure priorities to continue.')}
241
+ title={t('noPrioritiesConfigured', 'No priorities configured')}
242
+ />
243
+ ) : hasPriority && ind == visitsIndex ? (
244
+ <ContentSwitcher
245
+ size="sm"
246
+ selectedIndex={1}
247
+ className={styles.prioritySwitcher}
248
+ onChange={(e) => {
249
+ setPriority(e.name as any);
250
+ handleSubmit(e);
251
+ }}>
252
+ {priorities?.length > 0
253
+ ? priorities.map(({ uuid, display }) => {
254
+ return <Switch name={uuid} text={display} value={uuid} />;
255
+ })
256
+ : null}
257
+ </ContentSwitcher>
258
+ ) : null}
259
+ {hasPriority && ind == visitsIndex && isSubmitting ? (
260
+ <InlineLoading description={t('loading', 'Loading...')} />
261
+ ) : null}
262
+ </div>
263
+ </RadioTile>
264
+ );
265
+ })}
266
+ </TileGroup>
267
+ ) : (
268
+ <div className={styles.emptyAppointment}>
269
+ <p>{t('noAppointmentsFound', 'No appointments found')} </p>
270
+ </div>
271
+ )}
272
+ </div>
273
+ );
274
+ }
275
+ return (
276
+ <div className={styles.emptyAppointment}>
277
+ <p className={styles.heading}> {scheduledVisitHeader} </p>
278
+ </div>
279
+ );
280
+ };
281
+
282
+ const PatientScheduledVisits: React.FC<PatientScheduledVisitsProps> = ({
283
+ toggleSearchType,
284
+ patientUuid,
285
+ closePanel,
286
+ }) => {
287
+ const { t } = useTranslation();
288
+ const isTablet = useLayoutType() === 'tablet';
289
+ const { appointments, isLoading, isError } = useScheduledVisits(patientUuid);
290
+
291
+ if (isError) {
292
+ return <ErrorState headerTitle={t('errorFetchingAppoinments', 'Error fetching appointments')} error={isError} />;
293
+ }
294
+
295
+ if (isLoading) {
296
+ return <DataTableSkeleton role="progressbar" />;
297
+ }
298
+
299
+ if (isNil(appointments?.futureVisits) && isNil(appointments?.recentVisits)) {
300
+ toggleSearchType(SearchTypes.VISIT_FORM, patientUuid, true);
301
+ }
302
+
303
+ return (
304
+ <div className={styles.container}>
305
+ <ScheduledVisits
306
+ visitType={visitType.RECENT}
307
+ visits={appointments?.recentVisits}
308
+ scheduledVisitHeader={t('recentScheduledVisits', '{count} visit(s) scheduled for +/- 7 days', {
309
+ count: appointments?.recentVisits?.length,
310
+ })}
311
+ patientUuid={patientUuid}
312
+ closePanel={closePanel}
313
+ />
314
+ <ScheduledVisits
315
+ visitType={visitType.FUTURE}
316
+ visits={appointments?.futureVisits}
317
+ scheduledVisitHeader={t('futureScheduledVisits', '{count} visit(s) scheduled for dates in the future', {
318
+ count: appointments?.futureVisits?.length,
319
+ })}
320
+ patientUuid={patientUuid}
321
+ closePanel={closePanel}
322
+ />
323
+
324
+ <div className={styles['text-divider']}>{t('or', 'Or')}</div>
325
+
326
+ <div className={styles.buttonContainer}>
327
+ <Button
328
+ kind="ghost"
329
+ iconDescription="Start another visit type"
330
+ onClick={() => toggleSearchType(SearchTypes.VISIT_FORM, patientUuid, false)}>
331
+ {t('anotherVisitType', 'Start another visit type')}
332
+ </Button>
333
+ </div>
334
+
335
+ <ButtonSet className={isTablet ? styles.tablet : styles.desktop}>
336
+ <Button
337
+ className={styles.button}
338
+ kind="secondary"
339
+ onClick={() => toggleSearchType(SearchTypes.BASIC, patientUuid, false)}>
340
+ {t('cancel', 'Cancel')}
341
+ </Button>
342
+ <Button className={styles.button} kind="primary" type="submit">
343
+ {t('search', 'Search')}
344
+ </Button>
345
+ </ButtonSet>
346
+ </div>
347
+ );
348
+ };
349
+
350
+ export default PatientScheduledVisits;