Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
suhas92 committed Nov 5, 2020
1 parent fc361a7 commit dbe7b97
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 5 deletions.
44 changes: 44 additions & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Azure Cognitive Services Text Analytics is a cloud service that provides advance
* Named Entity Recognition
* Personally Identifiable Information (PII) Recognition
* Linked Entity Recognition
* Healthcare Recognition

[Source code][textanalytics_client_src] | [Package (NuGet)][textanalytics_nuget_package] | [API reference documentation][textanalytics_refdocs] | [Product documentation][textanalytics_docs] | [Samples][textanalytics_samples]

Expand Down Expand Up @@ -131,6 +132,7 @@ The following section provides several code snippets using the `client` [created
### Async examples
* [Detect Language Asynchronously](#detect-language-asynchronously)
* [Recognize Entities Asyncronously](#recognize-entities-asynchronously)
* [Recognize Healthcare Entities Asyncronously](#recognize-entities-asynchronously)

### Detect Language
Run a Text Analytics predictive model to determine the language that the passed-in document or batch of documents are written in.
Expand Down Expand Up @@ -279,6 +281,45 @@ foreach (CategorizedEntity entity in entities)
}
```

### Recognize Healthcare Entities Asynchronously
Text Analytics for health is a containerized service that extracts and labels relevant medical information from unstructured texts such as doctor's notes, discharge summaries, clinical documents, and electronic health records. For more information see [How to: Use Text Analytics for health][healthcare].

```C# Snippet:RecognizeHealthcareEntitiesAsync
string document = "Subject is taking 100mg of ibuprofen twice daily.";

HealthcareOperation healthOperation = await client.StartHealthcareAsync(document);

await healthOperation.WaitForCompletionAsync();

RecognizeHealthcareEntitiesResultCollection results = healthOperation.Value;

Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{results.ModelVersion}\"");
Console.WriteLine("");

foreach (DocumentHealthcareResult result in results)
{
Console.WriteLine($" Recognized the following {result.Entities.Count} healthcare entities:");

foreach (HealthcareEntity entity in result.Entities)
{
Console.WriteLine($" Entity: {entity.Text}");
Console.WriteLine($" Subcategory: {entity.Subcategory}");
Console.WriteLine($" Offset: {entity.Offset}");
Console.WriteLine($" Length: {entity.Length}");
Console.WriteLine($" IsNegated: {entity.IsNegated}");
Console.WriteLine($" Links:");

foreach (HealthcareEntityLink healthcareEntityLink in entity.Links)
{
Console.WriteLine($" ID: {healthcareEntityLink.Id}");
Console.WriteLine($" DataSource: {healthcareEntityLink.DataSource}");
}
}
Console.WriteLine("");
}
```
For samples on using the production recommended options `DocumentHealthcareResult` see [here][recognize_healthcare_sample].

## Troubleshooting

### General
Expand Down Expand Up @@ -340,6 +381,7 @@ Samples are provided for each main functional area, and for each area, samples a
- [Recognize Entities][recognize_entities_sample]
- [Recognize PII Entities][recognize_pii_entities_sample]
- [Recognize Linked Entities][recognize_linked_entities_sample]
- [Recognize Healthcare Entities][recognize_healthcare_sample]

### Advanced samples
- [Analyze Sentiment with Opinion Mining][analyze_sentiment_opinion_mining_sample]
Expand Down Expand Up @@ -367,6 +409,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[cognitive_resource_portal]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account
[cognitive_resource_cli]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account-cli

[recognize_healthcare_sample]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_RecognizeHealthcareEntities.md
[healthcare]: https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-for-health?tabs=ner
[language_detection]: https://docs.microsoft.com/azure/cognitive-services/Text-Analytics/how-tos/text-analytics-how-to-language-detection
[sentiment_analysis]: https://docs.microsoft.com/azure/cognitive-services/Text-Analytics/how-tos/text-analytics-how-to-sentiment-analysis
[key_phrase_extraction]: https://docs.microsoft.com/azure/cognitive-services/Text-Analytics/how-tos/text-analytics-how-to-keyword-extraction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Recognizing Healthcare Entities from Documents
This sample demonstrates how to recognize healthcare entities in one or more documents and get them asynchronously. To get started you will need a Text Analytics endpoint and credentials. See [README][README] for links and instructions.

## Creating a `TextAnalyticsClient`

To create a new `TextAnalyticsClient` to recognize healthcare entities in a document, you need a Text Analytics endpoint and credentials. You can use the [DefaultAzureCredential][DefaultAzureCredential] to try a number of common authentication methods optimized for both running as a service and development. In the sample below, however, you'll use a Text Analytics API key credential by creating an `AzureKeyCredential` object, that if needed, will allow you to update the API key without creating a new client.

You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application.

```C# Snippet:TextAnalyticsSample4CreateClient
var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
```

## Recognizing healthcare entities in a single document asynchronously

To recognize healthcare entities in a document, use the `StarthealthcareAsyc` method. The returned type is a Long Running operation of type `HealthcareOperation` which polls for the results from the API.

```C# Snippet:RecognizeHealthcareEntities
string document = "Subject is taking 100mg of ibuprofen twice daily.";

HealthcareOperation healthOperation = await client.StartHealthcareAsync(document);

await healthOperation.WaitForCompletionAsync();

RecognizeHealthcareEntitiesResultCollection results = healthOperation.Value;

Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{results.ModelVersion}\"");
Console.WriteLine("");

foreach (DocumentHealthcareResult result in results)
{
Console.WriteLine($" Recognized the following {result.Entities.Count} healthcare entities:");

foreach (HealthcareEntity entity in result.Entities)
{
Console.WriteLine($" Entity: {entity.Text}");
Console.WriteLine($" Subcategory: {entity.Subcategory}");
Console.WriteLine($" Offset: {entity.Offset}");
Console.WriteLine($" Length: {entity.Length}");
Console.WriteLine($" IsNegated: {entity.IsNegated}");
Console.WriteLine($" Links:");

foreach (HealthcareEntityLink healthcareEntityLink in entity.Links)
{
Console.WriteLine($" ID: {healthcareEntityLink.Id}");
Console.WriteLine($" DataSource: {healthcareEntityLink.DataSource}");
}
}
Console.WriteLine("");
}
}
```

## Recognizing healthcare entities in multiple documents

To recognize healthcare entities in multiple documents, call `StartHealthcareBatchAsync` on an `IEnumerable` of strings. The result is a Long Running operation of type `HealthcareOperation` which polls for the results from the API.

```C# Snippet:TextAnalyticsSampleRecognizeHealthcare
string document = "Subject is taking 100mg of ibuprofen twice daily.";

HealthcareOperation healthOperation = await client.StartHealthcareAsync(document);

await healthOperation.WaitForCompletionAsync();

RecognizeHealthcareEntitiesResultCollection results = healthOperation.Value;
```

To recognize healthcare entities in a collection of documents in different languages, call `RecognizeHealthcare EntitiesBatch` on an `IEnumerable` of `TextDocumentInput` objects, setting the `Language` on each document.

```C# Snippet:TextAnalyticsSampleRecognizeHealthcare
var documents = new List<TextDocumentInput>
{
new TextDocumentInput("1", "Subject is taking 100mg of ibuprofen twice daily.")
{
Language = "en",
},
new TextDocumentInput("2", "Can cause rapid or irregular heartbeat.")
{
Language = "en",
},
new TextDocumentInput("3", "The patient is a 54-year-old gentleman with a history of progressive angina over the past several months")
{
Language = "en",
}
};

HealthcareOperation healthOperation = await client.StartHealthcareAsync(document);

await healthOperation.WaitForCompletionAsync();

RecognizeHealthcareEntitiesResultCollection results = healthOperation.Value;
```

To see the full example source files, see:

* [Synchronously RecognizeHealthcare ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_Healthcare.cs)
* [Asynchronously RecognizeHealthcare ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareAsync.cs)
* [Synchronously RecognizeHealthcareBatch](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareBatch.cs)
* [Asynchronously RecognizeHealthcareBatch](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareBatchAsync.cs)
* [Synchronously RecognizeHealthcare Cancellation](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_Healthcare_Cancellation.cs)
* [Asynchronously RecognizeHealthcare Cancellation](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareAsync_Cancellation.cs)

[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/identity/Azure.Identity/README.md
[README]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ namespace Azure.AI.TextAnalytics.Samples
public partial class TextAnalyticsSamples: SamplesBase<TextAnalyticsTestEnvironment>
{
[Test]
public async Task HealthcareShowStats()
public async Task HealthcareBatch()
{
string endpoint = TestEnvironment.Endpoint;
string apiKey = TestEnvironment.ApiKey;

var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:TextAnalyticsSampleHealthcareShowStats
string document = "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.";
#region Snippet:TextAnalyticsSampleHealthcareBatch
string document = @"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.";

List<string> batchInput = new List<string>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace Azure.AI.TextAnalytics.Samples
public partial class TextAnalyticsSamples: SamplesBase<TextAnalyticsTestEnvironment>
{
[Test]
public async Task HealthcareAsyncShowStats()
public async Task HealthcareBatchAsync()
{
string endpoint = TestEnvironment.Endpoint;
string apiKey = TestEnvironment.ApiKey;

var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:TextAnalyticsSampleHealthcareAsyncShowStats
#region Snippet:TextAnalyticsSampleHealthcareBatchAsync
string document = @"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. \
Expand Down

0 comments on commit dbe7b97

Please sign in to comment.