Skip to content

Latest commit

 

History

History
674 lines (417 loc) · 18.8 KB

File metadata and controls

674 lines (417 loc) · 18.8 KB

Back to README.md

@openmrs/esm-api

Table of contents

Enumerations

Classes

Interfaces

Type aliases

API Variables

Other Variables

API Functions

API Object Functions

Other Functions

Workspace Functions

Type aliases

CurrentPatient

Ƭ CurrentPatient: fhir.Patient | FetchResponse<fhir.Patient>

Defined in

packages/framework/esm-api/src/shared-api-objects/current-patient.ts:4


PatientUuid

Ƭ PatientUuid: string | null

Defined in

packages/framework/esm-api/src/shared-api-objects/current-patient.ts:18


UpdateVisitPayload

Ƭ UpdateVisitPayload: NewVisitPayload & {}

Defined in

packages/framework/esm-api/src/types/visit-resource.ts:12

API Variables

fhir

Const fhir: FhirClient

The fhir object is an instance of fhir.js that can be used to call FHIR-compliant OpenMRS APIs. See the docs for fhir.js for more info and example usage.

Defined in

packages/framework/esm-api/src/fhir.ts:41


Other Variables

backendDependencies

Const backendDependencies: Object

Type declaration

Name Type
fhir2 string
webservices.rest string

Defined in

packages/framework/esm-api/src/openmrs-backend-dependencies.ts:1


fhirBaseUrl

Const fhirBaseUrl: "/ws/fhir2/R4"

Defined in

packages/framework/esm-api/src/fhir.ts:4


getStartedVisit

Const getStartedVisit: BehaviorSubject<null | VisitItem>

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:84


sessionEndpoint

Const sessionEndpoint: "/ws/rest/v1/session"

Defined in

packages/framework/esm-api/src/openmrs-fetch.ts:6

API Functions

openmrsFetch

openmrsFetch<T>(path, fetchInit?): Promise<FetchResponse<T>>

The openmrsFetch function is a wrapper around the browser's built-in fetch function, with extra handling for OpenMRS-specific API behaviors, such as request headers, authentication, authorization, and the API urls.

Type parameters

Name Type
T T = any

Parameters

Name Type Description
path string A string url to make the request to. Note that the openmrs base url (by default /openmrs) will be automatically prepended to the URL, so there is no need to include it.
fetchInit FetchConfig A fetch init object. Note that the body property does not need to be JSON.stringify()ed because openmrsFetch will do that for you.

Returns

Promise<FetchResponse<T>>

A Promise that resolves with a Response object. Note that the openmrs version of the Response object has already downloaded the HTTP response body as json, and has an additional data property with the HTTP response json as a javascript object.

Example

import { openmrsFetch } from '@openmrs/esm-api'
const abortController = new AbortController();
openmrsFetch('/ws/rest/v1/session', {signal: abortController.signal})
  .then(response => {
    console.log(response.data.authenticated)
  })
  .catch(err => {
    console.error(err.status);
  })
abortController.abort();
openmrsFetch('/ws/rest/v1/session', {
  method: 'POST',
  body: {
    username: 'hi',
    password: 'there',
  }
})

Cancellation

To cancel a network request, use an AbortController. It is best practice to cancel your network requests when the user navigates away from a page while the request is pending request, to free up memory and network resources and to prevent race conditions.

Defined in

packages/framework/esm-api/src/openmrs-fetch.ts:61


openmrsObservableFetch

openmrsObservableFetch<T>(url, fetchInit?): Observable<FetchResponse<T>>

The openmrsObservableFetch function is a wrapper around openmrsFetch that returns an Observable instead of a promise. It exists in case using an Observable is preferred or more convenient than a promise.

Type parameters

Name
T

Parameters

Name Type Description
url string See openmrsFetch
fetchInit FetchConfig See openmrsFetch

Returns

Observable<FetchResponse<T>>

An Observable that produces exactly one Response object. The response object is exactly the same as for openmrsFetch.

Example

import { openmrsObservableFetch } from '@openmrs/esm-api'
const subscription = openmrsObservableFetch('/ws/rest/v1/session').subscribe(
  response => console.log(response.data),
  err => {throw err},
  () => console.log('finished')
)
subscription.unsubscribe()

Cancellation

To cancel the network request, simply call subscription.unsubscribe();

Defined in

packages/framework/esm-api/src/openmrs-fetch.ts:232


API Object Functions

fetchCurrentPatient

fetchCurrentPatient(patientUuid): Promise<Object> | Promise<null>

Parameters

Name Type
patientUuid PatientUuid

Returns

Promise<Object> | Promise<null>

Defined in

packages/framework/esm-api/src/shared-api-objects/current-patient.ts:23


getCurrentUser

getCurrentUser(): Observable<LoggedInUser>

The getCurrentUser function returns an observable that produces zero or more values, over time. It will produce zero values by default if the user is not logged in. And it will provide a first value when the logged in user is fetched from the server. Subsequent values will be produced whenever the user object is updated.

Returns

Observable<LoggedInUser>

An Observable that produces zero or more values (as described above). The values produced will be a user object (if includeAuthStatus is set to false) or an object with a session and authenticated property (if includeAuthStatus is set to true).

Example

import { getCurrentUser } from '@openmrs/esm-api'
const subscription = getCurrentUser().subscribe(
  user => console.log(user)
)
subscription.unsubscribe()
getCurrentUser({includeAuthStatus: true}).subscribe(
  data => console.log(data.authenticated)
)

Be sure to unsubscribe when your component unmounts

Otherwise your code will continue getting updates to the user object even after the UI component is gone from the screen. This is a memory leak and source of bugs.

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:56

getCurrentUser(opts): Observable<UnauthenticatedUser>

Parameters

Name Type
opts CurrentUserWithResponseOption

Returns

Observable<UnauthenticatedUser>

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:57

getCurrentUser(opts): Observable<LoggedInUser>

Parameters

Name Type
opts CurrentUserWithoutResponseOption

Returns

Observable<LoggedInUser>

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:60


refetchCurrentUser

refetchCurrentUser(): void

The refetchCurrentUser function causes a network request to redownload the user. All subscribers to the current user will be notified of the new users once the new version of the user object is downloaded.

Returns

void

The same observable as returned by getCurrentUser.

Example

import { refetchCurrentUser } from '@openmrs/esm-api'
refetchCurrentUser()

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:116


Other Functions

getLocations

getLocations(): Observable<Location[]>

Returns

Observable<Location[]>

Defined in

packages/framework/esm-api/src/shared-api-objects/location.ts:13


getLoggedInUser

getLoggedInUser(): Promise<LoggedInUser>

Returns

Promise<LoggedInUser>

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:125


getVisitTypes

getVisitTypes(): Observable<VisitType[]>

Returns

Observable<VisitType[]>

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-type.ts:14


getVisitsForPatient

getVisitsForPatient(patientUuid, abortController, v?): Observable<FetchResponse<Object>>

Parameters

Name Type
patientUuid string
abortController AbortController
v? string

Returns

Observable<FetchResponse<Object>>

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:23


makeUrl

makeUrl(path): string

Parameters

Name Type
path string

Returns

string

Defined in

packages/framework/esm-api/src/openmrs-fetch.ts:8


openVisitsNoteWorkspace

openVisitsNoteWorkspace(componentName, title): void

Parameters

Name Type
componentName string
title string

Returns

void

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:12


saveVisit

saveVisit(payload, abortController): Observable<FetchResponse<any>>

Parameters

Name Type
payload NewVisitPayload
abortController AbortController

Returns

Observable<FetchResponse<any>>

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:55


toLocationObject

toLocationObject(openmrsRestForm): Location

Parameters

Name Type
openmrsRestForm any

Returns

Location

Defined in

packages/framework/esm-api/src/shared-api-objects/location.ts:6


toVisitTypeObject

toVisitTypeObject(openmrsRestForm): VisitType

Parameters

Name Type
openmrsRestForm any

Returns

VisitType

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-type.ts:6


updateVisit

updateVisit(uuid, payload, abortController): Observable<any>

Parameters

Name Type
uuid string
payload UpdateVisitPayload
abortController AbortController

Returns

Observable<any>

Defined in

packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:69


userHasAccess

userHasAccess(requiredPrivilege, user): undefined | Privilege

Parameters

Name Type
requiredPrivilege string
user LoggedInUser

Returns

undefined | Privilege

Defined in

packages/framework/esm-api/src/shared-api-objects/current-user.ts:121


Workspace Functions

getNewWorkspaceItem

getNewWorkspaceItem(): Observable<WorkspaceItem>

Returns

Observable<WorkspaceItem>

Defined in

packages/framework/esm-api/src/workspace/workspace.resource.tsx:19


newWorkspaceItem

newWorkspaceItem(item): void

Parameters

Name Type
item WorkspaceItem

Returns

void

Defined in

packages/framework/esm-api/src/workspace/workspace.resource.tsx:10