private DrugSuggestionInputModel PrepareDrugSuggestionInput(MedicalEntityResponse entityResponse, PatientDto patientDto) { var modelResult = new DrugSuggestionInputModel(); foreach (var item in entityResponse.MedicalConditions) { if (item.Text.Equals("fever", StringComparison.OrdinalIgnoreCase)) { modelResult.Fever = true; } if (item.Text.Equals("vomiting", StringComparison.OrdinalIgnoreCase) || item.Text.Equals("vomite", StringComparison.OrdinalIgnoreCase)) { modelResult.Vomiting = true; } if (item.Text.Equals("headache", StringComparison.OrdinalIgnoreCase) || item.Text.Equals("head ache", StringComparison.OrdinalIgnoreCase)) { modelResult.Headache = true; } if (item.Text.Equals("diarrhea", StringComparison.OrdinalIgnoreCase)) { modelResult.Diarrhea = true; } } modelResult.Age = patientDto?.Age; modelResult.Weight = patientDto?.Weight; return(modelResult); }
public async Task <List <string> > GetMedicineSuggestionByPatientSymptoms(string externalPatientId) { var modelResult = new DrugSuggestionInputModel(); try { //get patient demographic information var patientInfo = await _patientService.Get(externalPatientId); var patientProblems = await _problemService.GetAll(externalPatientId, 1); if (patientProblems.Count > 0) { foreach (var problem in patientProblems.Results) { if (problem.Name.Equals("fever", StringComparison.OrdinalIgnoreCase)) { modelResult.Fever = true; } if (problem.Name.Equals("vomiting", StringComparison.OrdinalIgnoreCase) || problem.Name.Equals("vomite", StringComparison.OrdinalIgnoreCase)) { modelResult.Vomiting = true; } if (problem.Name.Equals("headache", StringComparison.OrdinalIgnoreCase) || problem.Name.Equals("head ache", StringComparison.OrdinalIgnoreCase)) { modelResult.Headache = true; } if (problem.Name.Equals("diarrhea", StringComparison.OrdinalIgnoreCase)) { modelResult.Diarrhea = true; } } } modelResult.Age = patientInfo?.Age; modelResult.Weight = patientInfo?.Weight; if (_rootConfiguration.AWSAIServiceEnabled) { var response = await InvokeAIServiceAsync(modelResult); if (response.IsSuccess != true) { return(null); } //convert to medicine list var(medicineList1, rawList1) = GetMedicineList(response.RawResult); return(rawList1); } else { var tempdata = await LoadSampleResponseFromFile(); var(medicineList, rawList) = GetMedicineList(tempdata); return(rawList); } } catch (Exception ex) { throw; } }
public async Task <MLServiceResponse> InvokeAIServiceAsync(DrugSuggestionInputModel inputModel) { MLServiceResponse mlResponse = new MLServiceResponse(); using (var client = new HttpClient()) { var scoreRequest = new { Inputs = new Dictionary <string, List <Dictionary <string, string> > >() { { "input1", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "Age", inputModel.Age?.ToString() }, { "Weight", inputModel.Weight?.ToString() }, { "Pain", inputModel.Pain == true ? "1":"0" }, { "Fever", inputModel.Fever == true ? "1":"0" }, { "Vomiting", inputModel.Vomiting == true ? "1":"0" }, { "Diarrhea", inputModel.Diarrhea == true ? "1":"0" }, { "Headache", inputModel.Headache == true ? "1":"0" }, } } }, }, GlobalParameters = new Dictionary <string, string>() { } }; const string apiKey = "IRKObndmpuYuwSHXmtS0YZZhygs/cWuF7v5cgvebWzf2dTtBx4ezcm7D3xtps8j5zFjlmfQ8ovcX+yTMLYz08g=="; // Replace this with the API key for the web service client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/workspaces/96f334343d5348109dd6b13b5f3c6743/services/ff04126f8bd04e21a4c81c0cc2e2141e/execute?api-version=2.0&format=swagger"); // WARNING: The 'await' statement below can result in a deadlock // if you are calling this code from the UI thread of an ASP.Net application. // One way to address this would be to call ConfigureAwait(false) // so that the execution does not attempt to resume on the original context. // For instance, replace code such as: // result = await DoSomeTask() // with the following: // result = await DoSomeTask().ConfigureAwait(false) HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); // mlResponse = JsonConvert.DeserializeObject<MLServiceResponse>(result); mlResponse.RawResult = result; mlResponse.IsSuccess = true; return(mlResponse); } else { Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode)); // Print the headers - they include the requert ID and the timestamp, // which are useful for debugging the failure Console.WriteLine(response.Headers.ToString()); string responseContent = await response.Content.ReadAsStringAsync(); mlResponse.Error("Error occurred while calling ML Service on Cloud", responseContent); return(mlResponse); } } }