///<summary>Called after file is downloaded. Throws exceptions. It is assumed that this is called from a worker thread. Progress delegate will be called every 100th iteration to inform thread of current progress. Quit flag can be set at any time in order to quit importing prematurely.</summary> public static void ImportIcd9(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated, bool updateExisting) { if (tempFileName == null) { return; } //Customers may have an old codeset that has a truncated uppercase description, if so we want to update with new descriptions. bool IsOldDescriptions = ICD9s.IsOldDescriptions(); Dictionary <string, ICD9> dictCodes = ICD9s.GetAll().ToDictionary(x => x.ICD9Code, x => x); string[] lines = File.ReadAllLines(tempFileName); string[] arrayICD9; ICD9 icd9 = new ICD9(); for (int i = 0; i < lines.Length; i++) //each loop should read exactly one line of code. and each line of code should be a unique code { if (quit) { return; } if (i % 100 == 0) { progress(i + 1, lines.Length); } arrayICD9 = lines[i].Split('\t'); if (dictCodes.ContainsKey(arrayICD9[0])) //code already exists { icd9 = dictCodes[arrayICD9[0]]; if ((IsOldDescriptions || updateExisting) && icd9.Description != arrayICD9[1]) //The new description does not match the description in the database. { icd9.Description = arrayICD9[1]; ICD9s.Update(icd9); numCodesUpdated++; } continue; } icd9.ICD9Code = arrayICD9[0]; icd9.Description = arrayICD9[1]; ICD9s.Insert(icd9); numCodesImported++; } }
///<summary>Called after file is downloaded. Throws exceptions. It is assumed that this is called from a worker thread. Progress delegate will be called every 100th iteration to inform thread of current progress. Quit flag can be set at any time in order to quit importing prematurely.</summary> public static void ImportIcd9(string tempFileName, ProgressArgs progress, ref bool quit) { if (tempFileName == null) { return; } //Customers may have an old codeset that has a truncated uppercase description, if so we want to update with new descriptions. bool IsOldDescriptions = ICD9s.IsOldDescriptions(); HashSet <string> codeHash = new HashSet <string>(ICD9s.GetAllCodes()); string[] lines = File.ReadAllLines(tempFileName); string[] arrayICD9; ICD9 icd9 = new ICD9(); for (int i = 0; i < lines.Length; i++) //each loop should read exactly one line of code. and each line of code should be a unique code { if (quit) { return; } if (i % 100 == 0) { progress(i + 1, lines.Length); } arrayICD9 = lines[i].Split('\t'); if (codeHash.Contains(arrayICD9[0])) //code already exists { if (!IsOldDescriptions) { continue; //code exists and has updated description } string command = "UPDATE icd9 SET description='" + POut.String(arrayICD9[1]) + "' WHERE ICD9Code='" + POut.String(arrayICD9[0]) + "'"; Db.NonQ(command); continue; //we have updated the description of an existing code. } icd9.ICD9Code = arrayICD9[0]; icd9.Description = arrayICD9[1]; ICD9s.Insert(icd9); } }