@openmrs/esm-react-utils 5.0.3-pre.876 → 5.0.3-pre.878
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "5.0.3-pre.
|
|
3
|
+
"version": "5.0.3-pre.878",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"browser": "dist/openmrs-esm-react-utils.js",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"react-i18next": "11.x"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@openmrs/esm-api": "^5.0.3-pre.
|
|
60
|
-
"@openmrs/esm-config": "^5.0.3-pre.
|
|
61
|
-
"@openmrs/esm-error-handling": "^5.0.3-pre.
|
|
62
|
-
"@openmrs/esm-extensions": "^5.0.3-pre.
|
|
63
|
-
"@openmrs/esm-globals": "^5.0.3-pre.
|
|
59
|
+
"@openmrs/esm-api": "^5.0.3-pre.878",
|
|
60
|
+
"@openmrs/esm-config": "^5.0.3-pre.878",
|
|
61
|
+
"@openmrs/esm-error-handling": "^5.0.3-pre.878",
|
|
62
|
+
"@openmrs/esm-extensions": "^5.0.3-pre.878",
|
|
63
|
+
"@openmrs/esm-globals": "^5.0.3-pre.878",
|
|
64
64
|
"dayjs": "^1.10.8",
|
|
65
65
|
"i18next": "^19.6.0",
|
|
66
66
|
"react": "^18.1.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"rxjs": "^6.5.3",
|
|
70
70
|
"webpack": "^5.88.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "5da82b59cb36589912a307f3fafb146d70b186dd"
|
|
73
73
|
}
|
package/src/useVisit.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
2
|
import {
|
|
3
3
|
defaultVisitCustomRepresentation,
|
|
4
|
+
getVisitStore,
|
|
4
5
|
openmrsFetch,
|
|
5
6
|
Visit,
|
|
6
7
|
} from "@openmrs/esm-api";
|
|
@@ -8,14 +9,16 @@ import useSWR from "swr";
|
|
|
8
9
|
import dayjs from "dayjs";
|
|
9
10
|
import isToday from "dayjs/plugin/isToday";
|
|
10
11
|
import { useMemo } from "react";
|
|
12
|
+
import { useStore } from "./useStore";
|
|
11
13
|
|
|
12
14
|
dayjs.extend(isToday);
|
|
13
15
|
|
|
14
|
-
interface VisitReturnType {
|
|
16
|
+
export interface VisitReturnType {
|
|
15
17
|
error: Error;
|
|
16
18
|
mutate: () => void;
|
|
17
19
|
isValidating: boolean;
|
|
18
20
|
currentVisit: Visit | null;
|
|
21
|
+
isRetrospective: boolean;
|
|
19
22
|
isLoading: boolean;
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -27,19 +30,31 @@ interface VisitReturnType {
|
|
|
27
30
|
* @returns Object {`error` `isValidating`, `currentVisit`, `mutate`}
|
|
28
31
|
*/
|
|
29
32
|
export function useVisit(patientUuid: string): VisitReturnType {
|
|
33
|
+
const { patientUuid: visitStorePatientUuid, manuallySetVisitUuid } = useStore(
|
|
34
|
+
getVisitStore()
|
|
35
|
+
);
|
|
36
|
+
// Ignore the visit store data if it is not for this patient
|
|
37
|
+
const retrospectiveVisitUuid =
|
|
38
|
+
patientUuid && visitStorePatientUuid == patientUuid
|
|
39
|
+
? manuallySetVisitUuid
|
|
40
|
+
: null;
|
|
41
|
+
const visitGetUrlSuffix = retrospectiveVisitUuid
|
|
42
|
+
? `/${retrospectiveVisitUuid}`
|
|
43
|
+
: `?patient=${patientUuid}&v=${defaultVisitCustomRepresentation}&includeInactive=false`;
|
|
30
44
|
const { data, error, mutate, isValidating } = useSWR<{
|
|
31
|
-
data: { results: Array<Visit> };
|
|
45
|
+
data: Visit | { results: Array<Visit> };
|
|
32
46
|
}>(
|
|
33
|
-
patientUuid
|
|
34
|
-
? `/ws/rest/v1/visit?patient=${patientUuid}&v=${defaultVisitCustomRepresentation}&includeInactive=false`
|
|
35
|
-
: null,
|
|
47
|
+
patientUuid ? `/ws/rest/v1/visit${visitGetUrlSuffix}` : null,
|
|
36
48
|
openmrsFetch
|
|
37
49
|
);
|
|
38
50
|
|
|
39
51
|
const currentVisit = useMemo(
|
|
40
52
|
() =>
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
retrospectiveVisitUuid
|
|
54
|
+
? data?.data
|
|
55
|
+
: data?.data.results.find((visit) => visit.stopDatetime === null) ??
|
|
56
|
+
null,
|
|
57
|
+
[data]
|
|
43
58
|
);
|
|
44
59
|
|
|
45
60
|
return {
|
|
@@ -47,6 +62,7 @@ export function useVisit(patientUuid: string): VisitReturnType {
|
|
|
47
62
|
mutate,
|
|
48
63
|
isValidating,
|
|
49
64
|
currentVisit,
|
|
65
|
+
isRetrospective: Boolean(retrospectiveVisitUuid),
|
|
50
66
|
isLoading: !data && !error,
|
|
51
67
|
};
|
|
52
68
|
}
|