Skip to main content

openmrs@5.0.1

create(path, data)
destroy(path, [options])
get(path, [options])
update(path, data)
upsert(path, data, params)

This adaptor exports the following namespaced functions:

http.delete(path, [options])
http.get(path, [options])
http.post(path, data, [options])
http.request(method, path, [options])
fhir.get(path, query, [callback])

Functions

create

create(path, data) ⇒ Operation

Create a resource. For a list of valid resources, see OpenMRS Docs

ParamTypeDescription
pathstringPath to resource (excluding /ws/rest/v1/)
dataobjectResource definition

This operation writes the following keys to state:

State KeyDescription
dataThe newly created resource, as returned by OpenMRS

Example: Create a person (see OpenMRS API)

create("person", {
names: [
{
givenName: "Mohit",
familyName: "Kumar",
},
],
gender: "M",
birthdate: "1997-09-02",
addresses: [
{
address1: "30, Vivekananda Layout, Munnekolal,Marathahalli",
cityVillage: "Bengaluru",
country: "India",
postalCode: "560037",
},
],
});

Example: Create an encounter (see OpenMRS API)

create("encounter", {
encounterDatetime: '2023-05-25T06:08:25.000+0000',
patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
encounterType: 'dd528487-82a5-4082-9c72-ed246bd49591',
location: 'ba685651-ed3b-4e63-9b35-78893060758a',
encounterProviders: [],
visit: {
patient: '1fdaa696-e759-4a7d-a066-f1ae557c151b',
visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',
startDatetime: '2023-05-25T06:08:25.000+0000',
stopDatetime: '2023-05-25T06:09:25.000+0000',
},
})

Example: Create a patient (see OpenMRS API)

create("patient", {
identifiers: [
{
identifier: '4023287',
identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',
preferred: true,
},
],
person: {
gender: 'M',
age: 42,
birthdate: '1970-01-01T00:00:00.000+0100',
birthdateEstimated: false,
names: [
{
givenName: 'Doe',
familyName: 'John',
},
],
},
})

Example: Create a patientIdentifier subresource (see OpenMRS API)

create("patient/b52ec6f9-0e26-424c-a4a1-c64f9d571eb3/identifier", { 
"identifier" : "111:CLINIC1",
"identifierType" : "a5d38e09-efcb-4d91-a526-50ce1ba5011a",
"location" : "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
"preferred" : true
})
}

destroy

destroy(path, [options]) ⇒ Operation

Delete a resource. Must include a UUID in the path. Throws an error if the resource does not exist.

ParamTypeDefaultDescription
pathstringPath to resource (excluding /ws/rest/v1/)
[options]object{}
[options.purge]objectfalseThe resource will be voided/retired unless true

This operation writes the following keys to state:

State KeyDescription
dataThe response from OpenMRS

Example: Void a patient

destroy("patient/12346");

Example: Purge a patient

destroy("patient/12346", {
purge: true
});

get

get(path, [options]) ⇒ Operation

Fetch resources from OpenMRS. Use this to fetch a single resource, or to search a list.

Options will be appended as query parameters to the request URL, refer to OpenMRS Docs for details.

Pagination is handled automatically by default (maximum 10k items). Set max to paginate with a higher limit, or pass limit to force a single request, as per the OpenMRS Rest API.

ParamTypeDefaultDescription
pathstringPath to resource (excluding /ws/rest/v1/)
[options]GetOptions{}Includes max, query, and extra query parameters

This operation writes the following keys to state:

State KeyDescription
dataAn array of result objects

Example: List all concepts (up to a maximum of 10k items, with pagination)

get("concept")

Example: List all concepts (with pagination)

get("concept", { query: "brian", max: Infinity })

Example: Search up to 100 patients by name (allowing pagination) (see OpenMRS API)

get("patient", { query: "brian", max: 100 })

Example: Fetch patient by UUID (returns an array of 1 item)

get("patient/abc")

Example: Fetch patient by UUID (returns an object of patient data)

get("patient/abc", { singleton: true })

Example: Search up to 10 patients by name (in a single request without pagination) (see OpenMRS API)

get("patient", { query: "brian", limit: 10 })

Example: List allergy subresources

get("patient/abc/allergy")

Example: Get allergy subresource by its UUID and parent patient UUID

get("patient/abc/allergy/xyz")

update

update(path, data) ⇒ Operation

Update a resource. Only properties included in the data will be affected. For a list of valid resources and for update rules, see the Update sections of the OpenMRS Docs

ParamTypeDescription
pathstringPath to resource (excluding /ws/rest/v1/)
dataObjectResource properties to update

This operation writes the following keys to state:

State KeyDescription
dataThe full updated resource, as returned by OpenMRS

Example: Update a person (see OpenMRS API)

update('person/3cad37ad-984d-4c65-a019-3eb120c9c373', {
'gender': 'M',
'birthdate':'1997-01-13'
})

upsert

upsert(path, data, params) ⇒ Operation

Update a resource if it already exists, or otherwise create a new one.

Upsert will first make a request for the target item (using the path and params) to see if it exists, and then issue a second create or update request. If the query request returns multiple items, the upsert will throw an error.

ParamTypeDescription
pathstringPath to resource (excluding /ws/rest/v1/)
dataObjectThe resource data
paramsObjectQuery parameters to append to the initial query

This operation writes the following keys to state:

State KeyDescription
dataThe created/updated resource, as returned by OpenMRS

Example: Upsert a patient (see OpenMRS API)

upsert("patient/a5d38e09-efcb-4d91-a526-50ce1ba5011a", {
identifiers: [
{
identifier: '4023287',
identifierType: '05a29f94-c0ed-11e2-94be-8c13b969e334',
preferred: true,
},
],
person: {
gender: 'M',
age: 42,
birthdate: '1970-01-01T00:00:00.000+0100',
birthdateEstimated: false,
names: [
{
givenName: 'Doe',
familyName: 'John',
},
],
},
})

Example: Upsert a patient using a query to identify the record

upsert("patient", $.data, { q: "Lamine Yamal" })

http

These functions belong to the http namespace.

http.delete

delete(path, [options]) ⇒ operation

Make a DELETE request to an OpenMRS endpoint

ParamTypeDefaultDescription
pathstringpath to resource
[options]HTTPRequestOptions{}An object containing query params and headers for the request

This operation writes the following keys to state:

State KeyDescription
dataThe response body (as JSON)
responseThe HTTP response from the OpenMRS server (excluding the body)
referencesAn array containing all previous data objects

Example: Delete a resource

http.delete(
"/ws/rest/v1/patient/abc/"
)

http.get

get(path, [options]) ⇒ operation

Make a GET request to any OpenMRS endpoint. Unlike the main get(), this does not append anything to the path you provide.

ParamTypeDefaultDescription
pathstringpath to resource
[options]HTTPRequestOptions{}An object containing query params and headers for the request

This operation writes the following keys to state:

State KeyDescription
dataThe response body (as JSON)
responseThe HTTP response from the OpenMRS server (excluding the body)
referencesAn array containing all previous data objects

Example: GET a resource with a query

http.get(
"/ws/rest/v1/patient",
{
query: {
limit: 1
}
}
)

Example: Don't throw if OpenMRS returns a 404 error code

http.get(
"/ws/rest/v1/patient",
{
errors: { 404: false }
}
)

http.post

post(path, data, [options]) ⇒ operation

Make a POST request to an OpenMRS endpoint

ParamTypeDefaultDescription
pathstringpath to resource
dataanythe payload
[options]HTTPRequestOptions{}An object containing query params and headers for the request

This operation writes the following keys to state:

State KeyDescription
dataThe response body (as JSON)
responseThe HTTP response from the OpenMRS server (excluding the body)
referencesAn array containing all previous data objects

Example: Post with a JSON payload

http.post(
"/ws/rest/v1/patient",
{
"person": {
"gender":"M",
"age":47,
"birthdate":"1970-01-01T00:00:00.000+0100",
"names":[
{
"givenName":"Jon",
"familyName":"Snow"
}
],
}
}
)

http.request

request(method, path, [options]) ⇒ Operation

Make a HTTP request to any OpenMRS endpoint

ParamTypeDefaultDescription
methodstringHTTP method to use
pathstringPath to resource
[options]HTTPRequestOptions{}An object containing query, headers, and body for the request

This operation writes the following keys to state:

State KeyDescription
dataThe response body (as JSON)
responseThe HTTP response from the OpenMRS server (excluding the body)
referencesAn array containing all previous data objects

Example: GET request with a query parameters

http.request("GET",
"/ws/rest/v1/patient/d3f7e1a8-0114-4de6-914b-41a11fc8a1a8", {
query:{
limit: 1,
startIndex: 20
},
});

fhir

These functions belong to the fhir namespace.

fhir.get

get(path, query, [callback]) ⇒ Operation

Make a get request to any FHIR endpoint in OpenMRS

ParamTypeDescription
pathstringPath to resource
queryFhirParametersRequest parameters
[callback]functionOptional callback to handle the response

This operation writes the following keys to state:

State KeyDescription
dataThe response body (as JSON)
responseThe HTTP response from the OpenMRS server (excluding the body)
referencesAn array containing all previous data objects

Example: Get encounters based on lastUpdated field

fhir.get('Encounter', { count: 100, lastUpdated: 'ge2024-01-01T00:00:00Z' })

Interfaces

FhirParameters

OpenMRS FHIR requests parameters options. This combines FHIR search parameters, resource-specific parameters, and pagination options.

Properties

NameTypeDescription
countstringNumber of results to return (_count in FHIR)
includestringResources to include in the response (_include in FHIR)
revincludestringReverse includes to include in the response (_revinclude in FHIR)
summarystringSummary mode for the response (_summary in FHIR)
totalstringWhether to include a total count of matching resources (_total in FHIR)
elementsstringList of elements to include in the response (_elements in FHIR)
containedstringWhether to include contained resources (_contained in FHIR)
containedTypestringType of contained resources (_containedType in FHIR)
idstringLogical ID of the resource to filter on (_id in FHIR)
lastUpdatedstringTimestamp to filter resources last updated after this date (_lastUpdated in FHIR)
tagstringTag to filter resources by (_tag in FHIR)
profilestringProfile URL to filter resources by (_profile in FHIR)
securitystringSecurity labels to filter resources by (_security in FHIR)
textstringText search on narrative content (_text in FHIR)
contentstringFull-text search on resource content (_content in FHIR)
liststringSearch resources included in a particular list (_list in FHIR)
hasstringPerform search based on reference chains (_has in FHIR)
getPagesOffsetstringOffset for pagination, used to skip a number of results (_getpagesoffset in OpenMRS)
getPagesstringGet specific pages of resources (_getpages in OpenMRS)
bundleTypestringType of bundle to return (e.g., searchset, batch, history) (_bundleType in FHIR)

GetOptions

Options to append to the request. Unless otherwise specified, options are appended to the URL as query parameters - see the OpenMRS Docs for all supported parameters.

Properties

NameTypeDefaultDescription
[query]string(OpenFn only) Query string. Maps to q in OpenMRS.
[max]number10000(OpenFn only) Restrict the maximum number of retrieved records. May be fetched in several pages. Not used if limit is set.
[pageSize]number1000(OpenFn only) Limits the size of each page of data. Not used if limit is set.
[singleton]boolean(OpenFn only) If set to true, only the first result will be returned. Useful for "get by id" APIs.

HTTPRequestOptions

Options object

Properties

NameTypeDefaultDescription
queryobjectAn object of query parameters to be encoded into the URL
headersobjectAn object of all request headers
bodyobjectThe request body (as JSON)
errorsobject | booleanPass false to not throw on errors. Pass a map of errorCodes: error messages, ie, { 404: 'Resource not found' }, or false to suppress errors for a specific code.
[parseAs]string"'json'"The response format to parse (e.g., 'json', 'text', or 'stream')