Package: azure-healthinsights-cancerprofiling
Azure Cognitive Services Health Insights Cancer Profiling client library for PythonHealth Insightsis an Azure Applied AI Service built with the Azure Cognitive Services Framework, that leverages multiple Cognitive Services, Healthcare API services and other Azure resources.TheCancer Profiling modelreceives clinical records of oncology patients and outputs cancer staging, such as clinical stage TNM categories and pathologic stage TNM categories as well as tumor site, histology.Source code|Package (PyPI)|API reference documentation|Product documentation|SamplesGetting startedPrerequisitesPython 3.7 or later is required to use this package.You need anAzure subscriptionto use this package.An existing Cognitive Services Health Insights instance.Install the packagepipinstallazure-healthinsights-cancerprofilingThis table shows the relationship between SDK versions and supported API versions of the service:SDK versionSupported API version of service1.0.0b12023-03-01-previewAuthenticate the clientGet the endpointYou can find the endpoint for your Health Insights service resource using theAzure PortalorAzure CLI# Get the endpoint for the Health Insights service resourceazcognitiveservicesaccountshow--name"resource-name"--resource-group"resource-group-name"--query"properties.endpoint"Get the API KeyYou can get theAPI Keyfrom the Health Insights service resource in the Azure Portal.
Alternatively, you can useAzure CLIsnippet below to get the API key of your resource.azcognitiveservicesaccountkeyslist--resource-group<your-resource-group-name>--name<your-resource-name>Create a CancerProfilingClient with an API Key CredentialOnce you have the value for the API key, you can pass it as a string into an instance ofAzureKeyCredential. Use the key as the credential parameter to authenticate the client:importosfromazure.core.credentialsimportAzureKeyCredentialfromazure.healthinsights.cancerprofiling.aioimportCancerProfilingClientKEY=os.environ["HEALTHINSIGHTS_KEY"]ENDPOINT=os.environ["HEALTHINSIGHTS_ENDPOINT"]cancer_profiling_client=CancerProfilingClient(endpoint=ENDPOINT,credential=AzureKeyCredential(KEY))Long-Running OperationsLong-running operations are operations which consist of an initial request sent to the service to start an operation,
followed by polling the service at intervals to determine whether the operation has completed or failed, and if it has
succeeded, to get the result.Methods that support healthcare analysis, custom text analysis, or multiple analyses are modeled as long-running operations.
The client exposes abegin_<method-name>method that returns a poller object. Callers should wait
for the operation to complete by callingresult()on the poller object returned from thebegin_<method-name>method.
Sample code snippets are provided to illustrate using long-running operationsbelow.Key conceptsThe Cancer Profiling model allows you to infer cancer attributes such as tumor site, histology, clinical stage TNM categories and pathologic stage TNM categories from unstructured clinical documents.ExamplesThe following section provides several code snippets covering some of the most common Health Insights - Cancer Profiling service tasks, including:Cancer ProfilingCancer ProfilingInfer key cancer attributes such as tumor site, histology, clinical stage TNM categories and pathologic stage TNM categories from a patient's unstructured clinical documents.importasyncioimportosimportdatetimefromazure.core.credentialsimportAzureKeyCredentialfromazure.healthinsights.cancerprofiling.aioimportCancerProfilingClientfromazure.healthinsights.cancerprofilingimportmodelsKEY=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.2021Jane Doe 091175-896742 year old female, married with 3 children, works as a nurseHealthy, 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 afollow-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 Clinic20.10.2021Jane Doe 091175-896742-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 rightbreast, 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. Genetictesting 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 REPORTClinical InformationUltrasound-guided biopsy; A. 18 mm mass; most likely diagnosis based on imaging:  IDCDiagnosisA.  BREAST, LEFT AT 2:00 4 CM FN; ULTRASOUND-GUIDED NEEDLE CORE BIOPSIES:- Invasive carcinoma of no special type (invasive ductal carcinoma), grade 1Nottingham histologic grade:  1/3 (tubules 2; nuclear grade 2; mitotic rate 1;total score; 5/9)Fragments involved by invasive carcinoma:  2Largest measurement of invasive carcinoma on a single fragment:  7 mmDuctal carcinoma in situ (DCIS):  PresentArchitectural pattern:  CribriformNuclear grade:  2--intermediateNecrosis:  Not identifiedFragments involved by DCIS:  1Largest measurement of DCIS on a single fragment:  Span 2 mmMicrocalcifications:  Present in benign breast tissue and invasive carcinomaBlocks with invasive carcinoma:  A1Special 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 inferencesconfiguration=models.OncoPhenotypeModelConfiguration(include_evidence=True)# Construct the request with the patient and configurationcancer_profiling_data=models.OncoPhenotypeData(patients=[patient1],configuration=configuration)poller=awaitcancer_profiling_client.begin_infer_cancer_profile(cancer_profiling_data)cancer_profiling_result=awaitpoller.result()ifcancer_profiling_result.status==models.JobStatus.SUCCEEDED:results=cancer_profiling_result.resultsforpatient_resultinresults.patients:print(f"\n==== Inferences of Patient{patient_result.id}====")forinferenceinpatient_result.inferences:print(f"\n=== Clinical Type:{str(inference.type)}Value:{inference.value}\ConfidenceScore:{inference.confidence_score}===")forevidenceininference.evidence:data_evidence=evidence.patient_data_evidenceprint(f"Evidence{data_evidence.id}{data_evidence.offset}{data_evidence.length}\{data_evidence.text}")else:errors=cancer_profiling_result.errorsiferrorsisnotNone:forerrorinerrors:print(f"{error.code}:{error.message}")TroubleshootingGeneralHealth Insights Cancer Profiling client library will raise exceptions defined inAzure Core.LoggingThis library uses the standardlogginglibrary for logging.Basic information about HTTP sessions (URLs, headers, etc.) is logged atINFOlevel.DetailedDEBUGlevel logging, including request/response bodies andunredactedheaders, can be enabled on the client or per-operation with thelogging_enablekeyword argument.See full SDK logging documentation with exampleshere.Optional ConfigurationOptional keyword arguments can be passed in at the client and per-operation level.
The azure-corereference documentationdescribes available configurations for retries, logging, transport protocols, and more.Next stepsAdditional documentationFor more extensive documentation on Azure Health Insights Cancer Profiling, see theCancer Profiling documentationon docs.microsoft.com.ContributingThis project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.This project has adopted theMicrosoft Open Source Code of Conduct. For more information,
see the Code of Conduct FAQ or contactopencode@microsoft.comwith any
additional questions or comments.