本页面介绍了如何启用 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 之前,您必须为您的 Google Cloud 项目启用该 API。您可以在不启用或使用 Cloud Healthcare API 功能的情况下使用 Healthcare Natural Language API。
如需启用 API,请完成以下步骤:
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      
        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
      (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). 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
      (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). 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.
- 
  
  
    
      Enable the Cloud Healthcare API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
      Install the 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 项目的 ID
- LOCATION:数据集位置
 请求 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 项目的 ID
- LOCATION:数据集位置
 请求 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 ContentSNOMEDCT_US和ICD10CM许可词汇中的词汇代码。输出如下,请求的许可词汇代码以粗体显示:将输出提取为 FHIR R4 软件包您可以从文本中提取实体,并将其映射到 FHIR R4 资源和元素。生成的 FHIR R4 软件包包含所有实体、实体提及和关系(采用 JSON 格式)。例如,Healthcare Natural Language API 会将基本实体 PROBLEM映射到ConditionFHIR R4 资源,并将实体PROBLEM.ANATOMICAL_STRUCTURE映射到Condition.bodySiteFHIR 元素。如需查看其他映射的列表,请参阅以 FHIR 软件包形式输出的 Healthcare Natural Language API。以下示例展示了如何从 FHIR R4 软件包中的医疗文本“Insulin regimen 5 units IV will be administered for diabetes.”中提取医疗数据洞见。 如需了解详情,请参阅 AlternativeOutputFormat对象。REST在使用任何请求数据之前,请先进行以下替换: - PROJECT_ID:您的 Google Cloud 项目的 ID
- LOCATION:数据集位置
 请求 JSON 正文: { "documentContent": "Insulin regimen 5 units IV will be administered for diabetes.", "alternativeOutputFormat": "FHIR_BUNDLE" }如需发送请求,请选择以下方式之一: 如果请求成功,则响应包含一个 JSON 对象,其中包含以下条目: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 格式包含所有实体、实体提及和关系。