diff --git a/healthcare/hl7v2/README.md b/healthcare/hl7v2/README.md
new file mode 100644
index 0000000000..c75d1ecf34
--- /dev/null
+++ b/healthcare/hl7v2/README.md
@@ -0,0 +1,71 @@
+
+
+# Cloud Healthcare API Node.js HL7v2 store and HL7v2 message example
+
+This sample app demonstrates HL7v2 store and HL7v2 message management for the Cloud Healthcare API.
+
+# Setup
+
+Run the following command to install the library dependencies for Node.js:
+
+ npm install
+
+# Running the samples
+
+## HL7v2 stores
+
+ hl7v2_stores.js
+
+ Commands:
+ hl7v2_stores.js createHl7v2Store Creates a new HL7v2 store within the parent dataset.
+ hl7v2_stores.js deleteHl7v2Store Deletes the HL7v2 store and removes all resources that
+ are contained within it.
+ hl7v2_stores.js getHl7v2Store Gets the specified HL7v2 store or returns NOT_FOUND if
+ it doesn't exist.
+ hl7v2_stores.js listHl7v2Stores Lists the HL7v2 stores in the given dataset.
+ hl7v2_stores.js patchHl7v2Store Updates the HL7v2 store.
+
+
+ Options:
+ --version Show version number [boolean]
+ --apiKey, -a The API key used for discovering the API.
+ [string]
+ --cloudRegion, -c [string] [default: "us-central1"]
+ --projectId, -p The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT
+ environment variables. [string]
+ --serviceAccount, -s The path to your service credentials JSON.
+ [string]
+ --help Show help [boolean]
+
+
+## HL7v2 messages
+
+ hl7v2_messages.js
+
+ Commands:
+ hl7v2_messages.js createHl7v2Message Creates a new HL7v2 message and, if configured, sends a
+ notification to the parent store's Cloud Pub/Sub topic.
+ hl7v2_messages.js ingestHl7v2Message Ingests a new HL7v2 message from the hospital and, if
+ configured, sends a notification to the Cloud Pub/Sub
+ topic.
+ hl7v2_messages.js deleteHl7v2Message Deletes the specified HL7v2 message.
+
+ hl7v2_messages.js getHl7v2Message Gets the specified HL7v2 message.
+
+ hl7v2_messages.js listHl7v2Messages Lists all the messages in the given HL7v2 store.
+
+ hl7v2_messages.js patchHl7v2Message Updates the specified HL7v2 message.
+
+
+ Options:
+ --version Show version number [boolean]
+ --apiKey, -a The API key used for discovering the API.
+ [string]
+ --cloudRegion, -c [string] [default: "us-central1"]
+ --projectId, -p The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT
+ environment variables. [string]
+ --serviceAccount, -s The path to your service credentials JSON.
+ [string]
+ --help Show help [boolean]
+
+For more information, see https://cloud.google.com/healthcare/docs
diff --git a/healthcare/hl7v2/hl7v2_messages.js b/healthcare/hl7v2/hl7v2_messages.js
new file mode 100644
index 0000000000..d2a617d53f
--- /dev/null
+++ b/healthcare/hl7v2/hl7v2_messages.js
@@ -0,0 +1,400 @@
+/**
+ * Copyright 2018, Google, LLC
+ * Licensed under the Apache License, Version 2.0 (the `License`);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an `AS IS` BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+const fs = require('fs');
+const {google} = require('googleapis');
+
+// [START healthcare_create_hl7v2_message]
+function createHl7v2Message(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ messageFile
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const messageFile = './hl7-sample-ingest.json';
+ const hl7v2MessageParent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ const hl7v2Message = fs.readFileSync(messageFile);
+ const hl7v2MessageJson = JSON.parse(hl7v2Message);
+
+ const request = {
+ parent: hl7v2MessageParent,
+ resource: hl7v2MessageJson,
+ };
+
+ client.projects.locations.datasets.hl7V2Stores.messages
+ .create(request)
+ .then(() => {
+ console.log(`Created HL7v2 message`);
+ })
+ .catch(err => {
+ console.error(err);
+ });
+}
+// [END healthcare_create_hl7v2_message]
+
+// [START healthcare_ingest_hl7v2_message]
+function ingestHl7v2Message(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ messageFile
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const messageFile = './hl7-sample-ingest.json';
+ const hl7v2MessageParent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ const hl7v2Message = fs.readFileSync(messageFile);
+ const hl7v2MessageJson = JSON.parse(hl7v2Message);
+
+ const request = {
+ parent: hl7v2MessageParent,
+ resource: hl7v2MessageJson,
+ };
+
+ client.projects.locations.datasets.hl7V2Stores.messages
+ .ingest(request)
+ .then(() => {
+ console.log(`Ingested HL7v2 message`);
+ })
+ .catch(err => {
+ console.error(err);
+ });
+}
+// [END healthcare_ingest_hl7v2_message]
+
+// [START healthcare_delete_hl7v2_message]
+function deleteHl7v2Message(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ messageId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const messageId = 'E9_pxOBKhmlxiFxE4cg8zwJKUHMlOzIfeLBrZPf0Zg=';
+ const hl7v2Message = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}/messages/${messageId}`;
+
+ 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);
+ });
+}
+// [END healthcare_delete_hl7v2_message]
+
+// [START healthcare_get_hl7v2_message]
+function getHl7v2Message(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ messageId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const messageId = 'E9_pxOBKhmlxiFxE4cg8zwJKUHMlOzIfeLBrZPf0Zg=';
+ const hl7v2Message = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}/messages/${messageId}`;
+
+ 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);
+ });
+}
+// [END healthcare_get_hl7v2_message]
+
+// [START healthcare_list_hl7v2_messages]
+function listHl7v2Messages(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ const hl7v2StoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ 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);
+ });
+}
+// [END healthcare_list_hl7v2_messages]
+
+// [START healthcare_patch_hl7v2_message]
+function patchHl7v2Message(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ messageId,
+ labelKey,
+ labelValue
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const messageId = 'E9_pxOBKhmlxiFxE4cg8zwJKUHMlOzIfeLBrZPf0Zg=';
+ // const labelKey = 'my-key';
+ // const labelValue = 'my-value';
+ const hl7v2Message = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}/messages/${messageId}`;
+
+ const request = {
+ name: hl7v2Message,
+ updateMask: 'labels',
+ labels: {
+ labelKey: labelValue,
+ },
+ };
+
+ client.projects.locations.datasets.hl7V2Stores.messages
+ .patch(request)
+ .then(() => {
+ 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 API_VERSION = 'v1alpha';
+ 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}`;
+
+ google.options({auth: authClient});
+
+ google
+ .discoverAPI(discoveryUrl)
+ .then(client => {
+ cb(client);
+ })
+ .catch(err => {
+ console.error(err);
+ });
+ });
+}
+// [END healthcare_get_client]
+
+require(`yargs`) // eslint-disable-line
+ .demand(1)
+ .options({
+ apiKey: {
+ alias: 'a',
+ default: process.env.API_KEY,
+ description: 'The API key used for discovering the API.',
+ requiresArg: true,
+ type: 'string',
+ },
+ cloudRegion: {
+ alias: 'c',
+ default: 'us-central1',
+ requiresArg: true,
+ type: 'string',
+ },
+ projectId: {
+ alias: 'p',
+ default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
+ description:
+ 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.',
+ 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(
+ `createHl7v2Message `,
+ `Creates a new HL7v2 message and, if configured, sends a notification to the parent store's Cloud Pub/Sub topic.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ createHl7v2Message(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId,
+ opts.messageFile
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .command(
+ `ingestHl7v2Message `,
+ `Ingests a new HL7v2 message from the hospital and, if configured, sends a notification to the Cloud Pub/Sub topic.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ ingestHl7v2Message(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId,
+ opts.messageFile
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .command(
+ `deleteHl7v2Message `,
+ `Deletes the specified HL7v2 message.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ deleteHl7v2Message(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId,
+ opts.messageId
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .command(
+ `getHl7v2Message `,
+ `Gets the specified HL7v2 message.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ getHl7v2Message(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId,
+ opts.messageId
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .command(
+ `listHl7v2Messages `,
+ `Lists all the messages in the given HL7v2 store.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ listHl7v2Messages(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .command(
+ `patchHl7v2Message `,
+ `Updates the specified HL7v2 message.`,
+ {},
+ opts => {
+ const cb = function(client) {
+ patchHl7v2Message(
+ client,
+ opts.projectId,
+ opts.cloudRegion,
+ opts.datasetId,
+ opts.hl7v2StoreId,
+ opts.labelKey,
+ opts.labelValue
+ );
+ };
+ getClient(opts.apiKey, opts.serviceAccount, cb);
+ }
+ )
+ .wrap(120)
+ .recommendCommands()
+ .epilogue(
+ `For more information, see https://cloud.google.com/healthcare/docs`
+ )
+ .help()
+ .strict().argv;
diff --git a/healthcare/hl7v2/hl7v2_stores.js b/healthcare/hl7v2/hl7v2_stores.js
new file mode 100644
index 0000000000..daa65b5683
--- /dev/null
+++ b/healthcare/hl7v2/hl7v2_stores.js
@@ -0,0 +1,320 @@
+/**
+ * Copyright 2018, Google, LLC
+ * Licensed under the Apache License, Version 2.0 (the `License`);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an `AS IS` BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+const {google} = require('googleapis');
+
+// [START healthcare_create_hl7v2_store]
+function createHl7v2Store(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ const parentName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
+
+ 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);
+ });
+}
+// [END healthcare_create_hl7v2_store]
+
+// [START healthcare_delete_hl7v2_store]
+function deleteHl7v2Store(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ const hl7v2StoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ const request = {name: hl7v2StoreName};
+
+ client.projects.locations.datasets.hl7V2Stores
+ .delete(request)
+ .then(() => {
+ console.log(`Deleted HL7v2 store: ${hl7v2StoreId}`);
+ })
+ .catch(err => {
+ console.error(err);
+ });
+}
+// [END healthcare_delete_hl7v2_store]
+
+// [START healthcare_get_hl7v2_store]
+function getHl7v2Store(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ const hl7v2StoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ 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);
+ });
+}
+// [END healthcare_get_hl7v2_store]
+
+// [START healthcare_list_hl7v2_stores]
+function listHl7v2Stores(client, projectId, cloudRegion, datasetId) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ const parentName = `projects/${projectId}/locations/${cloudRegion}/datasets/${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);
+ });
+}
+// [END healthcare_list_hl7v2_stores]
+
+// [START healthcare_patch_hl7v2_store]
+function patchHl7v2Store(
+ client,
+ projectId,
+ cloudRegion,
+ datasetId,
+ hl7v2StoreId,
+ pubsubTopic
+) {
+ // Client retrieved in callback
+ // getClient(serviceAccountJson, function(cb) {...});
+ // const cloudRegion = 'us-central1';
+ // const projectId = 'adjective-noun-123';
+ // const datasetId = 'my-dataset';
+ // const hl7v2StoreId = 'my-hl7v2-store';
+ // const pubsubTopic = 'my-topic'
+ const hl7v2StoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/hl7V2Stores/${hl7v2StoreId}`;
+
+ const request = {
+ name: hl7v2StoreName,
+ updateMask: 'notificationConfig',
+ resource: {
+ notificationConfig: {
+ pubsubTopic: `projects/${projectId}/locations/${cloudRegion}/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);
+ });
+}
+// [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 API_VERSION = 'v1alpha';
+ 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}`;
+
+ google.options({auth: authClient});
+
+ google
+ .discoverAPI(discoveryUrl)
+ .then(client => {
+ cb(client);
+ })
+ .catch(err => {
+ console.error(err);
+ });
+ });
+}
+// [END healthcare_get_client]
+
+require(`yargs`) // eslint-disable-line
+ .demand(1)
+ .options({
+ apiKey: {
+ alias: 'a',
+ default: process.env.API_KEY,
+ description: 'The API key used for discovering the API.',
+ requiresArg: true,
+ type: 'string',
+ },
+ cloudRegion: {
+ alias: 'c',
+ default: 'us-central1',
+ requiresArg: true,
+ type: 'string',
+ },
+ projectId: {
+ alias: 'p',
+ default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
+ description:
+ 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.',
+ 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(
+ `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);
+ }
+ )
+ .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);
+ }
+ )
+ .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);
+ }
+ )
+ .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);
+ }
+ )
+ .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);
+ }
+ )
+ .wrap(120)
+ .recommendCommands()
+ .epilogue(
+ `For more information, see https://cloud.google.com/healthcare/docs`
+ )
+ .help()
+ .strict().argv;
diff --git a/healthcare/hl7v2/package.json b/healthcare/hl7v2/package.json
new file mode 100644
index 0000000000..c82df83156
--- /dev/null
+++ b/healthcare/hl7v2/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "nodejs-docs-samples-healthcare",
+ "version": "0.0.1",
+ "private": true,
+ "license": "Apache-2.0",
+ "author": "Google LLC",
+ "repository": "GoogleCloudPlatform/nodejs-docs-samples",
+ "engines": {
+ "node": ">=6.0.0"
+ },
+ "scripts": {
+ "test": "ava -T 1m --verbose system-test/*.test.js"
+ },
+ "devDependencies": {
+ "@google-cloud/nodejs-repo-tools": "^3.0.0",
+ "ava": "^0.25.0"
+ },
+ "dependencies": {
+ "googleapis": "^32.0.0",
+ "uuid": "^3.3.2",
+ "yargs": "^12.0.1"
+ },
+ "cloud-repo-tools": {
+ "requiresKeyFile": true,
+ "requiresProjectId": true,
+ "test": {
+ "build": {
+ "requiredEnvVars": [
+ "API_KEY",
+ "GCLOUD_PROJECT"
+ ]
+ }
+ }
+ }
+}
diff --git a/healthcare/hl7v2/resources/hl7v2-sample-ingest.json b/healthcare/hl7v2/resources/hl7v2-sample-ingest.json
new file mode 100644
index 0000000000..bde1ee86fd
--- /dev/null
+++ b/healthcare/hl7v2/resources/hl7v2-sample-ingest.json
@@ -0,0 +1,5 @@
+{
+ "message": {
+ "data" : "TVNIfF5+XCZ8QXxTRU5EX0ZBQ0lMSVRZfEF8QXwyMDE4MDEwMTAwMDAwMHx8VFlQRV5BfDIwMTgwMTAxMDAwMDAwfFR8MC4wfHx8QUF8fDAwfEFTQ0lJDUVWTnxBMDB8MjAxODAxMDEwNDAwMDANUElEfHwxNAExMTFeXl5eTVJOfDExMTExMTExXl5eXk1STn4xMTExMTExMTExXl5eXk9SR05NQlI="
+ }
+}
diff --git a/healthcare/hl7v2/system-test/hl7v2_messages.test.js b/healthcare/hl7v2/system-test/hl7v2_messages.test.js
new file mode 100644
index 0000000000..901a87aea9
--- /dev/null
+++ b/healthcare/hl7v2/system-test/hl7v2_messages.test.js
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2018, Google, LLC
+ * Licensed under the Apache License, Version 2.0 (the `License`);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an `AS IS` BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+const path = require(`path`);
+const test = require(`ava`);
+const tools = require(`@google-cloud/nodejs-repo-tools`);
+const uuid = require(`uuid`);
+
+const cmdDataset = `node datasets.js`;
+const cmd = `node hl7v2_messages.js`;
+const cmdHl7v2Store = `node hl7v2_stores.js`;
+const cwdDatasets = path.join(__dirname, `../../datasets`);
+const cwd = path.join(__dirname, `..`);
+const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_');
+const hl7v2StoreId = `nodejs-docs-samples-test-hl7v2-store${uuid.v4()}`.replace(
+ /-/gi,
+ '_'
+);
+
+const messageFile = `resources/hl7v2-sample-ingest.json`;
+const messageId = `2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=`;
+const labelKey = `my-key`;
+const labelValue = `my-value`;
+
+test.before(tools.checkCredentials);
+test.before(async () => {
+ return tools
+ .runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets)
+ .then(results => {
+ console.log(results);
+ return results;
+ });
+});
+test.after.always(async () => {
+ try {
+ await tools.runAsync(
+ `${cmdDataset} deleteDataset ${datasetId}`,
+ cwdDatasets
+ );
+ } catch (err) {} // Ignore error
+});
+
+test.serial(`should create an HL7v2 message`, async t => {
+ await tools.runAsync(
+ `${cmdHl7v2Store} createHl7v2Store ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+ const output = await tools.runAsync(
+ `${cmd} createHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageFile}`,
+ cwd
+ );
+ t.regex(output, /Created HL7v2 message/);
+});
+
+test.serial(`should ingest an HL7v2 message`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} ingestHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageFile}`,
+ cwd
+ );
+ t.regex(output, /Ingested HL7v2 message/);
+});
+
+test.serial(`should get an HL7v2 message`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} getHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId}`,
+ cwd
+ );
+ t.regex(output, /Got HL7v2 message/);
+});
+
+test.serial(`should list HL7v2 messages`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} listHl7v2Messages ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+ t.regex(output, /HL7v2 messages/);
+});
+
+test.serial(`should patch an HL7v2 message`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} patchHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId} ${labelKey} ${labelValue}`,
+ cwd
+ );
+ t.regex(output, /Patched HL7v2 message/);
+});
+
+test(`should delete an HL7v2 message`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} deleteHl7v2Message ${datasetId} ${hl7v2StoreId} ${messageId}`,
+ cwd
+ );
+ t.regex(output, /Deleted HL7v2 message/);
+
+ // Clean up
+ tools.runAsync(
+ `${cmdHl7v2Store} deleteHl7v2Store ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+});
diff --git a/healthcare/hl7v2/system-test/hl7v2_stores.test.js b/healthcare/hl7v2/system-test/hl7v2_stores.test.js
new file mode 100644
index 0000000000..9aef63ca27
--- /dev/null
+++ b/healthcare/hl7v2/system-test/hl7v2_stores.test.js
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2018, Google, LLC
+ * Licensed under the Apache License, Version 2.0 (the `License`);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an `AS IS` BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+const path = require(`path`);
+const test = require(`ava`);
+const tools = require(`@google-cloud/nodejs-repo-tools`);
+const uuid = require(`uuid`);
+
+const cmdDataset = `node datasets.js`;
+const cmd = `node hl7v2_stores.js`;
+const cwdDatasets = path.join(__dirname, `../../datasets`);
+const cwd = path.join(__dirname, `..`);
+const datasetId = `nodejs-docs-samples-test-${uuid.v4()}`.replace(/-/gi, '_');
+const hl7v2StoreId = `nodejs-docs-samples-test-hl7v2-store${uuid.v4()}`.replace(
+ /-/gi,
+ '_'
+);
+const pubsubTopic = `nodejs-docs-samples-test-pubsub${uuid.v4()}`.replace(
+ /-/gi,
+ '_'
+);
+
+test.before(tools.checkCredentials);
+test.before(async () => {
+ return tools
+ .runAsync(`${cmdDataset} createDataset ${datasetId}`, cwdDatasets)
+ .then(results => {
+ console.log(results);
+ return results;
+ });
+});
+test.after.always(async () => {
+ try {
+ await tools.runAsync(
+ `${cmdDataset} deleteDataset ${datasetId}`,
+ cwdDatasets
+ );
+ } catch (err) {} // Ignore error
+});
+
+test.serial(`should create an HL7v2 store`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} createHl7v2Store ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+ t.regex(output, /Created HL7v2 store/);
+});
+
+test.serial(`should get an HL7v2 store`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} getHl7v2Store ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+ t.regex(output, /Got HL7v2 store/);
+});
+
+test.serial(`should patch an HL7v2 store`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} patchHl7v2Store ${datasetId} ${hl7v2StoreId} ${pubsubTopic}`,
+ cwd
+ );
+ t.regex(output, /Patched HL7v2 store with Cloud Pub\/Sub topic/);
+});
+
+test.serial(`should list HL7v2 stores`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} listHl7v2Stores ${datasetId}`,
+ cwd
+ );
+ t.regex(output, /HL7v2 stores/);
+});
+
+test(`should delete an HL7v2 Store`, async t => {
+ const output = await tools.runAsync(
+ `${cmd} deleteHl7v2Store ${datasetId} ${hl7v2StoreId}`,
+ cwd
+ );
+ t.regex(output, /Deleted HL7v2 store/);
+});