@openmrs/esm-api 5.3.3-pre.1237 → 5.3.3-pre.1247
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 +2 -2
- package/__mocks__/openmrs-esm-config.mock.ts +1 -3
- package/dist/openmrs-esm-api.js.map +1 -1
- package/jest.config.js +8 -9
- package/package.json +4 -4
- package/src/environment.ts +1 -4
- package/src/index.ts +9 -9
- package/src/openmrs-backend-dependencies.ts +2 -2
- package/src/openmrs-fetch.test.ts +63 -78
- package/src/openmrs-fetch.ts +32 -63
- package/src/public.ts +8 -8
- package/src/setup.ts +6 -7
- package/src/shared-api-objects/current-patient.test.ts +20 -28
- package/src/shared-api-objects/current-patient.ts +11 -18
- package/src/shared-api-objects/current-user.ts +29 -57
- package/src/shared-api-objects/location.ts +6 -7
- package/src/shared-api-objects/visit-type.ts +6 -7
- package/src/shared-api-objects/visit-utils.ts +35 -48
- package/src/types/fetch.ts +1 -1
- package/src/types/fhir.ts +95 -95
- package/src/types/index.ts +5 -5
- package/src/types/visit-resource.ts +1 -1
- package/webpack.config.js +14 -14
|
@@ -1,59 +1,51 @@
|
|
|
1
|
-
import { fhirBaseUrl, openmrsFetch } from
|
|
2
|
-
import { fetchCurrentPatient } from
|
|
1
|
+
import { fhirBaseUrl, openmrsFetch } from '../openmrs-fetch';
|
|
2
|
+
import { fetchCurrentPatient } from './current-patient';
|
|
3
3
|
|
|
4
|
-
jest.mock(
|
|
4
|
+
jest.mock('../openmrs-fetch', () => ({
|
|
5
5
|
openmrsFetch: jest.fn(),
|
|
6
6
|
}));
|
|
7
7
|
|
|
8
|
-
describe(
|
|
8
|
+
describe('current patient', () => {
|
|
9
9
|
beforeEach(() => {
|
|
10
10
|
(openmrsFetch as jest.MockedFunction<any>).mockReset();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it(
|
|
13
|
+
it('fetches the correct patient from a patient chart URL', () => {
|
|
14
14
|
(openmrsFetch as jest.MockedFunction<any>).mockReturnValueOnce(
|
|
15
15
|
Promise.resolve({
|
|
16
16
|
data: {},
|
|
17
|
-
})
|
|
17
|
+
}),
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
return fetchCurrentPatient(
|
|
21
|
-
expect(openmrsFetch as jest.MockedFunction<any>).toHaveBeenCalledWith(
|
|
22
|
-
`${fhirBaseUrl}/Patient/12`,
|
|
23
|
-
undefined
|
|
24
|
-
);
|
|
20
|
+
return fetchCurrentPatient('12', undefined, false).then(() => {
|
|
21
|
+
expect(openmrsFetch as jest.MockedFunction<any>).toHaveBeenCalledWith(`${fhirBaseUrl}/Patient/12`, undefined);
|
|
25
22
|
});
|
|
26
23
|
});
|
|
27
24
|
|
|
28
|
-
it(
|
|
25
|
+
it('fetches the correct patient from the patient home URL', () => {
|
|
29
26
|
(openmrsFetch as jest.MockedFunction<any>).mockReturnValueOnce(
|
|
30
27
|
Promise.resolve({
|
|
31
28
|
data: {},
|
|
32
|
-
})
|
|
29
|
+
}),
|
|
33
30
|
);
|
|
34
31
|
|
|
35
|
-
return fetchCurrentPatient(
|
|
36
|
-
expect(openmrsFetch as jest.MockedFunction<any>).toHaveBeenCalledWith(
|
|
37
|
-
`${fhirBaseUrl}/Patient/34`,
|
|
38
|
-
undefined
|
|
39
|
-
);
|
|
32
|
+
return fetchCurrentPatient('34', undefined, false).then(() => {
|
|
33
|
+
expect(openmrsFetch as jest.MockedFunction<any>).toHaveBeenCalledWith(`${fhirBaseUrl}/Patient/34`, undefined);
|
|
40
34
|
});
|
|
41
35
|
});
|
|
42
36
|
|
|
43
|
-
it(
|
|
37
|
+
it('can handle dashes and alphanumeric characters in the patient uuid', () => {
|
|
44
38
|
(openmrsFetch as jest.MockedFunction<any>).mockReturnValueOnce(
|
|
45
39
|
Promise.resolve({
|
|
46
40
|
data: {},
|
|
47
|
-
})
|
|
41
|
+
}),
|
|
48
42
|
);
|
|
49
43
|
|
|
50
|
-
return fetchCurrentPatient(
|
|
51
|
-
(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
);
|
|
44
|
+
return fetchCurrentPatient('34-asdsd-234243h342', undefined, false).then(() => {
|
|
45
|
+
expect(openmrsFetch as jest.MockedFunction<any>).toHaveBeenCalledWith(
|
|
46
|
+
`${fhirBaseUrl}/Patient/34-asdsd-234243h342`,
|
|
47
|
+
undefined,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
58
50
|
});
|
|
59
51
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
|
-
import { getSynchronizationItems } from
|
|
3
|
-
import { FetchConfig, fhirBaseUrl, openmrsFetch } from
|
|
4
|
-
import { FetchResponse } from
|
|
2
|
+
import { getSynchronizationItems } from '@openmrs/esm-offline';
|
|
3
|
+
import { FetchConfig, fhirBaseUrl, openmrsFetch } from '../openmrs-fetch';
|
|
4
|
+
import { FetchResponse } from '../types';
|
|
5
5
|
|
|
6
6
|
export type CurrentPatient = fhir.Patient | FetchResponse<fhir.Patient>;
|
|
7
7
|
export interface CurrentPatientOptions {
|
|
@@ -21,18 +21,15 @@ export type PatientUuid = string | null;
|
|
|
21
21
|
export async function fetchCurrentPatient(
|
|
22
22
|
patientUuid: PatientUuid,
|
|
23
23
|
fetchInit?: FetchConfig,
|
|
24
|
-
includeOfflinePatients: boolean = true
|
|
24
|
+
includeOfflinePatients: boolean = true,
|
|
25
25
|
): Promise<fhir.Patient | null> {
|
|
26
26
|
if (patientUuid) {
|
|
27
27
|
let err: Error | null = null;
|
|
28
28
|
const [onlinePatient, offlinePatient] = await Promise.all([
|
|
29
|
-
openmrsFetch<fhir.Patient>(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
includeOfflinePatients
|
|
34
|
-
? getOfflineRegisteredPatientAsFhirPatient(patientUuid)
|
|
35
|
-
: Promise.resolve(null),
|
|
29
|
+
openmrsFetch<fhir.Patient>(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit).catch<FetchResponse<fhir.Patient>>(
|
|
30
|
+
(e) => (err = e),
|
|
31
|
+
),
|
|
32
|
+
includeOfflinePatients ? getOfflineRegisteredPatientAsFhirPatient(patientUuid) : Promise.resolve(null),
|
|
36
33
|
]);
|
|
37
34
|
|
|
38
35
|
if (onlinePatient.ok) {
|
|
@@ -51,15 +48,11 @@ export async function fetchCurrentPatient(
|
|
|
51
48
|
return null;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
async function getOfflineRegisteredPatientAsFhirPatient(
|
|
55
|
-
patientUuid: string
|
|
56
|
-
): Promise<fhir.Patient | null> {
|
|
51
|
+
async function getOfflineRegisteredPatientAsFhirPatient(patientUuid: string): Promise<fhir.Patient | null> {
|
|
57
52
|
const patientRegistrationSyncItems = await getSynchronizationItems<{
|
|
58
53
|
fhirPatient: fhir.Patient;
|
|
59
|
-
}>(
|
|
60
|
-
const patientSyncItem = patientRegistrationSyncItems.find(
|
|
61
|
-
(item) => item.fhirPatient.id === patientUuid
|
|
62
|
-
);
|
|
54
|
+
}>('patient-registration');
|
|
55
|
+
const patientSyncItem = patientRegistrationSyncItems.find((item) => item.fhirPatient.id === patientUuid);
|
|
63
56
|
|
|
64
57
|
return patientSyncItem?.fhirPatient ?? null;
|
|
65
58
|
}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
|
-
import { reportError } from
|
|
3
|
-
import { createGlobalStore } from
|
|
4
|
-
import isUndefined from
|
|
5
|
-
import { Observable } from
|
|
6
|
-
import { openmrsFetch, sessionEndpoint } from
|
|
7
|
-
import type {
|
|
8
|
-
LoggedInUser,
|
|
9
|
-
SessionLocation,
|
|
10
|
-
Privilege,
|
|
11
|
-
Role,
|
|
12
|
-
Session,
|
|
13
|
-
} from "../types";
|
|
2
|
+
import { reportError } from '@openmrs/esm-error-handling';
|
|
3
|
+
import { createGlobalStore } from '@openmrs/esm-state';
|
|
4
|
+
import isUndefined from 'lodash-es/isUndefined';
|
|
5
|
+
import { Observable } from 'rxjs';
|
|
6
|
+
import { openmrsFetch, sessionEndpoint } from '../openmrs-fetch';
|
|
7
|
+
import type { LoggedInUser, SessionLocation, Privilege, Role, Session } from '../types';
|
|
14
8
|
|
|
15
9
|
export type SessionStore = LoadedSessionStore | UnloadedSessionStore;
|
|
16
10
|
|
|
@@ -24,7 +18,7 @@ export type UnloadedSessionStore = {
|
|
|
24
18
|
session: null;
|
|
25
19
|
};
|
|
26
20
|
|
|
27
|
-
const sessionStore = createGlobalStore<SessionStore>(
|
|
21
|
+
const sessionStore = createGlobalStore<SessionStore>('session', {
|
|
28
22
|
loaded: false,
|
|
29
23
|
session: null,
|
|
30
24
|
});
|
|
@@ -70,16 +64,9 @@ let lastFetchTimeMillis = 0;
|
|
|
70
64
|
*/
|
|
71
65
|
function getCurrentUser(): Observable<Session>;
|
|
72
66
|
function getCurrentUser(opts: { includeAuthStatus: true }): Observable<Session>;
|
|
73
|
-
function getCurrentUser(opts: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function getCurrentUser(
|
|
77
|
-
opts = { includeAuthStatus: true }
|
|
78
|
-
): Observable<Session | LoggedInUser> {
|
|
79
|
-
if (
|
|
80
|
-
lastFetchTimeMillis < Date.now() - 1000 * 60 ||
|
|
81
|
-
!sessionStore.getState().loaded
|
|
82
|
-
) {
|
|
67
|
+
function getCurrentUser(opts: { includeAuthStatus: false }): Observable<LoggedInUser>;
|
|
68
|
+
function getCurrentUser(opts = { includeAuthStatus: true }): Observable<Session | LoggedInUser> {
|
|
69
|
+
if (lastFetchTimeMillis < Date.now() - 1000 * 60 || !sessionStore.getState().loaded) {
|
|
83
70
|
refetchCurrentUser();
|
|
84
71
|
}
|
|
85
72
|
|
|
@@ -103,10 +90,7 @@ function getCurrentUser(
|
|
|
103
90
|
export { getCurrentUser };
|
|
104
91
|
|
|
105
92
|
export function getSessionStore() {
|
|
106
|
-
if (
|
|
107
|
-
lastFetchTimeMillis < Date.now() - 1000 * 60 ||
|
|
108
|
-
!sessionStore.getState().loaded
|
|
109
|
-
) {
|
|
93
|
+
if (lastFetchTimeMillis < Date.now() - 1000 * 60 || !sessionStore.getState().loaded) {
|
|
110
94
|
refetchCurrentUser();
|
|
111
95
|
}
|
|
112
96
|
|
|
@@ -115,7 +99,7 @@ export function getSessionStore() {
|
|
|
115
99
|
|
|
116
100
|
// NB locale is string only if this returns true
|
|
117
101
|
function isValidLocale(locale: unknown): locale is string {
|
|
118
|
-
if (locale === undefined || typeof locale !==
|
|
102
|
+
if (locale === undefined || typeof locale !== 'string') {
|
|
119
103
|
return false;
|
|
120
104
|
}
|
|
121
105
|
|
|
@@ -130,25 +114,18 @@ function isValidLocale(locale: unknown): locale is string {
|
|
|
130
114
|
|
|
131
115
|
export function setUserLanguage(data: Session) {
|
|
132
116
|
const locale = data?.user?.userProperties?.defaultLocale ?? data.locale;
|
|
133
|
-
const htmlLang = document.documentElement.getAttribute(
|
|
117
|
+
const htmlLang = document.documentElement.getAttribute('lang');
|
|
134
118
|
|
|
135
119
|
if (isValidLocale(locale) && locale !== htmlLang) {
|
|
136
|
-
document.documentElement.setAttribute(
|
|
120
|
+
document.documentElement.setAttribute('lang', locale);
|
|
137
121
|
}
|
|
138
122
|
}
|
|
139
123
|
|
|
140
|
-
function userHasPrivilege(
|
|
141
|
-
requiredPrivilege
|
|
142
|
-
|
|
143
|
-
) {
|
|
144
|
-
if (typeof requiredPrivilege === "string") {
|
|
145
|
-
return !isUndefined(
|
|
146
|
-
user.privileges.find((p) => requiredPrivilege === p.display)
|
|
147
|
-
);
|
|
124
|
+
function userHasPrivilege(requiredPrivilege: string | string[] | undefined, user: { privileges: Array<Privilege> }) {
|
|
125
|
+
if (typeof requiredPrivilege === 'string') {
|
|
126
|
+
return !isUndefined(user.privileges.find((p) => requiredPrivilege === p.display));
|
|
148
127
|
} else if (Array.isArray(requiredPrivilege)) {
|
|
149
|
-
return requiredPrivilege.every(
|
|
150
|
-
(rp) => !isUndefined(user.privileges.find((p) => rp === p.display))
|
|
151
|
-
);
|
|
128
|
+
return requiredPrivilege.every((rp) => !isUndefined(user.privileges.find((p) => rp === p.display)));
|
|
152
129
|
} else if (!isUndefined(requiredPrivilege)) {
|
|
153
130
|
console.error(`Could not understand privileges "${requiredPrivilege}"`);
|
|
154
131
|
}
|
|
@@ -157,9 +134,7 @@ function userHasPrivilege(
|
|
|
157
134
|
}
|
|
158
135
|
|
|
159
136
|
function isSuperUser(user: { roles: Array<Role> }) {
|
|
160
|
-
return !isUndefined(
|
|
161
|
-
user.roles.find((role) => role.display === "System Developer")
|
|
162
|
-
);
|
|
137
|
+
return !isUndefined(user.roles.find((role) => role.display === 'System Developer'));
|
|
163
138
|
}
|
|
164
139
|
|
|
165
140
|
/**
|
|
@@ -180,7 +155,7 @@ export function refetchCurrentUser() {
|
|
|
180
155
|
lastFetchTimeMillis = Date.now();
|
|
181
156
|
openmrsFetch(sessionEndpoint)
|
|
182
157
|
.then((res) => {
|
|
183
|
-
if (typeof res?.data ===
|
|
158
|
+
if (typeof res?.data === 'object') {
|
|
184
159
|
setUserLanguage(res.data);
|
|
185
160
|
resolve(res.data);
|
|
186
161
|
sessionStore.setState({ loaded: true, session: res.data });
|
|
@@ -193,7 +168,7 @@ export function refetchCurrentUser() {
|
|
|
193
168
|
reportError(`Failed to fetch new session information: ${err}`);
|
|
194
169
|
reject(err);
|
|
195
170
|
return {
|
|
196
|
-
sessionId:
|
|
171
|
+
sessionId: '',
|
|
197
172
|
authenticated: false,
|
|
198
173
|
};
|
|
199
174
|
});
|
|
@@ -203,13 +178,13 @@ export function refetchCurrentUser() {
|
|
|
203
178
|
export function clearCurrentUser() {
|
|
204
179
|
sessionStore.setState({
|
|
205
180
|
loaded: true,
|
|
206
|
-
session: { authenticated: false, sessionId:
|
|
181
|
+
session: { authenticated: false, sessionId: '' },
|
|
207
182
|
});
|
|
208
183
|
}
|
|
209
184
|
|
|
210
185
|
export function userHasAccess(
|
|
211
186
|
requiredPrivilege: string | string[],
|
|
212
|
-
user: { privileges: Array<Privilege>; roles: Array<Role> }
|
|
187
|
+
user: { privileges: Array<Privilege>; roles: Array<Role> },
|
|
213
188
|
) {
|
|
214
189
|
if (user === undefined) {
|
|
215
190
|
// if the user hasn't been loaded, then return false iff there is a required privilege
|
|
@@ -251,15 +226,12 @@ export function getSessionLocation() {
|
|
|
251
226
|
});
|
|
252
227
|
}
|
|
253
228
|
|
|
254
|
-
export async function setSessionLocation(
|
|
255
|
-
locationUuid: string,
|
|
256
|
-
abortController: AbortController
|
|
257
|
-
): Promise<any> {
|
|
229
|
+
export async function setSessionLocation(locationUuid: string, abortController: AbortController): Promise<any> {
|
|
258
230
|
await openmrsFetch(sessionEndpoint, {
|
|
259
|
-
method:
|
|
231
|
+
method: 'POST',
|
|
260
232
|
body: { sessionLocation: locationUuid },
|
|
261
233
|
headers: {
|
|
262
|
-
|
|
234
|
+
'Content-Type': 'application/json',
|
|
263
235
|
},
|
|
264
236
|
signal: abortController.signal,
|
|
265
237
|
});
|
|
@@ -272,16 +244,16 @@ export async function setUserProperties(
|
|
|
272
244
|
userProperties: {
|
|
273
245
|
[x: string]: string;
|
|
274
246
|
},
|
|
275
|
-
abortController?: AbortController
|
|
247
|
+
abortController?: AbortController,
|
|
276
248
|
): Promise<any> {
|
|
277
249
|
if (!abortController) {
|
|
278
250
|
abortController = new AbortController();
|
|
279
251
|
}
|
|
280
252
|
await openmrsFetch(`/ws/rest/v1/user/${userUuid}`, {
|
|
281
|
-
method:
|
|
253
|
+
method: 'POST',
|
|
282
254
|
body: { userProperties },
|
|
283
255
|
headers: {
|
|
284
|
-
|
|
256
|
+
'Content-Type': 'application/json',
|
|
285
257
|
},
|
|
286
258
|
signal: abortController.signal,
|
|
287
259
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
|
-
import { Observable } from
|
|
3
|
-
import { map, take } from
|
|
4
|
-
import { openmrsObservableFetch } from
|
|
5
|
-
import { Location } from
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { map, take } from 'rxjs/operators';
|
|
4
|
+
import { openmrsObservableFetch } from '../openmrs-fetch';
|
|
5
|
+
import { Location } from '../types';
|
|
6
6
|
|
|
7
7
|
export function toLocationObject(openmrsRestForm: any): Location {
|
|
8
8
|
return {
|
|
@@ -15,10 +15,9 @@ export function getLocations(): Observable<Array<Location>> {
|
|
|
15
15
|
return openmrsObservableFetch<any>(`/ws/rest/v1/location`)
|
|
16
16
|
.pipe(
|
|
17
17
|
map((results) => {
|
|
18
|
-
const locations: Array<Location> =
|
|
19
|
-
results.data.results.map(toLocationObject);
|
|
18
|
+
const locations: Array<Location> = results.data.results.map(toLocationObject);
|
|
20
19
|
return locations;
|
|
21
|
-
})
|
|
20
|
+
}),
|
|
22
21
|
)
|
|
23
22
|
.pipe(take(1));
|
|
24
23
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
|
-
import { Observable } from
|
|
3
|
-
import { map, take } from
|
|
4
|
-
import { openmrsObservableFetch } from
|
|
5
|
-
import { VisitType } from
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { map, take } from 'rxjs/operators';
|
|
4
|
+
import { openmrsObservableFetch } from '../openmrs-fetch';
|
|
5
|
+
import { VisitType } from '../types';
|
|
6
6
|
|
|
7
7
|
export function toVisitTypeObject(openmrsRestForm: any): VisitType {
|
|
8
8
|
return {
|
|
@@ -16,10 +16,9 @@ export function getVisitTypes(): Observable<Array<VisitType>> {
|
|
|
16
16
|
return openmrsObservableFetch<any>(`/ws/rest/v1/visittype`)
|
|
17
17
|
.pipe(
|
|
18
18
|
map((results) => {
|
|
19
|
-
const visitTypes: Array<VisitType> =
|
|
20
|
-
results.data.results.map(toVisitTypeObject);
|
|
19
|
+
const visitTypes: Array<VisitType> = results.data.results.map(toVisitTypeObject);
|
|
21
20
|
return visitTypes;
|
|
22
|
-
})
|
|
21
|
+
}),
|
|
23
22
|
)
|
|
24
23
|
.pipe(take(1));
|
|
25
24
|
}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
/** @module @category API */
|
|
2
|
-
import { Observable, BehaviorSubject } from
|
|
3
|
-
import { take, map } from
|
|
4
|
-
import { openmrsObservableFetch } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
NewVisitPayload,
|
|
8
|
-
UpdateVisitPayload,
|
|
9
|
-
Visit,
|
|
10
|
-
} from "../types";
|
|
11
|
-
import { getGlobalStore } from "@openmrs/esm-state";
|
|
2
|
+
import { Observable, BehaviorSubject } from 'rxjs';
|
|
3
|
+
import { take, map } from 'rxjs/operators';
|
|
4
|
+
import { openmrsObservableFetch } from '../openmrs-fetch';
|
|
5
|
+
import { FetchResponse, NewVisitPayload, UpdateVisitPayload, Visit } from '../types';
|
|
6
|
+
import { getGlobalStore } from '@openmrs/esm-state';
|
|
12
7
|
|
|
13
8
|
export const defaultVisitCustomRepresentation =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
'custom:(uuid,encounters:(uuid,encounterDatetime,' +
|
|
10
|
+
'form:(uuid,name),location:ref,' +
|
|
11
|
+
'encounterType:ref,encounterProviders:(uuid,display,' +
|
|
12
|
+
'provider:(uuid,display))),patient:(uuid,uuid),' +
|
|
13
|
+
'visitType:(uuid,name,display),' +
|
|
14
|
+
'attributes:(uuid,display,attributeType:(name,datatypeClassname,uuid),value),' +
|
|
15
|
+
'location:(uuid,name,display),startDatetime,stopDatetime)';
|
|
21
16
|
|
|
22
17
|
export interface VisitStoreState {
|
|
23
18
|
patientUuid: string | null;
|
|
@@ -29,7 +24,7 @@ const initialState = getVisitLocalStorage() || {
|
|
|
29
24
|
manuallySetVisitUuid: null,
|
|
30
25
|
};
|
|
31
26
|
export function getVisitStore() {
|
|
32
|
-
return getGlobalStore<VisitStoreState>(
|
|
27
|
+
return getGlobalStore<VisitStoreState>('visit', initialState);
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
export function setCurrentVisit(patientUuid: string, visitUuid: string) {
|
|
@@ -41,14 +36,12 @@ getVisitStore().subscribe((state) => {
|
|
|
41
36
|
});
|
|
42
37
|
|
|
43
38
|
function setVisitLocalStorage(value: VisitStoreState) {
|
|
44
|
-
localStorage.setItem(
|
|
39
|
+
localStorage.setItem('openmrs:visitStoreState', JSON.stringify(value));
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
function getVisitLocalStorage(): VisitStoreState | null {
|
|
48
43
|
try {
|
|
49
|
-
return JSON.parse(
|
|
50
|
-
localStorage.getItem("openmrs:visitStoreState") || "null"
|
|
51
|
-
);
|
|
44
|
+
return JSON.parse(localStorage.getItem('openmrs:visitStoreState') || 'null');
|
|
52
45
|
} catch (e) {
|
|
53
46
|
return null;
|
|
54
47
|
}
|
|
@@ -57,37 +50,31 @@ function getVisitLocalStorage(): VisitStoreState | null {
|
|
|
57
50
|
export function getVisitsForPatient(
|
|
58
51
|
patientUuid: string,
|
|
59
52
|
abortController: AbortController,
|
|
60
|
-
v?: string
|
|
53
|
+
v?: string,
|
|
61
54
|
): Observable<FetchResponse<{ results: Array<Visit> }>> {
|
|
62
55
|
const custom = v ?? defaultVisitCustomRepresentation;
|
|
63
56
|
|
|
64
|
-
return openmrsObservableFetch(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
)
|
|
57
|
+
return openmrsObservableFetch(`/ws/rest/v1/visit?patient=${patientUuid}&v=${custom}`, {
|
|
58
|
+
signal: abortController.signal,
|
|
59
|
+
method: 'GET',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-type': 'application/json',
|
|
62
|
+
},
|
|
63
|
+
})
|
|
74
64
|
.pipe(take(1))
|
|
75
65
|
.pipe(
|
|
76
66
|
map((response: FetchResponse<{ results: Array<Visit> }>) => {
|
|
77
67
|
return response;
|
|
78
|
-
})
|
|
68
|
+
}),
|
|
79
69
|
);
|
|
80
70
|
}
|
|
81
71
|
|
|
82
|
-
export function saveVisit(
|
|
83
|
-
payload: NewVisitPayload,
|
|
84
|
-
abortController: AbortController
|
|
85
|
-
): Observable<FetchResponse<any>> {
|
|
72
|
+
export function saveVisit(payload: NewVisitPayload, abortController: AbortController): Observable<FetchResponse<any>> {
|
|
86
73
|
return openmrsObservableFetch(`/ws/rest/v1/visit`, {
|
|
87
74
|
signal: abortController.signal,
|
|
88
|
-
method:
|
|
75
|
+
method: 'POST',
|
|
89
76
|
headers: {
|
|
90
|
-
|
|
77
|
+
'Content-type': 'application/json',
|
|
91
78
|
},
|
|
92
79
|
body: payload,
|
|
93
80
|
});
|
|
@@ -96,13 +83,13 @@ export function saveVisit(
|
|
|
96
83
|
export function updateVisit(
|
|
97
84
|
uuid: string,
|
|
98
85
|
payload: UpdateVisitPayload,
|
|
99
|
-
abortController: AbortController
|
|
86
|
+
abortController: AbortController,
|
|
100
87
|
): Observable<any> {
|
|
101
88
|
return openmrsObservableFetch(`/ws/rest/v1/visit/${uuid}`, {
|
|
102
89
|
signal: abortController.signal,
|
|
103
|
-
method:
|
|
90
|
+
method: 'POST',
|
|
104
91
|
headers: {
|
|
105
|
-
|
|
92
|
+
'Content-type': 'application/json',
|
|
106
93
|
},
|
|
107
94
|
body: payload,
|
|
108
95
|
});
|
|
@@ -119,12 +106,12 @@ export interface VisitItem {
|
|
|
119
106
|
}
|
|
120
107
|
|
|
121
108
|
export enum VisitMode {
|
|
122
|
-
NEWVISIT =
|
|
123
|
-
EDITVISIT =
|
|
124
|
-
LOADING =
|
|
109
|
+
NEWVISIT = 'startVisit',
|
|
110
|
+
EDITVISIT = 'editVisit',
|
|
111
|
+
LOADING = 'loadingVisit',
|
|
125
112
|
}
|
|
126
113
|
|
|
127
114
|
export enum VisitStatus {
|
|
128
|
-
NOTSTARTED =
|
|
129
|
-
ONGOING =
|
|
115
|
+
NOTSTARTED = 'notStarted',
|
|
116
|
+
ONGOING = 'ongoing',
|
|
130
117
|
}
|
package/src/types/fetch.ts
CHANGED