Skip to content

Commit 22130a4

Browse files
author
Mohamed Shaban
authored
simplify samples for healthcare operations (Azure#21464)
1 parent 96cf9ba commit 22130a4

10 files changed

+217
-103
lines changed

sdk/textanalytics/Azure.AI.TextAnalytics/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ catch (RequestFailedException exception)
436436
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].
437437

438438
```C# Snippet:Sample7_AnalyzeHealthcareEntitiesBatchConvenience
439+
// get input documents
439440
string document1 = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE | Signed | DIS | \
440441
Admission Date: 5/22/2001 Report Status: Signed Discharge Date: 4/24/2001 ADMISSION DIAGNOSIS: CORONARY ARTERY DISEASE. \
441442
HISTORY OF PRESENT ILLNESS: The patient is a 54-year-old gentleman with a history of progressive angina over the past several months. \
@@ -448,6 +449,7 @@ Text Analytics for health is a containerized service that extracts and labels re
448449

449450
string document2 = "Prescribed 100mg ibuprofen, taken twice daily.";
450451

452+
// prepare analyze operation input
451453
List<string> batchInput = new List<string>()
452454
{
453455
document1,
@@ -456,17 +458,20 @@ Text Analytics for health is a containerized service that extracts and labels re
456458
};
457459
var options = new AnalyzeHealthcareEntitiesOptions { };
458460

461+
// start analysis process
459462
AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(batchInput, "en", options);
460463

461464
await healthOperation.WaitForCompletionAsync();
462465

463466
Console.WriteLine($"AnalyzeHealthcareEntities operation was completed");
464467

468+
// view operation status
465469
Console.WriteLine($"Created On : {healthOperation.CreatedOn}");
466470
Console.WriteLine($"Expires On : {healthOperation.ExpiresOn}");
467471
Console.WriteLine($"Status : {healthOperation.Status}");
468472
Console.WriteLine($"Last Modified: {healthOperation.LastModified}");
469473

474+
// view operation results
470475
foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues())
471476
{
472477
Console.WriteLine($"Results of Azure Text Analytics \"Healthcare\" Model, version: \"{documentsInPage.ModelVersion}\"");
@@ -484,6 +489,7 @@ Text Analytics for health is a containerized service that extracts and labels re
484489
{
485490
Console.WriteLine($" Recognized the following {result.Entities.Count} healthcare entities:");
486491

492+
// view recognized healthcare entities
487493
foreach (HealthcareEntity entity in result.Entities)
488494
{
489495
Console.WriteLine($" Entity: {entity.Text}");
@@ -493,12 +499,14 @@ Text Analytics for health is a containerized service that extracts and labels re
493499
Console.WriteLine($" NormalizedText: {entity.NormalizedText}");
494500
Console.WriteLine($" Links:");
495501

502+
// view entity data sources
496503
foreach (EntityDataSource entityDataSource in entity.DataSources)
497504
{
498505
Console.WriteLine($" Entity ID in Data Source: {entityDataSource.EntityId}");
499506
Console.WriteLine($" DataSource: {entityDataSource.Name}");
500507
}
501508

509+
// view assertion
502510
if (entity.Assertion != null)
503511
{
504512
Console.WriteLine($" Assertions:");
@@ -521,11 +529,13 @@ Text Analytics for health is a containerized service that extracts and labels re
521529
Console.WriteLine($" We found {result.EntityRelations.Count} relations in the current document:");
522530
Console.WriteLine("");
523531

532+
// view recognized healthcare relations
524533
foreach (HealthcareEntityRelation relations in result.EntityRelations)
525534
{
526535
Console.WriteLine($" Relation: {relations.RelationType}");
527536
Console.WriteLine($" For this relation there are {relations.Roles.Count} roles");
528537

538+
// view relation roles
529539
foreach (HealthcareEntityRelationRole role in relations.Roles)
530540
{
531541
Console.WriteLine($" Role Name: {role.Name}");

sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_RecognizeHealthcareEntities.md

Lines changed: 100 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,116 +12,130 @@ string endpoint = "<endpoint>";
1212
string apiKey = "<apiKey>";
1313
var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
1414
```
15-
16-
## Recognizing healthcare entities in multiple documents
15+
## Analyze Documents
1716

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

20-
```C# Snippet:TextAnalyticsSampleHealthcareBatchConvenienceAsync
21-
string document1 = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE | Signed | DIS | \
22-
Admission Date: 5/22/2001 Report Status: Signed Discharge Date: 4/24/2001 ADMISSION DIAGNOSIS: CORONARY ARTERY DISEASE. \
23-
HISTORY OF PRESENT ILLNESS: The patient is a 54-year-old gentleman with a history of progressive angina over the past several months. \
24-
The patient had a cardiac catheterization in July of this year revealing total occlusion of the RCA and 50% left main disease ,\
25-
with a strong family history of coronary artery disease with a brother dying at the age of 52 from a myocardial infarction and \
26-
another brother who is status post coronary artery bypass grafting. The patient had a stress echocardiogram done on July , 2001 , \
27-
which showed no wall motion abnormalities , but this was a difficult study due to body habitus. The patient went for six minutes with \
28-
minimal ST depressions in the anterior lateral leads , thought due to fatigue and wrist pain , his anginal equivalent. Due to the patient's \
29-
increased symptoms and family history and history left main disease with total occasional of his RCA was referred for revascularization with open heart surgery.";
30-
31-
string document2 = "Prescribed 100mg ibuprofen, taken twice daily.";
32-
33-
List<string> batchInput = new List<string>()
34-
{
35-
document1,
36-
document2,
37-
string.Empty
38-
};
39-
40-
var options = new AnalyzeHealthcareEntitiesOptions { };
41-
42-
AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, "en", options);
43-
44-
await healthOperation.WaitForCompletionAsync();
19+
```C# Snippet:TextAnalyticsSampleHealthcareBatchConvenienceAnalyzeDocumentsAsync
20+
// get input documents
21+
string document1 = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE | Signed | DIS | \
22+
Admission Date: 5/22/2001 Report Status: Signed Discharge Date: 4/24/2001 ADMISSION DIAGNOSIS: CORONARY ARTERY DISEASE. \
23+
HISTORY OF PRESENT ILLNESS: The patient is a 54-year-old gentleman with a history of progressive angina over the past several months. \
24+
The patient had a cardiac catheterization in July of this year revealing total occlusion of the RCA and 50% left main disease ,\
25+
with a strong family history of coronary artery disease with a brother dying at the age of 52 from a myocardial infarction and \
26+
another brother who is status post coronary artery bypass grafting. The patient had a stress echocardiogram done on July , 2001 , \
27+
which showed no wall motion abnormalities , but this was a difficult study due to body habitus. The patient went for six minutes with \
28+
minimal ST depressions in the anterior lateral leads , thought due to fatigue and wrist pain , his anginal equivalent. Due to the patient's \
29+
increased symptoms and family history and history left main disease with total occasional of his RCA was referred for revascularization with open heart surgery.";
30+
31+
string document2 = "Prescribed 100mg ibuprofen, taken twice daily.";
32+
33+
// prepare analyze operation input
34+
List<string> batchInput = new List<string>()
35+
{
36+
document1,
37+
document2,
38+
string.Empty
39+
};
40+
41+
var options = new AnalyzeHealthcareEntitiesOptions { };
42+
43+
// start analysis process
44+
AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, "en", options);
45+
46+
await healthOperation.WaitForCompletionAsync();
47+
```
48+
The returned healthcare operation contains general information about the status of the operation. It can be requested while the operation is running or when it completed. For example:
4549

46-
Console.WriteLine($"Created On : {healthOperation.CreatedOn}");
47-
Console.WriteLine($"Expires On : {healthOperation.ExpiresOn}");
48-
Console.WriteLine($"Status : {healthOperation.Status}");
49-
Console.WriteLine($"Last Modified: {healthOperation.LastModified}");
5050

51-
await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
51+
```C# Snippet:TextAnalyticsSampleHealthcareOperationStatus
52+
// view operation status
53+
Console.WriteLine($"Created On : {healthOperation.CreatedOn}");
54+
Console.WriteLine($"Expires On : {healthOperation.ExpiresOn}");
55+
Console.WriteLine($"Status : {healthOperation.Status}");
56+
Console.WriteLine($"Last Modified: {healthOperation.LastModified}");
57+
```
58+
To view the final results of the long-running operation:
59+
```C# Snippet:TextAnalyticsSampleHealthcareBatchConvenienceAsyncViewResults
60+
// view operation results
61+
await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
62+
{
63+
Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
64+
Console.WriteLine("");
65+
66+
foreach (AnalyzeHealthcareEntitiesResult entitiesInDoc in documentsInPage)
5267
{
53-
Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
54-
Console.WriteLine("");
55-
56-
foreach (AnalyzeHealthcareEntitiesResult entitiesInDoc in documentsInPage)
68+
if (!entitiesInDoc.HasError)
5769
{
58-
if (!entitiesInDoc.HasError)
70+
foreach (var entity in entitiesInDoc.Entities)
5971
{
60-
foreach (var entity in entitiesInDoc.Entities)
72+
// view recognized healthcare entities
73+
Console.WriteLine($" Entity: {entity.Text}");
74+
Console.WriteLine($" Category: {entity.Category}");
75+
Console.WriteLine($" Offset: {entity.Offset}");
76+
Console.WriteLine($" Length: {entity.Length}");
77+
Console.WriteLine($" NormalizedText: {entity.NormalizedText}");
78+
Console.WriteLine($" Links:");
79+
80+
// view entity data sources
81+
foreach (EntityDataSource entityDataSource in entity.DataSources)
82+
{
83+
Console.WriteLine($" Entity ID in Data Source: {entityDataSource.EntityId}");
84+
Console.WriteLine($" DataSource: {entityDataSource.Name}");
85+
}
86+
87+
// view assertion
88+
if (entity.Assertion != null)
6189
{
62-
Console.WriteLine($" Entity: {entity.Text}");
63-
Console.WriteLine($" Category: {entity.Category}");
64-
Console.WriteLine($" Offset: {entity.Offset}");
65-
Console.WriteLine($" Length: {entity.Length}");
66-
Console.WriteLine($" NormalizedText: {entity.NormalizedText}");
67-
Console.WriteLine($" Links:");
68-
69-
foreach (EntityDataSource entityDataSource in entity.DataSources)
90+
Console.WriteLine($" Assertions:");
91+
92+
if (entity.Assertion?.Association != null)
7093
{
71-
Console.WriteLine($" Entity ID in Data Source: {entityDataSource.EntityId}");
72-
Console.WriteLine($" DataSource: {entityDataSource.Name}");
94+
Console.WriteLine($" Association: {entity.Assertion?.Association}");
7395
}
7496

75-
if (entity.Assertion != null)
97+
if (entity.Assertion?.Certainty != null)
98+
{
99+
Console.WriteLine($" Certainty: {entity.Assertion?.Certainty}");
100+
}
101+
if (entity.Assertion?.Conditionality != null)
76102
{
77-
Console.WriteLine($" Assertions:");
78-
79-
if (entity.Assertion?.Association != null)
80-
{
81-
Console.WriteLine($" Association: {entity.Assertion?.Association}");
82-
}
83-
84-
if (entity.Assertion?.Certainty != null)
85-
{
86-
Console.WriteLine($" Certainty: {entity.Assertion?.Certainty}");
87-
}
88-
if (entity.Assertion?.Conditionality != null)
89-
{
90-
Console.WriteLine($" Conditionality: {entity.Assertion?.Conditionality}");
91-
}
103+
Console.WriteLine($" Conditionality: {entity.Assertion?.Conditionality}");
92104
}
93105
}
106+
}
94107

95-
Console.WriteLine($" We found {entitiesInDoc.EntityRelations.Count} relations in the current document:");
96-
Console.WriteLine("");
97-
98-
foreach (HealthcareEntityRelation relations in entitiesInDoc.EntityRelations)
99-
{
100-
Console.WriteLine($" Relation: {relations.RelationType}");
101-
Console.WriteLine($" For this relation there are {relations.Roles.Count} roles");
108+
Console.WriteLine($" We found {entitiesInDoc.EntityRelations.Count} relations in the current document:");
109+
Console.WriteLine("");
102110

103-
foreach (HealthcareEntityRelationRole role in relations.Roles)
104-
{
105-
Console.WriteLine($" Role Name: {role.Name}");
111+
// view recognized healthcare relations
112+
foreach (HealthcareEntityRelation relations in entitiesInDoc.EntityRelations)
113+
{
114+
Console.WriteLine($" Relation: {relations.RelationType}");
115+
Console.WriteLine($" For this relation there are {relations.Roles.Count} roles");
106116

107-
Console.WriteLine($" Associated Entity Text: {role.Entity.Text}");
108-
Console.WriteLine($" Associated Entity Category: {role.Entity.Category}");
117+
// view relation roles
118+
foreach (HealthcareEntityRelationRole role in relations.Roles)
119+
{
120+
Console.WriteLine($" Role Name: {role.Name}");
109121

110-
Console.WriteLine("");
111-
}
122+
Console.WriteLine($" Associated Entity Text: {role.Entity.Text}");
123+
Console.WriteLine($" Associated Entity Category: {role.Entity.Category}");
112124

113125
Console.WriteLine("");
114126
}
115-
}
116-
else
117-
{
118-
Console.WriteLine(" Error!");
119-
Console.WriteLine($" Document error code: {entitiesInDoc.Error.ErrorCode}.");
120-
Console.WriteLine($" Message: {entitiesInDoc.Error.Message}");
121-
}
122127

123-
Console.WriteLine("");
128+
Console.WriteLine("");
129+
}
124130
}
131+
else
132+
{
133+
Console.WriteLine(" Error!");
134+
Console.WriteLine($" Document error code: {entitiesInDoc.Error.ErrorCode}.");
135+
Console.WriteLine($" Message: {entitiesInDoc.Error.Message}");
136+
}
137+
138+
Console.WriteLine("");
125139
}
126140
}
127141
```

0 commit comments

Comments
 (0)