@openmrs/esm-emr-api 10.0.1-pre.5539 → 10.0.1-pre.5545

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 21 files with swc (121.1ms)
1
+ [0] Successfully compiled: 21 files with swc (103.66ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -12,18 +12,13 @@ export interface OnlyThePatient extends CurrentPatientOptions {
12
12
  }
13
13
  export type PatientUuid = string | null;
14
14
  /**
15
- * Fetches a patient by their UUID from the FHIR API. This function first attempts
16
- * to fetch the patient from the server. If the server request fails and offline
17
- * patients are included, it will check for a matching patient in the offline
18
- * patient registration sync queue.
15
+ * Fetches a patient by their UUID from the FHIR API.
19
16
  *
20
17
  * @param patientUuid The UUID of the patient to fetch, or `null`.
21
18
  * @param fetchInit Optional fetch configuration options to pass to the request.
22
- * @param includeOfflinePatients Whether to include patients from the offline
23
- * registration queue if the server request fails. Defaults to `true`.
24
19
  * @returns A Promise that resolves with the FHIR Patient object, or `null` if
25
- * the patient UUID is null or the patient is not found.
26
- * @throws Rethrows any error from the server request if no offline patient is found.
20
+ * the patient UUID is null.
21
+ * @throws Rethrows any error from the server request.
27
22
  *
28
23
  * @example
29
24
  * ```ts
@@ -34,5 +29,5 @@ export type PatientUuid = string | null;
34
29
  * }
35
30
  * ```
36
31
  */
37
- export declare function fetchCurrentPatient(patientUuid: PatientUuid, fetchInit?: FetchConfig, includeOfflinePatients?: boolean): Promise<fhir.Patient | null>;
32
+ export declare function fetchCurrentPatient(patientUuid: PatientUuid, fetchInit?: FetchConfig): Promise<fhir.Patient | null>;
38
33
  //# sourceMappingURL=current-patient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"current-patient.d.ts","sourceRoot":"","sources":["../src/current-patient.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAA6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WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,WAAW,GACtB,OAAO,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAO9B"}
@@ -1,18 +1,12 @@
1
1
  /** @module @category API */ import { fhirBaseUrl, openmrsFetch } from "@openmrs/esm-api";
2
- import { getSynchronizationItems } from "@openmrs/esm-offline";
3
2
  /**
4
- * Fetches a patient by their UUID from the FHIR API. This function first attempts
5
- * to fetch the patient from the server. If the server request fails and offline
6
- * patients are included, it will check for a matching patient in the offline
7
- * patient registration sync queue.
3
+ * Fetches a patient by their UUID from the FHIR API.
8
4
  *
9
5
  * @param patientUuid The UUID of the patient to fetch, or `null`.
10
6
  * @param fetchInit Optional fetch configuration options to pass to the request.
11
- * @param includeOfflinePatients Whether to include patients from the offline
12
- * registration queue if the server request fails. Defaults to `true`.
13
7
  * @returns A Promise that resolves with the FHIR Patient object, or `null` if
14
- * the patient UUID is null or the patient is not found.
15
- * @throws Rethrows any error from the server request if no offline patient is found.
8
+ * the patient UUID is null.
9
+ * @throws Rethrows any error from the server request.
16
10
  *
17
11
  * @example
18
12
  * ```ts
@@ -22,27 +16,10 @@ import { getSynchronizationItems } from "@openmrs/esm-offline";
22
16
  * console.log('Patient name:', patient.name?.[0]?.text);
23
17
  * }
24
18
  * ```
25
- */ export async function fetchCurrentPatient(patientUuid, fetchInit, includeOfflinePatients = true) {
19
+ */ export async function fetchCurrentPatient(patientUuid, fetchInit) {
26
20
  if (patientUuid) {
27
- let err = null;
28
- const [onlinePatient, offlinePatient] = await Promise.all([
29
- openmrsFetch(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit).catch((e)=>err = e),
30
- includeOfflinePatients ? getOfflineRegisteredPatientAsFhirPatient(patientUuid) : Promise.resolve(null)
31
- ]);
32
- if (onlinePatient.ok) {
33
- return onlinePatient.data;
34
- }
35
- if (offlinePatient) {
36
- return offlinePatient;
37
- }
38
- if (err) {
39
- throw err;
40
- }
21
+ const response = await openmrsFetch(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit);
22
+ return response.data;
41
23
  }
42
24
  return null;
43
25
  }
44
- async function getOfflineRegisteredPatientAsFhirPatient(patientUuid) {
45
- const patientRegistrationSyncItems = await getSynchronizationItems('patient-registration');
46
- const patientSyncItem = patientRegistrationSyncItems.find((item)=>item.fhirPatient.id === patientUuid);
47
- return patientSyncItem?.fhirPatient ?? null;
48
- }
@@ -1,5 +1,4 @@
1
- import type { Observable } from 'rxjs';
2
1
  import type { Location } from './types';
3
2
  export declare function toLocationObject(openmrsRestForm: any): Location;
4
- export declare function getLocations(tagUuidOrName?: string | null, query?: string | null): Observable<Array<Location>>;
3
+ export declare function getLocations(tagUuidOrName?: string | null, query?: string | null): Promise<Array<Location>>;
5
4
  //# sourceMappingURL=location.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,eAAe,EAAE,GAAG,GAAG,QAAQ,CAK/D;AAED,wBAAgB,YAAY,CAC1B,aAAa,GAAE,MAAM,GAAG,IAAW,EACnC,KAAK,GAAE,MAAM,GAAG,IAAW,GAC1B,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAmB7B"}
1
+ {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,eAAe,EAAE,GAAG,GAAG,QAAQ,CAK/D;AAED,wBAAgB,YAAY,CAC1B,aAAa,GAAE,MAAM,GAAG,IAAW,EACnC,KAAK,GAAE,MAAM,GAAG,IAAW,GAC1B,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAc1B"}
package/dist/location.js CHANGED
@@ -1,5 +1,4 @@
1
- /** @module @category API */ import { openmrsObservableFetch, restBaseUrl } from "@openmrs/esm-api";
2
- import { map, take } from "rxjs/operators/index.js";
1
+ /** @module @category API */ import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
3
2
  export function toLocationObject(openmrsRestForm) {
4
3
  return {
5
4
  uuid: openmrsRestForm.uuid,
@@ -16,8 +15,5 @@ export function getLocations(tagUuidOrName = null, query = null) {
16
15
  }
17
16
  const queryString = params.toString();
18
17
  const url = `${restBaseUrl}/location${queryString ? '?' + queryString : ''}`;
19
- return openmrsObservableFetch(url).pipe(map((results)=>{
20
- const locations = results.data.results.map(toLocationObject);
21
- return locations;
22
- })).pipe(take(1));
18
+ return openmrsFetch(url).then((response)=>response.data.results.map(toLocationObject));
23
19
  }
@@ -1,19 +1,20 @@
1
- import type { Observable } from 'rxjs';
2
1
  import { type VisitType } from './types';
3
2
  export declare function toVisitTypeObject(openmrsRestForm: any): VisitType;
3
+ /** The endpoint {@link getVisitTypes} reads from. Use it as the SWR key when caching visit types. */
4
+ export declare const visitTypesUrl = "/ws/rest/v1/visittype";
4
5
  /**
5
6
  * Fetches all available visit types from the OpenMRS REST API.
6
7
  *
7
- * @returns An Observable that emits an array of VisitType objects and then completes.
8
- * The Observable will emit exactly one value containing all visit types.
8
+ * @param url The endpoint to read from, defaulting to {@link visitTypesUrl}. This exists so that the
9
+ * function can be passed straight to SWR as a fetcher, which calls it with the cache key.
10
+ * @returns A Promise that resolves with an array of VisitType objects.
9
11
  *
10
12
  * @example
11
13
  * ```ts
12
14
  * import { getVisitTypes } from '@openmrs/esm-framework';
13
- * getVisitTypes().subscribe((visitTypes) => {
14
- * console.log('Available visit types:', visitTypes);
15
- * });
15
+ * const visitTypes = await getVisitTypes();
16
+ * console.log('Available visit types:', visitTypes);
16
17
  * ```
17
18
  */
18
- export declare function getVisitTypes(): Observable<Array<VisitType>>;
19
+ export declare function getVisitTypes(url?: string): Promise<Array<VisitType>>;
19
20
  //# sourceMappingURL=visit-type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visit-type.d.ts","sourceRoot":"","sources":["../src/visit-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,GAAG,GAAG,SAAS,CAMjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAS5D"}
1
+ {"version":3,"file":"visit-type.d.ts","sourceRoot":"","sources":["../src/visit-type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,GAAG,GAAG,SAAS,CAMjE;AAED,qGAAqG;AACrG,eAAO,MAAM,aAAa,0BAA6B,CAAC;AAExD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAEpF"}
@@ -1,5 +1,4 @@
1
- /** @module @category API */ import { openmrsObservableFetch, restBaseUrl } from "@openmrs/esm-api";
2
- import { map, take } from "rxjs/operators/index.js";
1
+ /** @module @category API */ import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
3
2
  export function toVisitTypeObject(openmrsRestForm) {
4
3
  return {
5
4
  uuid: openmrsRestForm.uuid,
@@ -7,22 +6,20 @@ export function toVisitTypeObject(openmrsRestForm) {
7
6
  name: openmrsRestForm.name
8
7
  };
9
8
  }
9
+ /** The endpoint {@link getVisitTypes} reads from. Use it as the SWR key when caching visit types. */ export const visitTypesUrl = `${restBaseUrl}/visittype`;
10
10
  /**
11
11
  * Fetches all available visit types from the OpenMRS REST API.
12
12
  *
13
- * @returns An Observable that emits an array of VisitType objects and then completes.
14
- * The Observable will emit exactly one value containing all visit types.
13
+ * @param url The endpoint to read from, defaulting to {@link visitTypesUrl}. This exists so that the
14
+ * function can be passed straight to SWR as a fetcher, which calls it with the cache key.
15
+ * @returns A Promise that resolves with an array of VisitType objects.
15
16
  *
16
17
  * @example
17
18
  * ```ts
18
19
  * import { getVisitTypes } from '@openmrs/esm-framework';
19
- * getVisitTypes().subscribe((visitTypes) => {
20
- * console.log('Available visit types:', visitTypes);
21
- * });
20
+ * const visitTypes = await getVisitTypes();
21
+ * console.log('Available visit types:', visitTypes);
22
22
  * ```
23
- */ export function getVisitTypes() {
24
- return openmrsObservableFetch(`${restBaseUrl}/visittype`).pipe(map((results)=>{
25
- const visitTypes = results.data.results.map(toVisitTypeObject);
26
- return visitTypes;
27
- })).pipe(take(1));
23
+ */ export function getVisitTypes(url = visitTypesUrl) {
24
+ return openmrsFetch(url).then((response)=>response.data.results.map(toVisitTypeObject));
28
25
  }
@@ -1,6 +1,5 @@
1
1
  /** @module @category API */
2
2
  import { type FetchResponse } from '@openmrs/esm-api';
3
- import { BehaviorSubject } from 'rxjs';
4
3
  import { type NewVisitPayload, type UpdateVisitPayload, type Visit } from './types';
5
4
  export interface VisitItem {
6
5
  mode: VisitMode;
@@ -105,6 +104,4 @@ export declare function updateVisit(uuid: string, payload: UpdateVisitPayload, a
105
104
  export declare function getVisitsForPatient(patientUuid: string, abortController: AbortController, v?: string): Promise<FetchResponse<{
106
105
  results: Array<Visit>;
107
106
  }>>;
108
- /** @deprecated */
109
- export declare const getStartedVisit: BehaviorSubject<VisitItem | null>;
110
107
  //# sourceMappingURL=visit-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visit-utils.d.ts","sourceRoot":"","sources":["../src/visit-utils.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjF,OA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AAI,EAAE,MAAM,EACZ,OAAO,EAAE,kBAAkB,EAC3B,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAS/B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,eAAe,EAChC,CAAC,CAAC,EAAE,MAAM,GACT,OAAO,CAAC,aAAa,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;CAAE,CAAC,CAAC,CAUnD"}
@@ -1,6 +1,5 @@
1
1
  /** @module @category API */ import { openmrsFetch, restBaseUrl } from "@openmrs/esm-api";
2
2
  import { getGlobalStore } from "@openmrs/esm-state";
3
- import { BehaviorSubject } from "rxjs";
4
3
  export var VisitMode = /*#__PURE__*/ function(VisitMode) {
5
4
  VisitMode["NEWVISIT"] = "startVisit";
6
5
  VisitMode["EDITVISIT"] = "editVisit";
@@ -139,4 +138,3 @@ function getVisitSessionStorage() {
139
138
  }
140
139
  });
141
140
  }
142
- /** @deprecated */ export const getStartedVisit = new BehaviorSubject(null);
package/mock-jest.ts CHANGED
@@ -13,4 +13,3 @@ export const deleteAttachmentPermanently = jest.fn();
13
13
  export const updateVisit = jest.fn();
14
14
  export const saveVisit = jest.fn();
15
15
  export const getVisitsForPatient = jest.fn();
16
- export const getStartedVisit = jest.fn();
package/mock.ts CHANGED
@@ -14,4 +14,3 @@ export const deleteAttachmentPermanently = vi.fn();
14
14
  export const updateVisit = vi.fn();
15
15
  export const saveVisit = vi.fn();
16
16
  export const getVisitsForPatient = vi.fn();
17
- export const getStartedVisit = vi.fn();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-emr-api",
3
- "version": "10.0.1-pre.5539",
3
+ "version": "10.0.1-pre.5545",
4
4
  "license": "MPL-2.0",
5
5
  "description": "The javascript module for interacting with the OpenMRS API",
6
6
  "type": "module",
@@ -58,14 +58,12 @@
58
58
  "lodash-es": "^4.17.21"
59
59
  },
60
60
  "peerDependencies": {
61
- "@openmrs/esm-api": "^10.0.1-pre.5539",
62
- "@openmrs/esm-offline": "^10.0.1-pre.5539",
63
- "@openmrs/esm-state": "^10.0.1-pre.5539"
61
+ "@openmrs/esm-api": "^10.0.1-pre.5545",
62
+ "@openmrs/esm-state": "^10.0.1-pre.5545"
64
63
  },
65
64
  "devDependencies": {
66
- "@openmrs/esm-api": "10.0.1-pre.5539",
67
- "@openmrs/esm-offline": "10.0.1-pre.5539",
68
- "@openmrs/esm-state": "10.0.1-pre.5539",
65
+ "@openmrs/esm-api": "10.0.1-pre.5545",
66
+ "@openmrs/esm-state": "10.0.1-pre.5545",
69
67
  "@swc/cli": "0.8.1",
70
68
  "@swc/core": "1.15.21",
71
69
  "@vitest/coverage-v8": "^4.1.2",
@@ -73,7 +71,6 @@
73
71
  "cross-env": "^10.1.0",
74
72
  "happy-dom": "^20.6.0",
75
73
  "rimraf": "^6.1.3",
76
- "rxjs": "^6.5.3",
77
74
  "vitest": "^4.1.2"
78
75
  },
79
76
  "stableVersion": "10.0.0"
@@ -1,25 +1,19 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
  import { openmrsFetch, type FetchResponse } from '@openmrs/esm-api';
3
- import { getSynchronizationItems } from '@openmrs/esm-offline';
4
3
  import { fetchCurrentPatient } from './current-patient';
5
4
 
6
5
  vi.mock('@openmrs/esm-api');
7
6
 
8
7
  const mockOpenmrsFetch = vi.mocked(openmrsFetch);
9
- const mockGetSynchronizationItems = vi.mocked(getSynchronizationItems);
10
8
 
11
9
  vi.mock('../openmrs-fetch', () => ({
12
10
  openmrsFetch: vi.fn(),
13
11
  fhirBaseUrl: '/ws/fhir2/R4',
14
12
  }));
15
13
 
16
- vi.mock('@openmrs/esm-offline', () => ({
17
- getSynchronizationItems: vi.fn(),
18
- }));
19
-
20
- describe('fetchPatientData', () => {
14
+ describe('fetchCurrentPatient', () => {
21
15
  beforeEach(() => {
22
- mockGetSynchronizationItems.mockResolvedValue([]);
16
+ mockOpenmrsFetch.mockReset();
23
17
  });
24
18
 
25
19
  it('should return null when patientUuid is falsy', async () => {
@@ -27,7 +21,7 @@ describe('fetchPatientData', () => {
27
21
  expect(result).toBeNull();
28
22
  });
29
23
 
30
- it('should return online patient data when available', async () => {
24
+ it('should return patient data when available', async () => {
31
25
  const mockPatient = { id: '123', name: [{ given: ['John'], family: 'Doe' }] };
32
26
  mockOpenmrsFetch.mockResolvedValue({ data: mockPatient, ok: true } as Partial<FetchResponse> as FetchResponse);
33
27
 
@@ -35,18 +29,8 @@ describe('fetchPatientData', () => {
35
29
  expect(result).toEqual(mockPatient);
36
30
  });
37
31
 
38
- it('should return offline patient data when online fetch fails', async () => {
39
- const mockOfflinePatient = { id: '123', name: [{ given: ['Jane'], family: 'Doe' }] };
40
- mockOpenmrsFetch.mockRejectedValue(new Error('Network error'));
41
- mockGetSynchronizationItems.mockResolvedValue([{ fhirPatient: mockOfflinePatient }]);
42
-
43
- const result = await fetchCurrentPatient('123');
44
- expect(result).toEqual(mockOfflinePatient);
45
- });
46
-
47
- it('should throw an error when both online and offline fetches fail', async () => {
32
+ it('should throw an error when the fetch fails', async () => {
48
33
  mockOpenmrsFetch.mockRejectedValue(new Error('Network error'));
49
- mockGetSynchronizationItems.mockResolvedValue([]);
50
34
 
51
35
  await expect(fetchCurrentPatient('123')).rejects.toThrow('Network error');
52
36
  });
@@ -1,6 +1,5 @@
1
1
  /** @module @category API */
2
2
  import { fhirBaseUrl, openmrsFetch, type FetchConfig, type FetchResponse } from '@openmrs/esm-api';
3
- import { getSynchronizationItems } from '@openmrs/esm-offline';
4
3
 
5
4
  export type CurrentPatient = fhir.Patient | FetchResponse<fhir.Patient>;
6
5
 
@@ -19,18 +18,13 @@ export interface OnlyThePatient extends CurrentPatientOptions {
19
18
  export type PatientUuid = string | null;
20
19
 
21
20
  /**
22
- * Fetches a patient by their UUID from the FHIR API. This function first attempts
23
- * to fetch the patient from the server. If the server request fails and offline
24
- * patients are included, it will check for a matching patient in the offline
25
- * patient registration sync queue.
21
+ * Fetches a patient by their UUID from the FHIR API.
26
22
  *
27
23
  * @param patientUuid The UUID of the patient to fetch, or `null`.
28
24
  * @param fetchInit Optional fetch configuration options to pass to the request.
29
- * @param includeOfflinePatients Whether to include patients from the offline
30
- * registration queue if the server request fails. Defaults to `true`.
31
25
  * @returns A Promise that resolves with the FHIR Patient object, or `null` if
32
- * the patient UUID is null or the patient is not found.
33
- * @throws Rethrows any error from the server request if no offline patient is found.
26
+ * the patient UUID is null.
27
+ * @throws Rethrows any error from the server request.
34
28
  *
35
29
  * @example
36
30
  * ```ts
@@ -44,38 +38,11 @@ export type PatientUuid = string | null;
44
38
  export async function fetchCurrentPatient(
45
39
  patientUuid: PatientUuid,
46
40
  fetchInit?: FetchConfig,
47
- includeOfflinePatients: boolean = true,
48
41
  ): Promise<fhir.Patient | null> {
49
42
  if (patientUuid) {
50
- let err: Error | null = null;
51
- const [onlinePatient, offlinePatient] = await Promise.all([
52
- openmrsFetch<fhir.Patient>(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit).catch<FetchResponse<fhir.Patient>>(
53
- (e) => (err = e),
54
- ),
55
- includeOfflinePatients ? getOfflineRegisteredPatientAsFhirPatient(patientUuid) : Promise.resolve(null),
56
- ]);
57
-
58
- if (onlinePatient.ok) {
59
- return onlinePatient.data;
60
- }
61
-
62
- if (offlinePatient) {
63
- return offlinePatient;
64
- }
65
-
66
- if (err) {
67
- throw err;
68
- }
43
+ const response = await openmrsFetch<fhir.Patient>(`${fhirBaseUrl}/Patient/${patientUuid}`, fetchInit);
44
+ return response.data;
69
45
  }
70
46
 
71
47
  return null;
72
48
  }
73
-
74
- async function getOfflineRegisteredPatientAsFhirPatient(patientUuid: string): Promise<fhir.Patient | null> {
75
- const patientRegistrationSyncItems = await getSynchronizationItems<{
76
- fhirPatient: fhir.Patient;
77
- }>('patient-registration');
78
- const patientSyncItem = patientRegistrationSyncItems.find((item) => item.fhirPatient.id === patientUuid);
79
-
80
- return patientSyncItem?.fhirPatient ?? null;
81
- }
package/src/location.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /** @module @category API */
2
- import { openmrsObservableFetch, restBaseUrl } from '@openmrs/esm-api';
3
- import type { Observable } from 'rxjs';
4
- import { map, take } from 'rxjs/operators/index.js';
2
+ import { openmrsFetch, restBaseUrl } from '@openmrs/esm-api';
5
3
  import type { Location } from './types';
6
4
 
7
5
  export function toLocationObject(openmrsRestForm: any): Location {
@@ -14,7 +12,7 @@ export function toLocationObject(openmrsRestForm: any): Location {
14
12
  export function getLocations(
15
13
  tagUuidOrName: string | null = null,
16
14
  query: string | null = null,
17
- ): Observable<Array<Location>> {
15
+ ): Promise<Array<Location>> {
18
16
  const params = new URLSearchParams();
19
17
  if (tagUuidOrName) {
20
18
  params.set('tag', tagUuidOrName);
@@ -25,12 +23,7 @@ export function getLocations(
25
23
  const queryString = params.toString();
26
24
  const url = `${restBaseUrl}/location${queryString ? '?' + queryString : ''}`;
27
25
 
28
- return openmrsObservableFetch<{ results: Array<Location> }>(url)
29
- .pipe(
30
- map((results) => {
31
- const locations: Array<Location> = results.data.results.map(toLocationObject);
32
- return locations;
33
- }),
34
- )
35
- .pipe(take(1));
26
+ return openmrsFetch<{ results: Array<Location> }>(url).then((response) =>
27
+ response.data.results.map(toLocationObject),
28
+ );
36
29
  }
package/src/visit-type.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /** @module @category API */
2
- import { openmrsObservableFetch, restBaseUrl } from '@openmrs/esm-api';
3
- import type { Observable } from 'rxjs';
4
- import { map, take } from 'rxjs/operators/index.js';
2
+ import { openmrsFetch, restBaseUrl } from '@openmrs/esm-api';
5
3
  import { type VisitType } from './types';
6
4
 
7
5
  export function toVisitTypeObject(openmrsRestForm: any): VisitType {
@@ -12,27 +10,23 @@ export function toVisitTypeObject(openmrsRestForm: any): VisitType {
12
10
  };
13
11
  }
14
12
 
13
+ /** The endpoint {@link getVisitTypes} reads from. Use it as the SWR key when caching visit types. */
14
+ export const visitTypesUrl = `${restBaseUrl}/visittype`;
15
+
15
16
  /**
16
17
  * Fetches all available visit types from the OpenMRS REST API.
17
18
  *
18
- * @returns An Observable that emits an array of VisitType objects and then completes.
19
- * The Observable will emit exactly one value containing all visit types.
19
+ * @param url The endpoint to read from, defaulting to {@link visitTypesUrl}. This exists so that the
20
+ * function can be passed straight to SWR as a fetcher, which calls it with the cache key.
21
+ * @returns A Promise that resolves with an array of VisitType objects.
20
22
  *
21
23
  * @example
22
24
  * ```ts
23
25
  * import { getVisitTypes } from '@openmrs/esm-framework';
24
- * getVisitTypes().subscribe((visitTypes) => {
25
- * console.log('Available visit types:', visitTypes);
26
- * });
26
+ * const visitTypes = await getVisitTypes();
27
+ * console.log('Available visit types:', visitTypes);
27
28
  * ```
28
29
  */
29
- export function getVisitTypes(): Observable<Array<VisitType>> {
30
- return openmrsObservableFetch<any>(`${restBaseUrl}/visittype`)
31
- .pipe(
32
- map((results) => {
33
- const visitTypes: Array<VisitType> = results.data.results.map(toVisitTypeObject);
34
- return visitTypes;
35
- }),
36
- )
37
- .pipe(take(1));
30
+ export function getVisitTypes(url: string = visitTypesUrl): Promise<Array<VisitType>> {
31
+ return openmrsFetch<{ results: Array<any> }>(url).then((response) => response.data.results.map(toVisitTypeObject));
38
32
  }
@@ -1,7 +1,6 @@
1
1
  /** @module @category API */
2
2
  import { openmrsFetch, restBaseUrl, type FetchResponse } from '@openmrs/esm-api';
3
3
  import { getGlobalStore } from '@openmrs/esm-state';
4
- import { BehaviorSubject } from 'rxjs';
5
4
  import { type NewVisitPayload, type UpdateVisitPayload, type Visit } from './types';
6
5
 
7
6
  export interface VisitItem {
@@ -185,6 +184,3 @@ export function getVisitsForPatient(
185
184
  },
186
185
  });
187
186
  }
188
-
189
- /** @deprecated */
190
- export const getStartedVisit = new BehaviorSubject<VisitItem | null>(null);