Microsoft Azure Health Insights - Python的放射学洞察力客户端库
项目描述
Azure认知服务健康洞察放射学洞察力Python客户端库
健康洞察力 是一个基于Azure认知服务框架构建的Azure应用AI服务,利用多个认知服务、Healthcare API服务和其它Azure资源。
放射学洞察力 是一个旨在提供质量检查作为错误和不一致(不匹配)的反馈,并确保通过报告的完整上下文识别和传达关键发现。还识别了放射科医生记录的后续建议和临床发现(尺寸)。
入门
先决条件
- 使用此软件包需要Python 3.8+。
- 使用此软件包需要Azure订阅。
- 现有的认知服务健康洞察实例。
有关创建资源或如何获取位置和SKU信息的更多信息,请参阅此处。
安装模块
python -m pip install azure-healthinsights-radiologyinsights
此表显示了SDK版本与服务支持的API版本之间的关系
SDK版本 | 服务支持的API版本 |
---|---|
1.0.0 | 2024-04-01 |
验证客户端
获取端点
您可以使用Azure门户或Azure CLI找到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"
使用DefaultAzureCredential创建RadiologyInsightsClient。
DefaultAzureCredential提供了多种与服务进行身份验证的方式。有关此信息的文档可以在这里找到。
import os
from azure.identity import DefaultAzureCredential
from azure.healthinsights.radiologyinsights import RadiologyInsightsClient
credential = DefaultAzureCredential()
ENDPOINT = os.environ["AZURE_HEALTH_INSIGHTS_ENDPOINT"]
radiology_insights_client = RadiologyInsightsClient(endpoint=ENDPOINT, credential=credential)
长时间运行的操作
长时间运行的操作是由初始请求组成的操作,该请求发送到服务以启动操作,然后以一定的时间间隔轮询服务以确定操作是否完成或失败,如果成功,则获取结果。
支持医疗分析、自定义文本分析或多个分析的方法被建模为长时间运行的操作。客户端公开了一个返回轮询对象的begin_<method-name>
方法。调用者应该通过在从begin_<method-name>
方法返回的轮询对象上调用result()
来等待操作完成。下面提供了使用长时间运行操作的示例代码片段。
关键概念
初始化“RadiologyInsightsClient”后,您可以使用它通过显示文本中找到的推理来分析文档文本。
- 年龄不匹配
- 侧别不一致
- 性别不匹配
- 完整订单不匹配
- 有限订单不匹配
- 发现
- 关键结果
- 后续建议
- 通讯
- 放射学程序
放射学洞察目前仅支持一份患者的文档。有关此服务产生的推理的更多详细信息,请参阅这里。
示例
对于每个推理,都提供了同步(阻塞直到操作完成,较慢)或异步(非阻塞,更快)检索信息的方式的示例。有关如何创建客户端、请求以及获取结果的示例,请参阅示例文件夹中的示例。
运行示例
- 打开终端窗口,并使用
cd
命令进入保存示例的目录。 - 设置要运行的示例文件中指定的环境变量。
- 运行示例。例如:
python <sample_name>.py
为放射学洞察服务创建请求
doc_content1 = """CLINICAL HISTORY:
20-year-old female presenting with abdominal pain. Surgical history significant for appendectomy.
COMPARISON:
Right upper quadrant sonographic performed 1 day prior.
TECHNIQUE:
Transabdominal grayscale pelvic sonography with duplex color Doppler and spectral waveform analysis of the ovaries.
FINDINGS:
The uterus is unremarkable given the transabdominal technique with endometrial echo complex within physiologic normal limits. The ovaries are symmetric in size, measuring 2.5 x 1.2 x 3.0 cm and the left measuring 2.8 x 1.5 x 1.9 cm.\n On duplex imaging, Doppler signal is symmetric.
IMPRESSION:
1. Normal pelvic sonography. Findings of testicular torsion.
A new US pelvis within the next 6 months is recommended.
These results have been discussed with Dr. Jones at 3 PM on November 5 2020."""
# Create ordered procedure
procedure_coding = models.Coding(
system="Http://hl7.org/fhir/ValueSet/cpt-all",
code="USPELVIS",
display="US PELVIS COMPLETE",
)
procedure_code = models.CodeableConcept(coding=[procedure_coding])
ordered_procedure = models.OrderedProcedure(description="US PELVIS COMPLETE", code=procedure_code)
# Create encounter
start = datetime.datetime(2021, 8, 28, 0, 0, 0, 0)
end = datetime.datetime(2021, 8, 28, 0, 0, 0, 0)
encounter = models.PatientEncounter(
id="encounter2",
class_property=models.EncounterClass.IN_PATIENT,
period=models.TimePeriod(start=start, end=end),
)
# Create patient info
birth_date = datetime.date(1959, 11, 11)
patient_info = models.PatientDetails(sex=models.PatientSex.FEMALE, birth_date=birth_date)
# Create author
author = models.DocumentAuthor(id="author2", full_name="authorName2")
create_date_time = datetime.datetime(2024, 2, 19, 0, 0, 0, 0, tzinfo=datetime.timezone.utc)
patient_document1 = models.PatientDocument(
type=models.DocumentType.NOTE,
clinical_type=models.ClinicalDocumentType.RADIOLOGY_REPORT,
id="doc2",
content=models.DocumentContent(source_type=models.DocumentContentSourceType.INLINE, value=doc_content1),
created_at=create_date_time,
specialty_type=models.SpecialtyType.RADIOLOGY,
administrative_metadata=models.DocumentAdministrativeMetadata(
ordered_procedures=[ordered_procedure], encounter_id="encounter2"
),
authors=[author],
language="en",
)
# Construct patient
patient1 = models.PatientRecord(
id="patient_id2",
details=patient_info,
encounters=[encounter],
patient_documents=[patient_document1],
)
# Create a configuration
configuration = models.RadiologyInsightsModelConfiguration(verbose=False, include_evidence=True, locale="en-US")
# Construct the request with the patient and configuration
patient_data = models.RadiologyInsightsJob(job_data=models.RadiologyInsightsData(patients=[patient1], configuration=configuration))
获取年龄不匹配推理信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.AGE_MISMATCH:
print(f"Age Mismatch Inference found")
获取完整订单不匹配推理信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.COMPLETE_ORDER_DISCREPANCY:
print(f"Complete Order Discrepancy Inference found")
获取关键结果推理信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.CRITICAL_RESULT:
critical_result = ri_inference.result
print(
f"Critical Result Inference found: {critical_result.description}")
获取发现推理信息
for patient_result in radiology_insights_result.patient_results:
counter = 0
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FINDING:
counter += 1
print(f"Finding Inference found")
获取后续通讯信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FOLLOWUP_COMMUNICATION:
print(f"Follow-up Communication Inference found")
获取后续建议信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.FOLLOWUP_RECOMMENDATION:
print(f"Follow-up Recommendation Inference found")
获取侧别不一致信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.LATERALITY_DISCREPANCY:
print(f"Laterality Discrepancy Inference found")
获取有限订单不匹配信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.LIMITED_ORDER_DISCREPANCY:
print(f"Limited Order Discrepancy Inference found")
获取放射学程序信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.RADIOLOGY_PROCEDURE:
print(f"Radiology Procedure Inference found")
获取性别不匹配信息
for patient_result in radiology_insights_result.patient_results:
for ri_inference in patient_result.inferences:
if ri_inference.kind == models.RadiologyInsightsInferenceType.SEX_MISMATCH:
print(f"Sex Mismatch Inference found")
有关此以及其他推理的详细概念信息,请参阅这里。
故障排除
一般
Health Insights放射学洞察客户端库将引发定义在Azure Core中的异常。
日志记录
此库使用标准的logging库进行日志记录。
HTTP会话(URL、头信息等)的基本信息在INFO
级别进行日志记录。
详细的DEBUG
级别日志记录,包括请求/响应体和未删除的头信息,可以通过客户端或通过操作使用logging_enable
关键字参数启用。
有关示例的完整SDK日志记录文档请参阅这里。
下一步操作
贡献
本项目欢迎贡献和建议。大多数贡献需要您同意贡献者许可协议(CLA),声明您有权且确实授予我们使用您的贡献的权利。有关详细信息,请访问 https://cla.microsoft.com。
提交拉取请求时,CLA机器人会自动判断您是否需要提供CLA,并相应地装饰PR(例如,标签、注释)。只需遵循机器人提供的说明。您只需要在整个使用我们的CLA的仓库中这样做一次。
本项目已采用 Microsoft开源行为准则。有关更多信息,请参阅行为准则常见问题解答或通过 opencode@microsoft.com 联系我们,提出任何额外的问题或评论。
项目详情
azure_healthinsights_radiologyinsights-1.0.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 312734f5acdfc2b17470142404bac7af3965f3a3bac0ce3457d333083714ff11 |
|
MD5 | aac31b703168610d72525c2a6c3921a0 |
|
BLAKE2b-256 | f888a5c8c42248862f79a555144639c6f40fa1aaa8363a75092e464fb535b32f |
azure_healthinsights_radiologyinsights-1.0.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | fdcc4968d7e02e52bbe5324c563f146c80cbf655cdeb06e2b866271f0ea1db9e |
|
MD5 | d3ca4bca5272db90b934239c2408db22 |
|
BLAKE2b-256 | bcd8ba667c5fb5a5af16afb56ff674395e39ea542d118dfdab517a5d67e3657a |