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
Param | Type | Description |
---|---|---|
resourceType | string | Type of resource to create. E.g. person , patient , encounter , ... |
data | OpenMRSData | Object 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] | function | Optional 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
Param | Type | Description |
---|---|---|
data | object | Data parameters of the encounter |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
data | object | Object parameters of the patient |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
path | string | Path to resource |
query | object | parameters for the request |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
uuid | object | A uuid for the encounter |
[callback] | function | Optional callback to handle the response |
Example
getEncounter("123")
getEncountersβ
getEncounters(query, [callback]) β Operation
Gets encounters matching params
Kind: global function
Param | Type | Description |
---|---|---|
query | object | Object for the patient |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
uuid | string | A uuid for the patient |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
path | string | Path to resource |
data | object | Object which defines data that will be used to create a given instance of resource |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
query | object | Object with query for the patient |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
query | object | object with query for the person |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
resourceType | string | The type of resource to be updated. E.g. person , patient , etc. |
path | string | The 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} |
data | Object | Data to update. It requires to send all required fields or the full body . If you want partial updates , use patch operation. |
[callback] | function | Optional 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
Param | Type | Description |
---|---|---|
resourceType | string | The type of a resource to upsert . E.g. trackedEntityInstances |
query | Object | A query object that allows to uniquely identify the resource to update. If no matches found, then the resource will be created. |
data | Object | The data to use for update or create depending on the result of the query. |
[callback] | function | Optional 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,
},
}
);