///<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 ImportRxNorm(string tempFileName, ProgressArgs progress, ref bool quit) { if (tempFileName == null) { return; } HashSet <string> codeHash = new HashSet <string>(RxNorms.GetAllCodes()); string[] lines = File.ReadAllLines(tempFileName); string[] arrayRxNorm; RxNorm rxNorm = new RxNorm(); 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); } arrayRxNorm = lines[i].Split('\t'); if (codeHash.Contains(arrayRxNorm[0])) //code already exists { continue; } rxNorm.RxCui = arrayRxNorm[0]; rxNorm.MmslCode = arrayRxNorm[1]; rxNorm.Description = arrayRxNorm[2]; RxNorms.Insert(rxNorm); } }
///<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 ImportRxNorm(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated, bool updateExisting) { if (tempFileName == null) { return; } //RxNorms can have two codes for each RxCui. One RxNorm will have a value in the MmslCode and a blank description and the other will have a //value in the Description and a blank MmslCode. List <RxNorm> listRxNorms = RxNorms.GetAll(); Dictionary <string, RxNorm> dictRxNormsMmslCodes = listRxNorms.Where(x => x.MmslCode != "").ToDictionary(x => x.RxCui, x => x); Dictionary <string, RxNorm> dictRxNormsDefinitions = listRxNorms.Where(x => x.Description != "").ToDictionary(x => x.RxCui, x => x); string[] lines = File.ReadAllLines(tempFileName); string[] arrayRxNorm; RxNorm rxNorm = new RxNorm(); for (int i = 0; i < lines.Length; i++) //Each loop should read exactly one line of code. Each line will NOT be a unique code. { if (quit) { return; } if (i % 100 == 0) { progress(i + 1, lines.Length); } arrayRxNorm = lines[i].Split('\t'); if (dictRxNormsMmslCodes.ContainsKey(arrayRxNorm[0])) //code with an MmslCode already exists { rxNorm = dictRxNormsMmslCodes[arrayRxNorm[0]]; if (updateExisting) { if (arrayRxNorm[1] != "" && arrayRxNorm[1] != rxNorm.MmslCode) { rxNorm.MmslCode = arrayRxNorm[1]; rxNorm.Description = ""; //Should be blank for all MMSL code entries. See below for non-MMSL entries with descriptions. RxNorms.Update(rxNorm); numCodesUpdated++; } } continue; } if (dictRxNormsDefinitions.ContainsKey(arrayRxNorm[0])) //code with a Description already exists { rxNorm = dictRxNormsDefinitions[arrayRxNorm[0]]; if (updateExisting) { string newDescript = arrayRxNorm[2]; //if(newDescript.Length>255) { // newDescript=newDescript.Substring(0,255);//Description column is only varchar(255) so some descriptions will get truncated. //} //if(arrayRxNorm[2]!="" && newDescript!=rxNorm.Description) { if (arrayRxNorm[2] != "" && arrayRxNorm[2] != rxNorm.Description) { rxNorm.MmslCode = ""; //should be blank for all entries that have a description. rxNorm.Description = arrayRxNorm[2]; RxNorms.Update(rxNorm); numCodesUpdated++; } } continue; } rxNorm.RxCui = arrayRxNorm[0]; rxNorm.MmslCode = arrayRxNorm[1]; rxNorm.Description = arrayRxNorm[2]; RxNorms.Insert(rxNorm); numCodesImported++; } }