Skip to main content

openmrs@3.0.2

Functions

create(resourceType, data, [callback])
createEncounter(data, [callback])
createPatient(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])

The following functions are exported from the common adaptor:

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

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

createEncounter

createEncounter(data, [callback]) ⇒ Operation

Creates an encounter

ParamTypeDescription
dataobjectData parameters of the encounter
[callback]functionOptional callback to handle the response

Example (Create an encounter)

createEncounter({
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',
},
})

createPatient

createPatient(data, [callback]) ⇒ Operation

Creates a new patient

ParamTypeDescription
dataobjectObject parameters of the patient
[callback]functionOptional callback to handle the response

Example

createPatient({
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

getPatient("123")

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,
},
}
);