public async Task Sample7_AnalyzeHealthcareEntitiesAsync_Cancellation()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsSampleHealthcareAsyncCancellation
            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.";

            var batchDocument = new List <string>();

            for (var i = 0; i < 10; i++)
            {
                batchDocument.Add(document);
            }

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocument, "en");

            await healthOperation.CancelAsync();
        }
        public async Task RecognizeHealthcareEntitiesWithFhir()
        {
            TextAnalyticsClient client = GetClient(useTokenCredential: true);

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                FhirVersion = FhirVersion.Four01
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments, options);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            List <AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, resultInPages.Count);

            //Take the first page
            var resultCollection = resultInPages.FirstOrDefault();

            Assert.AreEqual(s_batchDocuments.Count, resultCollection.Count);

            //Check Fhirbundle has content on it
            Assert.IsNotNull(resultCollection[0].FhirBundle);
            Assert.Greater(resultCollection[0].FhirBundle.Count, 0);
        }
示例#3
0
        public async Task RecognizeHealthcareEntitiesBatchWithPagination()
        {
            TextAnalyticsClient client = GetClient();
            string document            = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE.";

            var list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(document);
            }
            ;

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                Top = 2
            };

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(list, "en", options);

            AsyncPageable <AnalyzeHealthcareEntitiesResult> results = client.GetHealthcareEntities(healthOperation);

            int resultCount = 0;

            await foreach (AnalyzeHealthcareEntitiesResult result in results)
            {
                resultCount += 1;
            }

            Assert.AreEqual(10, resultCount);
        }
示例#4
0
        public async Task RecognizeHealthcareEntitiesBatchWithStatisticsTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments, options);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            //Take the first page
            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            var expectedOutput = new Dictionary <string, List <string> >()
            {
                { "1", s_document1ExpectedEntitiesOutput },
                { "2", s_document2ExpectedEntitiesOutput },
            };

            ValidateBatchDocumentsResult(resultCollection, expectedOutput, true);
        }
示例#5
0
        public async Task RecognizeHealthcareEntitiesBatchWithCancellation()
        {
            TextAnalyticsClient client = GetClient();
            string document            = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE | Signed | DIS |";

            var batchDocuments = new List <string>();

            for (var i = 0; i < 10; i++)
            {
                batchDocuments.Add(document);
            }

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments, "en");

            await operation.CancelAsync();

            RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(async() => await operation.WaitForCompletionAsync());

            Assert.IsTrue(ex.Message.Contains("The operation was canceled so no value is available."));

            Assert.IsTrue(operation.HasCompleted);
            Assert.IsFalse(operation.HasValue);
            Assert.AreEqual(200, operation.GetRawResponse().Status);
            Assert.AreEqual(TextAnalyticsOperationStatus.Cancelled, operation.Status);

            try
            {
                Assert.IsNull(operation.Value);
            }
            catch (RequestFailedException exception)
            {
                Assert.IsTrue(exception.Message.Contains("The operation was canceled so no value is available."));
            }
        }
示例#6
0
        public async Task RecognizeHealthcareEntitiesBatchConvenienceWithStatisticsTest()
        {
            TextAnalyticsClient client = GetClient();
            var documents = batchConvenienceDocuments;

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents, "en", options);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.AreEqual(documents.Count, resultCollection.Statistics.DocumentCount);

            Assert.AreEqual(48, resultCollection[0].Statistics.CharacterCount);
            Assert.AreEqual(1, resultCollection[0].Statistics.TransactionCount);

            Assert.Greater(resultCollection.Statistics.DocumentCount, 0);
            Assert.AreEqual(2, resultCollection.Statistics.DocumentCount);
            Assert.AreEqual(2, resultCollection.Statistics.TransactionCount);
            Assert.AreEqual(0, resultCollection.Statistics.InvalidDocumentCount);
            Assert.AreEqual(2, resultCollection.Statistics.ValidDocumentCount);
        }
示例#7
0
        public async Task RecognizeHealthcareEntitiesBatchWithErrorTest()
        {
            TextAnalyticsClient client = GetClient();
            var documents = new List <string>
            {
                "Subject is taking 100mg of ibuprofen twice daily",
                "Can cause rapid or irregular heartbeat, delirium, panic, psychosis, and heart failure.",
                "",
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            //Take the first page
            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            Assert.IsNotNull(resultCollection[2].Id);

            Assert.IsTrue(!resultCollection[0].HasError);
            Assert.IsTrue(!resultCollection[1].HasError);

            Assert.IsTrue(resultCollection[2].HasError);
            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => resultCollection[2].Entities.GetType());

            Assert.AreEqual(TextAnalyticsErrorCode.InvalidDocument, resultCollection[2].Error.ErrorCode.ToString());
        }
        public async Task HealthcareAsync_ManualPolling()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:RecognizeHealthcareEntitiesAsyncManualPolling
            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.";

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(new List <string>() { document });

            TimeSpan pollingInterval = new TimeSpan(1000);

            while (true)
            {
                await healthOperation.UpdateStatusAsync();

                if (healthOperation.HasCompleted)
                {
                    break;
                }

                await Task.Delay(pollingInterval);
            }

            AnalyzeHealthcareEntitiesResultCollection results = healthOperation.Value;

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

            foreach (AnalyzeHealthcareEntitiesResult 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($"    Category: {entity.Category}");
                    Console.WriteLine($"    Offset: {entity.Offset}");
                    Console.WriteLine($"    Length: {entity.Length}");
                    Console.WriteLine($"    Links:");

                    foreach (EntityDataSource entityDataSource in entity.DataSources)
                    {
                        Console.WriteLine($"        Entity ID in Data Source: {entityDataSource.EntityId}");
                        Console.WriteLine($"        DataSource: {entityDataSource.Name}");
                    }
                }
                Console.WriteLine("");
            }
        }
示例#9
0
        public async Task HealthcareBatchConvenienceAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsSampleHealthcareBatchConvenienceAsync
            string document = "Subject is taking 100mg of ibuprofen twice daily";

            var list = new List <string>();

            for (int i = 0; i < 6; i++)
            {
                list.Add(document);
            }
            ;

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(list, "en", new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            });

            await healthOperation.WaitForCompletionAsync();

            await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
            {
                Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
                Console.WriteLine("");

                foreach (AnalyzeHealthcareEntitiesResult entitiesInDoc in documentsInPage)
                {
                    if (!entitiesInDoc.HasError)
                    {
                        foreach (var entity in entitiesInDoc.Entities)
                        {
                            Console.WriteLine($"    Entity: {entity.Text}");
                            Console.WriteLine($"    Category: {entity.Category}");
                            Console.WriteLine($"    Offset: {entity.Offset}");
                            Console.WriteLine($"    Length: {entity.Length}");
                            Console.WriteLine($"    Links:");

                            foreach (EntityDataSource entityDataSource in entity.DataSources)
                            {
                                Console.WriteLine($"        Entity ID in Data Source: {entityDataSource.EntityId}");
                                Console.WriteLine($"        DataSource: {entityDataSource.Name}");
                            }
                        }
                    }
                }

                Console.WriteLine($"Request statistics:");
                Console.WriteLine($"    Document Count: {documentsInPage.Statistics.DocumentCount}");
                Console.WriteLine($"    Valid Document Count: {documentsInPage.Statistics.ValidDocumentCount}");
                Console.WriteLine($"    Transaction Count: {documentsInPage.Statistics.TransactionCount}");
                Console.WriteLine($"    Invalid Document Count: {documentsInPage.Statistics.InvalidDocumentCount}");
                Console.WriteLine("");
            }
        }
        public async Task RecognizeHealthcareEntitiesTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments);

            await operation.WaitForCompletionAsync(PollingInterval);

            ValidateOperationProperties(operation);

            List <AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, resultInPages.Count);

            //Take the first page
            var resultCollection = resultInPages.FirstOrDefault();

            Assert.AreEqual(s_batchDocuments.Count, resultCollection.Count);

            AnalyzeHealthcareEntitiesResult result1 = resultCollection[0];

            Assert.AreEqual(s_document1ExpectedEntitiesOutput.Count, result1.Entities.Count);
            Assert.IsNotNull(result1.Id);
            Assert.AreEqual("1", result1.Id);

            foreach (HealthcareEntity entity in result1.Entities)
            {
                Assert.IsTrue(s_document1ExpectedEntitiesOutput.Contains(entity.Text));

                if (entity.Text == "ibuprofen")
                {
                    var linksList = new List <string> {
                        "UMLS", "AOD", "ATC", "CCPSS", "CHV", "CSP", "DRUGBANK", "GS", "LCH_NW", "LNC", "MEDCIN", "MMSL", "MSH", "MTHSPL", "NCI", "NCI_CTRP", "NCI_DCP", "NCI_DTP", "NCI_FDA", "NCI_NCI-GLOSS", "NDDF", "PDQ", "RCD", "RXNORM", "SNM", "SNMI", "SNOMEDCT_US", "USP", "USPMG", "VANDF"
                    };

                    foreach (EntityDataSource entityDataSource in entity.DataSources)
                    {
                        Assert.IsTrue(linksList.Contains(entityDataSource.Name));
                    }
                }

                // TODO - Implement HC preview.4 https://github.com/Azure/azure-sdk-for-net/issues/18984
                //if (entity.Text == "100mg")
                //{
                //    Assert.IsTrue(entity.RelatedEntities.Count == 1);

                //    var relatedEntity = entity.RelatedEntities.FirstOrDefault().Key;

                //    Assert.AreEqual("ibuprofen", relatedEntity.Text);
                //    Assert.AreEqual("MedicationName", relatedEntity.Category);
                //    Assert.AreEqual(9, relatedEntity.Length);
                //    Assert.AreEqual(27, relatedEntity.Offset);
                //    Assert.AreEqual(1.0, relatedEntity.ConfidenceScore);
                //    Assert.AreEqual(HealthcareEntityRelationType.DosageOfMedication, entity.RelatedEntities.FirstOrDefault().Value);
                //}
            }
        }
示例#11
0
        public async Task RecognizeHealthcareEntitiesTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.AreEqual(2, resultCollection.Count);

            AnalyzeHealthcareEntitiesResult result = resultCollection[0];

            var entitiesList = new List <string> {
                "100mg", "ibuprofen", "twice daily"
            };

            Assert.AreEqual(3, result.Entities.Count);
            Assert.IsNotNull(result.Id);
            Assert.AreEqual("1", result.Id);

            foreach (HealthcareEntity entity in result.Entities)
            {
                Assert.IsTrue(entitiesList.Contains(entity.Text));

                if (entity.Text == "ibuprofen")
                {
                    var linksList = new List <string> {
                        "UMLS", "AOD", "ATC", "CCPSS", "CHV", "CSP", "DRUGBANK", "GS", "LCH_NW", "LNC", "MEDCIN", "MMSL", "MSH", "MTHSPL", "NCI", "NCI_CTRP", "NCI_DCP", "NCI_DTP", "NCI_FDA", "NCI_NCI-GLOSS", "NDDF", "PDQ", "RCD", "RXNORM", "SNM", "SNMI", "SNOMEDCT_US", "USP", "USPMG", "VANDF"
                    };

                    foreach (EntityDataSource entityDataSource in entity.DataSources)
                    {
                        Assert.IsTrue(linksList.Contains(entityDataSource.Name));
                    }
                }

                if (entity.Text == "100mg")
                {
                    Assert.IsTrue(entity.RelatedEntities.Count == 1);

                    var relatedEntity = entity.RelatedEntities.FirstOrDefault().Key;

                    Assert.AreEqual("ibuprofen", relatedEntity.Text);
                    Assert.AreEqual("MedicationName", relatedEntity.Category);
                    Assert.AreEqual(0, relatedEntity.Length);
                    Assert.AreEqual(27, relatedEntity.Offset);
                    Assert.AreEqual(1.0, relatedEntity.ConfidenceScore);

                    // TODO - DosageOfMedication is not in relation types and is returned from the service. Need to add to swagger.
                    //Assert.AreEqual(HealthcareEntityRelationType.DosageOfMedication, entity.RelatedEntities.ElementAt(0).Value);
                }
            }
        }
示例#12
0
        public async Task RecognizeHealthcareEntitiesBatchTest()
        {
            TextAnalyticsClient      client    = GetClient();
            List <TextDocumentInput> documents = batchDocuments;

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.AreEqual(2, resultCollection.Count);
        }
        public async Task RecognizeHealthcareEntitiesBatchWithCancellation()
        {
            TextAnalyticsClient client = GetClient();
            string document            = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE | Signed | DIS |";

            var batchDocuments = new List <string>();

            for (var i = 0; i < 10; i++)
            {
                batchDocuments.Add(document);
            }

            AnalyzeHealthcareEntitiesOperation operation = default;

            await TestRetryHelper.RetryAsync(async() =>
            {
                try
                {
                    operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments, "en");
                    await operation.CancelAsync();
                    await operation.WaitForCompletionAsync();
                }
                catch (Exception e)
                {
                    Assert.AreEqual(typeof(RequestFailedException), e.GetType());
                    Assert.IsTrue(e.Message.Contains("The operation was canceled so no value is available."));
                    return((Response)null);
                }

                // If we get here, that means that the operation completed successfully and didn't cancel.
                throw new InvalidOperationException("StartAnalyzeHealthcareEntitiesAsync operation did not get cancelled.");
            },
                                             maxIterations : 15, delay : TimeSpan.FromSeconds(1));

            Assert.IsTrue(operation.HasCompleted);
            Assert.IsFalse(operation.HasValue);
            Assert.AreEqual(200, operation.GetRawResponse().Status);
            Assert.AreEqual(TextAnalyticsOperationStatus.Cancelled, operation.Status);

            try
            {
                Assert.IsNull(operation.Value);
            }
            catch (RequestFailedException exception)
            {
                Assert.IsTrue(exception.Message.Contains("The operation was canceled so no value is available."));
            }
        }
示例#14
0
        public async Task HealthcareOperationConvenienceCanPollFromNewObject()
        {
            TextAnalyticsClient client = GetClient(out var nonInstrumentedClient);

            var documents = new List <string>
            {
                "Subject is taking 100mg of ibuprofen twice daily",
                "Can cause rapid or irregular heartbeat, delirium, panic, psychosis, and heart failure."
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents);

            var sameOperation = InstrumentOperation(new AnalyzeHealthcareEntitiesOperation(operation.Id, nonInstrumentedClient));
            await sameOperation.WaitForCompletionAsync();

            Assert.IsTrue(sameOperation.HasValue);
        }
示例#15
0
        public async Task RecognizeHealthcareEntitiesWithLanguageTest()
        {
            TextAnalyticsClient client = GetClient();
            string document            = singleEnglish;

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(new List <string>() { document }, "en");

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            foreach (AnalyzeHealthcareEntitiesResult result in resultCollection)
            {
                Assert.AreEqual(3, result.Entities.Count);
                Assert.IsNotNull(result.Id);
            }
        }
        public async Task RecognizeHealthcareEntitiesWithAADTest()
        {
            TextAnalyticsClient client = GetClient(useTokenCredential: true);

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            List <AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, resultInPages.Count);

            //Take the first page
            var resultCollection = resultInPages.FirstOrDefault();

            Assert.AreEqual(s_batchDocuments.Count, resultCollection.Count);
        }
示例#17
0
        public async Task RecognizeHealthcareEntitiesWithLanguageTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchConvenienceDocuments, "en");

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            //Take the first page
            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            var expectedOutput = new Dictionary <string, List <string> >()
            {
                { "0", s_document1ExpectedEntitiesOutput },
                { "1", s_document2ExpectedEntitiesOutput },
            };

            ValidateBatchDocumentsResult(resultCollection, expectedOutput);
        }
示例#18
0
        public async Task RecognizeHealthcareEntitiesBatchWithErrorTest()
        {
            TextAnalyticsClient client = GetClient();
            var documents = new List <string>
            {
                "Subject is taking 100mg of ibuprofen twice daily",
                "Can cause rapid or irregular heartbeat, delirium, panic, psychosis, and heart failure.",
                "",
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.IsNotNull(resultCollection[2].Id);

            Assert.IsTrue(resultCollection[2].HasError);
            Assert.AreEqual(TextAnalyticsErrorCode.InvalidDocument, resultCollection[2].Error.ErrorCode.ToString());
        }
示例#19
0
        public async Task RecognizeHealthcareEntitiesWithTopParameter()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                Top = 1
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments, options);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.AreEqual(1, resultCollection.Count);
            Assert.AreEqual(3, resultCollection[0].Entities.Count);
            Assert.IsNotNull(resultCollection[0].Id);
            Assert.AreEqual("1", resultCollection[0].Id);
            Assert.AreEqual("100mg", resultCollection[0].Entities.FirstOrDefault().Text);
            Assert.AreEqual("Dosage", resultCollection[0].Entities.FirstOrDefault().Category);
        }
        public async Task HealthcareAsyncPagination()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsSampleHealthcareAsyncPagination
            string document = @"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | CORONARY ARTERY DISEASE.";

            var list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(document);
            }
            ;

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                Top = 2
            };

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(list, "en", options);

            AsyncPageable <AnalyzeHealthcareEntitiesResult> results = client.GetHealthcareEntities(healthOperation);

            Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\"");
            Console.WriteLine("");

            int resultCount = 0;
            await foreach (AnalyzeHealthcareEntitiesResult result in results)
            {
                resultCount += 1;
            }

            Console.WriteLine("resultCount " + resultCount);
        }
示例#21
0
        public async Task AnalyzeHealthcareEntitiesPagination()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments);

            Assert.IsFalse(operation.HasCompleted);
            Assert.IsFalse(operation.HasValue);

            Assert.ThrowsAsync <InvalidOperationException>(async() => await Task.Run(() => operation.Value));
            Assert.Throws <InvalidOperationException>(() => operation.GetValues());

            await operation.WaitForCompletionAsync();

            Assert.IsTrue(operation.HasCompleted);
            Assert.IsTrue(operation.HasValue);

            ValidateOperationProperties(operation);

            // try async
            //There most be 1 page
            List <AnalyzeHealthcareEntitiesResultCollection> asyncPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, asyncPages.Count);

            // First page should have 2 results
            Assert.AreEqual(2, asyncPages[0].Count);

            // try sync
            //There most be 1 page
            List <AnalyzeHealthcareEntitiesResultCollection> pages = operation.GetValues().AsEnumerable().ToList();

            Assert.AreEqual(1, pages.Count);

            // First page should have 2 results
            Assert.AreEqual(2, pages[0].Count);
        }
示例#22
0
        public async Task RecognizeHealthcareEntitiesWithSkipParameter()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                Skip = 1
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments, options);

            await operation.WaitForCompletionAsync(PollingInterval);

            AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.IsFalse(resultCollection[0].HasError);
            Assert.IsNotNull(resultCollection[0].Warnings);
            Assert.AreEqual(1, resultCollection.Count);
            Assert.AreEqual(6, resultCollection[0].Entities.Count);
            Assert.IsNotNull(resultCollection[0].Id);
            Assert.AreEqual("2", resultCollection[0].Id);
            Assert.AreEqual("rapid", resultCollection[0].Entities.FirstOrDefault().Text);
            Assert.AreEqual("SymptomOrSign", resultCollection[0].Entities.FirstOrDefault().Category);
        }
        public async Task Sample7_AnalyzeHealthcareEntitiesBatch_ManualPolling()
        {
            // create a text analytics client
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;
            var    client   = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            #region Snippet:Sample7_AnalyzeHealthcareEntitiesBatch_ManualPolling
            // get input documents
            string document1 = @"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.";

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

            // prepare analyze operation input
            List <TextDocumentInput> batchInput = new List <TextDocumentInput>()
            {
                new TextDocumentInput("1", document1)
                {
                    Language = "en"
                },
                new TextDocumentInput("2", document2)
                {
                    Language = "en"
                }
            };

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            };

            // start analysis process
            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, options);

            TimeSpan pollingInterval = new TimeSpan(1000);

            // wait for completion with manual polling
            while (true)
            {
                await healthOperation.UpdateStatusAsync();

                if (healthOperation.HasCompleted)
                {
                    break;
                }

                await Task.Delay(pollingInterval);
            }

            // view operation results
            await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
            {
                Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
                Console.WriteLine("");

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

                    // view recognized healthcare entities
                    foreach (HealthcareEntity entity in result.Entities)
                    {
                        Console.WriteLine($"    Entity: {entity.Text}");
                        Console.WriteLine($"    Category: {entity.Category}");
                        Console.WriteLine($"    Offset: {entity.Offset}");
                        Console.WriteLine($"    Length: {entity.Length}");
                        Console.WriteLine($"    NormalizedText: {entity.NormalizedText}");
                        Console.WriteLine($"    Links:");

                        // view entity data sources
                        foreach (EntityDataSource entityDataSource in entity.DataSources)
                        {
                            Console.WriteLine($"        Entity ID in Data Source: {entityDataSource.EntityId}");
                            Console.WriteLine($"        DataSource: {entityDataSource.Name}");
                        }

                        // view assertion
                        if (entity.Assertion != null)
                        {
                            Console.WriteLine($"    Assertions:");

                            if (entity.Assertion?.Association != null)
                            {
                                Console.WriteLine($"        Association: {entity.Assertion?.Association}");
                            }

                            if (entity.Assertion?.Certainty != null)
                            {
                                Console.WriteLine($"        Certainty: {entity.Assertion?.Certainty}");
                            }
                            if (entity.Assertion?.Conditionality != null)
                            {
                                Console.WriteLine($"        Conditionality: {entity.Assertion?.Conditionality}");
                            }
                        }

                        Console.WriteLine($"    We found {result.EntityRelations.Count} relations in the current document:");
                        Console.WriteLine("");

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

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

                                Console.WriteLine($"            Associated Entity Text: {role.Entity.Text}");
                                Console.WriteLine($"            Associated Entity Category: {role.Entity.Category}");

                                Console.WriteLine("");
                            }

                            Console.WriteLine("");
                        }

                        Console.WriteLine("");
                    }
                    Console.WriteLine("");
                }
            }
        }
示例#24
0
        public async Task RecognizeHealthcareEntitiesTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            List <AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, resultInPages.Count);

            //Take the first page
            var resultCollection = resultInPages.FirstOrDefault();

            Assert.AreEqual(s_batchDocuments.Count, resultCollection.Count);

            AnalyzeHealthcareEntitiesResult result1 = resultCollection[0];

            Assert.AreEqual(s_document1ExpectedEntitiesOutput.Count, result1.Entities.Count);
            Assert.IsNotNull(result1.Id);
            Assert.AreEqual("1", result1.Id);

            foreach (HealthcareEntity entity in result1.Entities)
            {
                Assert.IsTrue(s_document1ExpectedEntitiesOutput.Contains(entity.Text));

                if (entity.Text == "ibuprofen")
                {
                    var linksList = new List <string> {
                        "UMLS", "AOD", "ATC", "CCPSS", "CHV", "CSP", "DRUGBANK", "GS", "LCH_NW", "LNC", "MEDCIN", "MMSL", "MSH", "MTHSPL", "NCI", "NCI_CTRP", "NCI_DCP", "NCI_DTP", "NCI_FDA", "NCI_NCI-GLOSS", "NDDF", "PDQ", "RCD", "RXNORM", "SNM", "SNMI", "SNOMEDCT_US", "USP", "USPMG", "VANDF"
                    };

                    foreach (EntityDataSource entityDataSource in entity.DataSources)
                    {
                        Assert.IsTrue(linksList.Contains(entityDataSource.Name));
                    }
                }

                if (entity.Text == "100mg")
                {
                    Assert.AreEqual(18, entity.Offset);
                    Assert.AreEqual("Dosage", entity.Category);
                    Assert.AreEqual(5, entity.Length);
                }
            }

            Assert.AreEqual(2, result1.EntityRelations.Count());
            foreach (HealthcareEntityRelation relation in result1.EntityRelations)
            {
                if (relation.RelationType == "DosageOfMedication")
                {
                    var role = relation.Roles.ElementAt(0);
                    Assert.IsNotNull(relation.Roles);
                    Assert.AreEqual(2, relation.Roles.Count());
                    Assert.AreEqual("Dosage", role.Name);
                    Assert.AreEqual("100mg", role.Entity.Text);
                    Assert.AreEqual(18, role.Entity.Offset);
                    Assert.AreEqual("Dosage", role.Entity.Category);
                    Assert.AreEqual(5, role.Entity.Length);
                }
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log,
            ExecutionContext executionContext)
        {
            string skillName = executionContext.FunctionName;
            IEnumerable <WebApiRequestRecord> requestRecords = WebApiSkillHelpers.GetRequestRecords(req);

            if (requestRecords == null)
            {
                return(new BadRequestObjectResult($"{skillName} - Invalid request record array."));
            }

            // Get Endpoint and access key from App Settings
            string apiKey      = Environment.GetEnvironmentVariable(textAnalyticsApiKeySetting, EnvironmentVariableTarget.Process);
            string apiEndpoint = Environment.GetEnvironmentVariable(textAnalyticsApiEndpointSetting, EnvironmentVariableTarget.Process);

            if (apiKey == null || apiEndpoint == null)
            {
                return(new BadRequestObjectResult($"{skillName} - TextAnalyticsForHealth API key or Endpoint is missing. Make sure to set it in the Environment Variables."));
            }
            var client = new TextAnalyticsClient(new Uri(apiEndpoint), new AzureKeyCredential(apiKey));

            // Get a custom timeout from the header, if it exists. If not use the default timeout.
            int timeout;

            if (!int.TryParse(req.Headers["timeout"].ToString(), out timeout))
            {
                timeout = defaultTimeout;
            }
            timeout = Math.Clamp(timeout - timeoutBuffer, 1, maxTimeout - timeoutBuffer);
            var timeoutMiliseconds = timeout * 1000;
            var timeoutTask        = Task.Delay(timeoutMiliseconds);

            // Get a custom default language, if none is provided, use english
            string defaultLanguage = req.Headers.ContainsKey("defaultLanguageCode")? req.Headers["defaultLanguageCode"].ToString(): "en";

            WebApiSkillResponse response = await WebApiSkillHelpers.ProcessRequestRecordsAsync(skillName, requestRecords,
                                                                                               async (inRecord, outRecord) => {
                if (timeoutTask.IsCompleted)
                {
                    // The time limit for all the skills has been met
                    outRecord.Errors.Add(new WebApiErrorWarningContract
                    {
                        Message = "TextAnalyticsForHealth Error: The Text Analysis Operation took too long to complete."
                    });
                    return(outRecord);
                }

                // Prepare analysis operation input
                if (!inRecord.Data.ContainsKey("text"))
                {
                    outRecord.Errors.Add(new WebApiErrorWarningContract
                    {
                        Message = "TextAnalyticsForHealth Error: The skill request did not contain 'text' in the input."
                    });
                    return(outRecord);
                }
                var document = inRecord.Data["text"] as string;
                var language = inRecord.Data.ContainsKey("languageCode") ? inRecord.Data["languageCode"] as string : defaultLanguage;

                var docInfo = new StringInfo(document);
                if (docInfo.LengthInTextElements >= maxCharLength)
                {
                    outRecord.Warnings.Add(new WebApiErrorWarningContract
                    {
                        Message = $"TextAnalyticsForHealth Warning: The submitted document was over {maxCharLength} elements. It has been truncated to fit this requirement."
                    });
                    document = docInfo.SubstringByTextElements(0, maxCharLength);
                }

                var options = new AnalyzeHealthcareEntitiesOptions {
                };
                List <string> batchInput = new List <string>()
                {
                    document
                };

                // start analysis process
                var timer = System.Diagnostics.Stopwatch.StartNew();
                AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, language, options);
                var healthOperationTask = healthOperation.WaitForCompletionAsync().AsTask();

                if (await Task.WhenAny(healthOperationTask, timeoutTask) == healthOperationTask)
                {
                    // Task Completed, now lets process the result.
                    outRecord.Data["status"] = healthOperation.Status.ToString();
                    if (healthOperation.Status != TextAnalyticsOperationStatus.Succeeded || !healthOperation.HasValue)
                    {
                        // The operation was not a success
                        outRecord.Errors.Add(new WebApiErrorWarningContract
                        {
                            Message = "TextAnalyticsForHealth Error: Health Operation returned a non-succeeded status."
                        });
                    }
                    else
                    {
                        // The operation was a success, so lets add the results to our output.
                        await ExtractEntityData(healthOperation.Value, outRecord);
                    }
                }
                else
                {
                    // Timeout
                    outRecord.Errors.Add(new WebApiErrorWarningContract
                    {
                        Message = "TextAnalyticsForHealth Error: The Text Analysis Operation took too long to complete."
                    });
                }

                // Record how long this task took to complete.
                timer.Stop();
                var timeToComplete = timer.Elapsed.TotalSeconds;
                log.LogInformation($"Time to complete request for document with ID {inRecord.RecordId}: {timeToComplete}");

                return(outRecord);
            });

            return(new OkObjectResult(response));
        }
        public async Task HealthcareBatchAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsSampleHealthcareBatchAsync
            string document1 = @"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.";

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

            List <string> batchInput = new List <string>()
            {
                document1,
                document2,
            };

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            };

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, "en", options);

            await healthOperation.WaitForCompletionAsync();

            await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
            {
                Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
                Console.WriteLine("");

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

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

                        foreach (EntityDataSource entityDataSource in entity.DataSources)
                        {
                            Console.WriteLine($"        Entity ID in Data Source: {entityDataSource.EntityId}");
                            Console.WriteLine($"        DataSource: {entityDataSource.Name}");
                        }
                    }

                    Console.WriteLine($"    Document statistics:");
                    Console.WriteLine($"        Character count (in Unicode graphemes): {result.Statistics.CharacterCount}");
                    Console.WriteLine($"        Transaction count: {result.Statistics.TransactionCount}");
                    Console.WriteLine("");
                }
                Console.WriteLine($"Request statistics:");
                Console.WriteLine($"    Document Count: {documentsInPage.Statistics.DocumentCount}");
                Console.WriteLine($"    Valid Document Count: {documentsInPage.Statistics.ValidDocumentCount}");
                Console.WriteLine($"    Transaction Count: {documentsInPage.Statistics.TransactionCount}");
                Console.WriteLine($"    Invalid Document Count: {documentsInPage.Statistics.InvalidDocumentCount}");
                Console.WriteLine("");
            }
        }
        public async Task Sample7_AnalyzeHealthcareEntitiesBatchAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsSampleHealthcareBatchAsync
            string document1 = @"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.";

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

            List <TextDocumentInput> batchInput = new List <TextDocumentInput>()
            {
                new TextDocumentInput("1", document1)
                {
                    Language = "en"
                },
                new TextDocumentInput("2", document2)
                {
                    Language = "en"
                },
                new TextDocumentInput("3", string.Empty)
            };

            AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions()
            {
                IncludeStatistics = true
            };

            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput, options);

            await healthOperation.WaitForCompletionAsync();

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

            Console.WriteLine($"Created On   : {healthOperation.CreatedOn}");
            Console.WriteLine($"Expires On   : {healthOperation.ExpiresOn}");
            Console.WriteLine($"Id           : {healthOperation.Id}");
            Console.WriteLine($"Status       : {healthOperation.Status}");
            Console.WriteLine($"Last Modified: {healthOperation.LastModified}");

            foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues())
            {
                Console.WriteLine($"Results of Azure Text Analytics \"Healthcare\" Model, version: \"{documentsInPage.ModelVersion}\"");
                Console.WriteLine("");

                int i = 0;

                foreach (AnalyzeHealthcareEntitiesResult result in documentsInPage)
                {
                    TextDocumentInput document = batchInput[i++];

                    Console.WriteLine($"On document (Id={document.Id}, Language=\"{document.Language}\"):");

                    if (result.HasError)
                    {
                        Console.WriteLine("  Error!");
                        Console.WriteLine($"  Document error code: {result.Error.ErrorCode}.");
                        Console.WriteLine($"  Message: {result.Error.Message}");
                    }
                    else
                    {
                        Console.WriteLine($"    Recognized the following {result.Entities.Count} healthcare entities:");

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

                            foreach (EntityDataSource entityDataSource in entity.DataSources)
                            {
                                Console.WriteLine($"        Entity ID in Data Source: {entityDataSource.EntityId}");
                                Console.WriteLine($"        DataSource: {entityDataSource.Name}");
                            }
                            if (entity.Assertion != null)
                            {
                                Console.WriteLine($"    Assertions:");

                                if (entity.Assertion?.Association != null)
                                {
                                    Console.WriteLine($"        Association: {entity.Assertion?.Association}");
                                }

                                if (entity.Assertion?.Certainty != null)
                                {
                                    Console.WriteLine($"        Certainty: {entity.Assertion?.Certainty}");
                                }
                                if (entity.Assertion?.Conditionality != null)
                                {
                                    Console.WriteLine($"        Conditionality: {entity.Assertion?.Conditionality}");
                                }
                            }
                        }

                        Console.WriteLine($"    We found {result.EntityRelations.Count} relations in the current document:");
                        Console.WriteLine("");

                        foreach (HealthcareEntityRelation relations in result.EntityRelations)
                        {
                            Console.WriteLine($"        Relation: {relations.RelationType}");
                            Console.WriteLine($"        For this relation there are {relations.Roles.Count} roles");

                            foreach (HealthcareEntityRelationRole role in relations.Roles)
                            {
                                Console.WriteLine($"            Role Name: {role.Name}");

                                Console.WriteLine($"            Associated Entity Text: {role.Entity.Text}");
                                Console.WriteLine($"            Associated Entity Category: {role.Entity.Category}");

                                Console.WriteLine("");
                            }

                            Console.WriteLine("");
                        }

                        Console.WriteLine("");
                    }

                    Console.WriteLine($"Batch operation statistics:");
                    Console.WriteLine($"  Document count: {result.Statistics.CharacterCount}");
                    Console.WriteLine($"  Valid document count: {result.Statistics.TransactionCount}");
                    Console.WriteLine("");
                }

                Console.WriteLine($"Batch operation statistics:");
                Console.WriteLine($"  Document count: {documentsInPage.Statistics.DocumentCount}");
                Console.WriteLine($"  Valid document count: {documentsInPage.Statistics.ValidDocumentCount}");
                Console.WriteLine($"  Invalid document count: {documentsInPage.Statistics.InvalidDocumentCount}");
                Console.WriteLine($"  Transaction count: {documentsInPage.Statistics.TransactionCount}");
                Console.WriteLine("");
            }
        }
示例#28
0
        public async Task RecognizeHealthcareEntitiesTestWithAssertions()
        {
            TextAnalyticsClient client = GetClient();

            IReadOnlyCollection <string> batchDocuments = new List <string>()
            {
                "Baby not likely to have Meningitis. in case of fever in the mother, consider Penicillin for the baby too."
            };

            IReadOnlyCollection <string> expectedEntitiesOutput = new List <string>
            {
                "Baby",
                "Meningitis",
                "fever",
                "mother",
                "Penicillin",
                "baby"
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(batchDocuments);

            await operation.WaitForCompletionAsync();

            ValidateOperationProperties(operation);

            List <AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;

            Assert.AreEqual(1, resultInPages.Count);

            var resultCollection = resultInPages.FirstOrDefault();

            Assert.AreEqual(batchDocuments.Count, resultCollection.Count);

            AnalyzeHealthcareEntitiesResult result1 = resultCollection[0];

            Assert.AreEqual(expectedEntitiesOutput.Count, result1.Entities.Count);

            foreach (HealthcareEntity entity in result1.Entities)
            {
                Assert.IsTrue(expectedEntitiesOutput.Contains(entity.Text));

                if (entity.Text == "Baby")
                {
                    var linksList = new List <string> {
                        "UMLS", "AOD", "CCPSS", "CHV", "DXP", "LCH", "LCH_NW", "LNC", "MDR", "MSH", "NCI", "NCI_FDA", "NCI_NICHD", "SNOMEDCT_US"
                    };

                    foreach (EntityDataSource entityDataSource in entity.DataSources)
                    {
                        Assert.IsTrue(linksList.Contains(entityDataSource.Name));
                    }
                    Assert.AreEqual("Infant", entity.NormalizedText);
                }

                if (entity.Text == "Meningitis")
                {
                    Assert.AreEqual(24, entity.Offset);
                    Assert.AreEqual("Diagnosis", entity.Category);
                    Assert.AreEqual(10, entity.Length);
                    Assert.IsNotNull(entity.Assertion);
                    Assert.AreEqual(EntityCertainty.NegativePossible, entity.Assertion.Certainty.Value);
                }

                if (entity.Text == "Penicillin")
                {
                    Assert.AreEqual("MedicationName", entity.Category);
                    Assert.AreEqual(10, entity.Length);
                    Assert.IsNotNull(entity.Assertion);
                    Assert.AreEqual(EntityCertainty.NeutralPossible, entity.Assertion.Certainty.Value);
                }
            }
        }
示例#29
0
        public async Task AnalyzeHealthcareEntitiesConvenienceAsync()
        {
            // create a text analytics client
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #region Snippet:TextAnalyticsAnalyzeHealthcareEntitiesConvenienceAsyncAll
            #region Snippet:TextAnalyticsAnalyzeHealthcareEntitiesConvenienceAsync
            // get input documents
            string document1 = @"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.";

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

            // prepare analyze operation input
            List <string> batchInput = new List <string>()
            {
                document1,
                document2
            };

            // start analysis process
            AnalyzeHealthcareEntitiesOperation healthOperation = await client.StartAnalyzeHealthcareEntitiesAsync(batchInput);

            await healthOperation.WaitForCompletionAsync();

            #endregion Snippet:TextAnalyticsAnalyzeHealthcareEntitiesConvenienceAsync

            #region Snippet:TextAnalyticsSampleHealthcareOperationStatus
            // view operation status
            Console.WriteLine($"Created On   : {healthOperation.CreatedOn}");
            Console.WriteLine($"Expires On   : {healthOperation.ExpiresOn}");
            Console.WriteLine($"Status       : {healthOperation.Status}");
            Console.WriteLine($"Last Modified: {healthOperation.LastModified}");
            #endregion Snippet:TextAnalyticsSampleHealthcareOperationStatus

            #region Snippet:TextAnalyticsSampleHealthcareConvenienceAsyncViewResults
            // view operation results
            await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.Value)
            {
                Console.WriteLine($"Results of Azure Text Analytics \"Healthcare Async\" Model, version: \"{documentsInPage.ModelVersion}\"");
                Console.WriteLine("");

                foreach (AnalyzeHealthcareEntitiesResult entitiesInDoc in documentsInPage)
                {
                    if (!entitiesInDoc.HasError)
                    {
                        foreach (var entity in entitiesInDoc.Entities)
                        {
                            // view recognized healthcare entities
                            Console.WriteLine($"  Entity: {entity.Text}");
                            Console.WriteLine($"  Category: {entity.Category}");
                            Console.WriteLine($"  Offset: {entity.Offset}");
                            Console.WriteLine($"  Length: {entity.Length}");
                            Console.WriteLine($"  NormalizedText: {entity.NormalizedText}");
                            Console.WriteLine($"  Links:");

                            // view entity data sources
                            foreach (EntityDataSource entityDataSource in entity.DataSources)
                            {
                                Console.WriteLine($"    Entity ID in Data Source: {entityDataSource.EntityId}");
                                Console.WriteLine($"    DataSource: {entityDataSource.Name}");
                            }

                            // view assertion
                            if (entity.Assertion != null)
                            {
                                Console.WriteLine($"  Assertions:");

                                if (entity.Assertion?.Association != null)
                                {
                                    Console.WriteLine($"    Association: {entity.Assertion?.Association}");
                                }

                                if (entity.Assertion?.Certainty != null)
                                {
                                    Console.WriteLine($"    Certainty: {entity.Assertion?.Certainty}");
                                }
                                if (entity.Assertion?.Conditionality != null)
                                {
                                    Console.WriteLine($"    Conditionality: {entity.Assertion?.Conditionality}");
                                }
                            }
                        }

                        Console.WriteLine($"  We found {entitiesInDoc.EntityRelations.Count} relations in the current document:");
                        Console.WriteLine("");

                        // view recognized healthcare relations
                        foreach (HealthcareEntityRelation relations in entitiesInDoc.EntityRelations)
                        {
                            Console.WriteLine($"    Relation: {relations.RelationType}");
                            Console.WriteLine($"    For this relation there are {relations.Roles.Count} roles");

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

                                Console.WriteLine($"      Associated Entity Text: {role.Entity.Text}");
                                Console.WriteLine($"      Associated Entity Category: {role.Entity.Category}");
                                Console.WriteLine("");
                            }

                            Console.WriteLine("");
                        }
                    }
                    else
                    {
                        Console.WriteLine("  Error!");
                        Console.WriteLine($"  Document error code: {entitiesInDoc.Error.ErrorCode}.");
                        Console.WriteLine($"  Message: {entitiesInDoc.Error.Message}");
                    }

                    Console.WriteLine("");
                }
            }
            #endregion Snippet:TextAnalyticsSampleHealthcareConvenienceAsyncViewResults

            #endregion Snippet:TextAnalyticsAnalyzeHealthcareEntitiesConvenienceAsyncAll
        }