Skip to main content

openmrs@4.1.3

create(resourceType, data, [callback])
get(path, query, [callback])
getEncounter(uuid, [callback])
getEncounters(query, [callback])
getPatient(uuid, [callback])
post(path, data, [callback])
searchPatient(query, [callback])
searchPerson(query, [callback])
update(resourceType, path, data, [callback])
upsert(resourceType, query, data, [callback])

This adaptor exports the following namespaced functions:

fhir.get(path, query, [callback])

This adaptor exports the following from common:

alterState()
arrayToString()
cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
fnIf()
lastReferenceValue()
merge()
sourceValue()

Functions

create

create(resourceType, data, [callback]) ⇒ Operation

Create a record

ParamTypeDescription
resourceTypestringType of resource to create. E.g. person, patient, encounter, ...
dataOpenMRSDataObject which defines data that will be used to create a given instance of resource. To create a single instance of a resource, data must be a javascript object, and to create multiple instances of a resources, data must be an array of javascript objects.
[callback]functionOptional callback to handle the response

Example: Create a person

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

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

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',
},
],
},
})

get

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

Make a get request to any OpenMRS endpoint

ParamTypeDescription
pathstringPath to resource
queryobjectparameters for the request
[callback]functionOptional callback to handle the response

Example

get("patient", {
q: "Patient",
limit: 1,
});

getEncounter

getEncounter(uuid, [callback]) ⇒ Operation

Gets encounter matching a uuid

ParamTypeDescription
uuidobjectA uuid for the encounter
[callback]functionOptional callback to handle the response

Example

getEncounter("123")

getEncounters

getEncounters(query, [callback]) ⇒ Operation

Gets encounters matching params

ParamTypeDescription
queryobjectObject for the patient
[callback]functionOptional callback to handle the response

Example

getEncounters({ patient: "123", fromdate: "2023-05-18" })

getPatient

getPatient(uuid, [callback]) ⇒ Operation

Gets patient matching a uuid

ParamTypeDescription
uuidstringA uuid for the patient
[callback]functionOptional callback to handle the response

Example: Get a patient by uuid

getPatient('681f8785-c9ca-4dc8-a091-7b869316ff93')

post

post(path, data, [callback]) ⇒ Operation

Make a post request to any OpenMRS endpoint

ParamTypeDescription
pathstringPath to resource
dataobjectObject which defines data that will be used to create a given instance of resource
[callback]functionOptional callback to handle the response

Example

post(
"idgen/identifiersource/8549f706-7e85-4c1d-9424-217d50a2988b/identifier",
{}
);

searchPatient

searchPatient(query, [callback]) ⇒ Operation

Fetch all non-retired patients that match any specified parameters

ParamTypeDescription
queryobjectObject with query for the patient.
[callback]functionOptional callback to handle the response

Example

searchPatient({ q: "Sarah"})

searchPerson

searchPerson(query, [callback]) ⇒ Operation

Fetch all non-retired persons that match any specified parameters

ParamTypeDescription
queryobjectobject with query for the person
[callback]functionOptional callback to handle the response

Example

searchPerson({ q: "Sarah" })

update

update(resourceType, path, data, [callback]) ⇒ Operation

Update data. A generic helper function to update a resource object of any type. Updating an object requires to send all required fields or the full body

ParamTypeDescription
resourceTypestringThe type of resource to be updated. E.g. person, patient, etc.
pathstringThe id or path to the object to be updated. E.g. e739808f-f166-42ae-aaf3-8b3e8fa13fda or e739808f-f166-42ae-aaf3-8b3e8fa13fda/{collection-name}/{object-id}
dataObjectData to update. It requires to send all required fields or the full body. If you want partial updates, use patch operation.
[callback]functionOptional callback to handle the response

Example: a person

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

upsert

upsert(resourceType, query, data, [callback]) ⇒ Operation

Upsert a record. A generic helper function used to atomically either insert a row, or on the basis of the row already existing, UPDATE that existing row instead.

Throws:

  • RangeError - Throws range error
ParamTypeDescription
resourceTypestringThe type of a resource to upsert. E.g. trackedEntityInstances
queryObjectA query object that allows to uniquely identify the resource to update. If no matches found, then the resource will be created.
dataObjectThe data to use for update or create depending on the result of the query.
[callback]functionOptional callback to handle the response

Example: For an existing patient using upsert

upsert('patient', { q: '10007JJ' }, { person: { age: 50 } });

Example: For non existing patient creating a patient record using upsert

upsert(
"patient",
{ q: "1000EHE" },
{
identifiers: [
{
identifier: "1000EHE",
identifierType: "05a29f94-c0ed-11e2-94be-8c13b969e334",
location: "44c3efb0-2583-4c80-a79e-1f756a03c0a1",
preferred: true,
},
],
person: {
gender: "M",
age: 42,
},
}
);

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

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)