public async Task <IActionResult> PostToHealthBot([FromBody] PatientSymptomInfoDto patientSymptomInfo) { if (string.IsNullOrWhiteSpace(patientSymptomInfo.Key) || patientSymptomInfo.Key != "tRwMs2Rw0U4si5fNZve3GZU6vskxCpfYLPFog") { return(BadRequest()); } var message = System.IO.File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DeploymentTemplates/healthbot-proactive-message.json")); var healthBotProactiveMessage = JsonConvert.DeserializeObject <HealthBotProActiveMessage>(message); healthBotProactiveMessage.args = new Args { Doctor = patientSymptomInfo.Doctor, AnatomicalSiteMention = patientSymptomInfo.AnatomicalSiteMention, DiseaseDisorderMention = patientSymptomInfo.DiseaseDisorderMention, Identifier = patientSymptomInfo.Identifier, MedicationMention = patientSymptomInfo.MedicationMention, PatientDob = patientSymptomInfo.PatientDob, PatientName = patientSymptomInfo.PatientName, SignSymptomMention = patientSymptomInfo.SignSymptomMention, Symptoms = patientSymptomInfo.Symptoms }; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", GenerateToken()); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var httpContent = new StringContent(JsonConvert.SerializeObject(healthBotProactiveMessage), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("https://bot-eu.healthbot.microsoft.com/api/tenants/beloning-9my8uj9/beginScenario", httpContent); } return(Ok()); }
public async Task SendDataToFHIRServer(PatientSymptomInfoDto patientSymptoms) { var accessToken = await GetS2SAccessToken(_configuration["Authentication:Microsoft:Resource"], _configuration["Authentication:Microsoft:ClientId"], _configuration["Authentication:Microsoft:ClientSecret"]); var client = GetClient(accessToken.AccessToken); var existingPatient = client.Search <Hl7.Fhir.Model.Patient>(new string[] { $"identifier=http://hl7.org/fhir/sid/eu-ssn|{patientSymptoms.Identifier}" }); var patient = new Hl7.Fhir.Model.Patient(); if (existingPatient.Entry.Count == 1) { var patientResult = client.Search <Hl7.Fhir.Model.Patient>(new string[] { $"_id={existingPatient.Entry[0].Resource.Id}" }); if ((patientResult.Entry != null) && (patientResult.Entry.Count > 0)) { patient = (Hl7.Fhir.Model.Patient)patientResult.Entry[0].Resource; } } else { var newPatient = new Hl7.Fhir.Model.Patient() { BirthDate = patientSymptoms.PatientDob, Name = new List <Hl7.Fhir.Model.HumanName>() { new Hl7.Fhir.Model.HumanName() { Given = new List <string>() { patientSymptoms.PatientName }, Use = Hl7.Fhir.Model.HumanName.NameUse.Official, } }, Identifier = new List <Hl7.Fhir.Model.Identifier>() { new Hl7.Fhir.Model.Identifier() { Type = new Hl7.Fhir.Model.CodeableConcept { Coding = new List <Hl7.Fhir.Model.Coding> { new Hl7.Fhir.Model.Coding { System = "http://hl7.org/fhir/identifier-type", Code = "SB", Display = "Social Security Number" }, }, Text = "Social Security Number", }, System = "http://hl7.org/fhir/sid/eu-ssn", Value = patientSymptoms.Identifier } } }; patient = client.Create <Hl7.Fhir.Model.Patient>(newPatient); } var appointment = new Hl7.Fhir.Model.Appointment() { CreatedElement = new Hl7.Fhir.Model.FhirDateTime(new DateTimeOffset()), Meta = new Hl7.Fhir.Model.Meta { Source = "Generated by Patient" }, Description = patientSymptoms.Symptoms, Status = Hl7.Fhir.Model.Appointment.AppointmentStatus.CheckedIn, ReasonCode = new List <Hl7.Fhir.Model.CodeableConcept>(), Participant = new List <Hl7.Fhir.Model.Appointment.ParticipantComponent> { new Hl7.Fhir.Model.Appointment.ParticipantComponent { Actor = new Hl7.Fhir.Model.ResourceReference { Reference = $"#{patient.Id}" } } } }; if (!string.IsNullOrWhiteSpace(patientSymptoms.MedicationMention)) { appointment.ReasonCode.Add(new Hl7.Fhir.Model.CodeableConcept { Text = patientSymptoms.MedicationMention, Coding = new List <Hl7.Fhir.Model.Coding> { new Hl7.Fhir.Model.Coding { Code = "MedicationMention", Display = patientSymptoms.MedicationMention } } }); } if (!string.IsNullOrWhiteSpace(patientSymptoms.SignSymptomMention)) { appointment.ReasonCode.Add(new Hl7.Fhir.Model.CodeableConcept { Text = patientSymptoms.SignSymptomMention, Coding = new List <Hl7.Fhir.Model.Coding> { new Hl7.Fhir.Model.Coding { Code = "SignSymptomMention", Display = patientSymptoms.SignSymptomMention } } }); } if (!string.IsNullOrWhiteSpace(patientSymptoms.DiseaseDisorderMention)) { appointment.ReasonCode.Add(new Hl7.Fhir.Model.CodeableConcept { Text = patientSymptoms.DiseaseDisorderMention, Coding = new List <Hl7.Fhir.Model.Coding> { new Hl7.Fhir.Model.Coding { Code = "DiseaseDisorderMention", Display = patientSymptoms.DiseaseDisorderMention } } }); } if (!string.IsNullOrWhiteSpace(patientSymptoms.AnatomicalSiteMention)) { appointment.ReasonCode.Add(new Hl7.Fhir.Model.CodeableConcept { Text = patientSymptoms.AnatomicalSiteMention, Coding = new List <Hl7.Fhir.Model.Coding> { new Hl7.Fhir.Model.Coding { Code = "AnatomicalSiteMention", Display = patientSymptoms.AnatomicalSiteMention } } }); } client.Create <Hl7.Fhir.Model.Appointment>(appointment); }
public async Task <IActionResult> Post([FromBody] PatientSymptomInfoDto patientSymptomInfo) { if (string.IsNullOrWhiteSpace(patientSymptomInfo.Key) || patientSymptomInfo.Key != "s2Rw0......") { return(new ContentResult() { Content = "<html><body><h1>Not all required fields are provided.</h1></body></html>", ContentType = "text/html", StatusCode = (int)HttpStatusCode.Unauthorized, }); } var container = GetCloudBlobContainer("bot-metadata"); BlobContinuationToken continuationToken = null; int?maxResultsPerQuery = null; var response = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, maxResultsPerQuery, continuationToken, null, null); continuationToken = response.ContinuationToken; foreach (var item in response.Results.OfType <CloudBlockBlob>()) { using (MemoryStream mem = new MemoryStream()) { await item.DownloadToStreamAsync(mem); mem.Position = 0; StreamReader reader = new StreamReader(mem); var conversationReference = JsonConvert.DeserializeObject <ConversationReference>(reader.ReadToEnd()); await((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, async(turnContext, token) => { MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl); var connectorClient = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), _credentialProvider.AppId, _credentialProvider.Password); var parameters = new ConversationParameters { Bot = turnContext.Activity.Recipient, Members = new List <ChannelAccount> { turnContext.Activity.From }, ChannelData = JObject.FromObject( new TeamsChannelData { Tenant = new TenantInfo { Id = "YOUR TENANT ID", }, Channel = new ChannelInfo { Id = "YOUR CHANNEL [email protected]" } }, JsonSerializer.Create(new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, })), }; var conversationResource = await connectorClient.Conversations.CreateConversationAsync(parameters); var message = Activity.CreateMessageActivity(); var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0)) { Body = new List <AdaptiveElement>() { new AdaptiveTextBlock($"Notification for {patientSymptomInfo.Doctor}") { Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium }, new AdaptiveColumnSet() { Columns = new List <AdaptiveColumn> { new AdaptiveColumn() { Width = "auto", Items = new List <AdaptiveElement>() { new AdaptiveImage("https://cdn1.iconfinder.com/data/icons/medical-health-care-thick-colored-version/33/male_patient-512.png") { Size = AdaptiveImageSize.Small, Style = AdaptiveImageStyle.Person } } }, new AdaptiveColumn() { Width = "stretch", Items = new List <AdaptiveElement>() { new AdaptiveTextBlock(patientSymptomInfo.PatientName) { Weight = AdaptiveTextWeight.Bolder, Wrap = true }, new AdaptiveTextBlock(patientSymptomInfo.PatientDob) { Wrap = true, IsSubtle = true, Spacing = AdaptiveSpacing.None } } } }, }, new AdaptiveTextBlock(patientSymptomInfo.Symptoms) { Wrap = true, IsSubtle = true }, new AdaptiveFactSet() { Facts = new List <AdaptiveFact>() { new AdaptiveFact("Symptom", patientSymptomInfo.SignSymptomMention), new AdaptiveFact("Medication", patientSymptomInfo.MedicationMention), new AdaptiveFact("Disease", patientSymptomInfo.DiseaseDisorderMention), new AdaptiveFact("Anatomical", patientSymptomInfo.AnatomicalSiteMention), } } }, Actions = new List <AdaptiveAction>() { new AdaptiveSubmitAction() { Title = "Send to EMR", Id = "sendToEmr", DataJson = JsonConvert.SerializeObject(patientSymptomInfo) } } }; await connectorClient.Conversations.SendToConversationAsync(conversationResource.Id, (Activity)MessageFactory.Attachment(new Attachment { ContentType = AdaptiveCard.ContentType, Content = JObject.FromObject(adaptiveCard), })); }, default(CancellationToken)); } } // Let the caller know proactive messages have been sent return(new ContentResult() { Content = "<html><body><h1>Proactive messages have been sent.</h1></body></html>", ContentType = "text/html", StatusCode = (int)HttpStatusCode.OK, }); }