Skip to content

Commit 564a221

Browse files
noerogengelke
authored andcommitted
Update export FHIR store to use GCS bucket. (#1803)
* Update export FHIR store to use GCS bucket. * Fixed import/export methods
1 parent eccb52e commit 564a221

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

healthcare/api-client/fhir/fhir_stores.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def patch_fhir_store(
202202
# [END healthcare_patch_fhir_store]
203203

204204

205-
# [START healthcare_export_fhir_resource]
206-
def export_fhir_resource(
205+
# [START healthcare_export_fhir_store_gcs]
206+
def export_fhir_store_gcs(
207207
service_account_json,
208208
api_key,
209209
project_id,
210210
cloud_region,
211211
dataset_id,
212212
fhir_store_id,
213-
uri_prefix):
213+
gcs_uri):
214214
"""Export resources to a Google Cloud Storage bucket by copying
215215
them from the FHIR store."""
216216
client = get_client(service_account_json, api_key)
@@ -220,12 +220,9 @@ def export_fhir_resource(
220220
fhir_store_parent, fhir_store_id)
221221

222222
body = {
223-
"outputConfig":
223+
"gcsDestinationLocation":
224224
{
225-
"gcsDestination":
226-
{
227-
"uriPrefix": 'gs://{}'.format(uri_prefix)
228-
}
225+
"gcsUri": 'gs://{}'.format(gcs_uri)
229226
}
230227
}
231228

@@ -234,23 +231,23 @@ def export_fhir_resource(
234231

235232
try:
236233
response = request.execute()
237-
print('Exported FHIR resources to bucket: gs://{}'.format(uri_prefix))
234+
print('Exported FHIR resources to bucket: gs://{}'.format(gcs_uri))
238235
return response
239236
except HttpError as e:
240237
print('Error, FHIR resources not exported: {}'.format(e))
241238
return ""
242-
# [END healthcare_export_fhir_resource]
239+
# [END healthcare_export_fhir_store_gcs]
243240

244241

245-
# [START healthcare_import_fhir_resource]
246-
def import_fhir_resource(
242+
# [START healthcare_import_fhir_store]
243+
def import_fhir_store(
247244
service_account_json,
248245
api_key,
249246
project_id,
250247
cloud_region,
251248
dataset_id,
252249
fhir_store_id,
253-
content_uri):
250+
gcs_uri):
254251
"""Import resources into the FHIR store by copying them from the
255252
specified source.
256253
"""
@@ -261,12 +258,13 @@ def import_fhir_resource(
261258
fhir_store_parent, fhir_store_id)
262259

263260
body = {
264-
"inputConfig":
261+
"gcsSourceLocation":
265262
{
266-
"gcsSource":
267-
{
268-
"contentUri": 'gs://{}'.format(content_uri)
269-
}
263+
"gcsUri": 'gs://{}'.format(gcs_uri)
264+
},
265+
"gcsErrorLocation":
266+
{
267+
"gcsUri": 'gs://{}/errors'.format(gcs_uri)
270268
}
271269
}
272270

@@ -277,12 +275,12 @@ def import_fhir_resource(
277275

278276
try:
279277
response = request.execute()
280-
print('Imported FHIR resources: {}'.format(content_uri))
278+
print('Imported FHIR resources: {}'.format(gcs_uri))
281279
return response
282280
except HttpError as e:
283281
print('Error, FHIR resources not imported: {}'.format(e))
284282
return ""
285-
# [END healthcare_import_fhir_resource]
283+
# [END healthcare_import_fhir_store]
286284

287285

288286
def parse_command_line_args():
@@ -329,16 +327,11 @@ def parse_command_line_args():
329327
'are published')
330328

331329
parser.add_argument(
332-
'--uri_prefix',
333-
default=None,
334-
help='URI for a Google Cloud Storage directory to which result files'
335-
'should be written (e.g., "bucket-id/path/to/destination/dir").')
336-
337-
parser.add_argument(
338-
'--content_uri',
330+
'--gcs_uri',
339331
default=None,
340332
help='URI for a Google Cloud Storage directory from which files'
341-
'should be imported (e.g., "bucket-id/path/to/destination/dir").')
333+
'should be import or to which result files'
334+
'should be written (e.g., "bucket-id/path/to/destination/dir").')
342335

343336
command = parser.add_subparsers(dest='command')
344337

@@ -348,11 +341,11 @@ def parse_command_line_args():
348341
command.add_parser('list-fhir-stores', help=list_fhir_stores.__doc__)
349342
command.add_parser('patch-fhir-store', help=patch_fhir_store.__doc__)
350343
command.add_parser(
351-
'export-fhir-resource',
352-
help=import_fhir_resource.__doc__)
344+
'import-fhir-store',
345+
help=import_fhir_store.__doc__)
353346
command.add_parser(
354-
'import-fhir-resource',
355-
help=export_fhir_resource.__doc__)
347+
'export-fhir-store-gcs',
348+
help=export_fhir_store_gcs.__doc__)
356349

357350
return parser.parse_args()
358351

@@ -409,25 +402,25 @@ def run_command(args):
409402
args.fhir_store_id,
410403
args.pubsub_topic)
411404

412-
elif args.command == 'export-fhir-resource':
413-
patch_fhir_store(
405+
elif args.command == 'export-fhir-store-gcs':
406+
export_fhir_store_gcs(
414407
args.service_account_json,
415408
args.api_key,
416409
args.project_id,
417410
args.cloud_region,
418411
args.dataset_id,
419412
args.fhir_store_id,
420-
args.uri_prefix)
413+
args.gcs_uri)
421414

422-
elif args.command == 'import-fhir-resource':
423-
patch_fhir_store(
415+
elif args.command == 'import-fhir-store':
416+
import_fhir_store(
424417
args.service_account_json,
425418
args.api_key,
426419
args.project_id,
427420
args.cloud_region,
428421
args.dataset_id,
429422
args.fhir_store_id,
430-
args.content_uri)
423+
args.gcs_uri)
431424

432425

433426
def main():

0 commit comments

Comments
 (0)