本頁說明如何啟用 Healthcare Natural Language API、設定權限,以及呼叫 analyzeEntities 方法,從醫療文字中擷取醫療洞察資料。
總覽
Healthcare Natural Language API 提供機器學習解決方案,可從醫療文字中取得深入分析資料。Healthcare Natural Language API 是 Cloud Healthcare API 的一部分。如要瞭解 Healthcare Natural Language API 總覽,請參閱 Healthcare Natural Language API 概念說明文件。
Healthcare Natural Language API 會剖析非結構化醫療文字,例如病歷或保險理賠申請。然後,系統會產生這些資料來源中儲存的醫療知識實體的結構化資料表示法,以供後續分析和自動化作業使用。例如,您可以:
- 擷取疾病、藥物、醫療器材、醫療程序等醫療概念的相關資訊,以及臨床相關屬性
- 將醫療概念對應至標準醫療詞彙,例如 RxNorm、ICD-10、MeSH 和 SNOMED CT (僅限美國和英國使用者)
- 從文字產生醫療洞察資料,並與 Google Cloud中的資料分析產品整合
服務地區
Healthcare Natural Language API 可在下列位置使用:
| 地點名稱 | 地點說明 |
|---|---|
asia-south1 |
印度孟買 |
australia-southeast1 |
澳洲雪梨 |
europe-west2 |
英國倫敦 |
europe-west4 |
荷蘭 |
northamerica-northeast1 |
加拿大蒙特婁 |
us-central1 |
美國愛荷華州 |
啟用 Healthcare Natural Language API
開始使用 Healthcare Natural Language API 前,請先為專案啟用 API。 Google Cloud 您可以使用 Healthcare Natural Language API,不必啟用或使用 Cloud Healthcare API 的功能。
如要啟用 API,請完成下列步驟:
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. 啟用 Cloud Healthcare API。
啟用 API 時所需的角色
您必須具備
serviceusage.services.enable權限,才能啟用 API。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「服務使用情形管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。-
安裝 Google Cloud CLI。
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init
設定權限
如要使用本指南中的功能,您必須具備 healthcare.nlpservice.analyzeEntities
權限,這項權限包含在 healthcare.nlpServiceViewer
角色中。
如要指派這個角色,請執行 gcloud projects add-iam-policy-binding 指令:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member serviceAccount:SERVICE_ACCOUNT_ID \ --role roles/healthcare.nlpServiceViewer
擷取實體、關係和情境屬性
Healthcare Natural Language API 會使用情境感知模型,擷取醫療實體、關係和情境屬性。每個文字實體都會擷取到醫療字典項目中。如要從醫療文字中擷取這類醫療洞察資訊,請使用 projects.locations.services.nlp.analyzeEntities 方法。
如要在實體提及內容中加入 SNOMED CT 授權詞彙,請參閱「加入授權詞彙」。
如要使用 Healthcare Natural Language API 從醫療文字中擷取醫療洞察資料,請發出 POST 要求,並在 documentContent 欄位中指定目標文字。醫療文字的大小上限為 20,000 個 Unicode 字元。
下列範例說明如何使用 analyzeEntities 方法,從醫療文字「Insulin regimen 5 units IV will be administered for diabetes.」擷取醫療洞察。
REST
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID:您 Google Cloud 專案的 IDLOCATION:資料集位置
JSON 要求內文:
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}
EOF接著執行下列指令,傳送 REST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"
PowerShell
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes."
}
'@ | 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" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand Content
如果要求成功,回應會包含下列資訊:
- 可辨識的醫療知識實體
- 功能
- 已辨識實體之間的關係
- 情境屬性
- 將醫療知識實體對應至標準術語
如需支援的實體、屬性和關係類型清單,請參閱「Healthcare Natural Language API 功能」一文。
下列回應會將 NCI 術語系統中代碼為 C581 的實體「治療性胰島素」識別為藥物。回覆內容也包含回覆的信賴度分數。如要進一步瞭解回應欄位,請參閱 analyzeEntities 說明文件。
加入已獲得授權的詞彙
根據預設,Healthcare Natural Language API 回應會包含支援的醫療詞彙。
如果要求符合下列規定,您可以在回覆中加入 SNOMED 臨床術語 (美國版) (SNOMEDCT_US) 詞彙:
- API 要求來自美國。
- 要求主體中的
licensedVocabularies欄位值為SNOMEDCT_US。
如果您不需要 SNOMED CT 詞彙,就不適用上述任何限制。
以下範例說明如何在 LicensedVocabularies 物件中加入 SNOMED CT 授權詞彙,從醫療文字「Insulin regimen 5 units IV will be administered for diabetes.」擷取醫療洞察。
REST
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID:您 Google Cloud 專案的 IDLOCATION:資料集位置
JSON 要求內文:
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"licensedVocabularies": [
"SNOMEDCT_US",
"ICD10CM"
]
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"licensedVocabularies": [
"SNOMEDCT_US",
"ICD10CM"
]
}
EOF接著執行下列指令,傳送 REST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"
PowerShell
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"licensedVocabularies": [
"SNOMEDCT_US",
"ICD10CM"
]
}
'@ | 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" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand Content
SNOMEDCT_US 和 ICD10CM 授權詞彙的詞彙代碼。輸出內容如下,且要求的授權字彙代碼會以粗體顯示:
將輸出內容擷取為 FHIR R4 軟體包
您可以從文字中擷取實體,並對應至 FHIR R4 資源和元素。產生的 FHIR R4 套件會以 JSON 格式包含所有實體、實體提及項目和關係。舉例來說,Healthcare Natural Language API 會將基本實體 PROBLEM 對應至 Condition FHIR R4 資源,並將實體 PROBLEM.ANATOMICAL_STRUCTURE 對應至 Condition.bodySite FHIR 元素。如需其他對應清單,請參閱「Healthcare Natural Language API 輸出內容 (FHIR 組合)」。
下列範例說明如何從 FHIR R4 組合中的醫療文字「Insulin regimen 5 units IV will be administered for diabetes.」擷取醫療洞察。詳情請參閱 AlternativeOutputFormat 物件。
REST
使用任何要求資料之前,請先修改下列項目的值:
PROJECT_ID:您 Google Cloud 專案的 IDLOCATION:資料集位置
JSON 要求內文:
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"alternativeOutputFormat": "FHIR_BUNDLE"
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
cat > request.json << 'EOF'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"alternativeOutputFormat": "FHIR_BUNDLE"
}
EOF接著執行下列指令,傳送 REST 要求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"
PowerShell
將要求主體儲存在名為 request.json 的檔案中。
在終端機中執行下列指令,在目前目錄中建立或覆寫這個檔案:
@'
{
"documentContent": "Insulin regimen 5 units IV will be administered for diabetes.",
"alternativeOutputFormat": "FHIR_BUNDLE"
}
'@ | 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" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities" | Select-Object -Expand Content
- 辨識出的實體提及內容,以及實體和實體之間的關係,格式與「 擷取實體、關係和情境屬性」中的輸出內容類似。
- 包含字串格式 FHIR Bundle 資源的
fhirBundle鍵。 FHIR 組合包含所有實體、實體提及項目和關係,格式為 JSON。