共用方式為


適用于 Python 的 Azure 認知服務 Health Insights 疾病分析用戶端程式庫 - 1.0.0b1 版

Health Insights 是使用 Azure 認知服務架構建置的 Azure 套用 AI 服務,可運用多個認知服務、醫療保健 API 服務和其他 Azure 資源。

疾病分析模型會接收疾病病患的臨床記錄,並輸出疾病預備,例如臨床階段 TNM 類別和臨床階段 TNM 類別,以及臨床網站、直方學。

| 原始程式碼套件 (PyPI) | API 參考檔 | 產品檔 | 樣品

開始使用

Prerequisites

  • 需要 Python 3.7 或更新版本才能使用此套件。
  • 您需要 Azure 訂用帳戶 才能使用此套件。
  • 現有的認知服務健康情況深入解析實例。

安裝套件

pip install azure-healthinsights-cancerprofiling

下表顯示 SDK 版本與服務支援的 API 版本之間的關聯性:

SDK 版本 服務支援的 API 版本
1.0.0b1 2023-03-01-preview

驗證用戶端

取得端點

您可以使用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"

取得 API 金鑰

您可以從 Azure 入口網站中的 Health Insights 服務資源取得 API 金鑰 。 或者,您可以使用下方 的 Azure CLI 程式碼片段來取得資源的 API 金鑰。

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

使用 API 金鑰認證建立 CancerProfilingClient

取得 API 金鑰的值之後,您可以將它當做字串傳遞至 AzureKeyCredential的實例。 使用金鑰作為認證參數來驗證用戶端:

import os
from azure.core.credentials import AzureKeyCredential
from azure.healthinsights.cancerprofiling.aio import CancerProfilingClient

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

cancer_profiling_client = CancerProfilingClient(endpoint=ENDPOINT, credential=AzureKeyCredential(KEY))

Long-Running作業

長時間執行的作業是由傳送至服務以啟動作業的初始要求所組成,後面接著以間隔輪詢服務,以判斷作業是否已完成或失敗,如果作業成功,則取得結果。

支援醫療保健分析、自訂文字分析或多個分析的方法會模型化為長時間執行的作業。 用戶端會 begin_<method-name> 公開傳回輪詢器物件的方法。 呼叫端應該等候作業完成,方法是呼叫 result() 從 方法傳回的 begin_<method-name> 輪詢器物件。 提供範例程式碼片段來說明如何使用長時間執行的作業

重要概念

疾病分析模型可讓您從非結構化臨床檔推斷疾病屬性,例如臨床網站、長條圖、臨床階段 TNM 類別和臨床階段 TNM 類別。

範例

下一節提供數個程式碼片段,涵蓋一些最常見的 Health Insights - 疾病分析服務工作,包括:

疾病分析

從病患的非結構化臨床檔中推斷主要疾病屬性,例如臨床網站、直方學、臨床階段 TNM 類別和臨床階段 TNM 類別。

import asyncio
import os
import datetime
from azure.core.credentials import AzureKeyCredential
from azure.healthinsights.cancerprofiling.aio import CancerProfilingClient
from azure.healthinsights.cancerprofiling import models

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

# Create an Onco Phenotype client
# <client>
cancer_profiling_client = CancerProfilingClient(endpoint=ENDPOINT,
                                                credential=AzureKeyCredential(KEY))
# </client>

# Construct patient
# <PatientConstructor>
patient_info = models.PatientInfo(sex=models.PatientInfoSex.FEMALE, birth_date=datetime.date(1979, 10, 8))
patient1 = models.PatientRecord(id="patient_id", info=patient_info)
# </PatientConstructor>

# Add document list
# <DocumentList>
doc_content1 = """
            15.8.2021
            Jane Doe 091175-8967
            42 year old female, married with 3 children, works as a nurse
            Healthy, no medications taken on a regular basis.
            PMHx is significant for migraines with aura, uses Mirena for contraception.
            Smoking history of 10 pack years (has stopped and relapsed several times).
            She is in c/o 2 weeks of productive cough and shortness of breath.
            She has a fever of 37.8 and general weakness.
            Denies night sweats and rash. She denies symptoms of rhinosinusitis, asthma, and heartburn.
            On PE:
            GENERAL: mild pallor, no cyanosis. Regular breathing rate.
            LUNGS: decreased breath sounds on the base of the right lung. Vesicular breathing. 
                No crackles, rales, and wheezes. Resonant percussion.
            PLAN:
            Will be referred for a chest x-ray.
            ======================================
            CXR showed mild nonspecific opacities in right lung base.
            PLAN:
            Findings are suggestive of a working diagnosis of pneumonia. The patient is referred to a
            follow-up CXR in 2 weeks."""

patient_document1 = models.PatientDocument(type=models.DocumentType.NOTE,
                                           id="doc1",
                                           content=models.DocumentContent(
                                               source_type=models.DocumentContentSourceType.INLINE,
                                               value=doc_content1),
                                           clinical_type=models.ClinicalDocumentType.IMAGING,
                                           language="en",
                                           created_date_time=datetime.datetime(2021, 8, 15))

doc_content2 = """
            Oncology Clinic
            20.10.2021
            Jane Doe 091175-8967
            42-year-old healthy female who works as a nurse in the ER of this hospital.
            First menstruation at 11 years old. First delivery- 27 years old. She has 3 children.
            Didn't breastfeed.
            Contraception- Mirena.
            Smoking- 10 pack years.
            Mother- Belarusian. Father- Georgian. 
            About 3 months prior to admission, she stated she had SOB and was febrile.
            She did a CXR as an outpatient which showed a finding in the base of the right lung-
            possibly an infiltrate.
            She was treated with antibiotics with partial response.
            6 weeks later a repeat CXR was performed- a few solid dense findings in the right lung.
            Therefore, she was referred for a PET-CT which demonstrated increased uptake in the right
            breast, lymph nodes on the right a few areas in the lungs and liver.
            On biopsy from the lesion in the right breast- triple negative adenocarcinoma. Genetic
            testing has not been done thus far.
            Genetic counseling- the patient denies a family history of breast, ovary, uterus,
            and prostate cancer. Her mother has chronic lymphocytic leukemia (CLL).
            She is planned to undergo genetic tests because the aggressive course of the disease,
            and her young age.
            Impression:
            Stage 4 triple negative breast adenocarcinoma.
            Could benefit from biological therapy.
            Different treatment options were explained- the patient wants to get a second opinion."""

patient_document2 = models.PatientDocument(type=models.DocumentType.NOTE,
                                           id="doc2",
                                           content=models.DocumentContent(
                                               source_type=models.DocumentContentSourceType.INLINE,
                                               value=doc_content2),
                                           clinical_type=models.ClinicalDocumentType.PATHOLOGY,
                                           language="en",
                                           created_date_time=datetime.datetime(2021, 10, 20))

doc_content3 = """
            PATHOLOGY REPORT
                                    Clinical Information
            Ultrasound-guided biopsy; A. 18 mm mass; most likely diagnosis based on imaging:  IDC
                                        Diagnosis
            A.  BREAST, LEFT AT 2:00 4 CM FN; ULTRASOUND-GUIDED NEEDLE CORE BIOPSIES:
            - Invasive carcinoma of no special type (invasive ductal carcinoma), grade 1
            Nottingham histologic grade:  1/3 (tubules 2; nuclear grade 2; mitotic rate 1;
            total score; 5/9)
            Fragments involved by invasive carcinoma:  2
            Largest measurement of invasive carcinoma on a single fragment:  7 mm
            Ductal carcinoma in situ (DCIS):  Present
            Architectural pattern:  Cribriform
            Nuclear grade:  2-
                            -intermediate
            Necrosis:  Not identified
            Fragments involved by DCIS:  1
            Largest measurement of DCIS on a single fragment:  Span 2 mm
            Microcalcifications:  Present in benign breast tissue and invasive carcinoma
            Blocks with invasive carcinoma:  A1
            Special studies: Pending"""

patient_document3 = models.PatientDocument(type=models.DocumentType.NOTE,
                                           id="doc3",
                                           content=models.DocumentContent(
                                               source_type=models.DocumentContentSourceType.INLINE,
                                               value=doc_content3),
                                           clinical_type=models.ClinicalDocumentType.PATHOLOGY,
                                           language="en",
                                           created_date_time=datetime.datetime(2022, 1, 1))

patient_doc_list = [patient_document1, patient_document2, patient_document3]
patient1.data = patient_doc_list
# <\DocumentList>

# Set configuration to include evidence for the cancer staging inferences
configuration = models.OncoPhenotypeModelConfiguration(include_evidence=True)

# Construct the request with the patient and configuration
cancer_profiling_data = models.OncoPhenotypeData(patients=[patient1], configuration=configuration)

poller = await cancer_profiling_client.begin_infer_cancer_profile(cancer_profiling_data)
cancer_profiling_result = await poller.result()
if cancer_profiling_result.status == models.JobStatus.SUCCEEDED:
    results = cancer_profiling_result.results
    for patient_result in results.patients:
        print(f"\n==== Inferences of Patient {patient_result.id} ====")
        for inference in patient_result.inferences:
            print(
                f"\n=== Clinical Type: {str(inference.type)} Value: {inference.value}\
                    ConfidenceScore: {inference.confidence_score} ===")
            for evidence in inference.evidence:
                data_evidence = evidence.patient_data_evidence
                print(
                    f"Evidence {data_evidence.id} {data_evidence.offset} {data_evidence.length}\
                        {data_evidence.text}")
else:
    errors = cancer_profiling_result.errors
    if errors is not None:
        for error in errors:
            print(f"{error.code} : {error.message}")

疑難排解

一般

Health Insights 疾病分析用戶端程式庫將會引發 Azure Core中定義的例外狀況。

記錄

此程式庫會使用標準 記錄 程式庫進行記錄。

HTTP 會話的基本資訊 (URL、標頭等) 會在 INFO 層級記錄。

詳細的 DEBUG 層級記錄,包括要求/回應主體和 未處理的 標頭,都可以在 logging_enable 用戶端上或使用 關鍵字引數來啟用每個作業。

如需完整的 SDK 記錄檔,請參閱 這裡範例。

選用組態

選擇性關鍵字引數可以在用戶端和每個作業層級傳入。 azure 核心 參考檔 說明重試、記錄、傳輸通訊協定等可用的組態。

下一步

其他文件

如需有關 Azure Health Insights 疾病分析的詳細資訊檔,請參閱有關 docs.microsoft.com 的 疾病分析檔

參與

此專案歡迎參與和提供建議。 大部分的參與都要求您同意「參與者授權合約 (CLA)」,宣告您有權且確實授與我們使用投稿的權利。 如需詳細資料,請前往 https://cla.microsoft.com

當您提交提取要求時,CLA Bot 會自動判斷您是否需要提供 CLA,並適當地裝飾 PR (例如標籤、註解)。 請遵循 bot 提供的指示。 您只需要使用我們的 CLA 在所有存放庫上執行此動作一次。

此專案採用 Microsoft Open Source Code of Conduct (Microsoft 開放原始碼管理辦法)。 如需詳細資訊,請參閱管理辦法常見問題,或連絡 opencode@microsoft.com 任何其他問題或意見。