public async static Task <NDCs> GetAllNDCRecords() { var ndcs = new NDCs { data = new NDCs.NdcDatum[0], metadata = new Metadata() }; NDCs result = null; do { Console.WriteLine($"Loading records..."); result = await GetNDCRecords(page : (ndcs.metadata.next_page == null || ndcs.metadata.next_page == "null" || ndcs.metadata.next_page == "0")? 1 : Convert.ToInt32(ndcs.metadata.next_page)); ndcs.metadata = result.metadata; ndcs.data = ndcs.data.Concat(result.data).ToArray(); Console.WriteLine($"Loaded {ndcs.data.Length} records."); await Task.Run(() => { foreach (var item in result.data) { Console.WriteLine($"NDC: {item.ndc}"); } }); } while (result != null && result.metadata.total_elements > ndcs.data.Length); return(ndcs); }
public void MapResultsToViewModel(List <DrugSearchResult> results, string drugId) { this.SearchResults = results; if (results.Count > 0) { var uniqueDoages = results.GroupBy(d => d.dosage_form).Select(d => d.First()).ToList(); var uniqueStrengths = results.GroupBy(d => d.strength).Select(d => d.First()).ToList(); var resultGPIs = new List <GPIDto>(); results.ForEach(r => { var hasNDC = this.NDCs.FirstOrDefault(n => n.NDC == r.ndc_upc_hri); if (hasNDC == null) { this.NDCs.Add( new NDCDto { DisplayName = string.Format("{0} {1} {2}{3}", r.drug_name, r.dosage_form, r.strength, r.strength_unit_of_measure), MaintenanceCode = GetMaintenanceCode(r.maintenance_drug_code), MONY = r.multi_source_code, NDC = r.ndc_upc_hri }); } var gpiExists = resultGPIs.FirstOrDefault(n => n.GPI == r.generic_product_identifier); if (gpiExists == null) { resultGPIs.Add(new GPIDto { DisplayName = r.DisplayName, GPI = r.generic_product_identifier }); } var exists = this.DosageOptions.FirstOrDefault(n => n == r.dosage_form); if (string.IsNullOrEmpty(exists)) { this.DosageOptions.Add(r.dosage_form); } exists = this.Strengths.FirstOrDefault(n => n == r.strength + r.strength_unit_of_measure); if (string.IsNullOrEmpty(exists)) { if (!string.IsNullOrEmpty(r.strength)) { this.Strengths.Add(r.strength + r.strength_unit_of_measure); } } }); resultGPIs = resultGPIs.OrderBy(c => c.GPI).ToList(); int length = drugId.Length; var partialGPIs = new List <string>(); // make sure we have a proper partial GPI if (length % 2 == 0 && length < 13) { for (int i = drugId.Length; i < 13; i = i + 2) { partialGPIs.AddRange(GeneratePartialGPIs(results, i)); } } var sctx = new ScriptCycleContext(); var repo = new DrugRepo(sctx); var namedPartials = repo.GetPartialGPINames(partialGPIs); this.GPIs.AddRange(namedPartials); this.GPIs.AddRange(resultGPIs); var selectedGPI = this.GPIs.SingleOrDefault(g => g.GPI == drugId); if (selectedGPI != null) { this.DisplayAs = selectedGPI.DisplayName; this.GPIs.Remove(selectedGPI); } else { this.DisplayAs = results[0].DisplayName; } this.Strengths.Sort(); this.DosageOptions.Sort(); this.NDCs = NDCs.OrderBy(c => c.DisplayName).ThenBy(c => c.NDC).ToList(); } else { this.DisplayAs = string.Empty; this.DosageOptions = new List <string>(); this.Strengths = new List <string>(); this.NDCs = new List <NDCDto>(); this.GPIs = new List <GPIDto>(); } }