opencrvs@1.2.1
- createBirthNotification(body)
- createDocumentEntry(resource, [fullUrl])
- createEvent(type, options)
- getLocations(options)
- notifyEvent(eventId, declaration, options)
- queryEvents(variables, options)
- submitBirthNotification(declaration, options)
This adaptor exports the following namespaced functions:
This adaptor exports the following from common:
- combine()
- cursor()
- dataPath()
- dataValue()
- dateFns
- each()
- field()
- fields()
- fn()
- fnIf()
- group()
- lastReferenceValue()
- log()
- merge()
- scrubEmojis()
- sourceValue()
- util
Functions
createBirthNotification
~~
createBirthNotification(body) ⇒ Operation
Create a Birth Notification. Pass an array of FHIR resources wrapped in entry
objects like { fullUrl, resource }. References must use the full URL
of the corresponding resources. See OpenCRVS Event Notification Postman documentation
| Param | Type | Description |
|---|---|---|
| body | Array | An array of Birth Notification bundle entries. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Create a birth notification
createBirthNotification($.bundleData)
Example: Cross-reference two bundle resources
createBirthNotification([
{
fullUrl: 'urn:uuid:abcde',
resource: {
resourceType: 'Composition',
section:[
{
title: "Mother's details",
code: {
coding: [
{
system: 'http://opencrvs.org/specs/sections',
code: 'mother-details',
},
],
text: "Mother's details",
},
entry: [
{
reference: 'urn:uuid:wxyz',
},
],
}
// ... other section details
]
// ... other resource details
},
},
{
fullUrl: 'urn:uuid:wxyz',
resource: {
resourceType: 'Patient',
// ... other resource details
},
},
]);
createDocumentEntry
createDocumentEntry(resource, [fullUrl]) ⇒ Object
Create a document bundle entry with automatic UUID generation
Returns: Object - Bundle entry with fullUrl and resource
| Param | Type | Description |
|---|---|---|
| resource | Object | A FHIR resource using builders from fhir-4 |
| [fullUrl] | string | Custom fullUrl. Auto-generated if not provided |
Example
createDocumentEntry(builders.patient({ name: [{ given: ['John'] }] }))
createEvent
createEvent(type, options) ⇒ Operation
Create an OpenCRVS v2 event (e.g. a birth or death registration).
Posts to the register.<domain> host. The returned event id is
available on state.data.id for use with notifyEvent.
| Param | Type | Description |
|---|---|---|
| type | string | Event type, e.g. 'birth' or 'death'. |
| options | object | Optional fields: createdAtLocation (string) and transactionId (string, defaults to a random UUID). |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Create a birth event at a known location
createEvent('birth', { createdAtLocation: 'a1b2-...' });
getLocations
getLocations(options) ⇒ Operation
Fetch the list of locations from the countryconfig.<domain> host.
Useful for picking createdAtLocation or child.birthLocation.
| Param | Type | Description |
|---|---|---|
| options | object | Optional fields: params (object of query parameters to append to the request). |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example
getLocations();
notifyEvent
notifyEvent(eventId, declaration, options) ⇒ Operation
Notify an existing OpenCRVS v2 event with declaration data.
Posts to register.<domain>/api/events/events/{eventId}/notify.
| Param | Type | Description |
|---|---|---|
| eventId | string | The event id returned by createEvent. |
| declaration | object | Flat dotted-key declaration (e.g. 'child.name', 'child.dob'). |
| options | object | Optional fields: createdAtLocation (string), transactionId (string, defaults to a random UUID) and annotation (object). |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Notify a birth event
notifyEvent($.id, {
'child.name': { firstname: 'Test', surname: 'Baby' },
'child.dob': '2026-05-01',
'child.gender': 'female',
}, { createdAtLocation: $.locationId });
queryEvents
queryEvents(variables, options) ⇒ Operation
Make an events search query against the OpenCRVS GraphQL API.
| Param | Type | Description |
|---|---|---|
| variables | Object | GraphQL search parameters. For a full list of options, see variables.advancedSearchParameters in OpenCRVS Docs |
| options | Object | Options to control the request, such as count and skip. Count defaults to 10. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Search for events with specific parameters
queryEvents(
{
event: 'birth',
registrationStatuses: ['REGISTERED'],
childGender: 'male',
dateOfRegistrationEnd: '2022-12-31T23:59:59.999Z',
dateOfRegistrationStart: '2021-11-01T00:00:00.000Z',
declarationJurisdictionId: '',
eventLocationId: '704b9706-d729-4834-8656-05b562065deb',
fatherFirstNames: 'Dad',
motherFirstNames: 'Mom',
},
);
Example: Search for events with options
queryEvents(
{
event: 'birth',
registrationStatuses: ['REGISTERED'],
childGender: 'male',
dateOfRegistrationEnd: '2022-12-31T23:59:59.999Z',
dateOfRegistrationStart: '2021-11-01T00:00:00.000Z',
declarationJurisdictionId: '',
eventLocationId: '704b9706-d729-4834-8656-05b562065deb',
fatherFirstNames: 'Dad',
motherFirstNames: 'Mom',
},
{ count: 10, skip: 0 }
);
submitBirthNotification
submitBirthNotification(declaration, options) ⇒ Operation
Convenience helper: create a v2 birth event and notify it in one step.
Mirrors the reference integration script's create-then-notify chain.
The notify response is left on state.data.
| Param | Type | Description |
|---|---|---|
| declaration | object | Flat dotted-key declaration passed through to notifyEvent. |
| options | object | Optional fields: createdAtLocation (string), transactionId (string, applied to the create call only — notify always generates its own UUID) and annotation (object, passed to notify). |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Submit a birth notification in one call
submitBirthNotification({
'child.name': { firstname: 'Test', surname: 'Baby' },
'child.dob': '2026-05-01',
'child.gender': 'female',
'child.placeOfBirth': 'HEALTH_FACILITY',
'child.birthLocation': $.locationId,
'informant.relation': 'MOTHER',
}, { createdAtLocation: $.locationId });
http
These functions belong to the http namespace.
http.post
post(path, body, options) ⇒ Operation
Make a POST request
| Param | Type | Description |
|---|---|---|
| path | string | Path to resource |
| body | object | Object which will be attached to the POST body |
| options | RequestOptions | Optional request options |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example
http.post("/location", {
"statisticalID": "TEST_LOCATION",
"name": "My name",
"alias": "My alias",
"partOf": "Location/0",
"code": "ADMIN_STRUCTURE",
"jurisdictionType": "STATE",
"statistics": [
{
"year": 0,
"male_population": 0,
"female_population": 0,
"population": 0,
"crude_birth_rate": 0
}
]
});
http.request
request(method, path, body, options) ⇒ Operation
Make a general HTTP request
| Param | Type | Description |
|---|---|---|
| method | string | HTTP method to use |
| path | string | Path to resource |
| body | object | Object which will be attached to the POST body |
| options | RequestOptions | Optional request options |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
Example: Create a new administrative location
http.request("POST", "/location", {
"statisticalID": "TEST_LOCATION",
"name": "My name",
"alias": "My alias",
"partOf": "Location/0",
"code": "ADMIN_STRUCTURE",
"jurisdictionType": "STATE",
"statistics": [
{
"year": 0,
"male_population": 0,
"female_population": 0,
"population": 0,
"crude_birth_rate": 0
}
]
});
Interfaces
OpenCRVSHTTPState
State object
Properties
| Name | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
OpenCRVSState
State object
Properties
| Name | Description |
|---|---|
| data | the parsed response body |
| response | the response from the HTTP server, including headers, statusCode, body, etc |
| references | an array of all previous data objects used in the Job |
RequestOptions
Options provided to the HTTP request
Properties
| Name | Type | Description |
|---|---|---|
| errors | object | Map of errorCodes -> error messages, ie, { 404: 'Resource not found;' }. Pass false to suppress errors for this code. |
| query | object | An object of query parameters to be encoded into the URL. |