public static void ReadCsvIntoDatabase(IHostingEnvironment appEnvironment, ICD10DbContext dbContext) { if (dbContext.Codes.Any()) { return; } var rootDirectory = appEnvironment.ContentRootPath; var csvFile = File.OpenRead(Path.Join(rootDirectory, "Data/CSV/codes.csv")); TextReader textReader = new StreamReader(csvFile); var csv = new CsvReader(textReader); ConfigureCSVReader(csv); try { var records = csv.GetRecords <dynamic>().ToList(); foreach (var r in records) { if ((records.IndexOf(r)) == 0) { continue; } var record = new Dictionary <string, object>(r); var code = new ICD10Code(); string categoryCode = (string)record["Category Code"]; var dbCategory = dbContext.Categories.FirstOrDefault(c => c.Code.Equals(categoryCode)); code.Category = dbCategory; code.DiagnosisCode = (string)record["Diagnosis Code"]; code.AbbreviatedDescription = (string)record["Abbreviated Description"]; code.FullDescription = (string)record["Full Description"]; dbContext.Codes.Add(code); } dbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void ReadCsvIntoDatabase(IHostingEnvironment appEnvironment, ICD10DbContext dbContext) { if (dbContext.ICD9Codes.Any()) { return; } var rootDirectory = appEnvironment.ContentRootPath; var csvFile = File.OpenRead(Path.Join(rootDirectory, "Data/CSV/icd9dx2015.csv")); TextReader textReader = new StreamReader(csvFile); var csv = new CsvReader(textReader); ConfigureCSVReader(csv); try { var records = csv.GetRecords <dynamic>().ToList(); foreach (var r in records) { if ((records.IndexOf(r)) == 0) { continue; } var record = new Dictionary <string, object>(r); var code = new ICD9Code(); string dxCode = record["dgns_cd"] as string; code.Code = dxCode; code.LongDescription = record["longdesc"] as string; code.ShortDescription = record["shortdesc"] as string; code.Version = Int32.Parse(record["version"] as string); dbContext.ICD9Codes.Add(code); } dbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void ReadCsvIntoDatabase(IHostingEnvironment appEnvironment, ICD10DbContext dbContext) { if (dbContext.ICD9TOICD10Mappings.Any()) { return; } var rootDirectory = appEnvironment.ContentRootPath; var csvFile = File.OpenRead(Path.Join(rootDirectory, "Data/CSV/icd9toicd10cmgem.csv")); TextReader textReader = new StreamReader(csvFile); var csv = new CsvReader(textReader); ConfigureCSVReader(csv); try { var records = csv.GetRecords <dynamic>().ToList(); foreach (var r in records) { if ((records.IndexOf(r)) == 0) { continue; } var record = new Dictionary <string, object>(r); var code = new ICD9TOICD10Mapping(); string dxCode = record["icd9cm"] as string; code.ICD9Code = dxCode; code.ICD10Code = record["icd10cm"] as string; code.Flags = record["flags"] as string; dbContext.ICD9TOICD10Mappings.Add(code); } dbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void ReadCsvIntoDatabase(IHostingEnvironment appEnvironment, ICD10DbContext dbContext) { if (dbContext.Categories.Any()) { return; } var rootDirectory = appEnvironment.ContentRootPath; var csvFile = File.OpenRead(Path.Join(rootDirectory, "Data/CSV/categories.csv")); TextReader textReader = new StreamReader(csvFile); var csv = new CsvReader(textReader); ConfigureCSVReader(csv); try { var records = csv.GetRecords <dynamic>().ToList(); foreach (var r in records) { if ((records.IndexOf(r)) == 0) { continue; } var record = new Dictionary <string, object>(r); var category = new ICD10Category(); category.Code = (string)record["Field1"]; category.Title = (string)record["Field2"]; dbContext.Categories.Add(category); } dbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run(ICD10DbContext dbContext) { if (dbContext.ICD9CodeWithMappings.Any()) { return; } var icd9Codes = dbContext.ICD9Codes.ToList(); foreach (var mapping in dbContext.ICD10TOICD9Mappings) { var icd9code = icd9Codes.Where(c => c.Code == mapping.ICD9Code) .FirstOrDefault(); if (icd9code == null) { continue; } var codeWithMapping = new ICD9CodeWithMapping(); codeWithMapping.ICD10TOICD9Mapping = mapping; codeWithMapping.ICD9Code = icd9code; dbContext.ICD9CodeWithMappings.Add(codeWithMapping); } dbContext.SaveChanges(); }