Skip to main content

openmrs@2.0.8

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])

create​

create(resourceType, data, [callback]) β‡’ Operation Create a record

Kind: global function
Access: public

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function

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

Kind: global function
Access: public

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.

Kind: global function
Throws:

  • RangeError - Throws range error

Access: public

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