public async Task <string> SearchRxcui(OpenFdaSearch_Model model) { HttpClient client = new HttpClient(); string url = c3piUrlBuilder(model); HttpResponseMessage response = await client.GetAsync(url); return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
public async Task <string> SearchOpenFda(OpenFdaSearch_Model model) { HttpClient client = new HttpClient(); //string url = c3piUrlBuilder(model); string url = openfdaUrlBuilder(model); HttpResponseMessage response = await client.GetAsync(url); if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return(null); } return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
private string c3piUrlBuilder(OpenFdaSearch_Model search) { string baseUrl = "https://rximage.nlm.nih.gov/api/rximage/1/rxnav?"; string builtUrl = baseUrl; if (!string.IsNullOrEmpty(search.Name)) { builtUrl += $"name={search.Name}&"; } if (!string.IsNullOrEmpty(search.Ndc)) { builtUrl += $"ndc={search.Ndc}"; } return(builtUrl); }
public async Task <IActionResult> SearchOpenFda([FromBody] OpenFdaSearch_Model model) { try { var result = await _bll.SearchOpenFda(model).ConfigureAwait(false); if (result == null) { return(NotFound(new { errors = $"No medicines found with those search terms" })); } return(Ok(result)); } catch (Exception ex) { return(StatusCode(500, new { errors = ex.Message })); } }
//Deprecated - but here as reference for what was before - no longer using openfda private string openfdaUrlBuilder(OpenFdaSearch_Model search) { string baseUrl = @"https://api.fda.gov/drug/label.json?search="; string builtUrl = baseUrl; if (!string.IsNullOrEmpty(search.Name)) { builtUrl += $"openfda.brand_name:\"{search.Name}\"+"; } //if (!string.IsNullOrEmpty(search.GenericName)) // builtUrl += $"openfda.generic_name:{search.GenericName}+"; if (!string.IsNullOrEmpty(search.Ndc)) { builtUrl += $"openfda.package_ndc:\"{search.Ndc}\"+"; } builtUrl += "&limit=30"; return(builtUrl); }