1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
"""
FILE: sample_health_with_cancellation.py
DESCRIPTION:
This sample demonstrates how to cancel a Health job after it's been started.
Since the Health API is currently only available in a gated preview, you need
to have your subscription on the service's allow list. More information
here: https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-for-health?tabs=ner#request-access-to-the-public-preview.
USAGE:
python sample_health_with_cancellation.py
Set the environment variables with your own values before running the sample:
1) AZURE_TEXT_ANALYTICS_ENDPOINT - the endpoint to your Cognitive Services resource.
2) AZURE_TEXT_ANALYTICS_KEY - your Text Analytics subscription key
"""
import os
class HealthWithCancellationSample(object):
def health_with_cancellation(self):
# [START health_with_cancellation]
from azure.core.credentials import AzureKeyCredential
from azure.ai.textanalytics import TextAnalyticsClient
endpoint = os.environ["AZURE_TEXT_ANALYTICS_ENDPOINT"]
key = os.environ["AZURE_TEXT_ANALYTICS_KEY"]
text_analytics_client = TextAnalyticsClient(
endpoint=endpoint,
credential=AzureKeyCredential(key),
api_version="v3.1-preview.3")
documents = [
"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | \
CORONARY ARTERY DISEASE | Signed | DIS | Admission Date: 5/22/2001 \
Report Status: Signed Discharge Date: 4/24/2001 ADMISSION DIAGNOSIS: \
CORONARY ARTERY DISEASE. HISTORY OF PRESENT ILLNESS: \
The patient is a 54-year-old gentleman with a history of progressive angina over the past several months. \
The patient had a cardiac catheterization in July of this year revealing total occlusion of the RCA and \
50% left main disease , with a strong family history of coronary artery disease with a brother dying at \
the age of 52 from a myocardial infarction and another brother who is status post coronary artery bypass grafting. \
The patient had a stress echocardiogram done on July , 2001 , which showed no wall motion abnormalities ,\
but this was a difficult study due to body habitus. The patient went for six minutes with minimal ST depressions \
in the anterior lateral leads , thought due to fatigue and wrist pain , his anginal equivalent. Due to the patient's \
increased symptoms and family history and history left main disease with total occasional of his RCA was referred \
for revascularization with open heart surgery."
]
poller = text_analytics_client.begin_analyze_healthcare(documents)
text_analytics_client.begin_cancel_analyze_healthcare(poller)
poller.wait()
# [END health_with_cancellation]
if __name__ == "__main__":
sample = HealthWithCancellationSample()
sample.health_with_cancellation()
|