diff --git a/healthcare/datasets/createDataset.js b/healthcare/datasets/createDataset.js index 23d9be586f..9351e1028c 100644 --- a/healthcare/datasets/createDataset.js +++ b/healthcare/datasets/createDataset.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/deidentifyDataset.js b/healthcare/datasets/deidentifyDataset.js index 573a6b203c..957954581b 100644 --- a/healthcare/datasets/deidentifyDataset.js +++ b/healthcare/datasets/deidentifyDataset.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/deleteDataset.js b/healthcare/datasets/deleteDataset.js index 411d456afe..4106596dd4 100644 --- a/healthcare/datasets/deleteDataset.js +++ b/healthcare/datasets/deleteDataset.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/getDataset.js b/healthcare/datasets/getDataset.js index 5ed268e42f..792f60f9b2 100644 --- a/healthcare/datasets/getDataset.js +++ b/healthcare/datasets/getDataset.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/listDatasets.js b/healthcare/datasets/listDatasets.js index c4b8d7ae4f..796cc572ba 100644 --- a/healthcare/datasets/listDatasets.js +++ b/healthcare/datasets/listDatasets.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/patchDataset.js b/healthcare/datasets/patchDataset.js index cdb6aec666..3477c7c2b3 100644 --- a/healthcare/datasets/patchDataset.js +++ b/healthcare/datasets/patchDataset.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable no-warning-comments */ + 'use strict'; function main( diff --git a/healthcare/datasets/system-test/datasets.test.js b/healthcare/datasets/system-test/datasets.test.js index 6f81d4e41b..fa03eb2023 100644 --- a/healthcare/datasets/system-test/datasets.test.js +++ b/healthcare/datasets/system-test/datasets.test.js @@ -21,10 +21,10 @@ const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); const cwd = path.join(__dirname, '..'); +const projectId = process.env.GCLOUD_PROJECT; const datasetId = `dataset-${uuid.v4()}`.replace(/-/gi, '_'); const destinationDatasetId = `destination-${uuid.v4()}`.replace(/-/gi, '_'); const keeplistTags = 'PatientID'; -const projectId = process.env.GCLOUD_PROJECT; const cloudRegion = 'us-central1'; before(tools.checkCredentials); @@ -51,7 +51,7 @@ it('should get a dataset', async () => { `node getDataset.js ${projectId} ${cloudRegion} ${datasetId}`, cwd ); - assert.strictEqual(new RegExp(/name/).test(output), true); + assert.ok(output.includes('name')); }); it('should patch a dataset', async () => { @@ -71,7 +71,7 @@ it('should list datasets', async () => { `node listDatasets.js ${projectId} ${cloudRegion}`, cwd ); - assert.strictEqual(new RegExp(/datasets/).test(output), true); + assert.ok(output.includes('datasets')); }); it('should de-identify data in a dataset and write to a new dataset', async () => { diff --git a/healthcare/dicom/dicom_stores.js b/healthcare/dicom/dicom_stores.js index 724b8f14ce..26059a7796 100644 --- a/healthcare/dicom/dicom_stores.js +++ b/healthcare/dicom/dicom_stores.js @@ -18,15 +18,15 @@ const {google} = require('googleapis'); // [START healthcare_create_dicom_store] -function createDicomStore( +const createDicomStore = async ( client, projectId, cloudRegion, datasetId, dicomStoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -35,27 +35,25 @@ function createDicomStore( const request = {parent: parentName, dicomStoreId: dicomStoreId}; - client.projects.locations.datasets.dicomStores - .create(request) - .then(() => { - console.log(`Created DICOM store: ${dicomStoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.dicomStores.create(request); + console.log(`Created DICOM store: ${dicomStoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_create_dicom_store] // [START healthcare_delete_dicom_store] -function deleteDicomStore( +const deleteDicomStore = async ( client, projectId, cloudRegion, datasetId, dicomStoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -64,27 +62,25 @@ function deleteDicomStore( const request = {name: dicomStoreName}; - client.projects.locations.datasets.dicomStores - .delete(request) - .then(() => { - console.log(`Deleted DICOM store: ${dicomStoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.dicomStores.delete(request); + console.log(`Deleted DICOM store: ${dicomStoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_delete_dicom_store] // [START healthcare_get_dicom_store] -function getDicomStore( +const getDicomStore = async ( client, projectId, cloudRegion, datasetId, dicomStoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -93,21 +89,21 @@ function getDicomStore( const request = {name: dicomStoreName}; - client.projects.locations.datasets.dicomStores - .get(request) - .then(results => { - console.log('Got DICOM store:\n', results['data']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.dicomStores.get( + request + ); + console.log('Got DICOM store:\n', results['data']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_dicom_store] // [START healthcare_list_dicom_stores] -function listDicomStores(client, projectId, cloudRegion, datasetId) { +const listDicomStores = async (client, projectId, cloudRegion, datasetId) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -115,28 +111,28 @@ function listDicomStores(client, projectId, cloudRegion, datasetId) { const request = {parent: parentName}; - client.projects.locations.datasets.dicomStores - .list(request) - .then(results => { - console.log('DICOM stores:\n', results['data']['dicomStores']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.dicomStores.list( + request + ); + console.log('DICOM stores:\n', results['data']['dicomStores']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_list_dicom_stores] // [START healthcare_patch_dicom_store] -function patchDicomStore( +const patchDicomStore = async ( client, projectId, cloudRegion, datasetId, dicomStoreId, pubsubTopic -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -154,31 +150,31 @@ function patchDicomStore( }, }; - client.projects.locations.datasets.dicomStores - .patch(request) - .then(results => { - console.log( - 'Patched DICOM store with Cloud Pub/Sub topic', - results['data']['notificationConfig']['pubsubTopic'] - ); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.dicomStores.patch( + request + ); + console.log( + 'Patched DICOM store with Cloud Pub/Sub topic', + results['data']['notificationConfig']['pubsubTopic'] + ); + } catch (err) { + console.error(err); + } +}; // [END healthcare_patch_dicom_store] // [START healthcare_import_dicom_object] -function importDicomObject( +const importDicomObject = async ( client, projectId, cloudRegion, datasetId, dicomStoreId, gcsUri -) { +) => { // Token retrieved in callback - // getToken(serviceAccountJson, function(cb) {...}); + // getToken(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -190,33 +186,31 @@ function importDicomObject( name: dicomStoreName, resource: { gcsSource: { - gcsUri: `gs://${gcsUri}`, + uri: `gs://${gcsUri}`, }, }, }; - client.projects.locations.datasets.dicomStores - .import(request) - .then(() => { - console.log(`Imported DICOM objects from bucket ${gcsUri}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.dicomStores.import(request); + console.log(`Imported DICOM objects from bucket ${gcsUri}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_import_dicom_object] // [START healthcare_export_dicom_instance_gcs] -function exportDicomInstanceGcs( +const exportDicomInstanceGcs = async ( client, projectId, cloudRegion, datasetId, dicomStoreId, uriPrefix -) { +) => { // Token retrieved in callback - // getToken(serviceAccountJson, function(cb) {...}); + // getToken(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -233,41 +227,35 @@ function exportDicomInstanceGcs( }, }; - client.projects.locations.datasets.dicomStores - .export(request) - .then(() => { - console.log(`Exported DICOM instances to bucket ${uriPrefix}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.dicomStores.export(request); + console.log(`Exported DICOM instances to bucket ${uriPrefix}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_export_dicom_instance_gcs] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] -function getClient(apiKey, serviceAccountJson, cb) { +const getClient = async apiKey => { const API_VERSION = 'v1alpha2'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; - google.auth - .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) - .then(authClient => { - const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + const authClient = await google.auth.getClient({ + scopes: ['https://www.googleapis.com/auth/cloud-platform'], + }); + const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; - google.options({auth: authClient}); + google.options({auth: authClient}); - google - .discoverAPI(discoveryUrl) - .then(client => { - cb(client); - }) - .catch(err => { - console.error(err); - }); - }); -} + try { + return google.discoverAPI(discoveryUrl); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_client] require(`yargs`) // eslint-disable-line @@ -306,121 +294,107 @@ require(`yargs`) // eslint-disable-line `createDicomStore `, `Creates a new DICOM store within the parent dataset.`, {}, - opts => { - const cb = function(client) { - createDicomStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await createDicomStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId + ); } ) .command( `deleteDicomStore `, `Deletes the DICOM store and removes all resources that are contained within it.`, {}, - opts => { - const cb = function(client) { - deleteDicomStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await deleteDicomStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId + ); } ) .command( `getDicomStore `, `Gets the specified DICOM store or returns NOT_FOUND if it doesn't exist.`, {}, - opts => { - const cb = function(client) { - getDicomStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await getDicomStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId + ); } ) .command( `listDicomStores `, `Lists the DICOM stores in the given dataset.`, {}, - opts => { - const cb = function(client) { - listDicomStores( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await listDicomStores( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId + ); } ) .command( `patchDicomStore `, `Updates the DICOM store.`, {}, - opts => { - const cb = function(client) { - patchDicomStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId, - opts.pubsubTopic - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await patchDicomStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId, + opts.pubsubTopic + ); } ) .command( `importDicomObject `, `Imports data into the DICOM store by copying it from the specified source.`, {}, - opts => { - const cb = function(client) { - importDicomObject( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId, - opts.gcsUri - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await importDicomObject( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId, + opts.gcsUri + ); } ) .command( `exportDicomInstanceGcs `, `Exports data to a Cloud Storage bucket by copying it from the DICOM store.`, {}, - opts => { - const cb = function(client) { - exportDicomInstanceGcs( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.dicomStoreId, - opts.uriPrefix - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await exportDicomInstanceGcs( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.dicomStoreId, + opts.uriPrefix + ); } ) .wrap(120) diff --git a/healthcare/dicom/dicomweb.js b/healthcare/dicom/dicomweb.js index 19dad75b1c..104531077f 100644 --- a/healthcare/dicom/dicomweb.js +++ b/healthcare/dicom/dicomweb.js @@ -19,7 +19,7 @@ const fs = require('fs'); const BASE_URL = 'https://healthcare.googleapis.com/v1alpha2'; -function getToken(serviceAccountJson, cb) { +const getToken = (serviceAccountJson, cb) => { const gtoken = new GoogleToken({ keyFile: `${serviceAccountJson}`, scope: ['https://www.googleapis.com/auth/cloud-platform'], // or space-delimited string of scopes @@ -32,10 +32,10 @@ function getToken(serviceAccountJson, cb) { } cb(token); }); -} +}; // [START healthcare_dicomweb_store_instance] -function dicomWebStoreInstance( +const dicomWebStoreInstance = async ( token, projectId, cloudRegion, @@ -43,7 +43,7 @@ function dicomWebStoreInstance( dicomStoreId, dcmFile, boundary -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -68,25 +68,24 @@ function dicomWebStoreInstance( method: 'POST', }; - request(options) - .then(results => { - console.log('Stored instance:\n'); - console.log(results); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log('Stored instance:\n'); + console.log(results); + } catch (err) { + console.error(err); + } +}; // [END healthcare_dicomweb_store_instance] // [START healthcare_dicomweb_search_instances] -function dicomWebSearchInstances( +const dicomWebSearchInstances = async ( token, projectId, cloudRegion, datasetId, dicomStoreId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -106,26 +105,25 @@ function dicomWebSearchInstances( method: 'GET', }; - request(options) - .then(results => { - console.log('Instances:\n'); - console.log(results); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log('Instances:\n'); + console.log(results); + } catch (err) { + console.error(err); + } +}; // [END healthcare_dicomweb_search_instances] // [START healthcare_dicomweb_retrieve_study] -function dicomWebRetrieveStudy( +const dicomWebRetrieveStudy = async ( token, projectId, cloudRegion, datasetId, dicomStoreId, studyUid -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -146,25 +144,24 @@ function dicomWebRetrieveStudy( method: 'GET', }; - request(options) - .then(() => { - console.log(`Retrieved study with UID: ${studyUid}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await request(options); + console.log(`Retrieved study with UID: ${studyUid}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_dicomweb_retrieve_study] // [START healthcare_dicomweb_delete_study] -function dicomWebDeleteStudy( +const dicomWebDeleteStudy = async ( token, projectId, cloudRegion, datasetId, dicomStoreId, studyUid -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -185,14 +182,13 @@ function dicomWebDeleteStudy( method: 'DELETE', }; - request(options) - .then(() => { - console.log('Deleted study.'); - }) - .catch(err => { - console.error(err); - }); -} + try { + await request(options); + console.log('Deleted study.'); + } catch (err) { + console.error(err); + } +}; // [END healthcare_dicomweb_delete_study] require(`yargs`) // eslint-disable-line diff --git a/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE-edited.dcm b/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE-edited.dcm new file mode 100644 index 0000000000..1ce38558fd Binary files /dev/null and b/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE-edited.dcm differ diff --git a/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE.dcm b/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE.dcm new file mode 100644 index 0000000000..3e0064f21b Binary files /dev/null and b/healthcare/dicom/resources/IM-0002-0001-JPEG-BASELINE.dcm differ diff --git a/healthcare/dicom/system-test/dicom_stores.test.js b/healthcare/dicom/system-test/dicom_stores.test.js index d77808d256..617cec5c89 100644 --- a/healthcare/dicom/system-test/dicom_stores.test.js +++ b/healthcare/dicom/system-test/dicom_stores.test.js @@ -20,35 +20,36 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); -const cmdDataset = 'node datasets.js'; +const projectId = process.env.GCLOUD_PROJECT; +const bucketName = process.env.BUCKET_NAME; +const region = 'us-central1'; + const cmd = 'node dicom_stores.js'; const cwdDatasets = path.join(__dirname, '../../datasets'); const cwd = path.join(__dirname, '..'); const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_'); -const dicomStoreId = `nodejs-docs-samples-test-dicom-store${uuid.v4()}`.replace( +const dicomStoreId = `nodejs-docs-samples-test-dicom-store-${uuid.v4()}`.replace( /-/gi, '_' ); -const pubsubTopic = `nodejs-docs-samples-test-pubsub${uuid.v4()}`.replace( +const pubsubTopic = `nodejs-docs-samples-test-pubsub-${uuid.v4()}`.replace( /-/gi, '_' ); -const bucketName = process.env.GCLOUD_STORAGE_BUCKET; - const dcmFileName = `IM-0002-0001-JPEG-BASELINE.dcm`; -const gcsUri = bucketName + '/' + dcmFileName; +const gcsUri = `${bucketName}/${dcmFileName}`; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); }); after(async () => { try { - await tools.runAsync( - `${cmdDataset} deleteDataset ${datasetId}`, - cwdDatasets - ); + await tools.runAsync(`node deleteDataset.js ${datasetId}`, cwdDatasets); } catch (err) {} // Ignore error }); @@ -57,7 +58,7 @@ it('should create a DICOM store', async () => { `${cmd} createDicomStore ${datasetId} ${dicomStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Created DICOM store/).test(output), true); + assert.ok(output.includes('Created DICOM store')); }); it('should get a DICOM store', async () => { @@ -65,7 +66,7 @@ it('should get a DICOM store', async () => { `${cmd} getDicomStore ${datasetId} ${dicomStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Got DICOM store/).test(output), true); + assert.ok(output.includes('Got DICOM store')); }); it('should patch a DICOM store', async () => { @@ -73,10 +74,7 @@ it('should patch a DICOM store', async () => { `${cmd} patchDicomStore ${datasetId} ${dicomStoreId} ${pubsubTopic}`, cwd ); - assert.strictEqual( - new RegExp(/Patched DICOM store with Cloud Pub\/Sub topic/).test(output), - true - ); + assert.ok(output.includes('Patched DICOM store with Cloud Pub/Sub topic')); }); it('should list DICOM stores', async () => { @@ -84,7 +82,7 @@ it('should list DICOM stores', async () => { `${cmd} listDicomStores ${datasetId}`, cwd ); - assert.strictEqual(new RegExp(/DICOM stores/).test(output), true); + assert.ok(output.includes('DICOM stores')); }); it('should export a DICOM instance', async () => { @@ -92,10 +90,7 @@ it('should export a DICOM instance', async () => { `${cmd} exportDicomInstanceGcs ${datasetId} ${dicomStoreId} ${bucketName}`, cwd ); - assert.strictEqual( - new RegExp(/Exported DICOM instances to bucket/).test(output), - true - ); + assert.ok(output.includes('Exported DICOM instances to bucket')); }); it('should import a DICOM object from GCS', async () => { @@ -103,10 +98,7 @@ it('should import a DICOM object from GCS', async () => { `${cmd} importDicomObject ${datasetId} ${dicomStoreId} ${gcsUri}`, cwd ); - assert.strictEqual( - new RegExp(/Imported DICOM objects from bucket/).test(output), - true - ); + assert.ok(output.includes('Imported DICOM objects from bucket')); }); it('should delete a DICOM store', async () => { @@ -114,5 +106,5 @@ it('should delete a DICOM store', async () => { `${cmd} deleteDicomStore ${datasetId} ${dicomStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Deleted DICOM store/).test(output), true); + assert.ok(output.includes('Deleted DICOM store')); }); diff --git a/healthcare/dicom/system-test/dicomweb.test.js b/healthcare/dicom/system-test/dicomweb.test.js index de76a5ebf9..f1d48106c5 100644 --- a/healthcare/dicom/system-test/dicomweb.test.js +++ b/healthcare/dicom/system-test/dicomweb.test.js @@ -20,13 +20,19 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); -const cmdDataset = 'node datasets.js'; -const cmdDicomStore = 'node dicom_stores.js'; +const projectId = process.env.GCLOUD_PROJECT; +const region = 'us-central1'; + const cmd = 'node dicomweb.js'; +const cmdDicomStore = 'node dicom_stores.js'; + const cwdDatasets = path.join(__dirname, '../../datasets'); const cwd = path.join(__dirname, '..'); -const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_'); -const dicomStoreId = `nodejs-docs-samples-test-dicom-store${uuid.v4()}`.replace( +const datasetId = `nodejs-docs-samples-test-dicomweb-${uuid.v4()}`.replace( + /-/gi, + '_' +); +const dicomStoreId = `nodejs-docs-samples-test-dicomweb-dicom-store${uuid.v4()}`.replace( /-/gi, '_' ); @@ -39,27 +45,31 @@ const studyUid = '1.2.840.113619.2.176.3596.3364818.7819.1259708454.105'; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); + await tools.runAsync( + `${cmdDicomStore} createDicomStore ${datasetId} ${dicomStoreId}`, + cwd + ); }); after(async () => { try { await tools.runAsync( - `${cmdDataset} deleteDataset ${datasetId}`, - cwdDatasets + `${cmdDicomStore} deleteDicomStore ${datasetId} ${dicomStoreId}`, + cwd ); + await tools.runAsync(`node deleteDataset.js ${datasetId}`, cwdDatasets); } catch (err) {} // Ignore error }); it('should store a DICOM instance', async () => { - await tools.runAsync( - `${cmdDicomStore} createDicomStore ${datasetId} ${dicomStoreId}`, - cwd - ); const output = await tools.runAsync( `${cmd} dicomWebStoreInstance ${datasetId} ${dicomStoreId} ${dcmFile} ${boundary}`, cwd ); - assert.strictEqual(new RegExp(/Stored instance/).test(output), true); + assert.ok(output.includes('Stored instance')); }); it('should search DICOM instances', async () => { @@ -67,7 +77,7 @@ it('should search DICOM instances', async () => { `${cmd} dicomWebSearchInstances ${datasetId} ${dicomStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Instances/).test(output), true); + assert.ok(output.includes('Instances')); }); it('should retrieve a DICOM study', async () => { @@ -75,7 +85,7 @@ it('should retrieve a DICOM study', async () => { `${cmd} dicomWebRetrieveStudy ${datasetId} ${dicomStoreId} ${studyUid}`, cwd ); - assert.strictEqual(new RegExp(/Retrieved study/).test(output), true); + assert.ok(output.includes('Retrieved study')); }); it('should delete a DICOM study', async () => { @@ -83,11 +93,5 @@ it('should delete a DICOM study', async () => { `${cmd} dicomWebDeleteStudy ${datasetId} ${dicomStoreId} ${studyUid}`, cwd ); - assert.strictEqual(new RegExp(/Deleted study/).test(output), true); - - // Clean up - await tools.runAsync( - `${cmdDicomStore} deleteDicomStore ${datasetId} ${dicomStoreId}`, - cwd - ); + assert.ok(output.includes('Deleted study')); }); diff --git a/healthcare/fhir/fhir_resources.js b/healthcare/fhir/fhir_resources.js index 134e7f1a5b..bc6632f48d 100644 --- a/healthcare/fhir/fhir_resources.js +++ b/healthcare/fhir/fhir_resources.js @@ -19,7 +19,7 @@ const request = require('request-promise'); const BASE_URL = 'https://healthcare.googleapis.com/v1alpha2'; // [START healthcare_get_token] -function getToken(serviceAccountJson, cb) { +const getToken = (serviceAccountJson, cb) => { const gtoken = new GoogleToken({ keyFile: `${serviceAccountJson}`, scope: ['https://www.googleapis.com/auth/cloud-platform'], // or space-delimited string of scopes @@ -32,18 +32,18 @@ function getToken(serviceAccountJson, cb) { } cb(token); }); -} +}; // [END healthcare_get_token] // [START healthcare_create_fhir_resource] -function createResource( +const createResource = async ( token, projectId, cloudRegion, datasetId, fhirStoreId, resourceType -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -70,18 +70,17 @@ function createResource( method: 'POST', }; - request(options) - .then(resource => { - console.log(`Created resource ${resourceType} with ID ${resource.id}.`); - }) - .catch(err => { - console.error(err); - }); -} + try { + const resource = await request(options); + console.log(`Created resource ${resourceType} with ID ${resource.id}.`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_create_fhir_resource] // [START healthcare_update_fhir_resource] -function updateResource( +const updateResource = async ( token, projectId, cloudRegion, @@ -89,7 +88,7 @@ function updateResource( fhirStoreId, resourceType, resourceId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -119,18 +118,17 @@ function updateResource( method: 'PUT', }; - request(options) - .then(() => { - console.log(`Updated ${resourceType} with ID ${resourceId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await request(options); + console.log(`Updated ${resourceType} with ID ${resourceId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_update_fhir_resource] // [START healthcare_patch_fhir_resource] -function patchResource( +const patchResource = async ( token, projectId, cloudRegion, @@ -138,7 +136,7 @@ function patchResource( fhirStoreId, resourceType, resourceId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -164,18 +162,17 @@ function patchResource( method: 'PATCH', }; - request(options) - .then(() => { - console.log(`Patched ${resourceType} with ID ${resourceId}`); - }) - .catch(err => { - console.log('ERROR:', err.message); - }); -} + try { + await request(options); + console.log(`Patched ${resourceType} with ID ${resourceId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_patch_fhir_resource] // [START healthcare_delete_fhir_resource] -function deleteResource( +const deleteResource = async ( token, projectId, cloudRegion, @@ -183,7 +180,7 @@ function deleteResource( fhirStoreId, resourceType, resourceId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -206,18 +203,17 @@ function deleteResource( method: 'DELETE', }; - request(options) - .then(() => { - console.log(`Deleted ${resourceType} with ID ${resourceId}.`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await request(options); + console.log(`Deleted ${resourceType} with ID ${resourceId}.`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_delete_fhir_resource] // [START healthcare_get_fhir_resource] -function getResource( +const getResource = async ( token, projectId, cloudRegion, @@ -225,7 +221,7 @@ function getResource( fhirStoreId, resourceType, resourceId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -247,27 +243,26 @@ function getResource( json: true, }; - request(options) - .then(results => { - console.log( - `Got ${resourceType} resource:\n${JSON.stringify(results, null, 2)}` - ); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log( + `Got ${resourceType} resource:\n${JSON.stringify(results, null, 2)}` + ); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_fhir_resource] // [START healthcare_search_fhir_resources_get] -function searchResourcesGet( +const searchResourcesGet = async ( token, projectId, cloudRegion, datasetId, fhirStoreId, resourceType -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -288,25 +283,24 @@ function searchResourcesGet( json: true, }; - request(options) - .then(results => { - console.log(JSON.stringify(results, null, 2)); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log(JSON.stringify(results, null, 2)); + } catch (err) { + console.error(err); + } +}; // [END healthcare_search_fhir_resources_get] // [START healthcare_search_fhir_resources_post] -function searchResourcesPost( +const searchResourcesPost = async ( token, projectId, cloudRegion, datasetId, fhirStoreId, resourceType -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -328,25 +322,24 @@ function searchResourcesPost( method: 'POST', }; - request(options) - .then(results => { - console.log(JSON.stringify(results, null, 2)); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log(JSON.stringify(results, null, 2)); + } catch (err) { + console.error(err); + } +}; // [END healthcare_search_fhir_resources_post] // [START healthcare_fhir_get_patient_everything] -function getPatientEverything( +const getPatientEverything = async ( token, projectId, cloudRegion, datasetId, fhirStoreId, resourceId -) { +) => { // Token retrieved in callback // getToken(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -366,15 +359,14 @@ function getPatientEverything( json: true, }; - request(options) - .then(results => { - console.log(`Got all resources in patient ${resourceId} compartment:`); - console.log(results); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await request(options); + console.log(`Got all resources in patient ${resourceId} compartment:`); + console.log(results); + } catch (err) { + console.error(err); + } +}; // [END healthcare_fhir_get_patient_everything] require(`yargs`) // eslint-disable-line @@ -407,7 +399,7 @@ require(`yargs`) // eslint-disable-line `Creates a new resource in a FHIR store.`, {}, opts => { - const cb = function(token) { + const cb = token => { createResource( token, opts.projectId, @@ -425,7 +417,7 @@ require(`yargs`) // eslint-disable-line `Updates an existing resource in a FHIR store.`, {}, opts => { - const cb = function(token) { + const cb = token => { updateResource( token, opts.projectId, @@ -444,7 +436,7 @@ require(`yargs`) // eslint-disable-line `Patches an existing resource in a FHIR store.`, {}, opts => { - const cb = function(token) { + const cb = token => { patchResource( token, opts.projectId, @@ -463,7 +455,7 @@ require(`yargs`) // eslint-disable-line `Deletes a FHIR resource or returns NOT_FOUND if it doesn't exist.`, {}, opts => { - const cb = function(token) { + const cb = token => { deleteResource( token, opts.projectId, @@ -482,7 +474,7 @@ require(`yargs`) // eslint-disable-line `Gets a FHIR resource.`, {}, opts => { - const cb = function(token) { + const cb = token => { getResource( token, opts.projectId, @@ -501,7 +493,7 @@ require(`yargs`) // eslint-disable-line `Searches resources in the given FHIR store using the searchResources GET method.`, {}, opts => { - const cb = function(token) { + const cb = token => { searchResourcesGet( token, opts.projectId, @@ -519,7 +511,7 @@ require(`yargs`) // eslint-disable-line `Searches resources in the given FHIR store using the _search POST method.`, {}, opts => { - const cb = function(token) { + const cb = token => { searchResourcesPost( token, opts.projectId, @@ -537,7 +529,7 @@ require(`yargs`) // eslint-disable-line `Gets all the resources in the patient compartment.`, {}, opts => { - const cb = function(token) { + const cb = token => { getPatientEverything( token, opts.projectId, diff --git a/healthcare/fhir/fhir_stores.js b/healthcare/fhir/fhir_stores.js index 1fca31003d..e8745559ae 100644 --- a/healthcare/fhir/fhir_stores.js +++ b/healthcare/fhir/fhir_stores.js @@ -18,15 +18,15 @@ const {google} = require('googleapis'); // [START healthcare_create_fhir_store] -function createFhirStore( +const createFhirStore = async ( client, projectId, cloudRegion, datasetId, fhirStoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -35,27 +35,25 @@ function createFhirStore( const request = {parent: parentName, fhirStoreId: fhirStoreId}; - client.projects.locations.datasets.fhirStores - .create(request) - .then(() => { - console.log(`Created FHIR store: ${fhirStoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.fhirStores.create(request); + console.log(`Created FHIR store: ${fhirStoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_create_fhir_store] // [START healthcare_delete_fhir_store] -function deleteFhirStore( +const deleteFhirStore = async ( client, projectId, cloudRegion, datasetId, fhirStoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -64,21 +62,25 @@ function deleteFhirStore( const request = {name: fhirStoreName}; - client.projects.locations.datasets.fhirStores - .delete(request) - .then(() => { - console.log(`Deleted FHIR store: ${fhirStoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.fhirStores.delete(request); + console.log(`Deleted FHIR store: ${fhirStoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_delete_fhir_store] // [START healthcare_get_fhir_store] -function getFhirStore(client, projectId, cloudRegion, datasetId, fhirStoreId) { +const getFhirStore = async ( + client, + projectId, + cloudRegion, + datasetId, + fhirStoreId +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -87,21 +89,21 @@ function getFhirStore(client, projectId, cloudRegion, datasetId, fhirStoreId) { const request = {name: fhirStoreName}; - client.projects.locations.datasets.fhirStores - .get(request) - .then(results => { - console.log('Got FHIR store:\n', results['data']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.fhirStores.get( + request + ); + console.log('Got FHIR store:\n', results['data']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_fhir_store] // [START healthcare_list_fhir_stores] -function listFhirStores(client, projectId, cloudRegion, datasetId) { +const listFhirStores = async (client, projectId, cloudRegion, datasetId) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -109,28 +111,28 @@ function listFhirStores(client, projectId, cloudRegion, datasetId) { const request = {parent: parentName}; - client.projects.locations.datasets.fhirStores - .list(request) - .then(results => { - console.log('FHIR stores:\n', results['data']['fhirStores']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.fhirStores.list( + request + ); + console.log('FHIR stores:\n', results['data']['fhirStores']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_list_fhir_stores] // [START healthcare_patch_fhir_store] -function patchFhirStore( +const patchFhirStore = async ( client, projectId, cloudRegion, datasetId, fhirStoreId, pubsubTopic -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -143,29 +145,35 @@ function patchFhirStore( updateMask: 'notificationConfig', resource: { notificationConfig: { - pubsubTopic: `projects/${projectId}/locations/${cloudRegion}/topics/${pubsubTopic}`, + pubsubTopic: `projects/${projectId}/topics/${pubsubTopic}`, }, }, }; - client.projects.locations.datasets.fhirStores - .patch(request) - .then(results => { - console.log( - 'Patched FHIR store with Cloud Pub/Sub topic', - results['data']['notificationConfig']['pubsubTopic'] - ); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.fhirStores.patch( + request + ); + console.log( + 'Patched FHIR store with Cloud Pub/Sub topic', + results['data']['notificationConfig']['pubsubTopic'] + ); + } catch (err) { + console.error(err); + } +}; // [END healthcare_patch_fhir_store] // [START healthcare_get_fhir_store_metadata] -function getMetadata(client, projectId, cloudRegion, datasetId, fhirStoreId) { +const getMetadata = async ( + client, + projectId, + cloudRegion, + datasetId, + fhirStoreId +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -174,42 +182,38 @@ function getMetadata(client, projectId, cloudRegion, datasetId, fhirStoreId) { const request = {name: fhirStoreName}; - client.projects.locations.datasets.fhirStores - .getMetadata(request) - .then(results => { - console.log(`Capabilities statement for FHIR store ${fhirStoreId}:`); - console.log(results); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.fhirStores.capabilities( + request + ); + console.log(`Capabilities statement for FHIR store ${fhirStoreId}:`); + console.log(results); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_fhir_store_metadata] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] -function getClient(apiKey, serviceAccountJson, cb) { +const getClient = async apiKey => { const API_VERSION = 'v1alpha2'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; - google.auth - .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) - .then(authClient => { - const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + try { + const authClient = await google.auth.getClient({ + scopes: ['https://www.googleapis.com/auth/cloud-platform'], + }); - google.options({auth: authClient}); + const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + google.options({auth: authClient}); - google - .discoverAPI(discoveryUrl) - .then(client => { - cb(client); - }) - .catch(err => { - console.error(err); - }); - }); -} + return google.discoverAPI(discoveryUrl); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_client] require(`yargs`) // eslint-disable-line @@ -236,114 +240,95 @@ require(`yargs`) // eslint-disable-line requiresArg: true, type: 'string', }, - serviceAccount: { - alias: 's', - default: process.env.GOOGLE_APPLICATION_CREDENTIALS, - description: 'The path to your service credentials JSON.', - requiresArg: true, - type: 'string', - }, }) .command( `createFhirStore `, `Creates a new FHIR store within the parent dataset.`, {}, - opts => { - const cb = function(client) { - createFhirStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.fhirStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await createFhirStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.fhirStoreId + ); } ) .command( `deleteFhirStore `, `Deletes the FHIR store and removes all resources that are contained within it.`, {}, - opts => { - const cb = function(client) { - deleteFhirStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.fhirStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await deleteFhirStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.fhirStoreId + ); } ) .command( `getFhirStore `, `Gets the specified FHIR store or returns NOT_FOUND if it doesn't exist.`, {}, - opts => { - const cb = function(client) { - getFhirStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.fhirStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await getFhirStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.fhirStoreId + ); } ) .command( `listFhirStores `, `Lists the FHIR stores in the given dataset.`, {}, - opts => { - const cb = function(client) { - listFhirStores( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await listFhirStores( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId + ); } ) .command( `patchFhirStore `, `Updates the FHIR store.`, {}, - opts => { - const cb = function(client) { - patchFhirStore( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.fhirStoreId, - opts.pubsubTopic - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await patchFhirStore( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.fhirStoreId, + opts.pubsubTopic + ); } ) .command( `getMetadata `, `Gets the capabilities statement for a FHIR store.`, {}, - opts => { - const cb = function(client) { - getMetadata( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.fhirStoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey); + await getMetadata( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.fhirStoreId + ); } ) .wrap(120) diff --git a/healthcare/fhir/package.json b/healthcare/fhir/package.json index 23e659e451..fdf96f2055 100644 --- a/healthcare/fhir/package.json +++ b/healthcare/fhir/package.json @@ -30,7 +30,8 @@ "build": { "requiredEnvVars": [ "API_KEY", - "GCLOUD_PROJECT" + "GCLOUD_PROJECT", + "PUBSUB_TOPIC" ] } } diff --git a/healthcare/fhir/system-test/fhir_resources.test.js b/healthcare/fhir/system-test/fhir_resources.test.js index 5808fb6a25..c573520c88 100644 --- a/healthcare/fhir/system-test/fhir_resources.test.js +++ b/healthcare/fhir/system-test/fhir_resources.test.js @@ -20,7 +20,9 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); -const cmdDataset = 'node datasets.js'; +const projectId = process.env.GCLOUD_PROJECT; +const region = 'us-central1'; + const cmdFhirStores = 'node fhir_stores.js'; const cmd = 'node fhir_resources.js'; const cwd = path.join(__dirname, '..'); @@ -35,14 +37,14 @@ let resourceId; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); }); after(async () => { try { - await tools.runAsync( - `${cmdDataset} deleteDataset ${datasetId}`, - cwdDatasets - ); + await tools.runAsync(`node deleteDataset.js ${datasetId}`, cwdDatasets); } catch (err) {} // Ignore error }); @@ -59,7 +61,7 @@ it('should create a FHIR resource', async () => { `Created resource ${resourceType} with ID (.*).` ); assert.strictEqual(createdMessage.test(output), true); - resourceId = createdMessage.exec(output)[1]; + [, resourceId] = createdMessage.exec(output); }); it('should get a FHIR resource', async () => { diff --git a/healthcare/fhir/system-test/fhir_stores.test.js b/healthcare/fhir/system-test/fhir_stores.test.js index dc63ce3aca..bbee059332 100644 --- a/healthcare/fhir/system-test/fhir_stores.test.js +++ b/healthcare/fhir/system-test/fhir_stores.test.js @@ -20,7 +20,9 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); -const cmdDataset = 'node datasets.js'; +const projectId = process.env.GCLOUD_PROJECT; +const region = 'us-central1'; + const cmd = 'node fhir_stores.js'; const cwdDatasets = path.join(__dirname, '../../datasets'); const cwd = path.join(__dirname, '..'); @@ -29,21 +31,18 @@ const fhirStoreId = `nodejs-docs-samples-test-fhir-store${uuid.v4()}`.replace( /-/gi, '_' ); -const pubsubTopic = `nodejs-docs-samples-test-pubsub${uuid.v4()}`.replace( - /-/gi, - '_' -); +const pubsubTopic = process.env.PUBSUB_TOPIC; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); }); after(async () => { try { - await tools.runAsync( - `${cmdDataset} deleteDataset ${datasetId}`, - cwdDatasets - ); + await tools.runAsync(`node deleteDataset.js ${datasetId}`, cwdDatasets); } catch (err) {} // Ignore error }); @@ -52,7 +51,7 @@ it('should create a FHIR store', async () => { `${cmd} createFhirStore ${datasetId} ${fhirStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Created FHIR store/).test(output), true); + assert.ok(output.includes('Created FHIR store')); }); it('should get a FHIR store', async () => { @@ -60,7 +59,7 @@ it('should get a FHIR store', async () => { `${cmd} getFhirStore ${datasetId} ${fhirStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Got FHIR store/).test(output), true); + assert.ok(output.includes('Got FHIR store')); }); it('should list FHIR stores', async () => { @@ -68,7 +67,7 @@ it('should list FHIR stores', async () => { `${cmd} listFhirStores ${datasetId}`, cwd ); - assert.strictEqual(new RegExp(/FHIR stores/).test(output), true); + assert.ok(output.includes('FHIR stores')); }); it('should patch a FHIR store', async () => { @@ -76,7 +75,7 @@ it('should patch a FHIR store', async () => { `${cmd} patchFhirStore ${datasetId} ${fhirStoreId} ${pubsubTopic}`, cwd ); - assert.strictEqual(new RegExp(/Patched FHIR store/).test(output), true); + assert.ok(output.includes('Patched FHIR store')); }); it('should get FHIR store metadata', async () => { @@ -84,10 +83,7 @@ it('should get FHIR store metadata', async () => { `${cmd} getMetadata ${datasetId} ${fhirStoreId}`, cwd ); - assert.strictEqual( - new RegExp(/Capabilities statement for FHIR store/).test(output), - true - ); + assert.ok(output.includes('Capabilities statement for FHIR store')); }); it('should delete a FHIR store', async () => { @@ -95,5 +91,5 @@ it('should delete a FHIR store', async () => { `${cmd} deleteFhirStore ${datasetId} ${fhirStoreId}`, cwd ); - assert.strictEqual(new RegExp(/Deleted FHIR store/).test(output), true); + assert.ok(output.includes('Deleted FHIR store')); }); diff --git a/healthcare/hl7v2/hl7v2_messages.js b/healthcare/hl7v2/hl7v2_messages.js index 9ae2ba2823..d66c85c5fc 100644 --- a/healthcare/hl7v2/hl7v2_messages.js +++ b/healthcare/hl7v2/hl7v2_messages.js @@ -19,14 +19,14 @@ const fs = require('fs'); const {google} = require('googleapis'); // [START healthcare_create_hl7v2_message] -function createHl7v2Message( +const createHl7v2Message = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId, messageFile -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -44,26 +44,26 @@ function createHl7v2Message( resource: hl7v2MessageJson, }; - client.projects.locations.datasets.hl7V2Stores.messages - .create(request) - .then(() => { - console.log(`Created HL7v2 message`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.messages.create( + request + ); + console.log(`Created HL7v2 message`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_create_hl7v2_message] // [START healthcare_ingest_hl7v2_message] -function ingestHl7v2Message( +const ingestHl7v2Message = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId, messageFile -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -81,26 +81,26 @@ function ingestHl7v2Message( resource: hl7v2MessageJson, }; - client.projects.locations.datasets.hl7V2Stores.messages - .ingest(request) - .then(() => { - console.log(`Ingested HL7v2 message`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.messages.ingest( + request + ); + console.log(`Ingested HL7v2 message`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_ingest_hl7v2_message] // [START healthcare_delete_hl7v2_message] -function deleteHl7v2Message( +const deleteHl7v2Message = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId, messageId -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -112,26 +112,26 @@ function deleteHl7v2Message( const request = {name: hl7v2Message}; - client.projects.locations.datasets.hl7V2Stores.messages - .delete(request) - .then(() => { - console.log(`Deleted HL7v2 message with ID ${messageId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.messages.delete( + request + ); + console.log(`Deleted HL7v2 message with ID ${messageId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_delete_hl7v2_message] // [START healthcare_get_hl7v2_message] -function getHl7v2Message( +const getHl7v2Message = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId, messageId -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -143,26 +143,26 @@ function getHl7v2Message( const request = {name: hl7v2Message}; - client.projects.locations.datasets.hl7V2Stores.messages - .get(request) - .then(results => { - console.log('Got HL7v2 message:'); - console.log(JSON.stringify(results.data, null, 2)); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.hl7V2Stores.messages.get( + request + ); + console.log('Got HL7v2 message:'); + console.log(JSON.stringify(results.data, null, 2)); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_hl7v2_message] // [START healthcare_list_hl7v2_messages] -function listHl7v2Messages( +const listHl7v2Messages = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -173,19 +173,19 @@ function listHl7v2Messages( const request = {parent: hl7v2StoreName}; - client.projects.locations.datasets.hl7V2Stores.messages - .list(request) - .then(results => { - console.log('HL7v2 messages:\n', results['data']['messages']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.hl7V2Stores.messages.list( + request + ); + console.log('HL7v2 messages:\n', results['data']['messages']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_list_hl7v2_messages] // [START healthcare_patch_hl7v2_message] -function patchHl7v2Message( +const patchHl7v2Message = async ( client, projectId, cloudRegion, @@ -194,7 +194,7 @@ function patchHl7v2Message( messageId, labelKey, labelValue -) { +) => { // Client retrieved in callback // getClient(serviceAccountJson, function(cb) {...}); // const cloudRegion = 'us-central1'; @@ -216,41 +216,38 @@ function patchHl7v2Message( }, }; - client.projects.locations.datasets.hl7V2Stores.messages - .patch(request) - .then(() => { - console.log('Patched HL7v2 message'); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.messages.patch( + request + ); + console.log('Patched HL7v2 message'); + } catch (err) { + console.error(err); + } +}; // [END healthcare_patch_hl7v2_message] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] -function getClient(apiKey, serviceAccountJson, cb) { +const getClient = async (apiKey, serviceAccountJson, cb) => { const API_VERSION = 'v1alpha2'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; - google.auth - .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) - .then(authClient => { - const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + try { + const authClient = await google.auth.getClient({ + scopes: ['https://www.googleapis.com/auth/cloud-platform'], + }); - google.options({auth: authClient}); + const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + google.options({auth: authClient}); - google - .discoverAPI(discoveryUrl) - .then(client => { - cb(client); - }) - .catch(err => { - console.error(err); - }); - }); -} + const client = await google.discoverAPI(discoveryUrl); + cb(client); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_client] require(`yargs`) // eslint-disable-line diff --git a/healthcare/hl7v2/hl7v2_stores.js b/healthcare/hl7v2/hl7v2_stores.js index 79b4da2428..a2b1d7ced3 100644 --- a/healthcare/hl7v2/hl7v2_stores.js +++ b/healthcare/hl7v2/hl7v2_stores.js @@ -18,15 +18,15 @@ const {google} = require('googleapis'); // [START healthcare_create_hl7v2_store] -function createHl7v2Store( +const createHl7v2Store = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -35,27 +35,25 @@ function createHl7v2Store( const request = {parent: parentName, hl7V2StoreId: hl7v2StoreId}; - client.projects.locations.datasets.hl7V2Stores - .create(request) - .then(() => { - console.log(`Created HL7v2 store: ${hl7v2StoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.create(request); + console.log(`Created HL7v2 store: ${hl7v2StoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_create_hl7v2_store] // [START healthcare_delete_hl7v2_store] -function deleteHl7v2Store( +const deleteHl7v2Store = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -64,27 +62,25 @@ function deleteHl7v2Store( const request = {name: hl7v2StoreName}; - client.projects.locations.datasets.hl7V2Stores - .delete(request) - .then(() => { - console.log(`Deleted HL7v2 store: ${hl7v2StoreId}`); - }) - .catch(err => { - console.error(err); - }); -} + try { + await client.projects.locations.datasets.hl7V2Stores.delete(request); + console.log(`Deleted HL7v2 store: ${hl7v2StoreId}`); + } catch (err) { + console.error(err); + } +}; // [END healthcare_delete_hl7v2_store] // [START healthcare_get_hl7v2_store] -function getHl7v2Store( +const getHl7v2Store = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -93,21 +89,21 @@ function getHl7v2Store( const request = {name: hl7v2StoreName}; - client.projects.locations.datasets.hl7V2Stores - .get(request) - .then(results => { - console.log('Got HL7v2 store:\n', results['data']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.hl7V2Stores.get( + request + ); + console.log('Got HL7v2 store:\n', results['data']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_hl7v2_store] // [START healthcare_list_hl7v2_stores] -function listHl7v2Stores(client, projectId, cloudRegion, datasetId) { +const listHl7v2Stores = async (client, projectId, cloudRegion, datasetId) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -115,28 +111,28 @@ function listHl7v2Stores(client, projectId, cloudRegion, datasetId) { const request = {parent: parentName}; - client.projects.locations.datasets.hl7V2Stores - .list(request) - .then(results => { - console.log('HL7v2 stores:\n', results['data']['hl7v2Stores']); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.hl7V2Stores.list( + request + ); + console.log('HL7v2 stores:\n', results['data']['hl7v2Stores']); + } catch (err) { + console.error(err); + } +}; // [END healthcare_list_hl7v2_stores] // [START healthcare_patch_hl7v2_store] -function patchHl7v2Store( +const patchHl7v2Store = async ( client, projectId, cloudRegion, datasetId, hl7v2StoreId, pubsubTopic -) { +) => { // Client retrieved in callback - // getClient(serviceAccountJson, function(cb) {...}); + // getClient(apiKey); // const cloudRegion = 'us-central1'; // const projectId = 'adjective-noun-123'; // const datasetId = 'my-dataset'; @@ -149,49 +145,45 @@ function patchHl7v2Store( updateMask: 'notificationConfig', resource: { notificationConfig: { - pubsubTopic: `projects/${projectId}/locations/${cloudRegion}/topics/${pubsubTopic}`, + pubsubTopic: `projects/${projectId}/topics/${pubsubTopic}`, }, }, }; - client.projects.locations.datasets.hl7V2Stores - .patch(request) - .then(results => { - console.log( - 'Patched HL7v2 store with Cloud Pub/Sub topic', - results['data']['notificationConfig']['pubsubTopic'] - ); - }) - .catch(err => { - console.error(err); - }); -} + try { + const results = await client.projects.locations.datasets.hl7V2Stores.patch( + request + ); + console.log( + 'Patched HL7v2 store with Cloud Pub/Sub topic', + results['data']['notificationConfig']['pubsubTopic'] + ); + } catch (err) { + console.error(err); + } +}; // [END healthcare_patch_hl7v2_store] // Returns an authorized API client by discovering the Healthcare API with // the provided API key. // [START healthcare_get_client] -function getClient(apiKey, serviceAccountJson, cb) { +const getClient = async apiKey => { const API_VERSION = 'v1alpha2'; const DISCOVERY_API = 'https://healthcare.googleapis.com/$discovery/rest'; - google.auth - .getClient({scopes: ['https://www.googleapis.com/auth/cloud-platform']}) - .then(authClient => { - const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; + try { + const authClient = await google.auth.getClient({ + scopes: ['https://www.googleapis.com/auth/cloud-platform'], + }); + const discoveryUrl = `${DISCOVERY_API}?labels=CHC_ALPHA&version=${API_VERSION}&key=${apiKey}`; - google.options({auth: authClient}); + google.options({auth: authClient}); - google - .discoverAPI(discoveryUrl) - .then(client => { - cb(client); - }) - .catch(err => { - console.error(err); - }); - }); -} + return google.discoverAPI(discoveryUrl); + } catch (err) { + console.error(err); + } +}; // [END healthcare_get_client] require(`yargs`) // eslint-disable-line @@ -230,85 +222,75 @@ require(`yargs`) // eslint-disable-line `createHl7v2Store `, `Creates a new HL7v2 store within the parent dataset.`, {}, - opts => { - const cb = function(client) { - createHl7v2Store( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.hl7v2StoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await createHl7v2Store( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.hl7v2StoreId + ); } ) .command( `deleteHl7v2Store `, `Deletes the HL7v2 store and removes all resources that are contained within it.`, {}, - opts => { - const cb = function(client) { - deleteHl7v2Store( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.hl7v2StoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await deleteHl7v2Store( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.hl7v2StoreId + ); } ) .command( `getHl7v2Store `, `Gets the specified HL7v2 store or returns NOT_FOUND if it doesn't exist.`, {}, - opts => { - const cb = function(client) { - getHl7v2Store( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.hl7v2StoreId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await getHl7v2Store( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.hl7v2StoreId + ); } ) .command( `listHl7v2Stores `, `Lists the HL7v2 stores in the given dataset.`, {}, - opts => { - const cb = function(client) { - listHl7v2Stores( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await listHl7v2Stores( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId + ); } ) .command( `patchHl7v2Store `, `Updates the HL7v2 store.`, {}, - opts => { - const cb = function(client) { - patchHl7v2Store( - client, - opts.projectId, - opts.cloudRegion, - opts.datasetId, - opts.hl7v2StoreId, - opts.pubsubTopic - ); - }; - getClient(opts.apiKey, opts.serviceAccount, cb); + async opts => { + const client = await getClient(opts.apiKey, opts.serviceAccount); + await patchHl7v2Store( + client, + opts.projectId, + opts.cloudRegion, + opts.datasetId, + opts.hl7v2StoreId, + opts.pubsubTopic + ); } ) .wrap(120) diff --git a/healthcare/hl7v2/package.json b/healthcare/hl7v2/package.json index 66486e6d7f..cfd4e29971 100644 --- a/healthcare/hl7v2/package.json +++ b/healthcare/hl7v2/package.json @@ -27,7 +27,8 @@ "build": { "requiredEnvVars": [ "API_KEY", - "GCLOUD_PROJECT" + "GCLOUD_PROJECT", + "PUBSUB_TOPIC" ] } } diff --git a/healthcare/hl7v2/system-test/hl7v2_messages.test.js b/healthcare/hl7v2/system-test/hl7v2_messages.test.js index 928c23f255..1844e718bf 100644 --- a/healthcare/hl7v2/system-test/hl7v2_messages.test.js +++ b/healthcare/hl7v2/system-test/hl7v2_messages.test.js @@ -20,6 +20,9 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); +const projectId = process.env.GCLOUD_PROJECT; +const region = 'us-central1'; + const cmdDataset = 'node datasets.js'; const cmd = 'node hl7v2_messages.js'; const cmdHl7v2Store = 'node hl7v2_stores.js'; @@ -38,7 +41,10 @@ const labelValue = 'my-value'; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); }); after(async () => { try { @@ -58,7 +64,7 @@ it('should create an HL7v2 message', async () => { `${cmd} createHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageFile}`, cwd ); - assert.strictEqual(new RegExp(/Created HL7v2 message/).test(output), true); + assert.ok(output.includes('Created HL7v2 message')); }); it('should ingest an HL7v2 message', async () => { @@ -66,7 +72,7 @@ it('should ingest an HL7v2 message', async () => { `${cmd} ingestHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageFile}`, cwd ); - assert.strictEqual(new RegExp(/Ingested HL7v2 message/).test(output), true); + assert.ok(output.includes('Ingested HL7v2 message')); }); it('should get an HL7v2 message', async () => { @@ -74,7 +80,7 @@ it('should get an HL7v2 message', async () => { `${cmd} getHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId}`, cwd ); - assert.strictEqual(new RegExp(/Got HL7v2 message/).test(output), true); + assert.ok(output.includes('Got HL7v2 message')); }); it('should list HL7v2 messages', async () => { @@ -82,7 +88,7 @@ it('should list HL7v2 messages', async () => { `${cmd} listHl7v2Messages ${datasetId} ${hl7v2StoreId}`, cwd ); - assert.strictEqual(new RegExp(/HL7v2 messages/).test(output), true); + assert.ok(output.includes('HL7v2 messages')); }); it('should patch an HL7v2 message', async () => { @@ -90,7 +96,7 @@ it('should patch an HL7v2 message', async () => { `${cmd} patchHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId} ${labelKey} ${labelValue}`, cwd ); - assert.strictEqual(new RegExp(/Patched HL7v2 message/).test(output), true); + assert.ok(output.includes('Patched HL7v2 message')); }); it('should delete an HL7v2 message', async () => { @@ -98,7 +104,7 @@ it('should delete an HL7v2 message', async () => { `${cmd} deleteHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId}`, cwd ); - assert.strictEqual(new RegExp(/Deleted HL7v2 message/).test(output), true); + assert.ok(output.includes('Deleted HL7v2 message')); // Clean up tools.runAsync( diff --git a/healthcare/hl7v2/system-test/hl7v2_stores.test.js b/healthcare/hl7v2/system-test/hl7v2_stores.test.js index bacfc0fe5a..f12b089202 100644 --- a/healthcare/hl7v2/system-test/hl7v2_stores.test.js +++ b/healthcare/hl7v2/system-test/hl7v2_stores.test.js @@ -20,6 +20,9 @@ const assert = require('assert'); const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); +const projectId = process.env.GCLOUD_PROJECT; +const region = 'us-central1'; + const cmdDataset = 'node datasets.js'; const cmd = 'node hl7v2_stores.js'; const cwdDatasets = path.join(__dirname, '../../datasets'); @@ -29,14 +32,14 @@ const hl7v2StoreId = `nodejs-docs-samples-test-hl7v2-store${uuid.v4()}`.replace( /-/gi, '_' ); -const pubsubTopic = `nodejs-docs-samples-test-pubsub${uuid.v4()}`.replace( - /-/gi, - '_' -); +const pubsubTopic = process.env.PUBSUB_TOPIC; before(async () => { tools.checkCredentials(); - await tools.runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets); + await tools.runAsync( + `node createDataset.js ${projectId} ${region} ${datasetId}`, + cwdDatasets + ); }); after(async () => { try { @@ -52,7 +55,7 @@ it('should create an HL7v2 store', async () => { `${cmd} createHl7v2Store ${datasetId} ${hl7v2StoreId}`, cwd ); - assert.strictEqual(new RegExp(/Created HL7v2 store/).test(output), true); + assert.ok(output.includes('Created HL7v2 store')); }); it('should get an HL7v2 store', async () => { @@ -60,7 +63,7 @@ it('should get an HL7v2 store', async () => { `${cmd} getHl7v2Store ${datasetId} ${hl7v2StoreId}`, cwd ); - assert.strictEqual(new RegExp(/Got HL7v2 store/).test(output), true); + assert.ok(output.includes('Got HL7v2 store')); }); it('should patch an HL7v2 store', async () => { @@ -68,10 +71,7 @@ it('should patch an HL7v2 store', async () => { `${cmd} patchHl7v2Store ${datasetId} ${hl7v2StoreId} ${pubsubTopic}`, cwd ); - assert.strictEqual( - new RegExp(/Patched HL7v2 store with Cloud Pub\/Sub topic/).test(output), - true - ); + assert.ok(output.includes('Patched HL7v2 store with Cloud Pub/Sub topic')); }); it('should list HL7v2 stores', async () => { @@ -79,7 +79,7 @@ it('should list HL7v2 stores', async () => { `${cmd} listHl7v2Stores ${datasetId}`, cwd ); - assert.strictEqual(new RegExp(/HL7v2 stores/).test(output), true); + assert.ok(output.includes('HL7v2 stores')); }); it('should delete an HL7v2 Store', async () => { @@ -87,5 +87,5 @@ it('should delete an HL7v2 Store', async () => { `${cmd} deleteHl7v2Store ${datasetId} ${hl7v2StoreId}`, cwd ); - assert.strictEqual(new RegExp(/Deleted HL7v2 store/).test(output), true); + assert.ok(output.includes('Deleted HL7v2 store')); });