你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 Python 的 Azure 认知服务 Health Insights 临床匹配客户端库 - 版本 1.0.0b1

Health Insights 是使用 Azure 认知服务框架构建的 Azure 应用 AI 服务,它利用多个认知服务、医疗保健 API 服务和其他 Azure 资源。 临床匹配模型接收患者数据和临床试验协议,并根据资格标准提供相关的临床试验。

源代码 | 包 (PyPI) | API 参考文档 | 产品文档 | 样品

入门

先决条件

  • 使用此包需要 Python 3.7 或更高版本。
  • 需要 Azure 订阅 才能使用此包。
  • 现有的认知服务运行状况见解实例。

安装包

pip install azure-healthinsights-clinicalmatching

此表显示了 SDK 版本与服务支持的 API 版本之间的关系:

SDK 版本 服务支持的 API 版本
1.0.0b1 2023-03-01-preview

验证客户端

获取终结点

可以使用 Azure 门户或 AzureCLI 查找 Health Insights 服务资源的终结点

# Get the endpoint for the Health Insights service resource
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"

获取 API 密钥

可以从 Azure 门户中的 Health Insights 服务资源获取 API 密钥 。 或者,可以使用下面的 Azure CLI 代码片段获取资源的 API 密钥。

az cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>

使用 API 密钥凭据创建 ClinicalMatchingClient

获得 API 密钥的值后,可以将其作为字符串传递到 AzureKeyCredential 实例中。 使用密钥作为凭据参数对客户端进行身份验证:

import os
from azure.core.credentials import AzureKeyCredential
from azure.healthinsights.clinicalmatching import ClinicalMatchingClient

KEY = os.environ["HEALTHINSIGHTS_KEY"]
ENDPOINT = os.environ["HEALTHINSIGHTS_ENDPOINT"]

trial_matcher_client = ClinicalMatchingClient(endpoint=ENDPOINT, credential=AzureKeyCredential(KEY))

Long-Running操作

长时间运行的操作包括发送到服务以启动操作的初始请求,然后按间隔轮询服务以确定操作是否已完成或失败,如果操作成功,则获取结果。

支持医疗保健分析、自定义文本分析或多个分析的方法将建模为长时间运行的操作。 客户端公开一个 begin_<method-name> 返回轮询器对象的方法。 调用方应通过调用 result()begin_<method-name> 方法返回的轮询器对象来等待操作完成。 提供了示例代码片段来说明如何使用长时间运行的操作

关键概念

试用匹配器为服务的用户提供了两种main操作模式:以患者为中心和以临床试验为中心。

  • 在以患者为中心的模式下,试用匹配器模型基于患者匹配的临床条件、位置、优先级、资格标准以及患者和/或服务用户可能选择的优先顺序的其他条件。 该模型有助于缩小相关临床试验的范围,并将这些试验的优先级设置为一组较小的试验,而特定患者似乎有资格使用。
  • 以临床试验为中心,试验匹配器正在找到一组可能有资格参加临床试验的患者。 试验匹配器缩小患者范围,首先筛选临床状况和选定的临床观察结果,然后关注那些符合基线标准的患者,以找到似乎有资格参加试验的患者组。

示例

以下部分提供了几个代码片段,涵盖了一些最常见的 Health Insights - 临床匹配服务任务,包括:

匹配试用版

为患者查找潜在的合格试验。

import os
import datetime
from azure.core.credentials import AzureKeyCredential
from azure.healthinsights.clinicalmatching import ClinicalMatchingClient, models

KEY = os.environ["HEALTHINSIGHTS_KEY"]
ENDPOINT = os.environ["HEALTHINSIGHTS_ENDPOINT"]

# Create a Trial Matcher client
# <client>
trial_matcher_client = ClinicalMatchingClient(endpoint=ENDPOINT,
                                              credential=AzureKeyCredential(KEY))
# </client>

# Create clinical info list
# <clinicalInfo>
clinical_info_list = [models.ClinicalCodedElement(system="http://www.nlm.nih.gov/research/umls",
                                                  code="C0032181",
                                                  name="Platelet count",
                                                  value="250000"),
                      models.ClinicalCodedElement(system="http://www.nlm.nih.gov/research/umls",
                                                  code="C0002965",
                                                  name="Unstable Angina",
                                                  value="true"),
                      models.ClinicalCodedElement(system="http://www.nlm.nih.gov/research/umls",
                                                  code="C1522449",
                                                  name="Radiotherapy",
                                                  value="false"),
                      models.ClinicalCodedElement(system="http://www.nlm.nih.gov/research/umls",
                                                  code="C0242957",
                                                  name="GeneOrProtein-Expression",
                                                  value="Negative;EntityType:GENEORPROTEIN-EXPRESSION"),
                      models.ClinicalCodedElement(system="http://www.nlm.nih.gov/research/umls",
                                                  code="C1300072",
                                                  name="cancer stage",
                                                  value="2")]

# </clinicalInfo>

# Construct Patient
# <PatientConstructor>
patient_info = models.PatientInfo(sex=models.PatientInfoSex.MALE, birth_date=datetime.date(1965, 12, 26),
                                  clinical_info=clinical_info_list)
patient1 = models.PatientRecord(id="patient_id", info=patient_info)
# </PatientConstructor>

# Create registry filter
registry_filters = models.ClinicalTrialRegistryFilter()
# Limit the trial to a specific patient condition ("Non-small cell lung cancer")
registry_filters.conditions = ["non small cell lung cancer (nsclc)"]
# Specify the clinical trial registry source as ClinicalTrials.Gov
registry_filters.sources = [models.ClinicalTrialSource.CLINICALTRIALS_GOV]
# Limit the clinical trial to a certain location, in this case California, USA
registry_filters.facility_locations = [
    models.GeographicLocation(country_or_region="United States", city="Gilbert", state="Arizona")]
# Limit the trial to a specific recruitment status
registry_filters.recruitment_statuses = [models.ClinicalTrialRecruitmentStatus.RECRUITING]

# Construct ClinicalTrial instance and attach the registry filter to it.
clinical_trials = models.ClinicalTrials(registry_filters=[registry_filters])

# Create TrialMatcherRequest
configuration = models.TrialMatcherModelConfiguration(clinical_trials=clinical_trials)
trial_matcher_data = models.TrialMatcherData(patients=[patient1], configuration=configuration)

poller = trial_matcher_client.begin_match_trials(trial_matcher_data)
trial_matcher_result = poller.result()
if trial_matcher_result.status == models.JobStatus.SUCCEEDED:
    tm_results = trial_matcher_result.results
    for patient_result in tm_results.patients:
        print(f"Inferences of Patient {patient_result.id}")
        for tm_inferences in patient_result.inferences:
            print(f"Trial Id {tm_inferences.id}")
            print(f"Type: {str(tm_inferences.type)}  Value: {tm_inferences.value}")
            print(f"Description {tm_inferences.description}")
else:
    tm_errors = trial_matcher_result.errors
    if tm_errors is not None:
        for error in tm_errors:
            print(f"{error.code} : {error.message}")

疑难解答

常规

Health Insights 临床匹配客户端库将引发 Azure Core 中定义的异常。

Logging

此库使用标准 日志记录 库进行日志记录。

有关 HTTP 会话的基本信息 (URL、标头等) 记录在 INFO 级别。

可以使用 关键字 (keyword) 参数在客户端或每个操作logging_enable上启用详细DEBUG级别日志记录,包括请求/响应正文和未执行的标头。

请参阅此处的示例的完整 SDK 日志记录文档。

可选配置

可选的关键字 (keyword) 参数可以在客户端和每个操作级别传入。 azure-core 参考文档 介绍了重试、日志记录、传输协议等的可用配置。

后续步骤

其他文档

有关 Azure Health Insights 临床匹配的更多文档,请参阅有关 docs.microsoft.com 的临床匹配文档

贡献

本项目欢迎贡献和建议。 大多数贡献要求你同意贡献者许可协议 (CLA),并声明你有权(并且确实有权)授予我们使用你的贡献的权利。 有关详细信息,请访问 https://cla.microsoft.com

提交拉取请求时,CLA 机器人将自动确定你是否需要提供 CLA,并相应地修饰 PR(例如标签、注释)。 直接按机器人提供的说明操作。 只需使用 CLA 对所有存储库执行一次这样的操作。

本项目采用 Microsoft 开源行为准则。 有关详细信息,请参阅“行为准则常见问题解答”,如有其他任何问题或意见,请联系 opencode@microsoft.com。