Skip to content

Commit 9703458

Browse files
noerogengelke
andauthored
Chc cleanup hl7v2 (#6122)
* healthcare API: Hl7v2 formatting fixes and cleanup * fix README * fix README Co-authored-by: Charles Engelke <[email protected]>
1 parent c94dd8b commit 9703458

File tree

5 files changed

+326
-146
lines changed

5 files changed

+326
-146
lines changed

healthcare/api-client/v1/hl7v2/README.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ To run this sample:
8989
9090
$ python hl7v2_stores.py
9191
92-
usage: hl7v2_stores.py [-h] [--project_id PROJECT_ID]
93-
[--cloud_region CLOUD_REGION] [--dataset_id DATASET_ID]
92+
usage: hl7v2_stores.py [-h] [--project_id PROJECT_ID] [--location LOCATION]
93+
[--dataset_id DATASET_ID]
9494
[--hl7v2_store_id HL7V2_STORE_ID]
9595
[--pubsub_topic PUBSUB_TOPIC] [--member MEMBER]
9696
[--role ROLE]
@@ -104,8 +104,8 @@ To run this sample:
104104
get-hl7v2-store Gets the specified HL7v2 store.
105105
list-hl7v2-stores Lists the HL7v2 stores in the given dataset.
106106
patch-hl7v2-store Updates the HL7v2 store.
107-
get_iam_policy Gets the IAM policy for the specified hl7v2 store.
108-
set_iam_policy Sets the IAM policy for the specified hl7v2 store. A
107+
get_iam_policy Gets the IAM policy for the specified HL7v2 store.
108+
set_iam_policy Sets the IAM policy for the specified HL7v2 store. A
109109
single member will be assigned a single role. A member
110110
can be any of: - allUsers, that is, anyone -
111111
allAuthenticatedUsers, anyone authenticated with a
@@ -122,8 +122,7 @@ To run this sample:
122122
-h, --help show this help message and exit
123123
--project_id PROJECT_ID
124124
GCP project name
125-
--cloud_region CLOUD_REGION
126-
GCP region
125+
--location LOCATION GCP location
127126
--dataset_id DATASET_ID
128127
Name of dataset
129128
--hl7v2_store_id HL7V2_STORE_ID
@@ -152,8 +151,7 @@ To run this sample:
152151
153152
$ python hl7v2_messages.py
154153
155-
usage: hl7v2_messages.py [-h] [--project_id PROJECT_ID]
156-
[--cloud_region CLOUD_REGION]
154+
usage: hl7v2_messages.py [-h] [--project_id PROJECT_ID] [--location LOCATION]
157155
[--dataset_id DATASET_ID]
158156
[--hl7v2_store_id HL7V2_STORE_ID]
159157
[--hl7v2_message_file HL7V2_MESSAGE_FILE]
@@ -185,8 +183,7 @@ To run this sample:
185183
-h, --help show this help message and exit
186184
--project_id PROJECT_ID
187185
GCP project name
188-
--cloud_region CLOUD_REGION
189-
GCP region
186+
--location LOCATION GCP location
190187
--dataset_id DATASET_ID
191188
Name of dataset
192189
--hl7v2_store_id HL7V2_STORE_ID
@@ -219,4 +216,4 @@ to `browse the source`_ and `report issues`_.
219216
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
220217
221218
222-
.. _Google Cloud SDK: https://cloud.google.com/sdk/
219+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

healthcare/api-client/v1/hl7v2/hl7v2_messages.py

Lines changed: 137 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,37 @@
1313
# limitations under the License.
1414

1515
import argparse
16-
import json
1716
import os
1817

19-
from googleapiclient import discovery
20-
21-
22-
# [START healthcare_get_client]
23-
def get_client():
24-
"""Returns an authorized API client by discovering the Healthcare API and
25-
creating a service object using the service account credentials in the
26-
GOOGLE_APPLICATION_CREDENTIALS environment variable."""
27-
api_version = "v1"
28-
service_name = "healthcare"
29-
30-
return discovery.build(service_name, api_version)
31-
32-
33-
# [END healthcare_get_client]
34-
3518

3619
# [START healthcare_create_hl7v2_message]
3720
def create_hl7v2_message(
38-
project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file
21+
project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file
3922
):
4023
"""Creates an HL7v2 message and sends a notification to the
4124
Cloud Pub/Sub topic.
42-
"""
43-
client = get_client()
44-
hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region)
25+
26+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
27+
before running the sample."""
28+
# Imports the Google API Discovery Service.
29+
from googleapiclient import discovery
30+
31+
# Imports Python's built-in "json" module
32+
import json
33+
34+
api_version = "v1"
35+
service_name = "healthcare"
36+
# Returns an authorized API client by discovering the Healthcare API
37+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
38+
client = discovery.build(service_name, api_version)
39+
40+
# TODO(developer): Uncomment these lines and replace with your values.
41+
# project_id = 'my-project' # replace with your GCP project ID
42+
# location = 'us-central1' # replace with the parent dataset's location
43+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
44+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
45+
# hl7v2_message_file = 'hl7v2-message.json' # replace with the path to the HL7v2 file
46+
hl7v2_parent = "projects/{}/locations/{}".format(project_id, location)
4547
hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}".format(
4648
hl7v2_parent, dataset_id, hl7v2_store_id
4749
)
@@ -68,11 +70,28 @@ def create_hl7v2_message(
6870

6971
# [START healthcare_delete_hl7v2_message]
7072
def delete_hl7v2_message(
71-
project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id
73+
project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id
7274
):
73-
"""Deletes an HL7v2 message."""
74-
client = get_client()
75-
hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region)
75+
"""Deletes an HL7v2 message.
76+
77+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
78+
before running the sample."""
79+
# Imports the Google API Discovery Service.
80+
from googleapiclient import discovery
81+
82+
api_version = "v1"
83+
service_name = "healthcare"
84+
# Returns an authorized API client by discovering the Healthcare API
85+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
86+
client = discovery.build(service_name, api_version)
87+
88+
# TODO(developer): Uncomment these lines and replace with your values.
89+
# project_id = 'my-project' # replace with your GCP project ID
90+
# location = 'us-central1' # replace with the parent dataset's location
91+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
92+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
93+
# hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server
94+
hl7v2_parent = "projects/{}/locations/{}".format(project_id, location)
7695
hl7v2_message = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format(
7796
hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id
7897
)
@@ -96,11 +115,28 @@ def delete_hl7v2_message(
96115

97116
# [START healthcare_get_hl7v2_message]
98117
def get_hl7v2_message(
99-
project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_id
118+
project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_id
100119
):
101-
"""Gets an HL7v2 message."""
102-
client = get_client()
103-
hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region)
120+
"""Gets an HL7v2 message.
121+
122+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
123+
before running the sample."""
124+
# Imports the Google API Discovery Service.
125+
from googleapiclient import discovery
126+
127+
api_version = "v1"
128+
service_name = "healthcare"
129+
# Returns an authorized API client by discovering the Healthcare API
130+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
131+
client = discovery.build(service_name, api_version)
132+
133+
# TODO(developer): Uncomment these lines and replace with your values.
134+
# project_id = 'my-project' # replace with your GCP project ID
135+
# location = 'us-central1' # replace with the parent dataset's location
136+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
137+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
138+
# hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server
139+
hl7v2_parent = "projects/{}/locations/{}".format(project_id, location)
104140
hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format(
105141
hl7v2_parent, dataset_id, hl7v2_store_id, hl7v2_message_id
106142
)
@@ -130,14 +166,33 @@ def get_hl7v2_message(
130166

131167
# [START healthcare_ingest_hl7v2_message]
132168
def ingest_hl7v2_message(
133-
project_id, cloud_region, dataset_id, hl7v2_store_id, hl7v2_message_file
169+
project_id, location, dataset_id, hl7v2_store_id, hl7v2_message_file
134170
):
135171
"""Ingests a new HL7v2 message from the hospital and sends a notification
136172
to the Cloud Pub/Sub topic. Return is an HL7v2 ACK message if the message
137173
was successfully stored.
138-
"""
139-
client = get_client()
140-
hl7v2_parent = "projects/{}/locations/{}".format(project_id, cloud_region)
174+
175+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
176+
before running the sample."""
177+
# Imports the Google API Discovery Service.
178+
from googleapiclient import discovery
179+
180+
# Imports Python's built-in "json" module
181+
import json
182+
183+
api_version = "v1"
184+
service_name = "healthcare"
185+
# Returns an authorized API client by discovering the Healthcare API
186+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
187+
client = discovery.build(service_name, api_version)
188+
189+
# TODO(developer): Uncomment these lines and replace with your values.
190+
# project_id = 'my-project' # replace with your GCP project ID
191+
# location = 'us-central1' # replace with the parent dataset's location
192+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
193+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
194+
# hl7v2_message_file = 'hl7v2-message.json' # replace with the path to the HL7v2 file
195+
hl7v2_parent = "projects/{}/locations/{}".format(project_id, location)
141196
hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}".format(
142197
hl7v2_parent, dataset_id, hl7v2_store_id
143198
)
@@ -163,13 +218,28 @@ def ingest_hl7v2_message(
163218

164219

165220
# [START healthcare_list_hl7v2_messages]
166-
def list_hl7v2_messages(project_id, cloud_region, dataset_id, hl7v2_store_id):
221+
def list_hl7v2_messages(project_id, location, dataset_id, hl7v2_store_id):
167222
"""Lists all the messages in the given HL7v2 store with support for
168223
filtering.
169-
"""
170-
client = get_client()
224+
225+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
226+
before running the sample."""
227+
# Imports the Google API Discovery Service.
228+
from googleapiclient import discovery
229+
230+
api_version = "v1"
231+
service_name = "healthcare"
232+
# Returns an authorized API client by discovering the Healthcare API
233+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
234+
client = discovery.build(service_name, api_version)
235+
236+
# TODO(developer): Uncomment these lines and replace with your values.
237+
# project_id = 'my-project' # replace with your GCP project ID
238+
# location = 'us-central1' # replace with the parent dataset's location
239+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
240+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
171241
hl7v2_messages_parent = "projects/{}/locations/{}/datasets/{}".format(
172-
project_id, cloud_region, dataset_id
242+
project_id, location, dataset_id
173243
)
174244
hl7v2_message_path = "{}/hl7V2Stores/{}".format(
175245
hl7v2_messages_parent, hl7v2_store_id
@@ -198,18 +268,35 @@ def list_hl7v2_messages(project_id, cloud_region, dataset_id, hl7v2_store_id):
198268
# [START healthcare_patch_hl7v2_message]
199269
def patch_hl7v2_message(
200270
project_id,
201-
cloud_region,
271+
location,
202272
dataset_id,
203273
hl7v2_store_id,
204274
hl7v2_message_id,
205275
label_key,
206276
label_value,
207277
):
208-
"""Updates the message."""
209-
client = get_client()
210-
hl7v2_message_parent = "projects/{}/locations/{}".format(
211-
project_id, cloud_region
212-
)
278+
"""Updates the message.
279+
280+
See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/hl7v2
281+
before running the sample."""
282+
# Imports the Google API Discovery Service.
283+
from googleapiclient import discovery
284+
285+
api_version = "v1"
286+
service_name = "healthcare"
287+
# Returns an authorized API client by discovering the Healthcare API
288+
# and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
289+
client = discovery.build(service_name, api_version)
290+
291+
# TODO(developer): Uncomment these lines and replace with your values.
292+
# project_id = 'my-project' # replace with your GCP project ID
293+
# location = 'us-central1' # replace with the parent dataset's location
294+
# dataset_id = 'my-dataset' # replace with the HL7v2 store's parent dataset ID
295+
# hl7v2_store_id = 'my-hl7v2-store' # replace with the HL7v2 store's ID
296+
# hl7v2_message_id = '2yqbdhYHlk_ucSmWkcKOVm_N0p0OpBXgIlVG18rB-cw=' # replace with the HL7v2 message ID that was returned by the server
297+
# label_key = 'key1' # replace with a key
298+
# label_value = 'label2' # replace with a key value
299+
hl7v2_message_parent = "projects/{}/locations/{}".format(project_id, location)
213300
hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}".format(
214301
hl7v2_message_parent, dataset_id, hl7v2_store_id, hl7v2_message_id
215302
)
@@ -250,7 +337,7 @@ def parse_command_line_args():
250337
help="GCP project name",
251338
)
252339

253-
parser.add_argument("--cloud_region", default="us-central1", help="GCP region")
340+
parser.add_argument("--location", default="us-central1", help="GCP location")
254341

255342
parser.add_argument("--dataset_id", default=None, help="Name of dataset")
256343

@@ -302,7 +389,7 @@ def run_command(args):
302389
elif args.command == "create-hl7v2-message":
303390
create_hl7v2_message(
304391
args.project_id,
305-
args.cloud_region,
392+
args.location,
306393
args.dataset_id,
307394
args.hl7v2_store_id,
308395
args.hl7v2_message_file,
@@ -311,7 +398,7 @@ def run_command(args):
311398
elif args.command == "delete-hl7v2-message":
312399
delete_hl7v2_message(
313400
args.project_id,
314-
args.cloud_region,
401+
args.location,
315402
args.dataset_id,
316403
args.hl7v2_store_id,
317404
args.hl7v2_message_id,
@@ -320,7 +407,7 @@ def run_command(args):
320407
elif args.command == "get-hl7v2-message":
321408
get_hl7v2_message(
322409
args.project_id,
323-
args.cloud_region,
410+
args.location,
324411
args.dataset_id,
325412
args.hl7v2_store_id,
326413
args.hl7v2_message_id,
@@ -329,21 +416,21 @@ def run_command(args):
329416
elif args.command == "ingest-hl7v2-message":
330417
ingest_hl7v2_message(
331418
args.project_id,
332-
args.cloud_region,
419+
args.location,
333420
args.dataset_id,
334421
args.hl7v2_store_id,
335422
args.hl7v2_message_file,
336423
)
337424

338425
elif args.command == "list-hl7v2-messages":
339426
list_hl7v2_messages(
340-
args.project_id, args.cloud_region, args.dataset_id, args.hl7v2_store_id
427+
args.project_id, args.location, args.dataset_id, args.hl7v2_store_id
341428
)
342429

343430
elif args.command == "patch-hl7v2-message":
344431
patch_hl7v2_message(
345432
args.project_id,
346-
args.cloud_region,
433+
args.location,
347434
args.dataset_id,
348435
args.hl7v2_store_id,
349436
args.hl7v2_message_id,

0 commit comments

Comments
 (0)