本页介绍了如何创建、修改、查看、列出和删除数据集。创建数据集后,您可以创建用于存储电子健康记录和医学影像数据的数据存储区,对数据集进行去标识化等。
准备工作
请参阅 Cloud Healthcare API 数据模型。
创建数据集
以下示例展示了如何创建数据集。
执行此任务所需的权限
如需执行此任务,您必须已获得以下权限或以下 Identity and Access Management (IAM) 角色:
权限
healthcare.datasets.create
角色
您可以要求管理员为您授予这些 Identity and Access Management 角色。如需了解如何授予角色,请参阅管理访问权限或控制对 Cloud Healthcare API 资源的访问。您也可以通过自定义角色或其他预定义角色来获取所需的权限。
在 Google Cloud 控制台中,前往浏览器页面。
点击 add_box 创建数据集。系统随即会显示数据集属性页面。
在名称字段中,输入数据集的标识符,该标识符应符合数据集允许的字符和大小要求。
选择以下某一类型的位置:
Region 绑定将多选选项设置为所有记录中 Region 的所有值。数据集永久驻留在一个 Google Cloud 区域中。选择此选项后,在区域字段中输入或选择位置。
多区域。数据集永久驻留在跨多个 Google Cloud 区域的位置中。选择此选项后,在多区域字段中输入或选择多区域位置。
点击创建。系统会显示浏览器页面。新数据集将显示在数据集列表中。
运行 gcloud healthcare datasets create
命令。
在使用下面的命令数据之前,请先进行以下替换:
:数据集的受支持的位置LOCATION
:一个标识符,须遵循数据集允许的字符和大小要求DATASET_ID
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets createDATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets createDATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets createDATASET_ID ^ --location=LOCATION
您应该会收到类似如下所示的响应:
Create request issued for: [DATASET_ID ] Created dataset [DATASET_ID ].
使用
projects.locations.datasets.create
方法创建数据集。在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集的受支持的位置LOCATION
:一个标识符,须遵循数据集允许的字符和大小要求DATASET_ID
如需发送请求,请选择以下方式之一:
执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets?datasetId=DATASET_ID "执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets?datasetId=DATASET_ID " | Select-Object -Expand Content打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 填写所有必填字段,然后点击执行。
OPERATION_ID
的值。下一步中您需要用到该值。响应
{ "name": "projects/
PROJECT_ID /locations/LOCATION /datasets/DATASET_ID /operations/OPERATION_ID " }使用
projects.locations.datasets.operations.get
方法获取长时间运行的操作的状态。在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集位置LOCATION
:数据集 IDDATASET_ID
:从长时间运行的操作返回的 IDOPERATION_ID
如需发送请求,请选择以下方式之一:
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID /operations/OPERATION_ID "执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID /operations/OPERATION_ID " | Select-Object -Expand Content打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 填写所有必填字段,然后点击执行。
"done": true
,则表示长时间运行的操作已完成。响应
{ "name": "projects/
PROJECT_ID /locations/LOCATION /datasets/DATASET_ID /operations/OPERATION_ID ", "metadata": { "@type": "type.googleapis.com/google.cloud.healthcare.v1.OperationMetadata", "apiMethodName": "google.cloud.healthcare.v1.dataset.DatasetService.CreateDataset", "createTime": "YYYY-MM-DDTHH:MM:SS+ZZ:ZZ ", "endTime": "YYYY-MM-DDTHH:MM:SS+ZZ:ZZ ", "logsUrl": "https://console.cloud.google.com/CLOUD_LOGGING_URL " "counter": { "success": "SUCCESS_COUNT ", // If there were any failures, they display in the `failure` field. "failure": "FAILURE_COUNT " } }, "done": true, // The `response` field only displays if there were no errors. "response": { "@type": "type.googleapis.com/google.cloud.healthcare.v1.dataset.Dataset", "name": "PROJECT_ID /locations/LOCATION /datasets/DATASET_ID ", }, // If there were any errors, an `error` field displays instead of a `response` field. // See Troubleshooting long-running operations for a list of response codes. "error": { "code":ERROR_CODE , "message": "DESCRIPTION ", "details": [ { "@type": "...",FIELD1 : ..., ... } ] } }
编辑数据集
以下示例展示了如何修改数据集。
执行此任务所需的权限
如需执行此任务,您必须已获得以下权限或以下 Identity and Access Management (IAM) 角色:
权限
healthcare.datasets.update
角色
您可以要求管理员为您授予这些 Identity and Access Management 角色。如需了解如何授予角色,请参阅管理访问权限或控制对 Cloud Healthcare API 资源的访问。您也可以通过自定义角色或其他预定义角色来获取所需的权限。
Google Cloud 控制台不支持修改数据集。请改用 Google Cloud CLI 或 REST API。
运行 gcloud healthcare datasets update
命令。
在使用下面的命令数据之前,请先进行以下替换:
:数据集位置LOCATION
:数据集 IDDATASET_ID
:支持的时区,例如TIME_ZONE UTC
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets updateDATASET_ID \ --location=LOCATION \ --time-zone=TIME_ZONE
Windows (PowerShell)
gcloud healthcare datasets updateDATASET_ID ` --location=LOCATION ` --time-zone=TIME_ZONE
Windows (cmd.exe)
gcloud healthcare datasets updateDATASET_ID ^ --location=LOCATION ^ --time-zone=TIME_ZONE
您应该会收到类似如下所示的响应:
Updated dataset [DATASET_ID ]. name: projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID timeZone:TIME_ZONE
使用 projects.locations.datasets.patch
方法。
在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集位置LOCATION
:数据集 IDDATASET_ID
:支持的时区,例如TIME_ZONE UTC
请求 JSON 正文:
{ "timeZone": "TIME_ZONE " }
如需发送请求,请选择以下方式之一:
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID ?updateMask=timeZone"
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID ?updateMask=timeZone" | Select-Object -Expand Content
复制请求正文并打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 将请求正文粘贴到此工具中,填写任何其他必填字段,然后点击执行。
您应该收到类似以下内容的 JSON 响应:
响应
{ "name": "projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID " "timeZone": "TIME_ZONE " }
获取数据集详情
以下示例展示了如何获取有关数据集的详细信息。
执行此任务所需的权限
如需执行此任务,您必须已获得以下权限或以下 Identity and Access Management (IAM) 角色:
权限
healthcare.datasets.get
角色
-
Healthcare Dataset Viewer
(
roles/healthcare.datasetViewer
) -
Healthcare Dataset Administrator
(
roles/healthcare.datasetAdmin
)
您可以要求管理员为您授予这些 Identity and Access Management 角色。如需了解如何授予角色,请参阅管理访问权限或控制对 Cloud Healthcare API 资源的访问。您也可以通过自定义角色或其他预定义角色来获取所需的权限。
在 Google Cloud 控制台中,前往浏览器页面。
选择数据集。系统会显示数据集页面以及数据集中的数据存储区。
运行 gcloud healthcare datasets describe
命令。
在使用下面的命令数据之前,请先进行以下替换:
:数据集位置LOCATION
:数据集 IDDATASET_ID
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets describeDATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets describeDATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets describeDATASET_ID ^ --location=LOCATION
您应该会收到类似如下所示的响应:
name: projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID timeZone:TIME_ZONE
使用 projects.locations.datasets.get
方法。
在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集位置LOCATION
:数据集 IDDATASET_ID
如需发送请求,请选择以下方式之一:
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID "
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID " | Select-Object -Expand Content
打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 填写所有必填字段,然后点击执行。
您应该收到类似以下内容的 JSON 响应:
响应
{ "name": "projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID " "timeZone": "TIME_ZONE " }
列出数据集
以下示例展示了如何列出项目中的数据集。
执行此任务所需的权限
如需执行此任务,您必须已获得以下权限或以下 Identity and Access Management (IAM) 角色:
权限
healthcare.datasets.list
角色
-
Healthcare Dataset Viewer
(
roles/healthcare.datasetViewer
) -
Healthcare Dataset Administrator
(
roles/healthcare.datasetAdmin
)
您可以要求管理员为您授予这些 Identity and Access Management 角色。如需了解如何授予角色,请参阅管理访问权限或控制对 Cloud Healthcare API 资源的访问。您也可以通过自定义角色或其他预定义角色来获取所需的权限。
在 Google Cloud 控制台中,前往浏览器页面。
运行 gcloud healthcare datasets list
命令。
在使用下面的命令数据之前,请先进行以下替换:
:数据集位置LOCATION
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets list --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets list --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets list --location=LOCATION
您应该会收到类似如下所示的响应:
ID LOCATION TIMEZONEDATASET_ID LOCATION TIME_ZONE
使用 projects.locations.datasets.list
方法。
在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集位置LOCATION
如需发送请求,请选择以下方式之一:
执行以下命令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets"
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets" | Select-Object -Expand Content
打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 填写所有必填字段,然后点击执行。
您应该收到类似以下内容的 JSON 响应:
响应
{ "datasets": [ { "name": "projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID ", "timeZone": "TIME_ZONE " }, { ... } ] }
删除数据集
以下示例展示了如何删除数据集。
执行此任务所需的权限
如需执行此任务,您必须已获得以下权限或以下 Identity and Access Management (IAM) 角色:
权限
healthcare.datasets.delete
角色
您可以要求管理员为您授予这些 Identity and Access Management 角色。如需了解如何授予角色,请参阅管理访问权限或控制对 Cloud Healthcare API 资源的访问。您也可以通过自定义角色或其他预定义角色来获取所需的权限。
在 Google Cloud 控制台中,前往浏览器页面。
在数据集所在的行中,点击
操作选项,然后选择删除。在确认对话框中,输入数据集 ID,然后点击删除。
运行 gcloud healthcare datasets delete
命令。
在使用下面的命令数据之前,请先进行以下替换:
:数据集位置LOCATION
:数据集 IDDATASET_ID
执行以下命令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets deleteDATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets deleteDATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets deleteDATASET_ID ^ --location=LOCATION
要确认,请键入 Y。
输出如下所示:
Deleted dataset [DATASET_ID ]
使用 projects.locations.datasets.delete
方法。
在使用任何请求数据之前,请先进行以下替换:
:您的 Google Cloud 项目的 IDPROJECT_ID
:数据集位置LOCATION
:数据集 IDDATASET_ID
如需发送请求,请选择以下方式之一:
执行以下命令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID "
执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID /locations/LOCATION /datasets/DATASET_ID " | Select-Object -Expand Content
打开方法参考页面。APIs Explorer 面板会在页面右侧打开。您可以与此工具进行交互以发送请求。 填写所有必填字段,然后点击执行。
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。