建立及管理同意聲明存放區

本頁說明如何建立及管理同意聲明存放區。

同意聲明管理 API 可用來記錄使用者同意聲明、根據這些同意聲明管理動作,以及維護相關文件和記錄。

使用 Consent Management API 的機構必須負責取得並維持必要同意聲明,允許透過 Consent Management API 處理任何資料。

Consent Management API 會扮演政策決策點的角色,您必須在應用程式中或透過 Proxy 實施政策強制執行。詳情請參閱屬性型存取權控管

設定權限

如要使用本指南中的功能,您必須具備 roles/healthcare.consentStoreAdmin 角色。不過,如要使用 Consent Management API 執行其他實用作業,可能需要額外權限。詳情請參閱「存取權控管」。

同意聲明儲存空間是頂層資源,包含與 Consent Management API 設定和作業相關的所有資訊。同意事項儲存庫屬於 Cloud Healthcare API 資料集,建立時會指派給區域。這個區域是同意聲明商店的營運地理位置。

  1. 前往 Google Cloud 控制台的「Datasets」(資料集) 頁面。

    前往「資料集」頁面

  2. 選取要建立同意聲明儲存空間的資料集。

  3. 按一下「Create data store」(建立資料儲存庫)

  4. 選取「同意聲明」做為資料儲存庫類型。

  5. 在「ID」欄位中,輸入您選擇的名稱,該名稱在資料集中必須是專屬名稱。如果名稱不夠獨特,商店就無法建立。

  6. 點選「下一步」

  7. 在「設定同意聲明儲存庫」中,選取下列其中一個選項,決定儲存庫中的同意聲明何時到期:

    • 沒有預設到期時間表示同意聲明預設不會過期。
    • 預設到期時間是指同意聲明會在到期時間欄位中定義的天數後到期。
  8. 如要允許使用 consentStores.patch 建立新的同意聲明資源,請按一下「允許在更新時建立同意聲明」

  9. 點選「下一步」

  10. 按一下「新增標籤」,定義選用的鍵與值標籤,即可管理資源。Google Cloud

  11. 點選「建立」

如要建立同意聲明存放區,請執行 gcloud healthcare consent-stores create 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID: 同意聲明儲存空間的 ID。同意聲明儲存空間 ID 必須符合下列條件:
    • 資料集中的專屬 ID
    • 長度 1 到 256 個字元的 Unicode 字串,包含下列項目:
      • Numbers
      • 信件
      • 底線
      • 虛線
      • 經期

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare consent-stores create CONSENT_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare consent-stores create CONSENT_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare consent-stores create CONSENT_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION

您應該會收到類似以下的回應:

回應

Created consentStore [CONSENT_STORE_ID].

如要建立同意聲明存放區,請使用 projects.locations.datasets.consentStores.create 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID: 同意聲明儲存空間的 ID。同意聲明儲存空間 ID 必須符合下列條件:
    • 資料集中的專屬 ID
    • 長度 1 到 256 個字元的 Unicode 字串,包含下列項目:
      • Numbers
      • 信件
      • 底線
      • 虛線
      • 經期
  • DEFAULT_CONSENT_EXPIRATION_DURATION:(選填) 預設時間 (以秒為單位),同意聲明記錄會在指定時間後到期。時間長度必須至少 24 小時 (86400 秒),且格式必須為 DEFAULT_CONSENT_EXPIRATION_DURATIONs
  • ENABLE_CONSENT_CREATE_ON_UPDATE:選用的布林值,用於判斷是否應使用 consentStores.patch 建立資源,以修補不存在的同意聲明資源。預設值為 FALSE

JSON 要求主體:

{
  "defaultConsentTtl": "DEFAULT_CONSENT_EXPIRATION_DURATIONs",
  "enableConsentCreateOnUpdate": "ENABLE_CONSENT_CREATE_ON_UPDATE"
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中。 在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:

cat > request.json << 'EOF'
{
  "defaultConsentTtl": "DEFAULT_CONSENT_EXPIRATION_DURATIONs",
  "enableConsentCreateOnUpdate": "ENABLE_CONSENT_CREATE_ON_UPDATE"
}
EOF

接著,請執行下列指令來傳送 REST 要求:

curl -X POST \
-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/consentStores?consentStoreId=CONSENT_STORE_ID"

PowerShell

將要求主體儲存在名為 request.json 的檔案中。 在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:

@'
{
  "defaultConsentTtl": "DEFAULT_CONSENT_EXPIRATION_DURATIONs",
  "enableConsentCreateOnUpdate": "ENABLE_CONSENT_CREATE_ON_UPDATE"
}
'@  | Out-File -FilePath request.json -Encoding utf8

接著,請執行下列指令來傳送 REST 要求:

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

Invoke-WebRequest `
-Method POST `
-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/consentStores?consentStoreId=CONSENT_STORE_ID" | Select-Object -Expand Content

APIs Explorer

複製要求內文並開啟方法參考資料頁面。系統會在頁面右側開啟 APIs Explorer 面板。您可以使用這項工具來傳送要求。將要求內文貼到這項工具中,並填妥其他必填欄位,然後按一下「Execute」(執行)

您應該會收到如下的 JSON 回應:

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const createConsentStore = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const consentStoreId = 'my-consent-store';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {parent, consentStoreId};

  await healthcare.projects.locations.datasets.consentStores.create(request);
  console.log(`Created consent store: ${consentStoreId}`);
};

createConsentStore();
def create_consent_store(
    project_id: str, location: str, dataset_id: str, consent_store_id: str
):
    """Creates a new consent store within the parent dataset.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/consent
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns 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 = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the consent store's parent dataset ID
    # consent_store_id = 'my-consent-store'  # replace with the consent store's ID
    consent_store_parent = (
        f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
    )

    request = (
        client.projects()
        .locations()
        .datasets()
        .consentStores()
        .create(parent=consent_store_parent, body={}, consentStoreId=consent_store_id)
    )

    response = request.execute()
    print(f"Created consent store: {consent_store_id}")
    return response

建立同意聲明存放區後,您可以更新該存放區。舉例來說,您可以新增或移除標籤,整理同意聲明商店。

下列範例說明如何編輯同意聲明儲存區。

如要編輯同意事項儲存區,請完成下列步驟:

  1. 前往 Google Cloud 控制台的「Datasets」(資料集) 頁面。

    前往「資料集」頁面

  2. 選取要編輯的同意聲明存放區所在的資料集。
  3. 在「資料儲存庫」清單中,點選要編輯的資料儲存庫。
  4. 如要編輯同意聲明存放區的設定,請按一下「同意聲明存放區設定」旁的編輯圖示。

    如要進一步瞭解同意聲明存放區的設定選項,請參閱「建立同意聲明存放區」。
  5. 如要為商店新增一或多個標籤,請按一下「標籤」,然後按一下「新增標籤」,並輸入鍵/值標籤。如要進一步瞭解資源標籤,請參閱「使用資源標籤」。
  6. 按一下 [儲存]

如要編輯同意聲明存放區,請執行 gcloud healthcare consent-stores update 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID:同意聲明商店 ID
  • KEY:用於整理同意聲明儲存空間的鍵/值組合中的鍵。如要瞭解標籤規定和限制,請參閱labels
  • VALUE:用於整理同意聲明儲存空間的鍵/值組合中的值。如要瞭解標籤規定和限制,請參閱labels

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare consent-stores update CONSENT_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION \
  --update-labels=KEY=VALUE

Windows (PowerShell)

gcloud healthcare consent-stores update CONSENT_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION `
  --update-labels=KEY=VALUE

Windows (cmd.exe)

gcloud healthcare consent-stores update CONSENT_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION ^
  --update-labels=KEY=VALUE

您應該會收到類似以下的回應:

回應

Updated consentStore [CONSENT_STORE_ID].
labels:
  KEY: VALUE
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID

如要編輯同意聲明儲存空間,請使用 projects.locations.datasets.consentStores.patch 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID:同意聲明商店 ID
  • KEY:用於整理同意聲明儲存空間的鍵/值組合中的鍵。如要瞭解標籤規定和限制,請參閱labels
  • VALUE:用於整理同意聲明儲存空間的鍵/值組合中的值。如要瞭解標籤規定和限制,請參閱labels

JSON 要求主體:

{
  "labels": {
    "KEY": "VALUE"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中。 在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:

cat > request.json << 'EOF'
{
  "labels": {
    "KEY": "VALUE"
  }
}
EOF

接著,請執行下列指令來傳送 REST 要求:

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/consentStores/CONSENT_STORE_ID?updateMask=labels"

PowerShell

將要求主體儲存在名為 request.json 的檔案中。 在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:

@'
{
  "labels": {
    "KEY": "VALUE"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

接著,請執行下列指令來傳送 REST 要求:

$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/consentStores/CONSENT_STORE_ID?updateMask=labels" | Select-Object -Expand Content

APIs Explorer

複製要求內文並開啟方法參考資料頁面。系統會在頁面右側開啟 APIs Explorer 面板。您可以使用這項工具來傳送要求。將要求內文貼到這項工具中,並填妥其他必填欄位,然後按一下「Execute」(執行)

您應該會收到如下的 JSON 回應:

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const patchConsentStore = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const consentStoreId = 'my-consent-store';
  // const defaultConsentTtl = '172800s' Must be at least 24 hours, specified
  // in seconds, appended with 's' character.
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/consentStores/${consentStoreId}`;
  const request = {
    name,
    updateMask: 'defaultConsentTtl',
    resource: {
      defaultConsentTtl: defaultConsentTtl,
    },
  };

  await healthcare.projects.locations.datasets.consentStores.patch(request);
  console.log(
    `Patched consent store ${consentStoreId} with default consent time-to-live ${defaultConsentTtl}`
  );
};

patchConsentStore();
def patch_consent_store(
    project_id: str,
    location: str,
    dataset_id: str,
    consent_store_id: str,
    default_consent_ttl,
):
    """Updates the consent store.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/consent
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns 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 = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the consent store's parent dataset ID
    # consent_store_id = 'my-consent-store'  # replace with the consent store's ID
    # default_consent_ttl = '172800s'  # replace with a default TTL
    consent_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    consent_store_name = "{}/consentStores/{}".format(
        consent_store_parent, consent_store_id
    )

    # Updates the default time-to-live (TTL) of consents in the consent store.
    # Updating the TTL does not affect the expiration time of existing consents.
    # Specify as a duration in seconds with up to nine fractional digits,
    # terminated by "s", for example "172800s".
    # Minimum value is 24 hours, or "86400s" in seconds.
    patch = {"defaultConsentTtl": default_consent_ttl}

    request = (
        client.projects()
        .locations()
        .datasets()
        .consentStores()
        .patch(name=consent_store_name, updateMask="defaultConsentTtl", body=patch)
    )

    response = request.execute()
    print(
        "Patched consent store {} with new default consent TTL: {}".format(
            consent_store_id, default_consent_ttl
        )
    )

    return response

下列範例說明如何取得同意聲明儲存空間的詳細資料。

如要查看同意聲明商店的詳細資料:

  1. 前往 Google Cloud 控制台的「Datasets」(資料集) 頁面。

    前往「資料集」頁面

  2. 選取包含要查看同意聲明儲存空間的資料集。
  3. 按一下同意聲明儲存空間的名稱。
  4. 「資料儲存庫詳細資料」頁面會顯示所選同意聲明儲存庫的詳細資料。

如要取得同意聲明儲存空間的詳細資料,請執行 gcloud healthcare consent-stores describe 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID:同意聲明商店 ID

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare consent-stores describe CONSENT_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare consent-stores describe CONSENT_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare consent-stores describe CONSENT_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION
如果您在 ConsentStore 資源中設定任何欄位,這些欄位也會顯示在回應中。

回應

name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID

如要取得同意聲明商店的詳細資料,請使用 projects.locations.datasets.consentStores.get 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_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/consentStores/CONSENT_STORE_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/consentStores/CONSENT_STORE_ID" | Select-Object -Expand Content

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 APIs Explorer 面板。您可以使用這項工具來傳送要求。完成任何必填欄位,然後按一下「執行」

如果您在 ConsentStore 資源中設定任何欄位,這些欄位也會顯示在回應中。
const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getConsentStore = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const consentStoreId = 'my-consent-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/consentStores/${consentStoreId}`;
  const request = {name};

  const consentStore =
    await healthcare.projects.locations.datasets.consentStores.get(request);
  console.log(consentStore.data);
};

getConsentStore();
def get_consent_store(
    project_id: str, location: str, dataset_id: str, consent_store_id: str
):
    """Gets the specified consent store.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/consent
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    # Imports Python's built-in "json" module
    import json

    api_version = "v1"
    service_name = "healthcare"
    # Returns 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 = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the consent store's parent dataset ID
    # consent_store_id = 'my-consent-store'  # replace with the consent store's ID
    consent_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    consent_store_name = "{}/consentStores/{}".format(
        consent_store_parent, consent_store_id
    )

    consent_stores = client.projects().locations().datasets().consentStores()
    consent_store = consent_stores.get(name=consent_store_name).execute()

    print(json.dumps(consent_store, indent=2))
    return consent_store

下列範例說明如何列出資料集中的同意聲明存放區。

如要查看資料集中的資料儲存庫:

  1. 前往 Google Cloud 控制台的「Datasets」(資料集) 頁面。

    前往「資料集」頁面

  2. 選取包含要查看資料儲存庫的資料集。

如要列出資料集中的同意聲明存放區,請執行 gcloud healthcare consent-stores list 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • DATASET_ID:同意聲明儲存區的父項資料集
  • LOCATION:資料集位置

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare consent-stores list --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare consent-stores list --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare consent-stores list --dataset=DATASET_ID ^
  --location=LOCATION
如果您在 ConsentStore 資源中設定任何欄位,這些欄位也會顯示在回應中。
ID               LABELS  LOCATION
CONSENT_STORE_ID           LOCATION

如要列出資料集中的同意聲明存放區,請使用 projects.locations.datasets.consentStores.list 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的 Google Cloud 專案 ID
  • DATASET_ID:同意聲明儲存區的父項資料集
  • LOCATION:資料集位置

如要傳送要求,請選擇以下其中一個選項:

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/consentStores"

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/consentStores" | Select-Object -Expand Content

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 APIs Explorer 面板。您可以使用這項工具來傳送要求。完成任何必填欄位,然後按一下「執行」

如果您在 ConsentStore 資源中設定任何欄位,這些欄位也會顯示在回應中。
const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const listConsentStores = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {parent};

  const consentStores =
    await healthcare.projects.locations.datasets.consentStores.list(request);
  console.log(JSON.stringify(consentStores.data));
};

listConsentStores();
def list_consent_stores(project_id, location, dataset_id):
    """Lists the consent stores in the given dataset.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/consent
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns 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 = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the consent store's parent dataset ID
    consent_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )

    consent_stores = (
        client.projects()
        .locations()
        .datasets()
        .consentStores()
        .list(parent=consent_store_parent)
        .execute()
        .get("consentStores", [])
    )

    for consent_store in consent_stores:
        print(consent_store)

    return consent_stores

下列範例說明如何刪除同意聲明儲存空間。

如何刪除資料儲存庫:

  1. 前往 Google Cloud 控制台的「Datasets」(資料集) 頁面。

    前往「資料集」頁面

  2. 選取要刪除資料存放區的資料集。
  3. 在要刪除的資料存放區「動作」下拉式清單中,選擇「刪除」
  4. 如要確認,請輸入資料儲存庫名稱,然後按一下「Delete」(刪除)

如要刪除同意事項存放區,請執行 gcloud healthcare consent-stores delete 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_ID:同意聲明商店 ID

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare consent-stores delete CONSENT_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

Windows (PowerShell)

gcloud healthcare consent-stores delete CONSENT_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare consent-stores delete CONSENT_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION
如要確認,請輸入 Y。您應該會收到類似以下的回覆。
Deleted consentStore [CONSENT_STORE_ID].

如要刪除同意聲明存放區,請使用 projects.locations.datasets.consentStores.delete 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:資料集位置
  • DATASET_ID:同意聲明儲存區的父項資料集
  • CONSENT_STORE_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/consentStores/CONSENT_STORE_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/consentStores/CONSENT_STORE_ID" | Select-Object -Expand Content

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 APIs Explorer 面板。您可以使用這項工具來傳送要求。完成任何必填欄位,然後按一下「執行」

您應該會收到如下的 JSON 回應:

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const deleteConsentStore = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const consentStoreId = 'my-consent-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/consentStores/${consentStoreId}`;
  const request = {name};

  await healthcare.projects.locations.datasets.consentStores.delete(request);
  console.log(`Deleted consent store: ${consentStoreId}`);
};

deleteConsentStore();
def delete_consent_store(
    project_id: str, location: str, dataset_id: str, consent_store_id: str
):
    """Deletes the specified consent store.
    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/consent
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns 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 = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the consent store's parent dataset ID
    # consent_store_id = 'my-consent-store'  # replace with the consent store's ID
    consent_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    consent_store_name = "{}/consentStores/{}".format(
        consent_store_parent, consent_store_id
    )

    request = (
        client.projects()
        .locations()
        .datasets()
        .consentStores()
        .delete(name=consent_store_name)
    )

    response = request.execute()
    print(f"Deleted consent store: {consent_store_id}")
    return response

稽核記錄

Consent Management API 會寫入下列類型的稽核記錄:

  • 管理員活動:記錄修改資源設定或中繼資料的作業。您無法停用管理員活動稽核記錄。
  • 資料存取:包含讀取資源設定或中繼資料的 API 呼叫,以及建立、修改或讀取客戶提供資源資料的外部 API 呼叫。請務必啟用這些記錄。舉例來說,您可以使用「資料存取」稽核記錄,記錄哪些服務發出存取權判斷要求、該要求提供哪些資訊,以及 API 如何回應要求。如要進一步瞭解資料存取稽核記錄,請參閱「設定資料存取稽核記錄」一文。如要進一步瞭解 Cloud Healthcare API 中的稽核記錄,請參閱「查看 Cloud 稽核記錄」。

如要進一步瞭解 Consent Management API 的稽核記錄,請參閱「查看 Cloud 稽核記錄」。