diff --git a/healthcare/api-client/v1/hl7v2/README.rst b/healthcare/api-client/v1/hl7v2/README.rst index a762e1791bb..cf6fced462d 100644 --- a/healthcare/api-client/v1/hl7v2/README.rst +++ b/healthcare/api-client/v1/hl7v2/README.rst @@ -89,8 +89,8 @@ To run this sample: $ python hl7v2_stores.py - usage: hl7v2_stores.py [-h] [--project_id PROJECT_ID] - [--cloud_region CLOUD_REGION] [--dataset_id DATASET_ID] + usage: hl7v2_stores.py [-h] [--project_id PROJECT_ID] [--location LOCATION] + [--dataset_id DATASET_ID] [--hl7v2_store_id HL7V2_STORE_ID] [--pubsub_topic PUBSUB_TOPIC] [--member MEMBER] [--role ROLE] @@ -104,8 +104,8 @@ To run this sample: get-hl7v2-store Gets the specified HL7v2 store. list-hl7v2-stores Lists the HL7v2 stores in the given dataset. patch-hl7v2-store Updates the HL7v2 store. - get_iam_policy Gets the IAM policy for the specified hl7v2 store. - set_iam_policy Sets the IAM policy for the specified hl7v2 store. A + get_iam_policy Gets the IAM policy for the specified HL7v2 store. + set_iam_policy Sets the IAM policy for the specified HL7v2 store. A single member will be assigned a single role. A member can be any of: - allUsers, that is, anyone - allAuthenticatedUsers, anyone authenticated with a @@ -122,8 +122,7 @@ To run this sample: -h, --help show this help message and exit --project_id PROJECT_ID GCP project name - --cloud_region CLOUD_REGION - GCP region + --location LOCATION GCP location --dataset_id DATASET_ID Name of dataset --hl7v2_store_id HL7V2_STORE_ID @@ -152,8 +151,7 @@ To run this sample: $ python hl7v2_messages.py - usage: hl7v2_messages.py [-h] [--project_id PROJECT_ID] - [--cloud_region CLOUD_REGION] + usage: hl7v2_messages.py [-h] [--project_id PROJECT_ID] [--location LOCATION] [--dataset_id DATASET_ID] [--hl7v2_store_id HL7V2_STORE_ID] [--hl7v2_message_file HL7V2_MESSAGE_FILE] @@ -185,8 +183,7 @@ To run this sample: -h, --help show this help message and exit --project_id PROJECT_ID GCP project name - --cloud_region CLOUD_REGION - GCP region + --location LOCATION GCP location --dataset_id DATASET_ID Name of dataset --hl7v2_store_id HL7V2_STORE_ID @@ -219,4 +216,4 @@ to `browse the source`_ and `report issues`_. https://github.com/GoogleCloudPlatform/google-cloud-python/issues -.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file +.. _Google Cloud SDK: https://cloud.google.com/sdk/ diff --git a/healthcare/api-client/v1/hl7v2/hl7v2_messages.py b/healthcare/api-client/v1/hl7v2/hl7v2_messages.py index 61c1e30a55c..a95be054c36 100644 --- a/healthcare/api-client/v1/hl7v2/hl7v2_messages.py +++ b/healthcare/api-client/v1/hl7v2/hl7v2_messages.py @@ -13,35 +13,37 @@ # limitations under the License. import argparse -import json import os -from googleapiclient import discovery - - -# [START healthcare_get_client] -def get_client(): - """Returns an authorized API client by discovering the Healthcare API and - creating a service object using the service account credentials in the - GOOGLE_APPLICATION_CREDENTIALS environment variable.""" - api_version = "v1" - service_name = "healthcare" - - return discovery.build(service_name, api_version) - - -# [END healthcare_get_client] - # [START healthcare_create_hl7v2_message] def create_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file ): """Creates an HL7v2 message and sends a notification to the Cloud Pub/Sub topic. - """ - client = get_client() - hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region) + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + # Imports Python's built-in "json" module + import json + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # hl7v2_message_file = 'hl7v2-message.json' # replace with the path to the HL7v2 file + hl7v2_parent = "projects/{}/locations/{}".format(project_id, location) hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}".format( hl7v2_parent, dataset_id, hl7v2_store_id ) @@ -68,11 +70,28 @@ def create_hl7v2_message( # [START healthcare_delete_hl7v2_message] def delete_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ): - """Deletes an HL7v2 message.""" - client = get_client() - hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region) + """Deletes an HL7v2 message. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server + hl7v2_parent = "projects/{}/locations/{}".format(project_id, location) hl7v2_message = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format( hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id ) @@ -96,11 +115,28 @@ def delete_hl7v2_message( # [START healthcare_get_hl7v2_message] def get_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ): - """Gets an HL7v2 message.""" - client = get_client() - hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region) + """Gets an HL7v2 message. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server + hl7v2_parent = "projects/{}/locations/{}".format(project_id, location) hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format( hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id ) @@ -130,14 +166,33 @@ def get_hl7v2_message( # [START healthcare_ingest_hl7v2_message] def ingest_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file ): """Ingests a new HL7v2 message from the hospital and sends a notification to the Cloud Pub/Sub topic. Return is an HL7v2 ACK message if the message was successfully stored. - """ - client = get_client() - hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region) + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + # Imports Python's built-in "json" module + import json + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # hl7v2_message_file = 'hl7v2-message.json' # replace with the path to the HL7v2 file + hl7v2_parent = "projects/{}/locations/{}".format(project_id, location) hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}".format( hl7v2_parent, dataset_id, hl7v2_store_id ) @@ -163,13 +218,28 @@ def ingest_hl7v2_message( # [START healthcare_list_hl7v2_messages] -def list_hl7v2_messages(project_id, cloud_region, dataset_id, hl7v2_store_id): +def list_hl7v2_messages(project_id, location, dataset_id, hl7v2_store_id): """Lists all the messages in the given HL7v2 store with support for filtering. - """ - client = get_client() + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_messages_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_message_path = "{}/hl7V2Stores/{}".format( hl7v2_messages_parent, hl7v2_store_id @@ -198,18 +268,35 @@ def list_hl7v2_messages(project_id, cloud_region, dataset_id, hl7v2_store_id): # [START healthcare_patch_hl7v2_message] def patch_hl7v2_message( project_id, - cloud_region, + location, dataset_id, hl7v2_store_id, hl7v2_message_id, label_key, label_value, ): - """Updates the message.""" - client = get_client() - hl7v2_message_parent = "projects/{}/locations/{}".format( - project_id, cloud_region - ) + """Updates the message. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server + # label_key = 'key1' # replace with a key + # label_value = 'label2' # replace with a key value + hl7v2_message_parent = "projects/{}/locations/{}".format(project_id, location) hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format( hl7v2_message_parent, dataset_id, hl7v2_store_id, hl7v2_message_id ) @@ -250,7 +337,7 @@ def parse_command_line_args(): help="GCP project name", ) - parser.add_argument("--cloud_region", default="us-central1", help="GCP region") + parser.add_argument("--location", default="us-central1", help="GCP location") parser.add_argument("--dataset_id", default=None, help="Name of dataset") @@ -302,7 +389,7 @@ def run_command(args): elif args.command == "create-hl7v2-message": create_hl7v2_message( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.hl7v2_message_file, @@ -311,7 +398,7 @@ def run_command(args): elif args.command == "delete-hl7v2-message": delete_hl7v2_message( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.hl7v2_message_id, @@ -320,7 +407,7 @@ def run_command(args): elif args.command == "get-hl7v2-message": get_hl7v2_message( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.hl7v2_message_id, @@ -329,7 +416,7 @@ def run_command(args): elif args.command == "ingest-hl7v2-message": ingest_hl7v2_message( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.hl7v2_message_file, @@ -337,13 +424,13 @@ def run_command(args): elif args.command == "list-hl7v2-messages": list_hl7v2_messages( - args.project_id, args.cloud_region, args.dataset_id, args.hl7v2_store_id + args.project_id, args.location, args.dataset_id, args.hl7v2_store_id ) elif args.command == "patch-hl7v2-message": patch_hl7v2_message( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.hl7v2_message_id, diff --git a/healthcare/api-client/v1/hl7v2/hl7v2_messages_test.py b/healthcare/api-client/v1/hl7v2/hl7v2_messages_test.py index 06ae20b41a3..5fa2d838f00 100644 --- a/healthcare/api-client/v1/hl7v2/hl7v2_messages_test.py +++ b/healthcare/api-client/v1/hl7v2/hl7v2_messages_test.py @@ -27,7 +27,7 @@ import hl7v2_stores # noqa -cloud_region = "us-central1" +location = "us-central1" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] dataset_id = "test_dataset_{}".format(uuid.uuid4()) @@ -42,7 +42,7 @@ def test_dataset(): @backoff.on_exception(backoff.expo, HttpError, max_time=60) def create(): try: - datasets.create_dataset(project_id, cloud_region, dataset_id) + datasets.create_dataset(project_id, location, dataset_id) except HttpError as err: # We ignore 409 conflict here, because we know it's most # likely the first request failed on the client side, but @@ -60,7 +60,7 @@ def create(): @backoff.on_exception(backoff.expo, HttpError, max_time=60) def clean_up(): try: - datasets.delete_dataset(project_id, cloud_region, dataset_id) + datasets.delete_dataset(project_id, location, dataset_id) except HttpError as err: # The API returns 403 when the dataset doesn't exist. if err.resp.status == 404 or err.resp.status == 403: @@ -77,7 +77,7 @@ def test_hl7v2_store(): def create(): try: hl7v2_stores.create_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) except HttpError as err: # We ignore 409 conflict here, because we know it's most @@ -101,7 +101,7 @@ def create(): def clean_up(): try: hl7v2_stores.delete_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) except HttpError as err: # The API returns 403 when the HL7v2 store doesn't exist. @@ -119,13 +119,13 @@ def clean_up(): def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.create_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file ) @backoff.on_exception(backoff.expo, AssertionError, max_time=60) def run_eventually_consistent_test(): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) assert len(hl7v2_messages_list) > 0 @@ -138,11 +138,11 @@ def run_eventually_consistent_test(): hl7v2_message_id = run_eventually_consistent_test() hl7v2_messages.get_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ) hl7v2_messages.delete_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ) out, _ = capsys.readouterr() @@ -155,13 +155,13 @@ def run_eventually_consistent_test(): def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.ingest_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file ) @backoff.on_exception(backoff.expo, AssertionError, max_time=60) def run_eventually_consistent_test(): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) assert len(hl7v2_messages_list) > 0 @@ -174,11 +174,11 @@ def run_eventually_consistent_test(): hl7v2_message_id = run_eventually_consistent_test() hl7v2_messages.get_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ) hl7v2_messages.delete_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ) out, _ = capsys.readouterr() @@ -191,13 +191,13 @@ def run_eventually_consistent_test(): def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys): hl7v2_messages.create_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file ) @backoff.on_exception(backoff.expo, (AssertionError, HttpError), max_time=60) def run_eventually_consistent_test(): hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) assert len(hl7v2_messages_list) > 0 @@ -211,7 +211,7 @@ def run_eventually_consistent_test(): hl7v2_messages.patch_hl7v2_message( project_id, - cloud_region, + location, dataset_id, hl7v2_store_id, hl7v2_message_id, @@ -220,7 +220,7 @@ def run_eventually_consistent_test(): ) hl7v2_messages.delete_hl7v2_message( - project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id + project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id ) out, _ = capsys.readouterr() diff --git a/healthcare/api-client/v1/hl7v2/hl7v2_stores.py b/healthcare/api-client/v1/hl7v2/hl7v2_stores.py index d86061a7f82..fd4d88bfb68 100644 --- a/healthcare/api-client/v1/hl7v2/hl7v2_stores.py +++ b/healthcare/api-client/v1/hl7v2/hl7v2_stores.py @@ -15,29 +15,28 @@ import argparse import os -from googleapiclient import discovery +# [START healthcare_create_hl7v2_store] +def create_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id): + """Creates a new HL7v2 store within the parent dataset. + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery -# [START healthcare_get_client] -def get_client(): - """Returns an authorized API client by discovering the Healthcare API and - creating a service object using the service account credentials in the - GOOGLE_APPLICATION_CREDENTIALS environment variable.""" api_version = "v1" service_name = "healthcare" - - return discovery.build(service_name, api_version) - - -# [END healthcare_get_client] - - -# [START healthcare_create_hl7v2_store] -def create_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): - """Creates a new HL7v2 store within the parent dataset.""" - client = get_client() + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) request = ( @@ -57,11 +56,27 @@ def create_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): # [START healthcare_delete_hl7v2_store] -def delete_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): - """Deletes the specified HL7v2 store.""" - client = get_client() +def delete_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id): + """Deletes the specified HL7v2 store. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_store_name = "{}/hl7V2Stores/{}".format(hl7v2_store_parent, hl7v2_store_id) @@ -82,11 +97,27 @@ def delete_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): # [START healthcare_get_hl7v2_store] -def get_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): - """Gets the specified HL7v2 store.""" - client = get_client() +def get_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id): + """Gets the specified HL7v2 store. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_store_name = "{}/hl7V2Stores/{}".format(hl7v2_store_parent, hl7v2_store_id) @@ -108,11 +139,26 @@ def get_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): # [START healthcare_list_hl7v2_stores] -def list_hl7v2_stores(project_id, cloud_region, dataset_id): - """Lists the HL7v2 stores in the given dataset.""" - client = get_client() +def list_hl7v2_stores(project_id, location, dataset_id): + """Lists the HL7v2 stores in the given dataset. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_stores = ( @@ -129,7 +175,8 @@ def list_hl7v2_stores(project_id, cloud_region, dataset_id): print( "HL7v2 store: {}\n" "Notification config: {}".format( - hl7v2_store.get("name"), hl7v2_store.get("notificationConfig"), + hl7v2_store.get("name"), + hl7v2_store.get("notificationConfig"), ) ) @@ -140,14 +187,31 @@ def list_hl7v2_stores(project_id, cloud_region, dataset_id): # [START healthcare_patch_hl7v2_store] -def patch_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): - """Updates the HL7v2 store.""" - client = get_client() +def patch_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id): + """Updates the HL7v2 store. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_store_name = "{}/hl7V2Stores/{}".format(hl7v2_store_parent, hl7v2_store_id) + # TODO(developer): Replace with the full URI of an existing Pub/Sub topic patch = {"notificationConfigs": None} request = ( @@ -169,11 +233,27 @@ def patch_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id): # [START healthcare_hl7v2_store_get_iam_policy] -def get_hl7v2_store_iam_policy(project_id, cloud_region, dataset_id, hl7v2_store_id): - """Gets the IAM policy for the specified hl7v2 store.""" - client = get_client() +def get_hl7v2_store_iam_policy(project_id, location, dataset_id, hl7v2_store_id): + """Gets the IAM policy for the specified HL7v2 store. + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_store_name = "{}/hl7V2Stores/{}".format(hl7v2_store_parent, hl7v2_store_id) @@ -195,9 +275,9 @@ def get_hl7v2_store_iam_policy(project_id, cloud_region, dataset_id, hl7v2_store # [START healthcare_hl7v2_store_set_iam_policy] def set_hl7v2_store_iam_policy( - project_id, cloud_region, dataset_id, hl7v2_store_id, member, role, etag=None + project_id, location, dataset_id, hl7v2_store_id, member, role, etag=None ): - """Sets the IAM policy for the specified hl7v2 store. + """Sets the IAM policy for the specified HL7v2 store. A single member will be assigned a single role. A member can be any of: - allUsers, that is, anyone - allAuthenticatedUsers, anyone authenticated with a Google account @@ -208,10 +288,27 @@ def set_hl7v2_store_iam_policy( as in 'serviceAccount:my-other-app@appspot.gserviceaccount.com' A role can be any IAM role, such as 'roles/viewer', 'roles/owner', or 'roles/editor' - """ - client = get_client() + + See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2 + before running the sample.""" + # Imports the Google API Discovery Service. + from googleapiclient import discovery + + api_version = "v1" + service_name = "healthcare" + # Returns an authorized API client by discovering the Healthcare API + # and using GOOGLE_APPLICATION_CREDENTIALS environment variable. + client = discovery.build(service_name, api_version) + + # TODO(developer): Uncomment these lines and replace with your values. + # project_id = 'my-project' # replace with your GCP project ID + # location = 'us-central1' # replace with the parent dataset's location + # dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset + # hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID + # member = 'myemail@example.com' # replace with an authorized member + # role = 'roles/viewer' # replace with a Healthcare API IAM role hl7v2_store_parent = "projects/{}/locations/{}/datasets/{}".format( - project_id, cloud_region, dataset_id + project_id, location, dataset_id ) hl7v2_store_name = "{}/hl7V2Stores/{}".format(hl7v2_store_parent, hl7v2_store_id) @@ -250,7 +347,7 @@ def parse_command_line_args(): help="GCP project name", ) - parser.add_argument("--cloud_region", default="us-central1", help="GCP region") + parser.add_argument("--location", default="us-central1", help="GCP location") parser.add_argument("--dataset_id", default=None, help="Name of dataset") @@ -296,26 +393,26 @@ def run_command(args): elif args.command == "create-hl7v2-store": create_hl7v2_store( - args.project_id, args.cloud_region, args.dataset_id, args.hl7v2_store_id + args.project_id, args.location, args.dataset_id, args.hl7v2_store_id ) elif args.command == "delete-hl7v2-store": delete_hl7v2_store( - args.project_id, args.cloud_region, args.dataset_id, args.hl7v2_store_id + args.project_id, args.location, args.dataset_id, args.hl7v2_store_id ) elif args.command == "get-hl7v2-store": get_hl7v2_store( - args.project_id, args.cloud_region, args.dataset_id, args.hl7v2_store_id + args.project_id, args.location, args.dataset_id, args.hl7v2_store_id ) elif args.command == "list-hl7v2-stores": - list_hl7v2_stores(args.project_id, args.cloud_region, args.dataset_id) + list_hl7v2_stores(args.project_id, args.location, args.dataset_id) elif args.command == "patch-hl7v2-store": patch_hl7v2_store( args.project_id, - args.cloud_region, + args.location, args.dataset_id, args.hl7v2_store_id, args.pubsub_topic, @@ -323,15 +420,15 @@ def run_command(args): elif args.command == "get_hl7v2_store_iam_policy": get_hl7v2_store_iam_policy( - args.project_id, args.cloud_region, args.dataset_id, args.fhir_store_id + args.project_id, args.location, args.dataset_id, args.hl7v2_store_id ) elif args.command == "set_hl7v2_store_iam_policy": set_hl7v2_store_iam_policy( args.project_id, - args.cloud_region, + args.location, args.dataset_id, - args.fhir_store_id, + args.hl7v2_store_id, args.member, args.role, ) diff --git a/healthcare/api-client/v1/hl7v2/hl7v2_stores_test.py b/healthcare/api-client/v1/hl7v2/hl7v2_stores_test.py index fb28045e13c..8b523273b29 100644 --- a/healthcare/api-client/v1/hl7v2/hl7v2_stores_test.py +++ b/healthcare/api-client/v1/hl7v2/hl7v2_stores_test.py @@ -26,7 +26,7 @@ import hl7v2_stores # noqa -cloud_region = "us-central1" +location = "us-central1" project_id = os.environ["GOOGLE_CLOUD_PROJECT"] dataset_id = "test_dataset_{}".format(uuid.uuid4()) @@ -42,7 +42,7 @@ def test_dataset(): @backoff.on_exception(backoff.expo, HttpError, max_time=60) def create(): try: - datasets.create_dataset(project_id, cloud_region, dataset_id) + datasets.create_dataset(project_id, location, dataset_id) except HttpError as err: # We ignore 409 conflict here, because we know it's most # likely the first request failed on the client side, but @@ -60,7 +60,7 @@ def create(): @backoff.on_exception(backoff.expo, HttpError, max_time=60) def clean_up(): try: - datasets.delete_dataset(project_id, cloud_region, dataset_id) + datasets.delete_dataset(project_id, location, dataset_id) except HttpError as err: # The API returns 403 when the dataset doesn't exist. if err.resp.status == 404 or err.resp.status == 403: @@ -77,7 +77,7 @@ def test_hl7v2_store(): def create(): try: hl7v2_stores.create_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) except HttpError as err: # We ignore 409 conflict here, because we know it's most @@ -101,7 +101,7 @@ def create(): def clean_up(): try: hl7v2_stores.delete_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) except HttpError as err: # The API returns 403 when the HL7v2 store doesn't exist. @@ -126,7 +126,7 @@ def crud_hl7v2_store_id(): def clean_up(): try: hl7v2_stores.delete_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) except HttpError as err: # The API returns 403 when the HL7v2 store doesn't exist. @@ -146,17 +146,16 @@ def test_CRUD_hl7v2_store(test_dataset, crud_hl7v2_store_id, capsys): @backoff.on_exception(backoff.expo, HttpError, max_time=60) def create(): hl7v2_stores.create_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) + create() - hl7v2_stores.get_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id) + hl7v2_stores.get_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id) - hl7v2_stores.list_hl7v2_stores(project_id, cloud_region, dataset_id) + hl7v2_stores.list_hl7v2_stores(project_id, location, dataset_id) - hl7v2_stores.delete_hl7v2_store( - project_id, cloud_region, dataset_id, hl7v2_store_id - ) + hl7v2_stores.delete_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id) out, _ = capsys.readouterr() @@ -168,7 +167,7 @@ def create(): def test_patch_hl7v2_store(test_dataset, test_hl7v2_store, capsys): - hl7v2_stores.patch_hl7v2_store(project_id, cloud_region, dataset_id, hl7v2_store_id) + hl7v2_stores.patch_hl7v2_store(project_id, location, dataset_id, hl7v2_store_id) out, _ = capsys.readouterr() @@ -177,12 +176,12 @@ def test_patch_hl7v2_store(test_dataset, test_hl7v2_store, capsys): def test_get_set_hl7v2_store_iam_policy(test_dataset, test_hl7v2_store, capsys): get_response = hl7v2_stores.get_hl7v2_store_iam_policy( - project_id, cloud_region, dataset_id, hl7v2_store_id + project_id, location, dataset_id, hl7v2_store_id ) set_response = hl7v2_stores.set_hl7v2_store_iam_policy( project_id, - cloud_region, + location, dataset_id, hl7v2_store_id, "serviceAccount:python-docs-samples-tests@appspot.gserviceaccount.com",