快速入门:使用 curl 或 PowerShell

本页面介绍了如何将 Cloud Healthcare API 与 curl 或 Windows PowerShell 搭配使用来完成以下任务:

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

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

准备工作

  1. 登录您的 Google Cloud 帐号。如果您是 Google Cloud 新手,请创建一个帐号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. 在 Google Cloud Console 的项目选择器页面上,选择或创建一个 Google Cloud 项目。

    转到“项目选择器”

  3. 确保您的 Cloud 项目已启用结算功能。 了解如何确认您的项目是否已启用结算功能

  4. 启用 Cloud Healthcare API。

    启用 API

  5. 安装并初始化 Cloud SDK
  6. 使用 gcloud 命令行工具测试您的身份验证环境。检查以下命令是否输出无错误的文本字符串:
    gcloud auth application-default print-access-token

提示:需要命令提示符?您可以使用 Google Cloud Shell。Cloud Shell 命令行环境已经包含 Cloud SDK,因此您无需再进行安装。(Compute Engine 虚拟机也预安装了 Cloud SDK。)

创建数据集

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

使用 datasets.create 方法创建数据集:

curl

curl -X POST \
    --data "" \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets?datasetId=my-dataset"

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

响应如下所示。响应包含长时间运行的操作的标识符。当方法调用可能需要大量时间才能完成时,会返回长时间运行的操作。

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID",
}

在此输出中:

  • PROJECT_IDus-central1my-dataset:您在方法调用中提供的值
  • OPERATION_ID:Cloud Healthcare API 提供的长时间运行的操作的标识符

要跟踪操作的状态,请使用 operations.get 方法:

curl -X GET \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID"

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • OPERATION_ID:从长时间运行的操作返回的 ID

输出如下所示。如果响应包含 "done": true,则表示操作已完成。否则表示操作仍在运行;请等待几秒钟,然后再次调用 operations.get 方法。

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.CreateDataset",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME",
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset"
  }
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets?datasetId=my-dataset" | Select-Object -Expand Content

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

响应如下所示。响应包含长时间运行的操作的标识符。当方法调用可能需要大量时间才能完成时,会返回长时间运行的操作。

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID",
}

在此输出中:

  • PROJECT_IDus-central1my-dataset:您在方法调用中提供的值
  • OPERATION_ID:Cloud Healthcare API 提供的长时间运行的操作的标识符

要跟踪操作的状态,请使用 operations.get 方法:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID" | Select-Object -Expand Content

替换以下内容:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • OPERATION_ID:从长时间运行的操作返回的 ID

输出如下所示。如果响应包含 "done": true,则表示操作已完成。否则表示操作仍在运行;请等待几秒钟,然后再次调用 operations.get 方法。

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.CreateDataset",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME",
    "logsUrl": "https://console.cloud.google.com/logs/viewer/CLOUD_LOGGING_URL"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset"
  }
}

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

存储和查看 DICOM 实例

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

  1. 创建 DICOM 存储区。
  2. 将 DICOM 实例存储在 DICOM 存储区中。
  3. 查看 DICOM 实例的元数据。

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

创建 DICOM 存储区

DICOM 存储区位于数据集内,用于存储 DICOM 实例。使用 dicomStores.create 方法创建 DICOM 存储区:

curl

curl -X POST \
    --data "" \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores?dicomStoreId=my-dicom-store"

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store"
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores?dicomStoreId=my-dicom-store" | Select-Object -Expand Content

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store"
}

存储 DICOM 实例

  1. 示例 DICOM 实例文件下载到您的机器。该文件包含去标识化的患者 X 光片。

    curl

    curl -O https://cloud.google.com/healthcare/docs/resources/dicom_00000001_000.dcm
    

    PowerShell

    Invoke-WebRequest -Uri "https://cloud.google.com/healthcare/docs/resources/dicom_00000001_000.dcm" -OutFile $pwd/dicom_00000001_000.dcm
    
  2. 使用 dicomStores.storeInstances 方法存储 DICOM 实例。本快速入门假定您从下载 DICOM 实例的同一目录中运行该命令。

    curl

    curl -X POST \
        -H "Content-Type: application/dicom" \
        -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
        --data-binary @dicom_00000001_000.dcm \
        https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies
    

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

    输出如下所示(采用 XML 格式):

    <NativeDicomModel>
      <DicomAttribute tag="00081190" vr="UR" keyword="RetrieveURL">
        <Value number="1">https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies/1.3.6.1.4.1.11129.5.5.111396399361969898205364400549799252857604</Value>
      </DicomAttribute>
      <DicomAttribute tag="00081199" vr="SQ" keyword="ReferencedSOPSequence">
        <Item number="1">
          <DicomAttribute tag="00081150" vr="UI" keyword="ReferencedSOPClassUID">
            <Value number="1">1.2.840.10008.5.1.4.1.1.7</Value>
          </DicomAttribute>
          <DicomAttribute tag="00081155" vr="UI" keyword="ReferencedSOPInstanceUID">
            <Value number="1">1.3.6.1.4.1.11129.5.5.153751009835107614666834563294684339746480</Value>
          </DicomAttribute>
          <DicomAttribute tag="00081190" vr="UR" keyword="RetrieveURL">
            <Value number="1">https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies/1.3.6.1.4.1.11129.5.5.111396399361969898205364400549799252857604/series/1.3.6.1.4.1.11129.5.5.195628213694300498946760767481291263511724/instances/1.3.6.1.4.1.11129.5.5.153751009835107614666834563294684339746480</Value>
          </DicomAttribute>
        </Item>
      </DicomAttribute>
    </NativeDicomModel>
    

    PowerShell

    $cred = gcloud auth application-default print-access-token
    $headers = @{ Authorization = "Bearer $cred" }
    
    Invoke-WebRequest `
      -Method Post `
      -Headers $headers `
      -ContentType: "application/dicom" `
      -InFile dicom_00000001_000.dcm `
      -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies" | Select-Object -Expand Content
    

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

    输出如下所示(采用 XML 格式):

    <NativeDicomModel>
      <DicomAttribute tag="00081190" vr="UR" keyword="RetrieveURL">
        <Value number="1">https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies/1.3.6.1.4.1.11129.5.5.111396399361969898205364400549799252857604</Value>
      </DicomAttribute>
      <DicomAttribute tag="00081199" vr="SQ" keyword="ReferencedSOPSequence">
        <Item number="1">
          <DicomAttribute tag="00081150" vr="UI" keyword="ReferencedSOPClassUID">
            <Value number="1">1.2.840.10008.5.1.4.1.1.7</Value>
          </DicomAttribute>
          <DicomAttribute tag="00081155" vr="UI" keyword="ReferencedSOPInstanceUID">
            <Value number="1">1.3.6.1.4.1.11129.5.5.153751009835107614666834563294684339746480</Value>
          </DicomAttribute>
          <DicomAttribute tag="00081190" vr="UR" keyword="RetrieveURL">
            <Value number="1">https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/studies/1.3.6.1.4.1.11129.5.5.111396399361969898205364400549799252857604/series/1.3.6.1.4.1.11129.5.5.195628213694300498946760767481291263511724/instances/1.3.6.1.4.1.11129.5.5.153751009835107614666834563294684339746480</Value>
          </DicomAttribute>
        </Item>
      </DicomAttribute>
    </NativeDicomModel>
    

查看 DICOM 实例元数据

使用 dicomStores.searchForInstances 方法查看实例的元数据:

curl

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/instances"

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

输出如下所示:

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

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-RestMethod `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/dicomStores/my-dicom-store/dicomWeb/instances"

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

输出如下所示:

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

现在您已在 Cloud Healthcare API 中存储和查看了 DICOM 实例,请继续查看后续步骤以了解后续步骤。

存储和查看 FHIR 资源

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

  1. 创建 FHIR 存储区。
  2. 在 FHIR 存储区中存储 FHIR 资源。
  3. 查看 FHIR 资源的数据。

Cloud Healthcare API 实现了 FHIR 规范标准,用于存储和访问 FHIR 数据。

创建 FHIR 存储区

FHIR 存储区位于数据集内,用于存储 FHIR 资源。使用 fhirStores.create 方法创建 FHIR 存储区:

curl

curl -X POST \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'version': 'R4'
    }" "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores?fhirStoreId=my-fhir-store"

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store",
  "version": "R4"
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
      'version': 'R4'
  }" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores?fhirStoreId=my-fhir-store" | Select-Object -Expand Content

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store",
  "version": "R4"
}

存储 FHIR 资源

  1. 下载示例 JSON FHIR 资源文件。该文件包含针对一个患者资源的基本数据。

    curl

    curl -O https://cloud.google.com/healthcare/docs/resources/Patient.json
    

    PowerShell

    Invoke-WebRequest -Uri "https://cloud.google.com/healthcare/docs/resources/Patient.json" -OutFile $pwd/Patient.json
    
  2. 使用 fhir.create 方法存储患者资源。本快速入门假定您从下载“患者”资源的同一目录中运行该命令。

    curl

    curl -X POST \
        -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
        -H "Content-Type: application/fhir+json; charset=utf-8" \
        --data @Patient.json \
        "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient"
    

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

    输出如下所示:

    {
      "birthDate": "1970-01-01",
      "gender": "female",
      "id": "PATIENT_ID",
      "meta": {
        "lastUpdated": "LAST_UPDATED",
        "versionId": "VERSION_ID"
      },
      "name": [
        {
          "family": "Smith",
          "given": [
            "Darcy"
          ],
          "use": "official"
        }
      ],
      "resourceType": "Patient"
    }
    

    PowerShell

    $cred = gcloud auth application-default print-access-token
    $headers = @{ Authorization = "Bearer $cred" }
    
    Invoke-WebRequest `
      -Method Post `
      -Headers $headers `
      -ContentType: "application/dicom" `
      -InFile Patient.json `
      -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient" | Select-Object -Expand Content
    

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

    输出如下所示:

    {
      "birthDate": "1970-01-01",
      "gender": "female",
      "id": "PATIENT_ID",
      "meta": {
        "lastUpdated": "LAST_UPDATED",
        "versionId": "VERSION_ID"
      },
      "name": [
        {
          "family": "Smith",
          "given": [
            "Darcy"
          ],
          "use": "official"
        }
      ],
      "resourceType": "Patient"
    }
    

查看 FHIR 资源内容

使用 fhir.search 方法查看患者资源的相关信息。以下示例展示了如何搜索所有姓“Smith”的患者资源。

curl

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient?family:exact=Smith"

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

服务器将以 JSON 格式的 FHIR Bundle 形式返回响应。Bundle.typesearchset,搜索结果是 Bundle.entry 数组中的条目。在此示例中,请求返回单个患者资源,包括该资源内的数据:

{
  "entry": [
    {
      "fullUrl": "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient/PATIENT_ID",
      "resource": {
        "birthDate": "1970-01-01",
        "gender": "female",
        "id": "PATIENT_ID",
        "meta": {
          "lastUpdated": "LAST_UPDATED",
          "versionId": "VERSION_ID"
        },
        "name": [
          {
            "family": "Smith",
            "given": [
              "Darcy"
            ],
            "use": "official"
          }
        ],
        "resourceType": "Patient"
      },
      "search": {
        "mode": "match"
      }
    }
  ],
  "link": [
    {
      "url": "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient/?family%3Aexact=Smith"
    }
  ],
  "resourceType": "Bundle",
  "total": 1,
  "type": "searchset"
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-RestMethod `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/RESOURCE_TYPE?family:exact=Smith" | ConvertTo-Json

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

服务器将以 JSON 格式的 FHIR Bundle 形式返回响应。Bundle.typesearchset,搜索结果是 Bundle.entry 数组中的条目。在此示例中,请求返回单个患者资源,包括该资源内的数据:

{
  "entry": [
    {
      "fullUrl": "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient/PATIENT_ID",
      "resource": {
        "birthDate": "1970-01-01",
        "gender": "female",
        "id": "PATIENT_ID",
        "meta": {
          "lastUpdated": "LAST_UPDATED",
          "versionId": "VERSION_ID"
        },
        "name": [
          {
            "family": "Smith",
            "given": [
              "Darcy"
            ],
            "use": "official"
          }
        ],
        "resourceType": "Patient"
      },
      "search": {
        "mode": "match"
      }
    }
  ],
  "link": [
    {
      "url": "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/fhirStores/my-fhir-store/fhir/Patient/?family%3Aexact=Smith"
    }
  ],
  "resourceType": "Bundle",
  "total": 1,
  "type": "searchset"
}

现在您已在 Cloud Healthcare API 中存储和查看了 FHIR 资源,请继续查看后续步骤以了解后续步骤。

存储和查看 HL7v2 消息

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

  1. 创建 HL7v2 存储区
  2. 将 HL7v2 消息存储在 HL7v2 存储区中。
  3. 查看 HL7v2 消息的数据。

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

创建 HL7v2 存储区

HL7v2 存储区位于数据集内,用于存储 HL7v2 数据。使用 hl7V2Stores.create 方法创建 HL7v2 存储区:

curl

curl -X POST \
    --data "" \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores?hl7V2StoreId=my-hl7v2-store"

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store"
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores?hl7V2StoreId=my-hl7v2-store" | Select-Object -Expand Content

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store"
}

创建 HL7v2 消息

  1. 示例 HL7v2 消息文件下载到您的机器上:

    curl

    curl -O https://cloud.google.com/healthcare/docs/resources/hl7v2-sample.json
    

    PowerShell

    Invoke-WebRequest -Uri "https://cloud.google.com/healthcare/docs/resources/hl7v2-sample.json" -OutFile $pwd/hl7v2-sample.json
    

    HL7v2 消息包含以下基本信息,它采用 base-64 编码存放在示例文件的 data 字段中:

    MSH|^~\&|A|SEND_FACILITY|A|A|20180101000000||TYPE^A|20180101000000|T|0.0|||AA||00|ASCII
    EVN|A00|20180101040000
    PID||14^111^^^^MRN|11111111^^^^MRN~1111111111^^^^ORGNMBR
    
  2. 使用 messages.create 方法存储 HL7v2 消息。本快速入门假定您从下载 HL7v2 消息文件所在的目录中运行该命令。

    curl

    curl -X POST \
         -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
         -H "Content-Type: application/json; charset=utf-8" \
         --data-binary @hl7v2-sample.json \
         "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages"
    

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

    输出如下所示:

    {
      "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID",
      "data": "TVNIfF5+XCZ8QXxTRU5EX0ZBQ0lMSVRZfEF8QXwyMDE4MDEwMTAwMDAwMHx8VFlQRV5BfDIwMTgwMTAxMDAwMDAwfFR8MC4wfHx8QUF8fDAwfEFTQ0lJDUVWTnxBMDB8MjAxODAxMDEwNDAwMDANUElEfHwxNAExMTFeXl5eTVJOfDExMTExMTExXl5eXk1STn4xMTExMTExMTExXl5eXk9SR05NQlI=",
      "sendFacility": "SEND_FACILITY",
      "sendTime": "2018-01-01T00:00:00Z",
      "messageType": "TYPE",
      "createTime": "CREATE_TIME",
      "patientIds": [
        {
          "value": "14\u0001111",
          "type": "MRN"
        },
        {
          "value": "11111111",
          "type": "MRN"
        },
        {
          "value": "1111111111",
          "type": "ORGNMBR"
        }
      ]
    }
    

    在此输出中:

    • PROJECT_IDus-central1my-datasetmy-hl7v2-store:您在方法调用中提供的值
    • MESSAGE_ID:Cloud Healthcare API 提供的 HL7v2 消息的标识符
    • CREATE_TIME:消息发送到 Cloud Healthcare API 的时间戳

    PowerShell

    $cred = gcloud auth application-default print-access-token
    $headers = @{ Authorization = "Bearer $cred" }
    
    Invoke-WebRequest `
      -Method Post `
      -Headers $headers `
      -ContentType: "application/json; charset=utf-8" `
      -InFile hl7v2-sample.json `
      -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages" | Select-Object -Expand Content
    

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

    输出如下所示:

    {
      "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID",
      "data": "TVNIfF5+XCZ8QXxTRU5EX0ZBQ0lMSVRZfEF8QXwyMDE4MDEwMTAwMDAwMHx8VFlQRV5BfDIwMTgwMTAxMDAwMDAwfFR8MC4wfHx8QUF8fDAwfEFTQ0lJDUVWTnxBMDB8MjAxODAxMDEwNDAwMDANUElEfHwxNAExMTFeXl5eTVJOfDExMTExMTExXl5eXk1STn4xMTExMTExMTExXl5eXk9SR05NQlI=",
      "sendFacility": "SEND_FACILITY",
      "sendTime": "2018-01-01T00:00:00Z",
      "messageType": "TYPE",
      "createTime": "CREATE_TIME",
      "patientIds": [
        {
          "value": "14\u0001111",
          "type": "MRN"
        },
        {
          "value": "11111111",
          "type": "MRN"
        },
        {
          "value": "1111111111",
          "type": "ORGNMBR"
        }
      ]
    }
    

    在此输出中:

    • PROJECT_IDus-central1my-datasetmy-hl7v2-store:您在方法调用中提供的值
    • MESSAGE_ID:Cloud Healthcare API 提供的 HL7v2 消息的标识符
    • CREATE_TIME:消息发送到 Cloud Healthcare API 的时间戳

查看 HL7v2 消息内容

记下您在创建 HL7v2 消息时收到的响应中的 MESSAGE_ID。使用 messages.get 方法查看 HL7v2 消息的详细信息。

curl

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID"

替换以下内容:

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID",
  "data": "TVNIfF5+XCZ8QXxTRU5EX0ZBQ0lMSVRZfEF8QXwyMDE4MDEwMTAwMDAwMHx8VFlQRV5BfDIwMTgwMTAxMDAwMDAwfFR8MC4wfHx8QUF8fDAwfEFTQ0lJDUVWTnxBMDB8MjAxODAxMDEwNDAwMDANUElEfHwxNAExMTFeXl5eTVJOfDExMTExMTExXl5eXk1STn4xMTExMTExMTExXl5eXk9SR05NQlI=",
  "sendFacility": "SEND_FACILITY",
  "sendTime": "2018-01-01T00:00:00Z",
  "messageType": "TYPE",
  "createTime": "CREATE_TIME",
  "patientIds": [
    {
      "value": "14\u0001111",
      "type": "MRN"
    },
    {
      "value": "11111111",
      "type": "MRN"
    },
    {
      "value": "1111111111",
      "type": "ORGNMBR"
    }
  ],
  "parsedData": {
    "segments": [
      {
        "segmentId": "MSH",
        "fields": {
          "5": "A",
          "8.1": "TYPE",
          "6": "20180101000000",
          "8.2": "A",
          "3": "SEND_FACILITY",
          "4": "A",
          "11": "0.0",
          "10": "T",
          "1": "^~\\&",
          "17": "ASCII",
          "2": "A",
          "0": "MSH",
          "14": "AA",
          "9": "20180101000000",
          "16": "00"
        }
      },
      {
        "segmentId": "EVN",
        "fields": {
          "2": "20180101040000",
          "0": "EVN",
          "1": "A00"
        }
      },
      {
        "segmentId": "PID",
        "fields": {
          "3[0].5": "MRN",
          "3[1].1": "1111111111",
          "3[1].5": "ORGNMBR",
          "0": "PID",
          "2.1": "14\u0001111",
          "2.5": "MRN",
          "3[0].1": "11111111"
        }
      }
    ]
  }
}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID" | Select-Object -Expand Content

替换以下内容:

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

输出如下所示:

{
  "name": "projects/PROJECT_ID/locations/us-central1/datasets/my-dataset/hl7V2Stores/my-hl7v2-store/messages/MESSAGE_ID",
  "data": "TVNIfF5+XCZ8QXxTRU5EX0ZBQ0lMSVRZfEF8QXwyMDE4MDEwMTAwMDAwMHx8VFlQRV5BfDIwMTgwMTAxMDAwMDAwfFR8MC4wfHx8QUF8fDAwfEFTQ0lJDUVWTnxBMDB8MjAxODAxMDEwNDAwMDANUElEfHwxNAExMTFeXl5eTVJOfDExMTExMTExXl5eXk1STn4xMTExMTExMTExXl5eXk9SR05NQlI=",
  "sendFacility": "SEND_FACILITY",
  "sendTime": "2018-01-01T00:00:00Z",
  "messageType": "TYPE",
  "createTime": "CREATE_TIME",
  "patientIds": [
    {
      "value": "14\u0001111",
      "type": "MRN"
    },
    {
      "value": "11111111",
      "type": "MRN"
    },
    {
      "value": "1111111111",
      "type": "ORGNMBR"
    }
  ],
  "parsedData": {
    "segments": [
      {
        "segmentId": "MSH",
        "fields": {
          "5": "A",
          "8.1": "TYPE",
          "6": "20180101000000",
          "8.2": "A",
          "3": "SEND_FACILITY",
          "4": "A",
          "11": "0.0",
          "10": "T",
          "1": "^~\\&",
          "17": "ASCII",
          "2": "A",
          "0": "MSH",
          "14": "AA",
          "9": "20180101000000",
          "16": "00"
        }
      },
      {
        "segmentId": "EVN",
        "fields": {
          "2": "20180101040000",
          "0": "EVN",
          "1": "A00"
        }
      },
      {
        "segmentId": "PID",
        "fields": {
          "3[0].5": "MRN",
          "3[1].1": "1111111111",
          "3[1].5": "ORGNMBR",
          "0": "PID",
          "2.1": "14\u0001111",
          "2.5": "MRN",
          "3[0].1": "11111111"
        }
      }
    ]
  }
}

现在您已在 Cloud Healthcare API 中存储和查看了 HL7v2 消息,请继续查看后续步骤以了解后续步骤。

清理

为避免系统因本页中使用的资源向您的 Google Cloud 帐号收取费用,请按照以下步骤操作。

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

删除项目

  1. 在 Cloud Console 中,转到管理资源页面。

    转到“管理资源”

  2. 在项目列表中,选择要删除的项目,然后点击删除
  3. 在对话框中输入项目 ID,然后点击关闭以删除项目。

删除数据集

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

curl

curl -X DELETE \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset"

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

输出如下所示:

{}

PowerShell

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Delete `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/datasets/my-dataset" | Select-Object -Expand Content

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

输出如下所示:

{}

结果怎么样?

后续步骤

参阅以下部分,了解 Cloud Healthcare API 的一般信息以及如何使用 Cloud Console 和 gcloud 命令行工具执行任务:

DICOM

继续阅读 DICOM 指南,了解相关主题(例如以下主题):

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

FHIR

继续阅读 FHIR 指南,了解相关主题(例如以下主题):

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

HL7v2

继续阅读 HL7v2 指南,了解相关主题(例如以下主题):