@openfn/language-googlehealthcare 0.0.1

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.
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$comment": "OAuth2",
4
+ "type": "object",
5
+ "properties": {
6
+ "access_token": {
7
+ "title": "Access Token",
8
+ "type": "string",
9
+ "description": "Your Google Cloud Healthcare access token",
10
+ "writeOnly": true,
11
+ "minLength": 1,
12
+ "examples": [
13
+ "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjlGWERwYmZNRlQyU3ZRdVhoODQ2WVR3RUlCdyIsI"
14
+ ]
15
+ },
16
+ "apiVersion": {
17
+ "title": "API Version",
18
+ "type": "string",
19
+ "description": "The API version",
20
+ "default": "v1",
21
+ "examples": ["v1", "v1beta1"]
22
+ },
23
+ "cloudRegion": {
24
+ "type": "string",
25
+ "examples": ["us-central1"]
26
+ },
27
+ "projectId": {
28
+ "type": "string",
29
+ "examples": ["adjective-noun-123"]
30
+ },
31
+ "datasetId": {
32
+ "type": "string",
33
+ "examples": ["my-dataset"]
34
+ },
35
+ "fhirStoreId": {
36
+ "type": "string",
37
+ "examples": ["my-fhir-store"]
38
+ }
39
+ },
40
+ "required": [
41
+ "cloudRegion",
42
+ "projectId",
43
+ "datasetId",
44
+ "fhirStoreId",
45
+ "access_token"
46
+ ]
47
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,193 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.js
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ createFhirResource: () => createFhirResource,
23
+ dataPath: () => import_language_common2.dataPath,
24
+ dataValue: () => import_language_common2.dataValue,
25
+ dateFns: () => import_language_common2.dateFns,
26
+ default: () => src_default,
27
+ each: () => import_language_common2.each,
28
+ execute: () => execute,
29
+ field: () => import_language_common2.field,
30
+ fields: () => import_language_common2.fields,
31
+ fn: () => import_language_common2.fn,
32
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
33
+ merge: () => import_language_common2.merge,
34
+ request: () => request,
35
+ sourceValue: () => import_language_common2.sourceValue
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // src/Adaptor.js
40
+ var Adaptor_exports = {};
41
+ __export(Adaptor_exports, {
42
+ createFhirResource: () => createFhirResource,
43
+ dataPath: () => import_language_common2.dataPath,
44
+ dataValue: () => import_language_common2.dataValue,
45
+ dateFns: () => import_language_common2.dateFns,
46
+ each: () => import_language_common2.each,
47
+ execute: () => execute,
48
+ field: () => import_language_common2.field,
49
+ fields: () => import_language_common2.fields,
50
+ fn: () => import_language_common2.fn,
51
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
52
+ merge: () => import_language_common2.merge,
53
+ request: () => request,
54
+ sourceValue: () => import_language_common2.sourceValue
55
+ });
56
+ var import_language_common = require("@openfn/language-common");
57
+ var import_util = require("@openfn/language-common/util");
58
+
59
+ // src/Utils.js
60
+ function buildUrl({
61
+ apiVersion,
62
+ projectId,
63
+ cloudRegion,
64
+ datasetId,
65
+ fhirStoreId,
66
+ resourceType
67
+ }) {
68
+ const setApiVersion = apiVersion ? apiVersion : "v1";
69
+ const baseUrl = `https://healthcare.googleapis.com/${setApiVersion}`;
70
+ return `${baseUrl}/projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}`;
71
+ }
72
+ var request = async (url, params = {}, method = "GET") => {
73
+ const { auth } = params;
74
+ delete params.auth;
75
+ const options = {
76
+ method,
77
+ body: JSON.stringify(params),
78
+ headers: {
79
+ "Content-Type": "application/fhir+json",
80
+ Authorization: `Bearer ${auth.accessToken}`
81
+ }
82
+ };
83
+ if (method == "GET")
84
+ delete options.body;
85
+ const resolvedUrl = method == "GET" ? `${url}?${new URLSearchParams(params).toString()}` : url;
86
+ const response = await fetch(resolvedUrl, options);
87
+ const data = await response.json();
88
+ handleResponseError(response, data, method);
89
+ return data;
90
+ };
91
+ function handleResponseError(response, data, method) {
92
+ const { status, statusText, url } = response;
93
+ if (isEmpty(data)) {
94
+ const responseString = [
95
+ `Message: 0 results returned`,
96
+ `Request: ${method} ${url}`,
97
+ `Status: ${status}`
98
+ ].join("\n \u221F ");
99
+ console.log(`Info at ${new Date()}
100
+ ${responseString}`);
101
+ }
102
+ if (!response.ok) {
103
+ const errorString = [
104
+ `Message: ${statusText}`,
105
+ `Request: ${method} ${url}`,
106
+ `Status: ${status}`,
107
+ `Body: ${JSON.stringify(data, null, 2).replace(/\n/g, "\n ")}`
108
+ ].join("\n \u221F ");
109
+ throw new Error(errorString);
110
+ }
111
+ }
112
+ function isEmpty(obj) {
113
+ if (Array.isArray(obj)) {
114
+ return obj.length === 0;
115
+ }
116
+ if (typeof obj === "object" && obj !== null) {
117
+ return Object.keys(obj).length === 0;
118
+ }
119
+ return false;
120
+ }
121
+
122
+ // src/Adaptor.js
123
+ var import_language_common2 = require("@openfn/language-common");
124
+ function execute(...operations) {
125
+ const initialState = {
126
+ references: [],
127
+ data: null
128
+ };
129
+ return (state) => {
130
+ return (0, import_language_common.execute)(...operations)({
131
+ ...initialState,
132
+ ...state,
133
+ configuration: (0, import_util.normalizeOauthConfig)(state.configuration)
134
+ });
135
+ };
136
+ }
137
+ function createFhirResource(resource, callback) {
138
+ return async (state) => {
139
+ const {
140
+ cloudRegion,
141
+ projectId,
142
+ datasetId,
143
+ fhirStoreId,
144
+ apiVersion,
145
+ accessToken
146
+ } = state.configuration;
147
+ const [resolvedResource] = (0, import_util.expandReferences)(state, resource);
148
+ const { resourceType } = resolvedResource;
149
+ const url = buildUrl({
150
+ apiVersion,
151
+ projectId,
152
+ cloudRegion,
153
+ datasetId,
154
+ fhirStoreId,
155
+ resourceType
156
+ });
157
+ const payload = {
158
+ auth: { accessToken },
159
+ ...resolvedResource
160
+ };
161
+ return request(url, payload, "POST").then((response) => {
162
+ console.log(
163
+ `Created FHIR ${resourceType} resource with ID ${response.id}`
164
+ );
165
+ const nextState = {
166
+ ...(0, import_language_common.composeNextState)(state, response),
167
+ response
168
+ };
169
+ if (callback)
170
+ return callback(nextState);
171
+ return nextState;
172
+ });
173
+ };
174
+ }
175
+
176
+ // src/index.js
177
+ var src_default = Adaptor_exports;
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ createFhirResource,
181
+ dataPath,
182
+ dataValue,
183
+ dateFns,
184
+ each,
185
+ execute,
186
+ field,
187
+ fields,
188
+ fn,
189
+ lastReferenceValue,
190
+ merge,
191
+ request,
192
+ sourceValue
193
+ });
package/dist/index.js ADDED
@@ -0,0 +1,178 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Adaptor.js
8
+ var Adaptor_exports = {};
9
+ __export(Adaptor_exports, {
10
+ createFhirResource: () => createFhirResource,
11
+ dataPath: () => dataPath,
12
+ dataValue: () => dataValue,
13
+ dateFns: () => dateFns,
14
+ each: () => each,
15
+ execute: () => execute,
16
+ field: () => field,
17
+ fields: () => fields,
18
+ fn: () => fn,
19
+ lastReferenceValue: () => lastReferenceValue,
20
+ merge: () => merge,
21
+ request: () => request,
22
+ sourceValue: () => sourceValue
23
+ });
24
+ import {
25
+ execute as commonExecute,
26
+ composeNextState
27
+ } from "@openfn/language-common";
28
+ import {
29
+ expandReferences,
30
+ normalizeOauthConfig
31
+ } from "@openfn/language-common/util";
32
+
33
+ // src/Utils.js
34
+ function buildUrl({
35
+ apiVersion,
36
+ projectId,
37
+ cloudRegion,
38
+ datasetId,
39
+ fhirStoreId,
40
+ resourceType
41
+ }) {
42
+ const setApiVersion = apiVersion ? apiVersion : "v1";
43
+ const baseUrl = `https://healthcare.googleapis.com/${setApiVersion}`;
44
+ return `${baseUrl}/projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}`;
45
+ }
46
+ var request = async (url, params = {}, method = "GET") => {
47
+ const { auth } = params;
48
+ delete params.auth;
49
+ const options = {
50
+ method,
51
+ body: JSON.stringify(params),
52
+ headers: {
53
+ "Content-Type": "application/fhir+json",
54
+ Authorization: `Bearer ${auth.accessToken}`
55
+ }
56
+ };
57
+ if (method == "GET")
58
+ delete options.body;
59
+ const resolvedUrl = method == "GET" ? `${url}?${new URLSearchParams(params).toString()}` : url;
60
+ const response = await fetch(resolvedUrl, options);
61
+ const data = await response.json();
62
+ handleResponseError(response, data, method);
63
+ return data;
64
+ };
65
+ function handleResponseError(response, data, method) {
66
+ const { status, statusText, url } = response;
67
+ if (isEmpty(data)) {
68
+ const responseString = [
69
+ `Message: 0 results returned`,
70
+ `Request: ${method} ${url}`,
71
+ `Status: ${status}`
72
+ ].join("\n \u221F ");
73
+ console.log(`Info at ${new Date()}
74
+ ${responseString}`);
75
+ }
76
+ if (!response.ok) {
77
+ const errorString = [
78
+ `Message: ${statusText}`,
79
+ `Request: ${method} ${url}`,
80
+ `Status: ${status}`,
81
+ `Body: ${JSON.stringify(data, null, 2).replace(/\n/g, "\n ")}`
82
+ ].join("\n \u221F ");
83
+ throw new Error(errorString);
84
+ }
85
+ }
86
+ function isEmpty(obj) {
87
+ if (Array.isArray(obj)) {
88
+ return obj.length === 0;
89
+ }
90
+ if (typeof obj === "object" && obj !== null) {
91
+ return Object.keys(obj).length === 0;
92
+ }
93
+ return false;
94
+ }
95
+
96
+ // src/Adaptor.js
97
+ import {
98
+ dataPath,
99
+ dataValue,
100
+ dateFns,
101
+ each,
102
+ field,
103
+ fields,
104
+ fn,
105
+ lastReferenceValue,
106
+ merge,
107
+ sourceValue
108
+ } from "@openfn/language-common";
109
+ function execute(...operations) {
110
+ const initialState = {
111
+ references: [],
112
+ data: null
113
+ };
114
+ return (state) => {
115
+ return commonExecute(...operations)({
116
+ ...initialState,
117
+ ...state,
118
+ configuration: normalizeOauthConfig(state.configuration)
119
+ });
120
+ };
121
+ }
122
+ function createFhirResource(resource, callback) {
123
+ return async (state) => {
124
+ const {
125
+ cloudRegion,
126
+ projectId,
127
+ datasetId,
128
+ fhirStoreId,
129
+ apiVersion,
130
+ accessToken
131
+ } = state.configuration;
132
+ const [resolvedResource] = expandReferences(state, resource);
133
+ const { resourceType } = resolvedResource;
134
+ const url = buildUrl({
135
+ apiVersion,
136
+ projectId,
137
+ cloudRegion,
138
+ datasetId,
139
+ fhirStoreId,
140
+ resourceType
141
+ });
142
+ const payload = {
143
+ auth: { accessToken },
144
+ ...resolvedResource
145
+ };
146
+ return request(url, payload, "POST").then((response) => {
147
+ console.log(
148
+ `Created FHIR ${resourceType} resource with ID ${response.id}`
149
+ );
150
+ const nextState = {
151
+ ...composeNextState(state, response),
152
+ response
153
+ };
154
+ if (callback)
155
+ return callback(nextState);
156
+ return nextState;
157
+ });
158
+ };
159
+ }
160
+
161
+ // src/index.js
162
+ var src_default = Adaptor_exports;
163
+ export {
164
+ createFhirResource,
165
+ dataPath,
166
+ dataValue,
167
+ dateFns,
168
+ src_default as default,
169
+ each,
170
+ execute,
171
+ field,
172
+ fields,
173
+ fn,
174
+ lastReferenceValue,
175
+ merge,
176
+ request,
177
+ sourceValue
178
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@openfn/language-googlehealthcare",
3
+ "version": "0.0.1",
4
+ "description": "A Google Health Care language package for use with Open Function",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "author": "Open Function Group",
14
+ "license": "LGPLv3",
15
+ "files": [
16
+ "dist/",
17
+ "types/",
18
+ "ast.json",
19
+ "configuration-schema.json"
20
+ ],
21
+ "dependencies": {
22
+ "@openfn/language-common": "^1.8.1"
23
+ },
24
+ "devDependencies": {
25
+ "@openfn/buildtools": "^1.0.2",
26
+ "@openfn/simple-ast": "0.4.1",
27
+ "assertion-error": "2.0.0",
28
+ "chai": "4.3.6",
29
+ "deep-eql": "4.1.1",
30
+ "esno": "^0.16.3",
31
+ "mocha": "9.2.2",
32
+ "rimraf": "3.0.2",
33
+ "undici": "^5.22.1"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/openfn/adaptors.git"
38
+ },
39
+ "types": "types/index.d.ts",
40
+ "main": "dist/index.cjs",
41
+ "scripts": {
42
+ "build": "pnpm clean && build-adaptor googlehealthcare",
43
+ "test": "mocha --experimental-specifier-resolution=node --no-warnings",
44
+ "test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
45
+ "clean": "rimraf dist types docs",
46
+ "pack": "pnpm pack --pack-destination ../../dist",
47
+ "lint": "eslint src"
48
+ }
49
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Execute a sequence of operations.
3
+ * Wraps `language-common/execute` to make working with this API easier.
4
+ * @example
5
+ * execute(
6
+ * create('foo'),
7
+ * delete('bar')
8
+ * )(state)
9
+ * @private
10
+ * @param {Operations} operations - Operations to be performed.
11
+ * @returns {Operation}
12
+ */
13
+ export function execute(...operations: Operations): Operation;
14
+ /**
15
+ * Create some resource in Google Cloud Healthcare
16
+ * @public
17
+ * @example
18
+ * createFhirResource({
19
+ * name: [{ use: "official", family: "Smith", given: ["Darcy"] }],
20
+ * gender: "female",
21
+ * birthDate: "1970-01-01",
22
+ * resourceType: "Patient",
23
+ * });
24
+ * @example
25
+ * createFhirResource(state => ({
26
+ * resourceType: 'Encounter',
27
+ * status: 'finished',
28
+ * class: {
29
+ * system: 'http://hl7.org/fhir/v3/ActCode',
30
+ * code: 'IMP',
31
+ * display: 'inpatient encounter',
32
+ * },
33
+ * reasonCode: [
34
+ * {
35
+ * text: 'The patient had an abnormal heart rate. She was concerned about this.',
36
+ * },
37
+ * ],
38
+ * subject: {
39
+ * reference: `Patient/${state.data.id}`,
40
+ * },
41
+ * }));
42
+ * @function
43
+ * @param {object} resource - The data to create the new resource
44
+ * @param {function} callback - An optional callback function
45
+ * @returns {Operation}
46
+ */
47
+ export function createFhirResource(resource: object, callback: Function): Operation;
48
+ export { request } from "./Utils";
49
+ export { dataPath, dataValue, dateFns, each, field, fields, fn, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
@@ -0,0 +1,11 @@
1
+ export function buildUrl({ apiVersion, projectId, cloudRegion, datasetId, fhirStoreId, resourceType, }: {
2
+ apiVersion: any;
3
+ projectId: any;
4
+ cloudRegion: any;
5
+ datasetId: any;
6
+ fhirStoreId: any;
7
+ resourceType: any;
8
+ }): string;
9
+ export function handleResponseError(response: any, data: any, method: any): void;
10
+ export function isEmpty(obj: any): boolean;
11
+ export function request(url: any, params?: {}, method?: string): Promise<any>;
@@ -0,0 +1,3 @@
1
+ export default Adaptor;
2
+ export * from "./Adaptor";
3
+ import * as Adaptor from "./Adaptor";