13
13
# limitations under the License.
14
14
15
15
import argparse
16
- import json
17
16
import os
18
17
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
-
35
18
36
19
# [START healthcare_create_hl7v2_message]
37
20
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
39
22
):
40
23
"""Creates an HL7v2 message and sends a notification to the
41
24
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 )
45
47
hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}" .format (
46
48
hl7v2_parent , dataset_id , hl7v2_store_id
47
49
)
@@ -68,11 +70,28 @@ def create_hl7v2_message(
68
70
69
71
# [START healthcare_delete_hl7v2_message]
70
72
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
72
74
):
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 )
76
95
hl7v2_message = "{}/datasets/{}/hl7V2Stores/{}/messages/{}" .format (
77
96
hl7v2_parent , dataset_id , hl7v2_store_id , hl7v2_message_id
78
97
)
@@ -96,11 +115,28 @@ def delete_hl7v2_message(
96
115
97
116
# [START healthcare_get_hl7v2_message]
98
117
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
100
119
):
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 )
104
140
hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}" .format (
105
141
hl7v2_parent , dataset_id , hl7v2_store_id , hl7v2_message_id
106
142
)
@@ -130,14 +166,33 @@ def get_hl7v2_message(
130
166
131
167
# [START healthcare_ingest_hl7v2_message]
132
168
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
134
170
):
135
171
"""Ingests a new HL7v2 message from the hospital and sends a notification
136
172
to the Cloud Pub/Sub topic. Return is an HL7v2 ACK message if the message
137
173
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 )
141
196
hl7v2_store_name = "{}/datasets/{}/hl7V2Stores/{}" .format (
142
197
hl7v2_parent , dataset_id , hl7v2_store_id
143
198
)
@@ -163,13 +218,28 @@ def ingest_hl7v2_message(
163
218
164
219
165
220
# [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 ):
167
222
"""Lists all the messages in the given HL7v2 store with support for
168
223
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
171
241
hl7v2_messages_parent = "projects/{}/locations/{}/datasets/{}" .format (
172
- project_id , cloud_region , dataset_id
242
+ project_id , location , dataset_id
173
243
)
174
244
hl7v2_message_path = "{}/hl7V2Stores/{}" .format (
175
245
hl7v2_messages_parent , hl7v2_store_id
@@ -198,18 +268,35 @@ def list_hl7v2_messages(project_id, cloud_region, dataset_id, hl7v2_store_id):
198
268
# [START healthcare_patch_hl7v2_message]
199
269
def patch_hl7v2_message (
200
270
project_id ,
201
- cloud_region ,
271
+ location ,
202
272
dataset_id ,
203
273
hl7v2_store_id ,
204
274
hl7v2_message_id ,
205
275
label_key ,
206
276
label_value ,
207
277
):
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 )
213
300
hl7v2_message_name = "{}/datasets/{}/hl7V2Stores/{}/messages/{}" .format (
214
301
hl7v2_message_parent , dataset_id , hl7v2_store_id , hl7v2_message_id
215
302
)
@@ -250,7 +337,7 @@ def parse_command_line_args():
250
337
help = "GCP project name" ,
251
338
)
252
339
253
- parser .add_argument ("--cloud_region " , default = "us-central1" , help = "GCP region " )
340
+ parser .add_argument ("--location " , default = "us-central1" , help = "GCP location " )
254
341
255
342
parser .add_argument ("--dataset_id" , default = None , help = "Name of dataset" )
256
343
@@ -302,7 +389,7 @@ def run_command(args):
302
389
elif args .command == "create-hl7v2-message" :
303
390
create_hl7v2_message (
304
391
args .project_id ,
305
- args .cloud_region ,
392
+ args .location ,
306
393
args .dataset_id ,
307
394
args .hl7v2_store_id ,
308
395
args .hl7v2_message_file ,
@@ -311,7 +398,7 @@ def run_command(args):
311
398
elif args .command == "delete-hl7v2-message" :
312
399
delete_hl7v2_message (
313
400
args .project_id ,
314
- args .cloud_region ,
401
+ args .location ,
315
402
args .dataset_id ,
316
403
args .hl7v2_store_id ,
317
404
args .hl7v2_message_id ,
@@ -320,7 +407,7 @@ def run_command(args):
320
407
elif args .command == "get-hl7v2-message" :
321
408
get_hl7v2_message (
322
409
args .project_id ,
323
- args .cloud_region ,
410
+ args .location ,
324
411
args .dataset_id ,
325
412
args .hl7v2_store_id ,
326
413
args .hl7v2_message_id ,
@@ -329,21 +416,21 @@ def run_command(args):
329
416
elif args .command == "ingest-hl7v2-message" :
330
417
ingest_hl7v2_message (
331
418
args .project_id ,
332
- args .cloud_region ,
419
+ args .location ,
333
420
args .dataset_id ,
334
421
args .hl7v2_store_id ,
335
422
args .hl7v2_message_file ,
336
423
)
337
424
338
425
elif args .command == "list-hl7v2-messages" :
339
426
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
341
428
)
342
429
343
430
elif args .command == "patch-hl7v2-message" :
344
431
patch_hl7v2_message (
345
432
args .project_id ,
346
- args .cloud_region ,
433
+ args .location ,
347
434
args .dataset_id ,
348
435
args .hl7v2_store_id ,
349
436
args .hl7v2_message_id ,
0 commit comments