本頁面說明如何建立、編輯、查看、列出及刪除資料集。建立資料集後,您可以建立資料儲存庫來保存電子病歷和醫療影像資料、去識別化資料集等等。
事前準備
請參閱 Cloud Healthcare API 資料模型。
建立資料集
以下範例說明如何建立資料集。
控制台
前往 Google Cloud 控制台的「Browser」頁面。
按一下 add_box「Create dataset」(建立資料集)。系統隨即會顯示「Dataset properties」(資料集屬性) 頁面。
在「名稱」欄位中,輸入資料集的 ID,但必須符合資料集允許的字元和大小限制。
請選取下列其中一種地點類型:
區域:資料集會永久保留在一個 Google Cloud 區域內。選取這個選項後,請在「區域」欄位中輸入或選取位置。
多區域:資料集會永久保存在跨越多個 Google Cloud 區域的位置。選取這個選項後,請在「Multi-region」欄位中輸入或選取多區域位置。
按一下「建立」,系統隨即會顯示「Browser」頁面。新的資料集會顯示在資料集清單中。
gcloud
執行 gcloud healthcare datasets create
指令。
使用下列任何指令資料之前,請先替換以下項目:
LOCATION
:資料集的支援位置DATASET_ID
:符合資料集允許的字元和大小限制的 ID
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets create DATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets create DATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets create DATASET_ID ^ --location=LOCATION
您應該會收到類似以下的回應:
Create request issued for: [DATASET_ID] Created dataset [DATASET_ID].
REST
使用
projects.locations.datasets.create
方法建立資料集。使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集的支援位置DATASET_ID
:符合資料集允許的字元和大小限制的 ID
如要傳送要求,請選擇以下其中一個選項:
curl
執行下列指令:
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"PowerShell
執行下列指令:
$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 ContentAPIs Explorer
開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」。
OPERATION_ID
的值。您需要在下一個步驟中使用這個值。使用
projects.locations.datasets.operations.get
方法取得長時間執行作業的狀態。使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集位置DATASET_ID
:資料集 IDOPERATION_ID
:長時間執行作業傳回的 ID
如要傳送要求,請選擇以下其中一個選項:
curl
執行下列指令:
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"PowerShell
執行下列指令:
$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 ContentAPIs Explorer
開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」。
"done": true
,表示長時間執行作業已完成。
Go
Java
Node.js
Python
編輯資料集
以下範例說明如何編輯資料集。
控制台
Google Cloud 主控台不支援編輯資料集。請改用 Google Cloud CLI 或 REST API。
gcloud
執行 gcloud healthcare datasets update
指令。
使用下列任何指令資料之前,請先替換以下項目:
LOCATION
:資料集位置DATASET_ID
:資料集 IDTIME_ZONE
:支援的時區,例如UTC
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets update DATASET_ID \ --location=LOCATION \ --time-zone=TIME_ZONE
Windows (PowerShell)
gcloud healthcare datasets update DATASET_ID ` --location=LOCATION ` --time-zone=TIME_ZONE
Windows (cmd.exe)
gcloud healthcare datasets update DATASET_ID ^ --location=LOCATION ^ --time-zone=TIME_ZONE
您應該會收到類似以下的回應:
Updated dataset [DATASET_ID]. name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID timeZone: TIME_ZONE
REST
請使用 projects.locations.datasets.patch
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集位置DATASET_ID
:資料集 IDTIME_ZONE
:支援的時區,例如UTC
JSON 要求主體:
{ "timeZone": "TIME_ZONE" }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 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"
PowerShell
將要求主體儲存在名為 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
複製要求主體並開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。將要求主體貼到這項工具中,並填妥其他必填欄位,然後按一下「執行」。
您應該會收到如下的 JSON 回應:
Go
Java
Node.js
Python
取得資料集詳細資料
以下範例說明如何取得資料集的詳細資料。
控制台
前往 Google Cloud 控制台的「Browser」頁面。
選取資料集。系統會顯示「Dataset」頁面和資料集中的資料儲存庫。
gcloud
執行 gcloud healthcare datasets describe
指令。
使用下列任何指令資料之前,請先替換以下項目:
LOCATION
:資料集位置DATASET_ID
:資料集 ID
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets describe DATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets describe DATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets describe DATASET_ID ^ --location=LOCATION
您應該會收到類似以下的回應:
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID timeZone: TIME_ZONE
REST
請使用 projects.locations.datasets.get
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集位置DATASET_ID
:資料集 ID
如要傳送要求,請選擇以下其中一個選項:
curl
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID"
PowerShell
執行下列指令:
$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
開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」。
您應該會收到如下的 JSON 回應:
Go
Java
Node.js
Python
列出資料集
以下範例說明如何列出專案中的資料集。
控制台
前往 Google Cloud 控制台的「Browser」頁面。
gcloud
執行 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 TIMEZONE DATASET_ID LOCATION TIME_ZONE
REST
請使用 projects.locations.datasets.list
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集位置
如要傳送要求,請選擇以下其中一個選項:
curl
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets"
PowerShell
執行下列指令:
$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
開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」。
您應該會收到如下的 JSON 回應:
Go
Java
Node.js
Python
刪除資料集
下列範例說明如何刪除資料集。
控制台
前往 Google Cloud 控制台的「Browser」頁面。
在資料集所在的資料列中,按一下
「Actions」選項,然後選取「Delete」。在確認對話方塊中輸入資料集 ID,然後按一下「Delete」。
gcloud
執行 gcloud healthcare datasets delete
指令。
使用下列任何指令資料之前,請先替換以下項目:
LOCATION
:資料集位置DATASET_ID
:資料集 ID
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud healthcare datasets delete DATASET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud healthcare datasets delete DATASET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud healthcare datasets delete DATASET_ID ^ --location=LOCATION
輸入 Y 確認。
輸出內容如下:
Deleted dataset [DATASET_ID]
REST
請使用 projects.locations.datasets.delete
方法。
使用任何要求資料之前,請先替換以下項目:
PROJECT_ID
: Google Cloud 專案的 IDLOCATION
:資料集位置DATASET_ID
:資料集 ID
如要傳送要求,請選擇以下其中一個選項:
curl
執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID"
PowerShell
執行下列指令:
$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
開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」。
您應該會收到執行成功的狀態碼 (2xx) 和空白回應。