註冊使用者資料

本頁說明如何使用 Consent Management API 註冊使用者資料。

資料元素會透過 Consent Management API 註冊,並使用使用者資料對應與同意聲明建立關聯。使用者資料絕不會儲存在 Consent Management API 中。

UserDataMappings 資源表示的使用者資料對應包含下列元素:

  • 可識別使用者的使用者 ID。這個 ID 與應用程式向同意聲明管理 API 註冊同意聲明時提供的 ID 相符。
  • 資料 ID,用於識別儲存在其他位置 (例如Google Cloud 或內部部署) 的使用者資料。資料 ID 可以是不透明 ID、網址或任何其他 ID。
  • 資源屬性:使用屬性定義,針對同意聲明存放區設定資源屬性值,藉此描述使用者資料的特徵。舉例來說,資料可能包含值為 de-identifiedattribute_definition_id data_identifiable

下圖顯示建立使用者資料對應的資料流程:

使用者資料對應

註冊使用者資料對應

如要建立使用者資料對應,請使用 projects.locations.datasets.consentStores.userDataMappings.create 方法。提出 POST 要求,並在要求中指定下列資訊:

  • 父項同意商店的名稱
  • 代表與資料元素相關聯使用者的專屬隱晦 userID
  • 使用者資料資源的 ID,例如唯一資源的 REST 路徑
  • 一組描述資料元素的 RESOURCE 屬性
  • 存取權杖

curl

以下範例顯示使用 curlPOST 要求:

curl -X POST \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/consent+json; charset=utf-8" \
    --data "{
       'user_id': 'USER_ID',
       'data_id' : 'DATA_ID',
       'resource_attributes': [{
           'attribute_definition_id': 'data_identifiable',
           'values': ['de-identified']
      }]
    }" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID/userDataMappings"

如果要求成功,伺服器會以 JSON 格式傳回類似以下範例的回應:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID/userDataMappings/USER_DATA_MAPPING_ID",
  "dataId": "DATA_ID",
  "userId": "USER_ID",
  "resourceAttributes": [
    {
      "attributeDefinitionId": "data_identifiable",
      "values": [
        "de-identified"
      ]
    }
  ]
}

PowerShell

下列範例顯示如何使用 Windows PowerShell 提出 POST 要求:

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/consent+json; charset=utf-8" `
  -Body "{
       'user_id': 'USER_ID',
       'data_id' : 'DATA_ID',
       'resource_attributes': [{
           'attribute_definition_id': 'data_identifiable',
           'values': ['de-identified']
      }]
    }" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID/userDataMappings" | Select-Object -Expand Content

如果要求成功,伺服器會以 JSON 格式傳回類似以下範例的回應:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/consentStores/CONSENT_STORE_ID/userDataMappings/USER_DATA_MAPPING_ID",
  "dataId": "DATA_ID",
  "userId": "USER_ID",
  "resourceAttributes": [
    {
      "attributeDefinitionId": "data_identifiable",
      "values": [
        "de-identified"
      ]
    }
  ]
}

設定資料 ID

使用者資料對應資源的 data_id 欄位包含客戶指定的字串,用於說明使用者資料對應資源參照的資料。允許任何字串,例如不透明 ID 或 URI。

資料 ID 的精細程度可視應用程式需求而定。如果註冊的資料可在表格或 bucket 層級說明,請將 data_id 定義為該資源的 REST 路徑。如果註冊的資料需要更精細的粒度,建議您指定特定列或儲存格。如果應用程式使用概念資源 (例如允許的動作或資料類別),您應使用支援這些用途的慣例定義 data_id

data_id 的範例包括但不限於:

Google Cloud Storage 物件

  'data_id' : 'gs://BUCKET_NAME/OBJECT_NAME'
  

Amazon S3 物件

  'data_id' : 'https://BUCKET_NAME.s3.REGION.amazonaws.com/OBJECT_NAME'
  

BigQuery 資料表

  'data_id' : 'bigquery/v2/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID'
  

BigQuery 資料列 (BigQuery 資料列沒有 REST 路徑,因此您必須提供自己的 ID,以下是其中一種做法)

  'data_id' : 'bigquery/v2/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID/myRows/ROW_ID'
  

BigQuery 儲存格 (BigQuery 儲存格沒有 REST 路徑,因此您必須提供自己的 ID,以下提供一種可能的方法)

  'data_id' : 'bigquery/v2/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID/myRows/ROW_ID/myColumns/COLUMN_ID'
  

FHIR 資源

  'data_id' : 'https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID'
  

概念圖

  'data_id' : 'wearables/fitness/step_count/daily_sum'