使用 Healthcare Natural Language API

本页面介绍了如何启用 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 和 SNOEDED CT 等标准医学词汇相对应(仅限美国用户)
  • 从文本中提取医学数据分析,并将其与 Google Cloud 中的数据分析产品集成

可用位置

Healthcare Natural Language API 在以下位置可用:

地点名称 地点描述
us-central1 美国爱荷华州
europe-west4 荷兰

启用 Healthcare Natural Language API

在开始使用 Healthcare Natural Language API 之前,您必须为您的 Google Cloud 项目启用该 API。您可以在不启用或使用 Cloud Healthcare API 功能的情况下使用 Healthcare Natural Language API。

如需启用 API,请完成以下步骤:

  1. 登录您的 Google Cloud 帐号。如果您是 Google Cloud 新手,请创建一个帐号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. 在 Google Cloud Console 的项目选择器页面上,选择或创建一个 Google Cloud 项目。

    转到“项目选择器”

  3. 确保您的 Cloud 项目已启用结算功能。 了解如何确认您的项目是否已启用结算功能

  4. 创建服务帐号:

    1. 在 Cloud Console 中,转到创建服务帐号页面。

      转到“创建服务帐号”
    2. 选择一个项目。
    3. 服务帐号名称字段中,输入一个名称。 Cloud Console 会根据此名称填充服务帐号 ID 字段。

      服务帐号说明字段中,输入说明。例如,Service account for quickstart

    4. 点击创建
    5. 点击选择角色字段。

      快速访问下,点击基本,然后点击所有者

    6. 点击继续
    7. 点击完成以完成服务帐号的创建过程。

      不要关闭浏览器窗口。您将在下一步骤中用到它。

  5. 创建服务帐号密钥:

    1. 在 Cloud Console 中,点击您创建的服务帐号的电子邮件地址。
    2. 点击密钥
    3. 依次点击添加密钥创建新密钥
    4. 点击创建。JSON 密钥文件将下载到您的计算机上。
    5. 点击关闭
  6. 将环境变量 GOOGLE_APPLICATION_CREDENTIALS 设置为包含您的服务帐号密钥的 JSON 文件的路径。 此变量仅适用于当前的 shell 会话,因此,如果您打开新的会话,请重新设置该变量。

  7. 启用 Cloud Healthcare API。

    启用 API

  8. 安装并初始化 Cloud SDK

设置权限

为了使用本指南中的功能,您必须拥有 healthcare.nlpservce.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 方法。

如需使用 Healthcare Natural Language API 从医学信息中提取医学数据分析,请发出 POST 请求并在请求中指定以下信息:

  • 父服务的名称,包括项目 ID 和位置
  • 目标文本。大小上限为 10000 个 Unicode 字符。

curl

以下示例显示了使用 curl 的 POST 请求:

curl -X POST \
   -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
   -H "Content-Type:application/json" \
   --data "{
    'nlpService':'projects/PROJECT_ID/locations/LOCATION/services/nlp',
    'documentContent':'Insulin regimen human 5 units IV administered.'
   }" \
   "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"

PowerShell

以下示例显示了使用 Windows PowerShell 的 POST 请求:

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
    'nlpService':'projects/PROJECT_ID/locations/LOCATION/services/nlp',
    'documentContent':'Insulin regimen human 5 units IV administered.'
   }" `
   -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/services/nlp:analyzeEntities"  | Select-Object -Expand Content

如果请求成功,则响应会包含以下信息:

  • 识别出的医学知识实体
  • 功能特征
  • 识别出的实体之间的关系
  • 情境特性
  • 将医学知识实体映射到标准术语

如需查看受支持实体、特性和关系类型的列表,请参阅 Healthcare Natural Language API 概念文档

上述示例中的以下响应识别了属于药物的治疗用胰岛素,该实体在 NCI 术语系统中的代码为 C581。响应还包含为响应分配的置信度分数。如需详细了解响应字段,请参阅 analyzeEntities 文档。

{
  "entityMentions": [
    {
      "mentionId": "1",
      "type": "MEDICINE",
      "text": {
        "content": "Insulin regimen human"
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/3537244"
        },
        {
          "entityId": "UMLS/3714501"
        },
        {
          "entityId": "UMLS/21641"
        },
        {
          "entityId": "UMLS/795635"
        },
        {
          "entityId": "UMLS/1533581"
        },
        {
          "entityId": "UMLS/4721402"
        }
      ],
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.87631082534790039
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.9999774694442749
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.99999970197677612
      },
      "confidence": 0.41636556386947632
    },
    {
      "mentionId": "2",
      "type": "MED_DOSE",
      "text": {
        "content": "5 units",
        "beginOffset": 22
      },
      "confidence": 0.56910794973373413
    },
    {
      "mentionId": "3",
      "type": "MED_ROUTE",
      "text": {
        "content": "IV",
        "beginOffset": 30
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/348016"
        }
      ],
      "confidence": 0.9180646538734436
    }
  ],
  "entities": [
    {
      "entityId": "UMLS/1533581",
      "preferredTerm": "Therapeutic Insulin",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "NCI/C581"
      ]
    },
    {
      "entityId": "UMLS/21641",
      "preferredTerm": "Insulin",
      "vocabularyCodes": [
        "FMA/83365",
        "LNC/LA15805-7",
        "LNC/LP14676-8",
        "LNC/LP16325-0",
        "LNC/LP32542-0",
        "LNC/LP70329-5",
        "LNC/MTHU002108",
        "LNC/MTHU019392",
        "MSH/D007328",
        "MTH/NOCODE"
      ]
    },
    {
      "entityId": "UMLS/348016",
      "preferredTerm": "Intravenous",
      "vocabularyCodes": [
        "LNC/LA9437-0",
        "LNC/LP32453-0",
        "MTH/NOCODE",
        "NCI/C13346"
      ]
    },
    {
      "entityId": "UMLS/3537244",
      "preferredTerm": "Insulins",
      "vocabularyCodes": [
        "MSH/D061385",
        "MTH/NOCODE"
      ]
    },
    {
      "entityId": "UMLS/3714501",
      "preferredTerm": "Insulin Drug Class",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "VANDF/4021631"
      ]
    },
    {
      "entityId": "UMLS/4721402",
      "preferredTerm": "INS protein, human",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "NCI/C2271"
      ]
    },
    {
      "entityId": "UMLS/795635",
      "preferredTerm": "insulin, regular, human",
      "vocabularyCodes": [
        "LNC/LP17001-6",
        "MSH/D061386",
        "MTH/NOCODE",
        "NCI/C29125",
        "RXNORM/253182",
        "VANDF/4017559",
        "VANDF/4017569",
        "VANDF/4019786"
      ]
    }
  ],
  "relationships": [
    {
      "subjectId": "1",
      "objectId": "2",
      "confidence": 0.53775161504745483
    },
    {
      "subjectId": "1",
      "objectId": "3",
      "confidence": 0.95007365942001343
    }
  ]
}

包括许可词汇

您可以在向 Healthcare Natural Language API 发出的请求中添加以下许可的词汇:

以下示例展示了如何向 Healthcare Natural Language API 发出 POST 请求,并在 licensedVocabularies 对象中包含两个可用的许可词汇。您可以指定一个或多个可用的许可词汇。

curl

以下示例展示了使用 curlPOST 请求。

curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type:application/json" \
    --data "{
      'nlpService':'projects/PROJECT_ID/locations/us-central1/services/nlp',
       'documentContent':'Diabetes. Insulin regimen human 5 units IV administered.',
       'licensedVocabularies':['SNOMEDCT_US','ICD10CM']
    }" \
    "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/us-central1/services/nlp:analyzeEntities"

PROJECT_ID 替换为您的 Google Cloud 项目 ID。

输出如下所示。指定许可词汇的输出以粗体显示:

{
  "entityMentions": [
    {
      "mentionId": "1",
      "type": "PROBLEM",
      "text": {
        "content": "Diabetes"
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0011847"
        },
        {
          "entityId": "UMLS/C0011849"
        },
        {
          "entityId": "UMLS/C0241863"
        }
      ],
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.98781299591064453
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.872421145439148
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.99975031614303589
      },
      "confidence": 0.99663406610488892
    },
    {
      "mentionId": "2",
      "type": "MEDICINE",
      "text": {
        "content": "Insulin regimen",
        "beginOffset": 10
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0795635"
        },
        {
          "entityId": "UMLS/C0021641"
        },
        {
          "entityId": "UMLS/C3537244"
        },
        {
          "entityId": "UMLS/C1533581"
        },
        {
          "entityId": "UMLS/C3714501"
        }
      ],
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.91042423248291016
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.99766635894775391
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.999998152256012
      },
      "confidence": 0.716249406337738
    },
    {
      "mentionId": "3",
      "type": "MEDICINE",
      "text": {
        "content": "human",
        "beginOffset": 26
      },
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.64570724964141846
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.90325617790222168
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.97613298892974854
      },
      "confidence": 0.57638454437255859
    },
    {
      "mentionId": "4",
      "type": "MED_DOSE",
      "text": {
        "content": "5 units",
        "beginOffset": 32
      },
      "confidence": 0.92076742649078369
    },
    {
      "mentionId": "5",
      "type": "MED_ROUTE",
      "text": {
        "content": "IV",
        "beginOffset": 40
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0348016"
        }
      ],
      "confidence": 0.967033863067627
    }
  ],
  "entities": [
    {
      "entityId": "UMLS/C0011847",
      "preferredTerm": "Diabetes",
      "vocabularyCodes": [
        "ICD10CM/E11",
        "LNC/LA10529-8",
        "LNC/LP128793-9",
        "LNC/MTHU040702",
        "MTH/NOCODE",
        "OMIM/MTHU050182"
      ]
    },
    {
      "entityId": "UMLS/C0011849",
      "preferredTerm": "Diabetes Mellitus",
      "vocabularyCodes": [
        "HPO/HP:0000819",
        "ICD10CM/E08-E13",
        "ICD9CM/250",
        "LNC/LA14291-1",
        "LNC/LA27539-8",
        "LNC/MTHU020781",
        "MEDLINEPLUS/4",
        "MEDLINEPLUS/45",
        "MSH/D003920",
        "MTH/NOCODE",
        "MTH/U000263",
        "NCI/C2985",
        "NCI/OMFAQ",
        "NCI/TCGA",
        "OMIM/MTHU036798",
        "SNOMEDCT_US/73211009"
      ]
    },
    {
      "entityId": "UMLS/C0021641",
      "preferredTerm": "Insulin",
      "vocabularyCodes": [
        "FMA/83365",
        "LNC/LA15805-7",
        "LNC/LP14676-8",
        "LNC/LP16325-0",
        "LNC/LP32542-0",
        "LNC/LP70329-5",
        "LNC/MTHU002108",
        "LNC/MTHU019392",
        "MEDLINEPLUS/4935",
        "MSH/D007328",
        "MTH/NOCODE",
        "SNOMEDCT_US/39487003",
        "SNOMEDCT_US/412222002",
        "SNOMEDCT_US/67866001"
      ]
    },
    {
      "entityId": "UMLS/C0241863",
      "preferredTerm": "Diabetic",
      "vocabularyCodes": [
        "LNC/LA26134-9"
      ]
    },
    {
      "entityId": "UMLS/C0348016",
      "preferredTerm": "Intravenous",
      "vocabularyCodes": [
        "LNC/LA9437-0",
        "LNC/LP32453-0",
        "MTH/NOCODE",
        "NCI/C13346",
        "SNOMEDCT_US/255560000"
      ]
    },
    {
      "entityId": "UMLS/C0795635",
      "preferredTerm": "insulin, regular, human",
      "vocabularyCodes": [
        "LNC/LP17001-6",
        "MSH/D061386",
        "MTH/NOCODE",
        "NCI/C29125",
        "RXNORM/253182",
        "SNOMEDCT_US/126210001",
        "SNOMEDCT_US/417423002",
        "SNOMEDCT_US/420609005",
        "SNOMEDCT_US/96367001",
        "VANDF/4017559",
        "VANDF/4017569",
        "VANDF/4019786"
      ]
    },
    {
      "entityId": "UMLS/C1533581",
      "preferredTerm": "Therapeutic Insulin",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "NCI/C581"
      ]
    },
    {
      "entityId": "UMLS/C3537244",
      "preferredTerm": "Insulins",
      "vocabularyCodes": [
        "MSH/D061385",
        "MTH/NOCODE"
      ]
    },
    {
      "entityId": "UMLS/C3714501",
      "preferredTerm": "Insulin Drug Class",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "VANDF/4021631"
      ]
    }
  ],
  "relationships": [
    {
      "subjectId": "2",
      "objectId": "4",
      "confidence": 0.99827027320861816
    },
    {
      "subjectId": "2",
      "objectId": "5",
      "confidence": 0.99729859828948975
    },
    {
      "subjectId": "3",
      "objectId": "4",
      "confidence": 0.80851161479949951
    },
    {
      "subjectId": "3",
      "objectId": "5",
      "confidence": 0.67507040500640869
    }
  ]
}

PowerShell

以下示例展示了使用 Windows PowerShell 的 POST 请求:

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
    'nlpService':'projects/PROJECT_ID/locations/us-central1/services/nlp',
    'documentContent': 'Diabetes. Insulin regimen human 5 units IV administered.',
    'licensedVocabularies': ['SNOMEDCT_US','ICD10CM']
   }" `
   -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/us-central1/services/nlp:analyzeEntities"  | Select-Object -Expand Content

PROJECT_ID 替换为您的 Google Cloud 项目 ID。

输出如下所示。指定许可词汇的输出以粗体显示:

{
  "entityMentions": [
    {
      "mentionId": "1",
      "type": "PROBLEM",
      "text": {
        "content": "Diabetes"
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0011847"
        },
        {
          "entityId": "UMLS/C0011849"
        },
        {
          "entityId": "UMLS/C0241863"
        }
      ],
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.98781299591064453
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.872421145439148
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.99975031614303589
      },
      "confidence": 0.99663406610488892
    },
    {
      "mentionId": "2",
      "type": "MEDICINE",
      "text": {
        "content": "Insulin regimen",
        "beginOffset": 10
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0795635"
        },
        {
          "entityId": "UMLS/C0021641"
        },
        {
          "entityId": "UMLS/C3537244"
        },
        {
          "entityId": "UMLS/C1533581"
        },
        {
          "entityId": "UMLS/C3714501"
        }
      ],
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.91042423248291016
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.99766635894775391
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.999998152256012
      },
      "confidence": 0.716249406337738
    },
    {
      "mentionId": "3",
      "type": "MEDICINE",
      "text": {
        "content": "human",
        "beginOffset": 26
      },
      "temporalAssessment": {
        "value": "CURRENT",
        "confidence": 0.64570724964141846
      },
      "certaintyAssessment": {
        "value": "LIKELY",
        "confidence": 0.90325617790222168
      },
      "subject": {
        "value": "PATIENT",
        "confidence": 0.97613298892974854
      },
      "confidence": 0.57638454437255859
    },
    {
      "mentionId": "4",
      "type": "MED_DOSE",
      "text": {
        "content": "5 units",
        "beginOffset": 32
      },
      "confidence": 0.92076742649078369
    },
    {
      "mentionId": "5",
      "type": "MED_ROUTE",
      "text": {
        "content": "IV",
        "beginOffset": 40
      },
      "linkedEntities": [
        {
          "entityId": "UMLS/C0348016"
        }
      ],
      "confidence": 0.967033863067627
    }
  ],
  "entities": [
    {
      "entityId": "UMLS/C0011847",
      "preferredTerm": "Diabetes",
      "vocabularyCodes": [
        "ICD10CM/E11",
        "LNC/LA10529-8",
        "LNC/LP128793-9",
        "LNC/MTHU040702",
        "MTH/NOCODE",
        "OMIM/MTHU050182"
      ]
    },
    {
      "entityId": "UMLS/C0011849",
      "preferredTerm": "Diabetes Mellitus",
      "vocabularyCodes": [
        "HPO/HP:0000819",
        "ICD10CM/E08-E13",
        "ICD9CM/250",
        "LNC/LA14291-1",
        "LNC/LA27539-8",
        "LNC/MTHU020781",
        "MEDLINEPLUS/4",
        "MEDLINEPLUS/45",
        "MSH/D003920",
        "MTH/NOCODE",
        "MTH/U000263",
        "NCI/C2985",
        "NCI/OMFAQ",
        "NCI/TCGA",
        "OMIM/MTHU036798",
        "SNOMEDCT_US/73211009"
      ]
    },
    {
      "entityId": "UMLS/C0021641",
      "preferredTerm": "Insulin",
      "vocabularyCodes": [
        "FMA/83365",
        "LNC/LA15805-7",
        "LNC/LP14676-8",
        "LNC/LP16325-0",
        "LNC/LP32542-0",
        "LNC/LP70329-5",
        "LNC/MTHU002108",
        "LNC/MTHU019392",
        "MEDLINEPLUS/4935",
        "MSH/D007328",
        "MTH/NOCODE",
        "SNOMEDCT_US/39487003",
        "SNOMEDCT_US/412222002",
        "SNOMEDCT_US/67866001"
      ]
    },
    {
      "entityId": "UMLS/C0241863",
      "preferredTerm": "Diabetic",
      "vocabularyCodes": [
        "LNC/LA26134-9"
      ]
    },
    {
      "entityId": "UMLS/C0348016",
      "preferredTerm": "Intravenous",
      "vocabularyCodes": [
        "LNC/LA9437-0",
        "LNC/LP32453-0",
        "MTH/NOCODE",
        "NCI/C13346",
        "SNOMEDCT_US/255560000"
      ]
    },
    {
      "entityId": "UMLS/C0795635",
      "preferredTerm": "insulin, regular, human",
      "vocabularyCodes": [
        "LNC/LP17001-6",
        "MSH/D061386",
        "MTH/NOCODE",
        "NCI/C29125",
        "RXNORM/253182",
        "SNOMEDCT_US/126210001",
        "SNOMEDCT_US/417423002",
        "SNOMEDCT_US/420609005",
        "SNOMEDCT_US/96367001",
        "VANDF/4017559",
        "VANDF/4017569",
        "VANDF/4019786"
      ]
    },
    {
      "entityId": "UMLS/C1533581",
      "preferredTerm": "Therapeutic Insulin",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "NCI/C581"
      ]
    },
    {
      "entityId": "UMLS/C3537244",
      "preferredTerm": "Insulins",
      "vocabularyCodes": [
        "MSH/D061385",
        "MTH/NOCODE"
      ]
    },
    {
      "entityId": "UMLS/C3714501",
      "preferredTerm": "Insulin Drug Class",
      "vocabularyCodes": [
        "MTH/NOCODE",
        "VANDF/4021631"
      ]
    }
  ],
  "relationships": [
    {
      "subjectId": "2",
      "objectId": "4",
      "confidence": 0.99827027320861816
    },
    {
      "subjectId": "2",
      "objectId": "5",
      "confidence": 0.99729859828948975
    },
    {
      "subjectId": "3",
      "objectId": "4",
      "confidence": 0.80851161479949951
    },
    {
      "subjectId": "3",
      "objectId": "5",
      "confidence": 0.67507040500640869
    }
  ]
}