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:
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
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",
},
],
});
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
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
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
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
Param | Type | Description |
---|---|---|
uuid | string | A uuid for the patient |
[callback] | function | Optional 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
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
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
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
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.
Throws:
RangeError
- Throws range error
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,
},
}
);
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
Param | Type | Description |
---|---|---|
path | string | Path to resource |
query | FhirParameters | Request parameters |
[callback] | function | Optional 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
Name | Type | Description |
---|---|---|
count | string | Number of results to return (_count in FHIR) |
include | string | Resources to include in the response (_include in FHIR) |
revinclude | string | Reverse includes to include in the response (_revinclude in FHIR) |
summary | string | Summary mode for the response (_summary in FHIR) |
total | string | Whether to include a total count of matching resources (_total in FHIR) |
elements | string | List of elements to include in the response (_elements in FHIR) |
contained | string | Whether to include contained resources (_contained in FHIR) |
containedType | string | Type of contained resources (_containedType in FHIR) |
id | string | Logical ID of the resource to filter on (_id in FHIR) |
lastUpdated | string | Timestamp to filter resources last updated after this date (_lastUpdated in FHIR) |
tag | string | Tag to filter resources by (_tag in FHIR) |
profile | string | Profile URL to filter resources by (_profile in FHIR) |
security | string | Security labels to filter resources by (_security in FHIR) |
text | string | Text search on narrative content (_text in FHIR) |
content | string | Full-text search on resource content (_content in FHIR) |
list | string | Search resources included in a particular list (_list in FHIR) |
has | string | Perform search based on reference chains (_has in FHIR) |
getPagesOffset | string | Offset for pagination, used to skip a number of results (_getpagesoffset in OpenMRS) |
getPages | string | Get specific pages of resources (_getpages in OpenMRS) |
bundleType | string | Type of bundle to return (e.g., searchset, batch, history) (_bundleType in FHIR) |