Skip to main content

fhir-opensrp@1.0.0

create(path, body, options)
delete(path, options)
read(path, options)
request(method, path, body, options)
update(path, body, options)

This adaptor exports the following from common:

as()
combine()
cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
fnIf()
group()
lastReferenceValue()
map()
merge()
scrubEmojis()
sourceValue()
util

Functions

create

create(path, body, options) ⇒ Operation

Create a resource

ParamTypeDescription
pathstringPath to resource
bodyobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Create a Patient using builders (see fhir-4 docs)

create('Patient', builders.patient({
identifier: [
builders.identifier({
use: 'official',
system: 'http://ohie.org/National_Id',
value: 'NIN-TEST-001',
}),
],
name: [{ use: 'official', family: 'Nakamura', given: ['Aiko'], text: 'Aiko Nakamura' }],
gender: 'female',
birthDate: '1992-04-10',
active: true,
telecom: [{ system: 'phone', value: '0712345678' }],
}));

Example: Create a Patient without builders

create('Patient', {
resourceType: 'Patient',
active: true,
identifier: [
{ use: 'official', system: 'http://ohie.org/National_Id', value: 'NIN-TEST-001' },
],
name: [{ use: 'official', family: 'Nakamura', given: ['Aiko'] }],
gender: 'female',
birthDate: '1992-04-10',
telecom: [{ system: 'phone', value: '0712345678' }],
});

delete

delete(path, options) ⇒ Operation

Delete a resource

ParamTypeDescription
pathstringPath to resource
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Delete a Patient by ID

delete('Patient/97597');

read

read(path, options) ⇒ Operation

Read a resource

ParamTypeDescription
pathstringPath to resource
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Read server metadata

read('metadata');

Example: Search for recently updated Patients

read('Patient', {
query: {
'_lastUpdated': 'gt2026-07-01T00:00:00Z',
'_sort': '_lastUpdated',
'_count': 200
}
});

request

request(method, path, body, options) ⇒ Operation

Make a general HTTP request

ParamTypeDescription
methodstringHTTP method to use
pathstringPath to resource
bodyobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Search Observations for a specific patient

request('GET', 'Observation', null, {
query: { 'subject': 'Patient/0181038e-682b-4c7c-a946-e3757d2fa2f7' }
});

Example: Update a Patient resource

request('PUT', 'Patient/0181038e-682b-4c7c-a946-e3757d2fa2f7', {
resourceType: 'Patient',
id: '0181038e-682b-4c7c-a946-e3757d2fa2f7',
active: false,
name: [{ use: 'official', family: 'Mathenge', given: ['Monica'] }],
gender: 'female',
birthDate: '1990-07-07',
});

update

update(path, body, options) ⇒ Operation

Update a resource

ParamTypeDescription
pathstringPath to resource
bodyobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Update a Patient by ID

update('Patient/0181038e-682b-4c7c-a946-e3757d2fa2f7', {
resourceType: 'Patient',
id: '0181038e-682b-4c7c-a946-e3757d2fa2f7',
active: true,
name: [{ use: 'official', family: 'Mathenge', given: ['Monica'] }],
gender: 'female',
birthDate: '1990-07-07',
telecom: [{ system: 'phone', value: '0712010203' }],
managingOrganization: { reference: 'Organization/eb4963c3-3d6e-4ea9-bde8-6a5b638bc4f8' },
});

Interfaces

OnaFHIRState

State object

Properties

NameDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

RequestOptions

Options provided to Ona fhir request

Properties

NameTypeDescription
queryobjectAn object of query parameters to be encoded into the URL.
headersobjectAn object of headers to append to the request.