【问题标题】:python script to move a file from GCP cloud storage to FHIR store regularlypython脚本定期将文件从GCP云存储移动到FHIR存储
【发布时间】:2022-10-20 15:05:02
【问题描述】:

我正在尝试使用 python 脚本定期将文件从 GCP 云存储移动到 FHIR 存储。 我正在寻找一个选项: 1>云功能 2>使用 cron 作业调度的原始 python 脚本

非常感谢任何支持。

【问题讨论】:

  • 不要要求他人编写或提供代码。 Stack Overflow 不是代码编写服务。对于某些问题,答案中可能包含代码。请阅读本指南:stackoverflow.com/help/how-to-ask

标签: python-3.x google-cloud-platform google-cloud-storage


【解决方案1】:

我尝试了您的用例,并通过在 GCP 中使用 Cloud FunctionsCloud StorageCloud SchedulerCloud Healthcare API 服务,成功地将文件从云存储移动到 FHIR 存储。

Cloud Function 中,我使用了官方文档中的这个sample code 进行导入高频头来自云存储的资源。只需确保您已安装 dependencies 即可运行代码示例。下面是我的 Cloud Functions 上的示例代码。 (笔记我使用云功能default service account)

主文件

def hello_world(request):
  # Imports the Google API Discovery Service.
  from googleapiclient import discovery

  api_version = "v1"
  service_name = "healthcare"
  # Instantiates 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 = 'xxxx-xxxxx-'  # replace with your GCP project ID
  location = 'us-central1'  # replace with the parent dataset's location
  dataset_id = 'xxxxx-xxxxx'  # replace with the parent dataset's ID
  fhir_store_id = 'xxxx-xxxx'  # replace with the FHIR store ID
  gcs_uri = 'xxxx-xxxxx'  # replace with a Cloud Storage bucket
  fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
      project_id, location, dataset_id
  )
  fhir_store_name = "{}/fhirStores/{}".format(fhir_store_parent, fhir_store_id)

  body = {
      "contentStructure": "CONTENT_STRUCTURE_UNSPECIFIED",
      "gcsSource": {"uri": "gs://{}".format(gcs_uri)},
  }

  # Escape "import()" method keyword because "import"
  # is a reserved keyword in Python
  request = (
      client.projects()
      .locations()
      .datasets()
      .fhirStores()
      .import_(name=fhir_store_name, body=body)
  )

  response = request.execute()
  print("Imported FHIR resources: {}".format(gcs_uri))

  print(response)
  return response

要求.txt

google-api-python-client==2.47.0
google-auth-httplib2==0.1.0
google-auth==2.6.2
google-cloud==0.34.0
google-cloud-storage==2.0.0; python_version < '3.7'
google-cloud-storage==2.1.0; python_version > '3.6'

然后按照这个link 创建一个Cloud Scheduler 作业。这取决于你将如何schedule your job。请注意选择HTTP作为目标类型然后粘贴触发网址您的云功能并选择得到HTTP 方法。

可以看到导入是否成功医疗保健页面 -> 数据集 -> 操作选项卡.

样本输出:

【讨论】:

    【解决方案2】:

    是否可以定期将 apk 文件从 gcp 传输到 firebase app distrib

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2020-10-14
      • 2023-01-18
      • 1970-01-01
      • 2021-01-04
      • 2022-06-10
      • 1970-01-01
      • 2017-08-18
      • 2019-09-22
      相关资源
      最近更新 更多