Beispiel #1
0
        public async Task RecognizeHealthcareEntitiesBatchConvenienceTest()
        {
            TextAnalyticsClient client = GetClient();

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchConvenienceDocuments);

            await operation.WaitForCompletionAsync(PollingInterval);

            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);
        }
Beispiel #2
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());
        }
Beispiel #3
0
        public async Task RecognizeHealthcareEntitiesWithTopParameter()
        {
            TextAnalyticsClient client = GetClient();

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

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

            await operation.WaitForCompletionAsync(PollingInterval);

            RecognizeHealthcareEntitiesResultCollection 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);
        }
Beispiel #4
0
        public async Task RecognizeHealthcareEntitiesBatchWithStatisticsTest()
        {
            TextAnalyticsClient client = GetClient();
            var documents = batchDocuments;

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

            AnalyzeHealthcareEntitiesOperation operation = await client.StartHealthcareBatchAsync(documents, options);

            await operation.WaitForCompletionAsync(PollingInterval);

            RecognizeHealthcareEntitiesResultCollection resultCollection = operation.Value;

            Assert.AreEqual(2, resultCollection.Count);

            Assert.AreEqual(2, resultCollection.Statistics.DocumentCount);
            Assert.AreEqual(2, resultCollection.Statistics.TransactionCount);
            Assert.AreEqual(0, resultCollection.Statistics.InvalidDocumentCount);
        }
Beispiel #5
0
        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);
            }
            ;

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

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

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

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

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

            Console.WriteLine("resultCount " + resultCount);
        }
Beispiel #6
0
        public async Task HealthcareOperationCanPollFromNewObject()
        {
            TextAnalyticsClient client = GetClient(out var nonInstrumentedClient);

            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, delirium, panic, psychosis, and heart failure.")
                {
                    Language = "en",
                }
            };

            AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(documents);

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

            Assert.IsTrue(sameOperation.HasValue);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public async Task GetValuesSample()
        {
            #region Snippet:PageableOperationGetValues
            // create a client
            var client   = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
            var document = new List <string>()
            {
                "document with information"
            };

            // Start the operation
            AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document);

            await healthOperation.WaitForCompletionAsync();

            foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues())
            {
                foreach (HealthcareEntity entity in documentsInPage[0].Entities)
                {
                    Console.WriteLine($"    Entity: {entity.Text}");
                }
            }
            #endregion
        }
Beispiel #10
0
        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);
            }

            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("");
                }
            }
        }
        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("");
                }
            }
        }
        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));
        }
Beispiel #13
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);
                }
            }
        }
Beispiel #14
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);
                }
            }
        }
        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("");
            }
        }
        public static async Task RunAsync([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
        {
            //Extracting content type and url of the blob triggering the function
            var jsondata = JsonConvert.SerializeObject(eventGridEvent.Data);
            var tmp      = new { contentType = "", url = "" };
            var data     = JsonConvert.DeserializeAnonymousType(jsondata, tmp);

            //Checking if the trigger was iniatiated for a WAV File.
            if (data.contentType == "audio/wav")
            {
                var    audioUrl = data.url;
                string blobName = audioUrl.Split('/').Last();

                string contosoStorageConnectionString = System.Environment.GetEnvironmentVariable("ContosoStorageConnectionString", EnvironmentVariableTarget.Process);
                string speechRegion          = System.Environment.GetEnvironmentVariable("SpeechRegion", EnvironmentVariableTarget.Process);
                string speechKey             = System.Environment.GetEnvironmentVariable("SpeechKey", EnvironmentVariableTarget.Process);
                string translatorKey         = System.Environment.GetEnvironmentVariable("TranslatorKey", EnvironmentVariableTarget.Process);
                string translatorEndpoint    = System.Environment.GetEnvironmentVariable("TranslatorEndpoint", EnvironmentVariableTarget.Process);
                string translatorLocation    = System.Environment.GetEnvironmentVariable("TranslatorLocation", EnvironmentVariableTarget.Process);
                string cosmosEndpointUrl     = System.Environment.GetEnvironmentVariable("CosmosDBEndpointUrl", EnvironmentVariableTarget.Process);
                string cosmosPrimaryKey      = System.Environment.GetEnvironmentVariable("CosmosDBPrimaryKey", EnvironmentVariableTarget.Process);
                string textAnalyticsKey      = System.Environment.GetEnvironmentVariable("TextAnalyticsKey", EnvironmentVariableTarget.Process);
                string textAnalyticsEndpoint = System.Environment.GetEnvironmentVariable("TextAnalyticsEndpoint", EnvironmentVariableTarget.Process);

                // Download audio file to a local temp directory
                var tempPath = System.IO.Path.GetTempFileName();
                BlobContainerClient container = new BlobContainerClient(contosoStorageConnectionString, "audiorecordings");
                BlobClient          blob      = container.GetBlobClient(blobName);
                await blob.DownloadToAsync(tempPath);

                var speechConfig = SpeechConfig.FromSubscription(speechKey, speechRegion);
                speechConfig.SetProperty(PropertyId.SpeechServiceConnection_SingleLanguageIdPriority, "Latency");

                // Audio Language Identification
                // Considering only two languages: English and Spanish
                // Languages supported for language detection : https://docs.microsoft.com/azure/cognitive-services/speech-service/language-support
                var    autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig.FromLanguages(new string[] { "en-US", "es-MX" });
                string languageDetected = "en-US";
                using (var audioInput = AudioConfig.FromWavFileInput(tempPath))
                {
                    using (var recognizer = new SourceLanguageRecognizer(speechConfig, autoDetectSourceLanguageConfig, audioInput))
                    {
                        var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                        if (result.Reason == ResultReason.RecognizedSpeech)
                        {
                            var lidResult = AutoDetectSourceLanguageResult.FromResult(result);
                            languageDetected = lidResult.Language;
                        }
                    }
                }
                speechConfig.SpeechRecognitionLanguage = languageDetected;

                // Audio Transcription
                StringBuilder sb = new StringBuilder();
                using var audioConfig = AudioConfig.FromWavFileInput(tempPath);
                {
                    using var recognizer = new SpeechRecognizer(speechConfig, audioConfig);
                    {
                        var stopRecognition = new TaskCompletionSource <int>();
                        recognizer.SessionStopped += (s, e) =>
                        {
                            stopRecognition.TrySetResult(0);
                        };
                        recognizer.Canceled += (s, e) =>
                        {
                            stopRecognition.TrySetResult(0);
                        };
                        recognizer.Recognized += (s, e) =>
                        {
                            if (e.Result.Reason == ResultReason.RecognizedSpeech)
                            {
                                sb.Append(e.Result.Text);
                            }
                            else if (e.Result.Reason == ResultReason.NoMatch)
                            {
                                log.LogInformation($"NOMATCH: Speech could not be recognized.");
                            }
                        };
                        await recognizer.StartContinuousRecognitionAsync();

                        Task.WaitAny(new[] { stopRecognition.Task });
                    }
                }
                string transcribedText = sb.ToString();

                // If transcription is in Spanish we will translate it to English
                if (!languageDetected.Contains("en"))
                {
                    string   route           = $"/translate?api-version=3.0&to=en";
                    string   textToTranslate = sb.ToString();
                    object[] body            = new object[] { new { Text = textToTranslate } };
                    var      requestBody     = JsonConvert.SerializeObject(body);

                    using (var client = new HttpClient())
                        using (var request = new HttpRequestMessage())
                        {
                            request.Method     = HttpMethod.Post;
                            request.RequestUri = new Uri(translatorEndpoint + route);
                            request.Content    = new StringContent(requestBody, Encoding.UTF8, "application/json");
                            request.Headers.Add("Ocp-Apim-Subscription-Key", translatorKey);
                            request.Headers.Add("Ocp-Apim-Subscription-Region", translatorLocation);

                            HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                            var responseBody = await response.Content.ReadAsStringAsync();

                            List <Model.TranslatorService.Root> translatedDocuments = JsonConvert.DeserializeObject <List <Model.TranslatorService.Root> >(responseBody);
                            transcribedText = translatedDocuments.FirstOrDefault().Translations.FirstOrDefault().Text;
                        }
                }

                //Azure Text Analytics for Healthcare
                List <string> healthDocuments = new List <string>
                {
                    transcribedText
                };
                var textAnalyticsClient = new TextAnalyticsClient(new Uri(textAnalyticsEndpoint), new AzureKeyCredential(textAnalyticsKey));
                AnalyzeHealthcareEntitiesOperation healthOperation = textAnalyticsClient.StartAnalyzeHealthcareEntities(healthDocuments, "en", new AnalyzeHealthcareEntitiesOptions {
                });
                await healthOperation.WaitForCompletionAsync();

                AnalyzeHealthcareEntitiesResult healthcareResult = healthOperation.GetValues().FirstOrDefault().FirstOrDefault();

                //Insert documents into CosmosDB
                var cosmosClient    = new CosmosClient(cosmosEndpointUrl, cosmosPrimaryKey);
                var cosmosDatabase  = (await cosmosClient.CreateDatabaseIfNotExistsAsync("Contoso")).Database;
                var cosmosContainer = (await cosmosDatabase.CreateContainerIfNotExistsAsync("Transcriptions", "/id")).Container;

                Model.Transcription newTranscription = new Model.Transcription();
                newTranscription.Id           = Guid.NewGuid().ToString();
                newTranscription.DocumentDate = new DateTime(int.Parse(blobName.Substring(0, 4)),
                                                             int.Parse(blobName.Substring(4, 2)), int.Parse(blobName.Substring(6, 2)));
                newTranscription.FileName        = blobName;
                newTranscription.TranscribedText = transcribedText;
                foreach (var item in healthcareResult.Entities)
                {
                    newTranscription.HealthcareEntities.Add(new Model.HealthcareEntity()
                    {
                        Category = item.Category, Text = item.Text
                    });
                }

                try
                {
                    ItemResponse <Model.Transcription> cosmosResponse = await
                                                                        cosmosContainer.CreateItemAsync(newTranscription, new PartitionKey(newTranscription.Id));
                }
                catch (CosmosException ex) when(ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    //Conflicting documents are silently ignored for demo purposes.
                }

                System.IO.File.Delete(tempPath);
                log.LogInformation(eventGridEvent.Data.ToString());
            }
        }
Beispiel #17
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
        }
        public async Task HealthcareBatch()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

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

            #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>()
            {
                document,
                document,
            };

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

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

            await healthOperation.WaitForCompletionAsync();

            AnalyzeHealthcareEntitiesResultCollection results = healthOperation.Value;

            Console.WriteLine($"Results of Azure Text Analytics \"Healthcare\" 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($"    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: {results.Statistics.DocumentCount}");
            Console.WriteLine($"    Valid Document Count: {results.Statistics.ValidDocumentCount}");
            Console.WriteLine($"    Transaction Count: {results.Statistics.TransactionCount}");
            Console.WriteLine($"    Invalid Document Count: {results.Statistics.InvalidDocumentCount}");
            Console.WriteLine("");
        }