Udostępnij za pośrednictwem


Biblioteka klienta profilowania raka usługi Azure Cognitive Services Health Insights dla języka Python — wersja 1.0.0b1

Health Insights to usługa Azure Applied AI Service utworzona za pomocą platformy Azure Cognitive Services Framework, która korzysta z wielu usług Cognitive Services, usług Healthcare API i innych zasobów platformy Azure.

Model profilowania raka otrzymuje rejestry kliniczne pacjentów onkologicznych i wyprowadza inscenizacji raka, takie jak kategorie TNM etapu klinicznego i TNM etapu patologicznego, a także miejsce nowotworu, histologia.

Kod | źródłowy Pakiet (PyPI) | Dokumentacja referencyjna interfejsu | API Dokumentacja | produktu Próbki

Wprowadzenie

Wymagania wstępne

  • Do korzystania z tego pakietu jest wymagany język Python w wersji 3.7 lub nowszej.
  • Do korzystania z tego pakietu potrzebna jest subskrypcja platformy Azure .
  • Istniejące wystąpienie usługi Cognitive Services Health Insights.

Instalowanie pakietu

pip install azure-healthinsights-cancerprofiling

W tej tabeli przedstawiono relację między wersjami zestawu SDK i obsługiwanymi wersjami interfejsu API usługi:

Wersja zestawu SDK Obsługiwana wersja usługi interfejsu API
1.0.0b1 2023-03-01-preview

Uwierzytelnianie klienta

Uzyskiwanie punktu końcowego

Punkt końcowy zasobu usługi Health Insights można znaleźć za pomocą witryny Azure Portal lub interfejsu wiersza polecenia platformy Azure

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

Pobieranie klucza interfejsu API

Klucz interfejsu API można uzyskać z zasobu usługi Health Insights w witrynie Azure Portal. Alternatywnie możesz użyć poniższego fragmentu kodu interfejsu wiersza polecenia platformy Azure , aby uzyskać klucz interfejsu API zasobu.

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

Tworzenie elementu CancerProfilingClient przy użyciu poświadczeń klucza interfejsu API

Gdy masz wartość klucza interfejsu API, możesz przekazać go jako ciąg do wystąpienia obiektu AzureKeyCredential. Użyj klucza jako parametru poświadczeń, aby uwierzytelnić klienta:

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

Operacje Long-Running

Długotrwałe operacje to operacje, które składają się z początkowego żądania wysłanego do usługi w celu uruchomienia operacji, a następnie sondowania usługi w odstępach czasu w celu ustalenia, czy operacja została ukończona, czy nie powiodła się, i jeśli zakończyła się pomyślnie, aby uzyskać wynik.

Metody, które obsługują analizę opieki zdrowotnej, niestandardową analizę tekstu lub wiele analiz, są modelowane jako długotrwałe operacje. Klient uwidacznia metodę begin_<method-name> zwracającą obiekt poller. Obiekty wywołujące powinny czekać na zakończenie operacji przez wywołanie result() obiektu poller zwróconego begin_<method-name> z metody . Przykładowe fragmenty kodu są udostępniane w celu zilustrowania użycia długotrwałych operacji .

Kluczowe pojęcia

Model profilowania raka pozwala wywnioskować atrybuty raka, takie jak miejsce nowotworu, histologia, kategorie TNM etapu klinicznego i kategorie TNM etapu TNM z nieustrukturyzowanego dokumentu klinicznego.

Przykłady

Poniższa sekcja zawiera kilka fragmentów kodu obejmujących niektóre z najczęstszych zadań usługi Health Insights — Profilowanie raka, w tym:

Profilowanie raka

Wnioskowanie kluczowych atrybutów raka, takich jak miejsce guza, histologia, kategorie TNM etapu klinicznego i kategorie TNM etapu patologicznego z dokumentów klinicznych nieustrukturyzowanego pacjenta.

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

Rozwiązywanie problemów

Ogólne

Biblioteka klienta profilowania raka usługi Health Insights zgłosi wyjątki zdefiniowane w usłudze Azure Core.

Rejestrowanie

Ta biblioteka używa standardowej biblioteki rejestrowania do rejestrowania.

Podstawowe informacje o sesjach HTTP (adresach URL, nagłówkach itp.) są rejestrowane na INFO poziomie.

Szczegółowe DEBUG rejestrowanie na poziomie, w tym treści żądań/odpowiedzi i nieredagowanych nagłówków, można włączyć na kliencie lub na operację z argumentem słowa kluczowego logging_enable .

Zobacz pełną dokumentację rejestrowania zestawu SDK z przykładami tutaj.

Konfiguracja opcjonalna

Opcjonalne argumenty słów kluczowych można przekazać na poziomie klienta i na poziomie operacji. W dokumentacji referencyjnej platformy Azure opisano dostępne konfiguracje dotyczące ponownych prób, rejestrowania, protokołów transportowych i nie tylko.

Następne kroki

Dodatkowa dokumentacja

Aby uzyskać bardziej obszerną dokumentację dotyczącą profilowania raka usługi Azure Health Insights, zobacz dokumentację dotyczącą profilowania raka w docs.microsoft.com.

Współtworzenie

W tym projekcie zachęcamy do współtworzenia i zgłaszania sugestii. Współtworzenie w większości przypadków wymaga zgody na umowę licencyjną dotyczącą współautorów (CLA, Contributor License Agreement), zgodnie z którą współautor ma prawo udzielić i faktycznie udziela nam praw do używania wytworzonej przez siebie zawartości. Aby uzyskać szczegółowe informacje, odwiedź stronę https://cla.microsoft.com.

Po przesłaniu żądania ściągnięcia robot CLA automatycznie określi, czy musisz przekazać umowę CLA, i doda odpowiednie informacje do tego żądania (na przykład etykietę czy komentarz). Po prostu postępuj zgodnie z instrukcjami robota. Wystarczy zrobić to raz dla wszystkich repozytoriów, w przypadku których jest używana nasza umowa CLA.

W tym projekcie przyjęto Kodeks postępowania oprogramowania Open Source firmy Microsoft. Aby uzyskać więcej informacji, zobacz artykuł Code of Conduct FAQ (Często zadawane pytania dotyczące kodeksu postępowania). Jeśli będziesz mieć jeszcze jakieś pytania lub komentarze, wyślij wiadomość e-mail na adres opencode@microsoft.com.