重新整理醫療照護資料

將資料初次匯入 Vertex AI Search 醫療照護資料儲存庫後,您可能會在來源 FHIR 儲存庫中執行下列任一項更新:

  • 新增 FHIR 資源
  • 更新現有 FHIR 資源
  • 已刪除的 FHIR 資源

在這種情況下,您可以比對來源 FHIR 儲存庫中的變更,並將其匯入 Vertex AI Search 醫療照護資料儲存庫。

協調作業總覽

您可以逐漸或全面地進行變更調和作業。下表比較這兩種模式。

來源 FHIR 儲存庫的變更 增量模式 完整模式
新的 FHIR 資源 將新文件新增至 Vertex AI Search 資料儲存庫 將新文件新增至 Vertex AI Search 資料儲存庫
已更新的 FHIR 資源 取代 Vertex AI Search 資料儲存庫中的現有文件,同時保留文件 ID 取代 Vertex AI Search 資料儲存庫中的現有文件,同時保留文件 ID
已刪除的 FHIR 資源 無法比對 從 Vertex AI Search 資料儲存庫中移除對應的文件

事前準備

查看 Google Cloud 專案的配額與限制。每個 Vertex AI Search 醫療照護資料儲存庫專案最多可包含 100 萬份文件。如果匯入期間達到這個配額,匯入程序就會停止。

執行增量匯入

以下範例說明如何使用 documents.import 方法,從 Cloud Healthcare API FHIR 儲存庫匯入遞增變更。

REST

  1. 執行增量匯入作業。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://us-discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/us/dataStores/DATA_STORE_ID/branches/0/documents:import" \
    -d '{
       "reconciliation_mode": "INCREMENTAL",
       "fhir_store_source": {"fhir_store": "projects/PROJECT_ID/locations/CLOUD_HEALTHCARE_DATASET_LOCATION/datasets/CLOUD_HEALTHCARE_DATASET_ID/fhirStores/FHIR_STORE_ID"}
    }'
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案的 ID。
    • DATA_STORE_ID:Vertex AI Search 資料儲存庫的 ID。
    • CLOUD_HEALTHCARE_DATASET_ID:包含來源 FHIR 儲存庫的 Cloud Healthcare API 資料集 ID。
    • CLOUD_HEALTHCARE_DATASET_LOCATION:包含來源 FHIR 儲存庫的 Cloud Healthcare API 資料集位置。
    • FHIR_STORE_ID:Cloud Healthcare API FHIR R4 儲存庫的 ID。
  2. 確認 FHIR 資料匯入作業是否完成。

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    "https://us-discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/us/collections/default_collection/dataStores/DATA_STORE_ID/branches/0/operations/IMPORT_OPERATION_ID"
    

    更改下列內容:

    • PROJECT_ID: Google Cloud 專案的 ID。
    • DATA_STORE_ID:Vertex AI Search 資料儲存庫的 ID。
    • IMPORT_OPERATION_ID:呼叫 import 方法時傳回的長時間執行作業作業 ID。

Python

詳情請參閱 AI Applications Python API 參考說明文件

如要向 AI Applications 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine

# TODO(developer): Uncomment these variables before running the sample.
# project_id = "YOUR_PROJECT_ID"
# location = "YOUR_LOCATION" # Values: "us"
# data_store_id = "YOUR_DATA_STORE_ID"
# healthcare_project_id = "YOUR_HEALTHCARE_PROJECT_ID"
# healthcare_location = "YOUR_HEALTHCARE_LOCATION"
# healthcare_dataset_id = "YOUR_HEALTHCARE_DATASET_ID"
# healthcare_fihr_store_id = "YOUR_HEALTHCARE_FHIR_STORE_ID"

#  For more information, refer to:
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
client_options = (
    ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
    if location != "global"
    else None
)

# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)

# The full resource name of the search engine branch.
# e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
parent = client.branch_path(
    project=project_id,
    location=location,
    data_store=data_store_id,
    branch="default_branch",
)

request = discoveryengine.ImportDocumentsRequest(
    parent=parent,
    fhir_store_source=discoveryengine.FhirStoreSource(
        fhir_store=client.fhir_store_path(
            healthcare_project_id,
            healthcare_location,
            healthcare_dataset_id,
            healthcare_fihr_store_id,
        ),
    ),
    # Options: `FULL`, `INCREMENTAL`
    reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)

# Make the request
operation = client.import_documents(request=request)

print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result()

# After the operation is complete,
# get information from operation metadata
metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)

# Handle the response
print(response)
print(metadata)