跳转到主要内容

Microsoft Cognitive Services Health Insights Clinical Matching Client Library for Python

项目描述

Azure Cognitive Services Health Insights Clinical Matching客户端库

Health Insights 是一个基于Azure Cognitive Services框架构建的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门户Azure CLI找到您的健康洞察服务资源的端点

# 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门户中的健康洞察服务资源获取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))

长时间运行的操作

长时间运行的操作是指由初始请求到服务以启动操作组成,然后通过定时轮询服务以确定操作是否完成或失败,如果成功,则获取结果的操作。

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

关键概念

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

  • 在以患者为中心的模式下,试验匹配器模型基于临床状况、位置、优先级、资格标准以及其他患者和/或服务用户可能选择优先考虑的标准来匹配患者。该模型有助于将相关临床试验的集合缩小到一个更小的试验集合,以便从特定患者似乎有资格的试验开始。
  • 在以临床试验为中心的模式下,试验匹配器正在寻找可能符合临床试验资格的患者群体。试验匹配器首先根据临床状况和选定的临床观察结果进行筛选,然后专注于那些满足基线标准的患者,以找到似乎符合试验资格的患者群体。

示例

以下部分提供了几个代码片段,涵盖了健康洞察-临床匹配服务的一些常见任务,包括

匹配试验

寻找患者的潜在合格试验。

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}")

故障排除

一般

健康洞察临床匹配客户端库将引发在Azure Core中定义的异常。

日志记录

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

HTTP会话的基本信息(URL、标题等)以INFO级别进行记录。

详细的DEBUG级别日志记录,包括请求/响应体和未编辑的标题,可以通过logging_enable关键字参数在客户端或每个操作中启用。

有关示例的完整SDK日志记录文档请在此处查看

可选配置

可选关键字参数可以在客户端和操作级别传递。Azure Core的参考文档描述了重试、日志记录、传输协议等可用的配置。

下一步

附加文档

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

贡献

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

提交拉取请求时,CLA机器人会自动确定您是否需要提供CLA,并相应地装饰PR(例如,标签、注释)。只需遵循机器人提供的说明。您只需在所有使用我们的CLA的仓库中这样做一次。

本项目采用了Microsoft开源行为准则。有关更多信息,请参阅行为准则FAQ或联系opencode@microsoft.com以提出任何额外的问题或评论。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

构建分布

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面