使用 Google Cloud CLI 存储医疗保健数据

本页面介绍如何使用 Cloud Healthcare API 和 Google Cloud CLI 来完成以下任务:

  1. 创建 Cloud Healthcare API 数据集。
  2. 在数据集内创建以下数据存储区之一:
    • 医学数字图像和通信 (DICOM) 存储区
    • 快速医疗互操作性资源 (FHIR) 存储区
    • Health Level Seven International 版本 2 (HL7v2) 存储区
  3. 存储 DICOM、FHIR 和 HL7v2 数据,并查看 DICOM 元数据。

如果您只想使用一种数据存储区,则可在完成准备工作以及创建数据集中的步骤后,直接跳到快速入门的相应部分。

准备工作

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

  3. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  4. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  5. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Cloud Healthcare API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable healthcare.googleapis.com
  8. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/healthcare.datasetAdmin, roles/healthcare.fhirStoreAdmin, roles/healthcare.dicomStoreAdmin, roles/healthcare.hl7V2StoreAdmin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

    Replace the following:

    • PROJECT_ID: your project ID.
    • USER_IDENTIFIER: the identifier for your user account—for example, myemail@example.com.
    • ROLE: the IAM role that you grant to your user account.
  9. Install the Google Cloud CLI.

  10. 如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI

  11. 如需初始化 gcloud CLI,请运行以下命令:

    gcloud init
  12. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  13. Verify that billing is enabled for your Google Cloud project.

  14. Enable the Cloud Healthcare API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable healthcare.googleapis.com
  15. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/healthcare.datasetAdmin, roles/healthcare.fhirStoreAdmin, roles/healthcare.dicomStoreAdmin, roles/healthcare.hl7V2StoreAdmin

    gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

    Replace the following:

    • PROJECT_ID: your project ID.
    • USER_IDENTIFIER: the identifier for your user account—for example, myemail@example.com.
    • ROLE: the IAM role that you grant to your user account.
  16. 创建数据集

    数据集包含数据存储区,数据存储区包含医疗保健数据。 要使用 Cloud Healthcare API,您必须至少创建一个数据集。

    以下示例展示了如何在 us-central1 区域中创建名为 my-dataset 的数据集。在本快速入门中,您将使用该数据集来创建 DICOM 存储区、FHIR 存储区和 HL7v2 存储区。

    gcloud

    使用 gcloud healthcare datasets create 命令创建数据集。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare datasets create my-dataset \
      --project=PROJECT_ID \
      --location=us-central1

    Windows (PowerShell)

    gcloud healthcare datasets create my-dataset `
      --project=PROJECT_ID `
      --location=us-central1

    Windows (cmd.exe)

    gcloud healthcare datasets create my-dataset ^
      --project=PROJECT_ID ^
      --location=us-central1

    您应该会收到类似如下所示的响应:

    响应

    Create request issued for: [my-dataset]
    Created dataset [my-dataset].
    

    如需完成本快速入门,请从以下部分中选择一个:

    存储和查看 DICOM 实例

    本部分介绍了如何完成以下任务:

    1. 创建 DICOM 存储区。
    2. 将 DICOM 实例从公共 Cloud Storage 存储桶导入 DICOM 存储区。
    3. 查看 DICOM 实例的元数据。

    Cloud Healthcare API 实现了 DICOMweb 标准,用于存储和访问医学成像数据。

    创建 DICOM 存储区

    DICOM 存储区位于数据集内,包含 DICOM 实例。以下示例展示了如何创建名为 my-dicom-store 的 DICOM 存储区。

    gcloud

    使用 gcloud healthcare dicom-stores create 命令创建 DICOM 存储区。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare dicom-stores create my-dicom-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1

    Windows (PowerShell)

    gcloud healthcare dicom-stores create my-dicom-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1

    Windows (cmd.exe)

    gcloud healthcare dicom-stores create my-dicom-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1

    您应该会收到类似如下所示的响应:

    响应

    Created dicomStore [my-dicom-store].

    导入 DICOM 实例

    gs://gcs-public-data--healthcare-nih-chest-xray Cloud Storage 存储桶中提供了示例 DICOM 数据。

    gcloud

    使用 gcloud healthcare dicom-stores import 命令导入 gs://gcs-public-data--healthcare-nih-chest-xray/dicom/00000001_000.dcm 实例。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare dicom-stores import gcs my-dicom-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1 \
      --gcs-uri=gs://gcs-public-data--healthcare-nih-chest-xray/dicom/00000001_000.dcm

    Windows (PowerShell)

    gcloud healthcare dicom-stores import gcs my-dicom-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1 `
      --gcs-uri=gs://gcs-public-data--healthcare-nih-chest-xray/dicom/00000001_000.dcm

    Windows (cmd.exe)

    gcloud healthcare dicom-stores import gcs my-dicom-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1 ^
      --gcs-uri=gs://gcs-public-data--healthcare-nih-chest-xray/dicom/00000001_000.dcm

    在此输出中:

    • PROJECT_IDus-central1my-datasetmy-dicom-store:运行命令时您提供的值
    • OPERATION_ID:您导入 DICOM 实例时,Cloud Healthcare API 提供的长时间运行的操作的标识符。如果方法调用可能需要很长时间才能完成,系统就会返回长时间运行的操作。导入一个 DICOM 实例通常是一项快速操作,因此输出几乎会立即返回。

    响应

    Request issued for: [my-dicom-store]
    Waiting for operation [projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID] to complete...done.
    name: projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store
    

    查看 DICOM 实例元数据

    gcloud CLI 不支持 DICOMweb 事务,例如查看或检索实例。您可以改用 Google 的 DICOMweb 命令行工具,该工具使用 Python 运行。如需了解如何在 Google Cloud上设置 Python,请参阅设置 Python 开发环境

    完成以下步骤,使用 DICOMweb 命令行工具查看 DICOM 实例元数据:

    1. 使用 Pip 安装 DICOMweb 命令行工具:

      pip install https://github.com/GoogleCloudPlatform/healthcare-api-dicomweb-cli/archive/v1.0.zip
      
    2. 更新 PATH 变量以包括 dcmweb 安装位置:

      export PATH="$HOME/bin:$PATH"
      
    3. 查看 DICOM 实例的元数据:

      dcmweb \
        https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb \
        search instances

      PROJECT_ID 替换为您在准备工作中创建或选择的 Google Cloud 项目的 ID。

      输出如下所示。如需了解输出中的字段,请参阅 SOP 通用模块的属性

      [
        {
          "00080016": {
            "Value": [
              "1.2.840.10008.5.1.4.1.1.7"
            ],
            "vr": "UI"
          },
          "00080018": {
            "Value": [
              "1.3.6.1.4.1.11129.5.5.153751009835107614666834563294684339746480"
            ],
            "vr": "UI"
          },
          "00080060": {
            "Value": [
              "DX"
            ],
            "vr": "CS"
          },
          "00100020": {
            "Value": [
              "1"
            ],
            "vr": "LO"
          },
          "00100040": {
            "Value": [
              "M"
            ],
            "vr": "CS"
          },
          "0020000D": {
            "Value": [
              "1.3.6.1.4.1.11129.5.5.111396399361969898205364400549799252857604"
            ],
            "vr": "UI"
          },
          "0020000E": {
            "Value": [
              "1.3.6.1.4.1.11129.5.5.195628213694300498946760767481291263511724"
            ],
            "vr": "UI"
          },
          "00280010": {
            "Value": [
              1024
            ],
            "vr": "US"
          },
          "00280011": {
            "Value": [
              1024
            ],
            "vr": "US"
          },
          "00280100": {
            "Value": [
              8
            ],
            "vr": "US"
          }
        }
      ]
      

    将 DICOM 实例导入 Cloud Healthcare API 并查看其元数据后,请继续清理,以避免因本页中使用的资源导致您的 Google Cloud 账号产生费用。

    如需了解后续步骤(例如如何使用 Cloud Healthcare API 中的 DICOMweb 标准搜索或检索 DICOM 映像),请参阅后续步骤

    存储 FHIR 资源

    本部分介绍了如何完成以下任务:

    1. 创建 FHIR 存储区。
    2. 将 FHIR 资源从公共 Cloud Storage 存储桶导入 FHIR 存储区。

    创建 FHIR 存储区

    FHIR 存储区位于数据集内,包含 FHIR 资源。以下示例展示了如何创建名为 my-fhir-store 且使用 FHIR 版本 R4 的 FHIR 存储区。

    gcloud

    使用 gcloud healthcare fhir-stores create 命令创建 FHIR 存储区。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare fhir-stores create my-fhir-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1 \
      --version=R4

    Windows (PowerShell)

    gcloud healthcare fhir-stores create my-fhir-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1 `
      --version=R4

    Windows (cmd.exe)

    gcloud healthcare fhir-stores create my-fhir-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1 ^
      --version=R4

    您应该会收到类似如下所示的响应:

    响应

    Created fhirStore [my-fhir-store].

    导入 FHIR 资源

    gs://gcp-public-data--synthea-fhir-data-10-patients Cloud Storage 存储桶中提供了示例 FHIR 数据。

    gcloud

    使用 gcloud healthcare fhir-stores import 命令导入 gs://gcp-public-data--synthea-fhir-data-10-patients 中的 FHIR 资源。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare fhir-stores import gcs my-fhir-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1 \
      --gcs-uri=gs://gcp-public-data--synthea-fhir-data-10-patients/fhir_r4_ndjson/*.ndjson \
      --content-structure=RESOURCE

    Windows (PowerShell)

    gcloud healthcare fhir-stores import gcs my-fhir-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1 `
      --gcs-uri=gs://gcp-public-data--synthea-fhir-data-10-patients/fhir_r4_ndjson/*.ndjson `
      --content-structure=RESOURCE

    Windows (cmd.exe)

    gcloud healthcare fhir-stores import gcs my-fhir-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1 ^
      --gcs-uri=gs://gcp-public-data--synthea-fhir-data-10-patients/fhir_r4_ndjson/*.ndjson ^
      --content-structure=RESOURCE

    在此输出中:

    • PROJECT_IDus-central1my-datasetmy-fhir-store:运行命令时您提供的值
    • OPERATION_ID:导入 FHIR 资源时,Cloud Healthcare API 提供的长时间运行的操作的标识符。如果方法调用可能需要很长时间才能完成,系统就会返回长时间运行的操作。导入 FHIR 资源大约需要一到两分钟。
    • R4:FHIR 存储区版本

    响应

    Request issued for: [my-fhir-store]
    Waiting for operation [projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID] to complete...done.
    name: projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store
    version: R4
    

    将 FHIR 资源导入 Cloud Healthcare API 后,请继续清理,以避免因本页面中使用的资源导致您的 Google Cloud 账号产生费用。

    如需了解后续步骤(例如如何查看和搜索 FHIR 资源),请参阅后续步骤

    存储 HL7v2 消息

    本部分介绍了如何完成以下任务:

    1. 创建 HL7v2 存储区
    2. 将 HL7v2 消息从公共 Cloud Storage 存储桶导入到 HL7v2 存储区。

    Cloud Healthcare API 中的 HL7v2 实现符合 HL7v2 标准

    创建 HL7v2 存储区

    HL7v2 存储区位于数据集内,其中包含 HL7v2 消息。以下示例展示了如何创建名为 my-hl7v2-store 的 HL7v2 存储区。

    gcloud

    使用 gcloud healthcare hl7v2-stores create 命令创建 HL7v2 存储区。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare hl7v2-stores create my-hl7v2-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1

    Windows (PowerShell)

    gcloud healthcare hl7v2-stores create my-hl7v2-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1

    Windows (cmd.exe)

    gcloud healthcare hl7v2-stores create my-hl7v2-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1

    您应该会收到类似如下所示的响应:

    响应

    Created hl7v2Store [my-hl7v2-store].

    导入 HL7v2 消息

    gcloud

    使用 gcloud healthcare hl7v2-stores import 命令导入 gs://cloud-samples-data/healthcare/hl7v2/messages.ndjson HL7v2 消息。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare hl7v2-stores import gcs my-hl7v2-store \
      --project=PROJECT_ID \
      --dataset=my-dataset \
      --location=us-central1 \
      --gcs-uri=gs://cloud-samples-data/healthcare/hl7v2/messages.ndjson

    Windows (PowerShell)

    gcloud healthcare hl7v2-stores import gcs my-hl7v2-store `
      --project=PROJECT_ID `
      --dataset=my-dataset `
      --location=us-central1 `
      --gcs-uri=gs://cloud-samples-data/healthcare/hl7v2/messages.ndjson

    Windows (cmd.exe)

    gcloud healthcare hl7v2-stores import gcs my-hl7v2-store ^
      --project=PROJECT_ID ^
      --dataset=my-dataset ^
      --location=us-central1 ^
      --gcs-uri=gs://cloud-samples-data/healthcare/hl7v2/messages.ndjson

    在此输出中:

    • PROJECT_IDus-central1my-datasetmy-hl7v2-store:运行命令时您提供的值
    • OPERATION_ID:您导入 HL7v2 消息时,Cloud Healthcare API 提供的长时间运行的操作的标识符。如果方法调用可能需要很长时间才能完成,系统就会返回长时间运行的操作。导入一条 HL7v2 消息通常是一项快速操作,因此输出几乎会立即返回。

    响应

    Request issued for: [my-hl7v2-store]
    Waiting for operation [projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID] to complete...done.
    name: projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store
    

    将 HL7v2 消息导入 Cloud Healthcare API 后,请继续清理,以避免因本页面中使用的资源导致您的 Google Cloud 账号产生费用。

    如需了解后续步骤(例如如何查看 HL7v2 消息的内容),请参阅后续步骤

    清理

    为避免因本页面中使用的资源导致您的 Google Cloud 账号产生费用,请删除包含这些资源的 Google Cloud 项目。

    如果您为此快速入门创建了新项目,请按照删除项目中的步骤操作。否则,请按照删除数据集中的步骤操作。

    Optional: Revoke credentials from the gcloud CLI.

    gcloud auth revoke

    删除项目

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    删除数据集

    如果您不再需要在本快速入门中创建的数据集,可以将其删除。删除数据集会永久删除该数据集以及其中包含的任何 FHIR、HL7v2 或 DICOM 存储区。

    gcloud

    使用 gcloud healthcare datasets delete 命令删除数据集。

    在使用下面的命令数据之前,请先进行以下替换:

    • PROJECT_ID:您在准备工作中创建或选择的 Google Cloud 项目的 ID

    执行以下命令:

    Linux、macOS 或 Cloud Shell

    gcloud healthcare datasets delete my-dataset \
      --project=PROJECT_ID \
      --location=us-central1

    Windows (PowerShell)

    gcloud healthcare datasets delete my-dataset `
      --project=PROJECT_ID `
      --location=us-central1

    Windows (cmd.exe)

    gcloud healthcare datasets delete my-dataset ^
      --project=PROJECT_ID ^
      --location=us-central1
    如需确认,请输入 Y。您应该会收到类似如下所示的响应。

    响应

    You are about to delete dataset [my-dataset]
    
    Do you want to continue (Y/n)?  Y
    
    Deleted dataset [my-dataset].
    

    结果怎么样?

    后续步骤

    如需了解有关 Cloud Healthcare API 的一般信息以及如何使用其他界面执行本快速入门中的任务,请参阅以下部分:

    DICOM

    如需了解 Cloud Healthcare API 如何实现 DICOMweb 标准,请参阅 DICOM 一致性声明

    FHIR

    如需了解 Cloud Healthcare API 如何实现 FHIR 标准,请参阅 FHIR 一致性声明

    HL7v2