@openfn/language-openhim 0.3.15 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ast.json +680 -1
- package/dist/index.cjs +261 -54
- package/dist/index.js +239 -31
- package/package.json +11 -12
- package/types/Adaptor.d.ts +201 -4
- package/types/Util.d.ts +2 -0
- package/types/http.d.ts +139 -0
- package/types/index.d.ts +1 -0
- package/types/Client.d.ts +0 -6
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-openhim",
|
|
3
3
|
"label": "OpenHIM",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "OpenFn adaptor for OpenHIM",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"author": "Open Function Group",
|
|
8
8
|
"license": "LGPLv3",
|
|
@@ -14,21 +14,20 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"JSONPath": "^0.10.0",
|
|
17
|
-
"lodash-fp": "^0.10.
|
|
18
|
-
"
|
|
19
|
-
"@openfn/language-common": "3.0.0"
|
|
17
|
+
"lodash-fp": "^0.10.4",
|
|
18
|
+
"@openfn/language-common": "3.0.2"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"assertion-error": "^1.0
|
|
21
|
+
"assertion-error": "^1.1.0",
|
|
23
22
|
"babel-cli": "^6.26.0",
|
|
24
|
-
"babel-core": "^6.
|
|
25
|
-
"babel-preset-es2015": "^6.1
|
|
26
|
-
"babel-preset-stage-0": "^6.
|
|
27
|
-
"chai": "
|
|
23
|
+
"babel-core": "^6.26.3",
|
|
24
|
+
"babel-preset-es2015": "^6.24.1",
|
|
25
|
+
"babel-preset-stage-0": "^6.24.1",
|
|
26
|
+
"chai": "4.3.6",
|
|
28
27
|
"deep-eql": "^0.1.3",
|
|
28
|
+
"mocha": "^10.8.2",
|
|
29
29
|
"rimraf": "^3.0.2",
|
|
30
|
-
"sinon": "^1.17.
|
|
31
|
-
"superagent-mock": "^1.10.0"
|
|
30
|
+
"sinon": "^1.17.7"
|
|
32
31
|
},
|
|
33
32
|
"repository": {
|
|
34
33
|
"type": "git",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} HttpState
|
|
4
|
+
* @private
|
|
5
|
+
* @property data - the parsed response body
|
|
6
|
+
* @property response - the response from the OpenHIM server, including headers, statusCode, etc
|
|
7
|
+
* @property references - an array of all previous data objects used in the Job
|
|
8
|
+
**/
|
|
1
9
|
/**
|
|
2
10
|
* Execute a sequence of operations.
|
|
3
11
|
* Wraps `language-common/execute`, and prepends initial state for openhim.
|
|
@@ -13,11 +21,200 @@
|
|
|
13
21
|
export function execute(...operations: Operations): Operation;
|
|
14
22
|
/**
|
|
15
23
|
* Create an encounter
|
|
16
|
-
* @example <caption>Create an encounter</caption
|
|
17
|
-
*
|
|
24
|
+
* @example <caption>Create an encounter</caption>
|
|
25
|
+
* createEncounter(encounterData)
|
|
18
26
|
* @function
|
|
19
27
|
* @param {object} encounterData - Payload data for the encounter
|
|
20
28
|
* @returns {Operation}
|
|
21
29
|
*/
|
|
22
|
-
export function
|
|
23
|
-
|
|
30
|
+
export function createEncounter(encounterData: object): Operation;
|
|
31
|
+
/**
|
|
32
|
+
* Get transactions query options
|
|
33
|
+
* @typedef {Object} OpenHIMGetTransactionsOptions
|
|
34
|
+
* @public
|
|
35
|
+
* @property {string} transactionId - The ID of the transaction to retrieve. If provided, only this transaction will be returned.
|
|
36
|
+
* @property {number} filterLimit - The maximum number of transactions to return. Defaults to 100.
|
|
37
|
+
* @property {number} filterPage - The page to return (used in conjunction with filterLimit).
|
|
38
|
+
* @property {object} filterRepresentation - Determines how much information for a transaction to return.
|
|
39
|
+
* @property {object} filters - Advanced filters to apply to the transactions. This is a JSON object that can include properties like `response.status` or `properties.prop`.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Make a request to OpenHIM to get transactions
|
|
43
|
+
* @example <caption>Get all transactions</caption>
|
|
44
|
+
* getTransactions()
|
|
45
|
+
* @example <caption>Get a specific transaction</caption>
|
|
46
|
+
* getTransactions({transactionId:"686f56e070b851d7a21898f5"})
|
|
47
|
+
* @example <caption>Get transactions with filters</caption>
|
|
48
|
+
* getTransactions({
|
|
49
|
+
* filterLimit: 5,
|
|
50
|
+
* filterPage: 0,
|
|
51
|
+
* filterRepresentation: 'full',
|
|
52
|
+
* filters: '{"response.status":"200"}',
|
|
53
|
+
* });
|
|
54
|
+
* @function
|
|
55
|
+
* @public
|
|
56
|
+
* @param {OpenHIMGetTransactionsOptions} options - Optional request options. See [OpenHIM Transactions docs](https://openhim.org/docs/api/transactions/read/#read-all-transactions)
|
|
57
|
+
* @returns {Operation}
|
|
58
|
+
* @state {HttpState}
|
|
59
|
+
*/
|
|
60
|
+
export function getTransactions(options?: OpenHIMGetTransactionsOptions): Operation;
|
|
61
|
+
/**
|
|
62
|
+
* Make a request to OpenHIM to get all registered client records
|
|
63
|
+
* @example <caption>Get all clients</caption>
|
|
64
|
+
* getClients()
|
|
65
|
+
* @example <caption>Get a specific client</caption>
|
|
66
|
+
* getClients('6823172670b851d7a222075a');
|
|
67
|
+
* @function
|
|
68
|
+
* @public
|
|
69
|
+
* @param {string} clientId - Optional clientID to return a specific client.
|
|
70
|
+
* @returns {Operation}
|
|
71
|
+
* @state {HttpState}
|
|
72
|
+
*/
|
|
73
|
+
export function getClients(clientId: string): Operation;
|
|
74
|
+
/**
|
|
75
|
+
* Make a request to OpenHIM to create a new client record
|
|
76
|
+
* @example <caption>Create a client record</caption>
|
|
77
|
+
* registerClient({
|
|
78
|
+
* roles: ['fhir'],
|
|
79
|
+
* clientID: 'fhir-server-7',
|
|
80
|
+
* name: 'FHIR Server',
|
|
81
|
+
* passwordAlgorithm: 'sha512',
|
|
82
|
+
* passwordSalt: '3e74a280c568f27241e48e938edf21bf',
|
|
83
|
+
* passwordHash:
|
|
84
|
+
* '9a5158dc87a25da9d8822d48ed831a88bb4ba7fa636ddb6d6a725f73688546052cb7f2c355758e4839f9416e6cc0e37e1e3070f597af2836d39768a5ecc050db',
|
|
85
|
+
* });
|
|
86
|
+
* @function
|
|
87
|
+
* @public
|
|
88
|
+
* @param {object} body - The client data to register.
|
|
89
|
+
* @returns {Operation}
|
|
90
|
+
* @state {HttpState}
|
|
91
|
+
*/
|
|
92
|
+
export function registerClient(body: object): Operation;
|
|
93
|
+
/**
|
|
94
|
+
* Make a request to OpenHIM to update a client record
|
|
95
|
+
* @example <caption>Update a client record</caption>
|
|
96
|
+
* updateClient({
|
|
97
|
+
* _id:'6870c19870b851d7a22b8d27',
|
|
98
|
+
* roles: ['fhir', 'testing'],
|
|
99
|
+
* clientID: 'fhir-server-7',
|
|
100
|
+
* name: 'FHIR Server Testing',
|
|
101
|
+
* passwordAlgorithm: 'sha512',
|
|
102
|
+
* passwordSalt: '3e74a280c568f27241e48e938edf21bf',
|
|
103
|
+
* passwordHash:
|
|
104
|
+
* '9a5158dc87a25da9d8822d48ed831a88bb4ba7fa636ddb6d6a725f73688546052cb7f2c355758e4839f9416e6cc0e37e1e3070f597af2836d39768a5ecc050db',
|
|
105
|
+
* });
|
|
106
|
+
* @function
|
|
107
|
+
* @public
|
|
108
|
+
* @param {object} body - The client data to update.
|
|
109
|
+
* @returns {Operation}
|
|
110
|
+
* @state {HttpState}
|
|
111
|
+
*/
|
|
112
|
+
export function updateClient(body: object): Operation;
|
|
113
|
+
/**
|
|
114
|
+
* Make a request to OpenHIM to get all channel records
|
|
115
|
+
* @example <caption>Get all channels</caption>
|
|
116
|
+
* getChannels()
|
|
117
|
+
* @example <caption>Get a specific channel</caption>
|
|
118
|
+
* getChannels('67dac5fd70b851d7a26d1274');
|
|
119
|
+
* @function
|
|
120
|
+
* @public
|
|
121
|
+
* @param {string} channelId - Optional channelId to return a specific channel.
|
|
122
|
+
* @returns {Operation}
|
|
123
|
+
* @state {HttpState}
|
|
124
|
+
*/
|
|
125
|
+
export function getChannels(channelId: string): Operation;
|
|
126
|
+
/**
|
|
127
|
+
* Make a request to OpenHIM to create a new channel. See [OpenHIM Channels docs](https://openhim.org/docs/api/channels/create#create-channel)
|
|
128
|
+
* @example <caption>Create a channel</caption>
|
|
129
|
+
* createChannel({
|
|
130
|
+
* type: 'http',
|
|
131
|
+
* authType: 'public',
|
|
132
|
+
* status: 'enabled',
|
|
133
|
+
* routes: [
|
|
134
|
+
* {
|
|
135
|
+
* name: 'FHIR Server Testing',
|
|
136
|
+
* secured: false,
|
|
137
|
+
* host: 'localhost',
|
|
138
|
+
* port: '3447',
|
|
139
|
+
* primary: true,
|
|
140
|
+
* },
|
|
141
|
+
* ],
|
|
142
|
+
* requestBody: true,
|
|
143
|
+
* responseBody: true,
|
|
144
|
+
* name: 'FHIR Server Testing',
|
|
145
|
+
* urlPattern: '^/fhir/.*$',
|
|
146
|
+
* methods: [
|
|
147
|
+
* 'GET',
|
|
148
|
+
* 'POST',
|
|
149
|
+
* ],
|
|
150
|
+
* });
|
|
151
|
+
* @function
|
|
152
|
+
* @public
|
|
153
|
+
* @param {object} body - The channel data to create.
|
|
154
|
+
* @returns {Operation}
|
|
155
|
+
* @state {HttpState}
|
|
156
|
+
*/
|
|
157
|
+
export function createChannel(body: object): Operation;
|
|
158
|
+
/**
|
|
159
|
+
* Get tasks query options
|
|
160
|
+
* @typedef {Object} OpenHIMGetTasksOptions
|
|
161
|
+
* @public
|
|
162
|
+
* @property {string} taskId - The ID of the task to retrieve. If provided, only this task will be returned.
|
|
163
|
+
* @property {number} filterLimit - The maximum number of tasks to return. Defaults to 100.
|
|
164
|
+
* @property {number} filterPage - The page to return (used in conjunction with filterLimit).
|
|
165
|
+
* @property {object} filters - Advanced filters to apply to the tasks. This is a JSON object that can include properties like `response.status` or `properties.prop`.
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* Make a request to OpenHIM to get all tasks
|
|
169
|
+
* @example <caption>Get all tasks</caption>
|
|
170
|
+
* getTasks({
|
|
171
|
+
* filterLimit: 10,
|
|
172
|
+
* filterPage: 0,
|
|
173
|
+
* filters: '{}',
|
|
174
|
+
* });
|
|
175
|
+
* @example <caption>Get a specific task</caption>
|
|
176
|
+
* getTasks({
|
|
177
|
+
* taskId: '6870fbf470b851d7a22e9f05',
|
|
178
|
+
* filterLimit: 10,
|
|
179
|
+
* filterPage: 0,
|
|
180
|
+
* filters: '{}',
|
|
181
|
+
* });
|
|
182
|
+
* @function
|
|
183
|
+
* @public
|
|
184
|
+
* @param {OpenHIMGetTasksOptions} options - Required request options for each request. See [OpenHIM Tasks docs](https://openhim.org/docs/api/tasks/read/#read-all-tasks)
|
|
185
|
+
* @returns {Operation}
|
|
186
|
+
* @state {HttpState}
|
|
187
|
+
*/
|
|
188
|
+
export function getTasks(options: OpenHIMGetTasksOptions): Operation;
|
|
189
|
+
/**
|
|
190
|
+
* Make a request to OpenHIM to create a new task
|
|
191
|
+
* @example <caption>Create a task record</caption>
|
|
192
|
+
* createTask({
|
|
193
|
+
* tids: [
|
|
194
|
+
* '5bb777777bbb66cc5d4444ee',
|
|
195
|
+
* '5ceec0bb3ca344f9a30df633',
|
|
196
|
+
* '5af732d1cbf94ba88b8f0bc0',
|
|
197
|
+
* ],
|
|
198
|
+
* batchSize: 2,
|
|
199
|
+
* paused: true,
|
|
200
|
+
* });
|
|
201
|
+
* @function
|
|
202
|
+
* @public
|
|
203
|
+
* @param {object} body - The task data to create.
|
|
204
|
+
* @returns {Operation}
|
|
205
|
+
* @state {HttpState}
|
|
206
|
+
*/
|
|
207
|
+
export function createTask(body: object): Operation;
|
|
208
|
+
/**
|
|
209
|
+
* State object
|
|
210
|
+
*/
|
|
211
|
+
export type HttpState = any;
|
|
212
|
+
/**
|
|
213
|
+
* Get transactions query options
|
|
214
|
+
*/
|
|
215
|
+
export type OpenHIMGetTransactionsOptions = any;
|
|
216
|
+
/**
|
|
217
|
+
* Get tasks query options
|
|
218
|
+
*/
|
|
219
|
+
export type OpenHIMGetTasksOptions = any;
|
|
220
|
+
export { fnIf, dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue, as, map } from "@openfn/language-common";
|
package/types/Util.d.ts
ADDED
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} OpenHIMHttpState
|
|
4
|
+
* @private
|
|
5
|
+
* @property data - the parsed response body
|
|
6
|
+
* @property response - the response from the OpenHIM server, including headers, statusCode, etc
|
|
7
|
+
* @property references - an array of all previous data objects used in the Job
|
|
8
|
+
**/
|
|
9
|
+
/**
|
|
10
|
+
* Options provided to the OpenHIM request
|
|
11
|
+
* @typedef {Object} RequestOptions
|
|
12
|
+
* @public
|
|
13
|
+
* @property {object|string} body - body data to append to the request. JSON will be converted to a string.
|
|
14
|
+
* @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors for this code.
|
|
15
|
+
* @property {object} query - An object of query parameters to be encoded into the URL.
|
|
16
|
+
* @property {object} headers - An object of headers to append to the request.
|
|
17
|
+
* @property {string} parseAs - The format to parse the response body as. Defaults to `json`. Accepted values: `json`, `stream`, and `text`.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Make a GET request to OpenHIM
|
|
21
|
+
* @example <caption>Get all transactions</caption>
|
|
22
|
+
* http.get('/transactions')
|
|
23
|
+
* @function
|
|
24
|
+
* @public
|
|
25
|
+
* @param {string} path - Path to resource
|
|
26
|
+
* @param {RequestOptions} options - Optional request options
|
|
27
|
+
* @returns {Operation}
|
|
28
|
+
* @state {OpenHIMHttpState}
|
|
29
|
+
*/
|
|
30
|
+
export function get(path: string, options: RequestOptions): Operation;
|
|
31
|
+
/**
|
|
32
|
+
* Make a POST request to OpenHIM
|
|
33
|
+
* @example <caption>Create a client </caption>
|
|
34
|
+
* http.post(
|
|
35
|
+
'/clients',
|
|
36
|
+
{
|
|
37
|
+
roles: ['fhir'],
|
|
38
|
+
clientID: 'fhir-server-5',
|
|
39
|
+
name: 'FHIR Server',
|
|
40
|
+
passwordAlgorithm: 'sha512',
|
|
41
|
+
passwordSalt: '3e74a280c568f27241e48e938edf21bf',
|
|
42
|
+
passwordHash:
|
|
43
|
+
'9a5158dc87a25da9d8822d48ed831a88bb4ba7fa636ddb6d6a725f73688546052cb7f2c355758e4839f9416e6cc0e37e1e3070f597af2836d39768a5ecc050db',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
parseAs: 'text',
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
* @function
|
|
50
|
+
* @public
|
|
51
|
+
* @param {string} path - Path to resource
|
|
52
|
+
* @param {object} body - Object which will be attached to the POST body
|
|
53
|
+
* @param {RequestOptions} options - Optional request options
|
|
54
|
+
* @returns {Operation}
|
|
55
|
+
* @state {OpenHIMHttpState}
|
|
56
|
+
*/
|
|
57
|
+
export function post(path: string, body: object, options: RequestOptions): Operation;
|
|
58
|
+
/**
|
|
59
|
+
* Make a PUT request to OpenHIM
|
|
60
|
+
* @example <caption>Update an existing client</caption>
|
|
61
|
+
* http.put(
|
|
62
|
+
'/clients/686fb79470b851d7a21dad76',
|
|
63
|
+
{
|
|
64
|
+
_id: '686fb79470b851d7a21dad76',
|
|
65
|
+
roles: ['fhir', 'testing'],
|
|
66
|
+
clientID: 'fhir-server-5',
|
|
67
|
+
name: 'FHIR Server',
|
|
68
|
+
passwordAlgorithm: 'sha512',
|
|
69
|
+
passwordSalt: '3e74a280c568f27241e48e938edf21bf',
|
|
70
|
+
passwordHash:
|
|
71
|
+
'9a5158dc87a25da9d8822d48ed831a88bb4ba7fa636ddb6d6a725f73688546052cb7f2c355758e4839f9416e6cc0e37e1e3070f597af2836d39768a5ecc050db',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
parseAs: 'text',
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
* @function
|
|
78
|
+
* @public
|
|
79
|
+
* @param {string} path - Path to resource with the id of the resource to update
|
|
80
|
+
* @param {object} body - Object which will be attached to the PUT body
|
|
81
|
+
* @param {RequestOptions} options - Optional request options
|
|
82
|
+
* @returns {Operation}
|
|
83
|
+
* @state {OpenHIMHttpState}
|
|
84
|
+
*/
|
|
85
|
+
export function put(path: string, body: object, options: RequestOptions): Operation;
|
|
86
|
+
/**
|
|
87
|
+
* Make a DELETE request to OpenHIM
|
|
88
|
+
* @example <caption>Delete an existing client</caption>
|
|
89
|
+
* http.delete('/clients/686fb65870b851d7a21d9ca0', {
|
|
90
|
+
parseAs: 'text',
|
|
91
|
+
});
|
|
92
|
+
* @function
|
|
93
|
+
* @alias delete
|
|
94
|
+
* @public
|
|
95
|
+
* @param {string} path - Path to resource with the id of the resource to delete
|
|
96
|
+
* @param {RequestOptions} options - Optional request options
|
|
97
|
+
* @returns {Operation}
|
|
98
|
+
* @state {OpenHIMHttpState}
|
|
99
|
+
*/
|
|
100
|
+
export function _delete(path: string, options: RequestOptions): Operation;
|
|
101
|
+
/**
|
|
102
|
+
* Make a general HTTP request to OpenHIM
|
|
103
|
+
* @example <caption>Create a client</caption>
|
|
104
|
+
* http.request(
|
|
105
|
+
'POST',
|
|
106
|
+
'/clients',
|
|
107
|
+
{
|
|
108
|
+
roles: ['fhir'],
|
|
109
|
+
clientID: 'fhir-server-2',
|
|
110
|
+
name: 'FHIR Server',
|
|
111
|
+
passwordAlgorithm: 'sha512',
|
|
112
|
+
passwordSalt: '3e74a280c568f27241e48e938edf21bf',
|
|
113
|
+
passwordHash:
|
|
114
|
+
'9a5158dc87a25da9d8822d48ed831a88bb4ba7fa636ddb6d6a725f73688546052cb7f2c355758e4839f9416e6cc0e37e1e3070f597af2836d39768a5ecc050db',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
parseAs: 'text',
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
* @example <caption>Get all transactions</caption>
|
|
121
|
+
* http.request('GET','/transactions')
|
|
122
|
+
* @function
|
|
123
|
+
* @public
|
|
124
|
+
* @param {string} method - HTTP method to use
|
|
125
|
+
* @param {string} path - Path to resource
|
|
126
|
+
* @param {object} body - Object which will be attached to the POST body
|
|
127
|
+
* @param {RequestOptions} options - Optional request options
|
|
128
|
+
* @returns {Operation}
|
|
129
|
+
* @state {OpenHIMHttpState}
|
|
130
|
+
*/
|
|
131
|
+
export function request(method: string, path: string, body: object, options?: RequestOptions): Operation;
|
|
132
|
+
/**
|
|
133
|
+
* State object
|
|
134
|
+
*/
|
|
135
|
+
export type OpenHIMHttpState = any;
|
|
136
|
+
/**
|
|
137
|
+
* Options provided to the OpenHIM request
|
|
138
|
+
*/
|
|
139
|
+
export type RequestOptions = any;
|
package/types/index.d.ts
CHANGED