///<summary>Updates an existing CPT code description if versionID is newer than current versionIDs. If versionID is different than existing versionIDs, it will be added to the comma delimited list.</summary> public static void UpdateDescription(string cptCode, string description, string versionID) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), cptCode, description, versionID); return; } Cpt cpt = Cpts.GetByCode(POut.String(cptCode)); string[] versionIDs = cpt.VersionIDs.Split(','); bool versionIDFound = false; string maxVersionID = ""; for (int i = 0; i < versionIDs.Length; i++) { if (string.Compare(versionIDs[i], maxVersionID) > 0) //Find max versionID in list { maxVersionID = versionIDs[i]; } if (versionIDs[i] == versionID) //Find if versionID is already in list { versionIDFound = true; } } if (!versionIDFound) //If the current version isn't already in the list { cpt.VersionIDs += ',' + versionID; //VersionID should never be blank for an existing code... should we check? } if (string.Compare(versionID, maxVersionID) >= 0) //If newest version { cpt.Description = description; } Crud.CptCrud.Update(cpt); }
/////<summary>Called after file is downloaded. Throws exceptions.</summary> //public static void ImportCDT(string tempFileName) ... not necessary. ///<summary>Called after user provides resource file. 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. ///No UpdateExisting parameter because we force users to accept new descriptions.</summary> public static void ImportCpt(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated, string versionID) { if (tempFileName == null) { return; } Dictionary <string, string> dictCodes = Cpts.GetAll().ToDictionary(x => x.CptCode, x => x.Description); Regex regx = new Regex(@"^([\d]{4}[\d\w])\s+(.+?)$"); //Regex = "At the beginning of the string, find five numbers, followed by a white space (tab or space) followed by one or more characters (but as few as possible) to the end of the line." string[] lines = File.ReadAllLines(tempFileName); string[] arrayCpt; bool isHeader = true; Cpt cpt = new Cpt(); 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); } if (isHeader) { if (!regx.IsMatch(lines[i])) //if(!lines[i].Contains("\t")) { { continue; //Copyright info is present at the head of the file. } isHeader = false; } arrayCpt = new string[2]; arrayCpt[0] = regx.Match(lines[i]).Groups[1].Value; //First five alphanumeric characters arrayCpt[1] = regx.Match(lines[i]).Groups[2].Value; //Everything after the 6th character if (dictCodes.Keys.Contains(arrayCpt[0])) //code already exists { Cpts.UpdateDescription(arrayCpt[0], arrayCpt[1], versionID); if (dictCodes[arrayCpt[0]] != arrayCpt[1]) //The description is different { numCodesUpdated++; } } else { cpt.CptCode = arrayCpt[0]; cpt.Description = arrayCpt[1]; cpt.VersionIDs = versionID; Cpts.Insert(cpt); numCodesImported++; } } }
///<summary>Called after file is downloaded. Throws exceptions.</summary> //public static void ImportCDT(string tempFileName) ... not necessary. ///<summary>Called after user provides resource file. 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 ImportCpt(string tempFileName, ProgressArgs progress, ref bool quit) { if (tempFileName == null) { return; } HashSet <string> codeHash = new HashSet <string>(Cpts.GetAllCodes()); string[] lines = File.ReadAllLines(tempFileName); string[] arrayCpt; bool isHeader = true; Cpt cpt = new Cpt(); 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); } if (isHeader) { if (!lines[i].Contains("\t")) { continue; //Copyright info is present at the head of the file. } isHeader = false; } arrayCpt = lines[i].Split('\t'); if (codeHash.Contains(arrayCpt[0])) //code already exists { continue; } cpt.CptCode = arrayCpt[0]; cpt.Description = arrayCpt[1]; Cpts.Insert(cpt); } }
/// <summary>If the CodeValue of the EhrCode exists in its respective code table (I.e. Snomed, Loinc, Cpt, etc.) this will set IsInDb=true otherwise false.</summary> private static void updateCodeExistsHelper() { //No need to check RemotingRole; no call to db. if (listt.Count == 0) { return; } //Cache lists of codes. HashSet <string> cdcrecHS = new HashSet <string>(Cdcrecs.GetAllCodes()); HashSet <string> cdtHS = new HashSet <string>(ProcedureCodes.GetAllCodes()); HashSet <string> cptHS = new HashSet <string>(Cpts.GetAllCodes()); HashSet <string> cvxHS = new HashSet <string>(Cvxs.GetAllCodes()); HashSet <string> hcpcsHS = new HashSet <string>(Hcpcses.GetAllCodes()); HashSet <string> icd10HS = new HashSet <string>(Icd10s.GetAllCodes()); HashSet <string> icd9HS = new HashSet <string>(ICD9s.GetAllCodes()); HashSet <string> loincHS = new HashSet <string>(Loincs.GetAllCodes()); HashSet <string> rxnormHS = new HashSet <string>(RxNorms.GetAllCodes()); HashSet <string> snomedHS = new HashSet <string>(Snomeds.GetAllCodes()); HashSet <string> sopHS = new HashSet <string>(Sops.GetAllCodes()); for (int i = 0; i < listt.Count; i++) { switch (listt[i].CodeSystem) { case "AdministrativeSex": //always "in DB", even though there is no DB table listt[i].IsInDb = true; break; case "CDCREC": listt[i].IsInDb = cdcrecHS.Contains(listt[i].CodeValue); break; case "CDT": listt[i].IsInDb = cdtHS.Contains(listt[i].CodeValue); break; case "CPT": listt[i].IsInDb = cptHS.Contains(listt[i].CodeValue); break; case "CVX": listt[i].IsInDb = cvxHS.Contains(listt[i].CodeValue); break; case "HCPCS": listt[i].IsInDb = hcpcsHS.Contains(listt[i].CodeValue); break; case "ICD9CM": listt[i].IsInDb = icd9HS.Contains(listt[i].CodeValue); break; case "ICD10CM": listt[i].IsInDb = icd10HS.Contains(listt[i].CodeValue); break; case "LOINC": listt[i].IsInDb = loincHS.Contains(listt[i].CodeValue); break; case "RXNORM": listt[i].IsInDb = rxnormHS.Contains(listt[i].CodeValue); break; case "SNOMEDCT": listt[i].IsInDb = snomedHS.Contains(listt[i].CodeValue); break; case "SOP": listt[i].IsInDb = sopHS.Contains(listt[i].CodeValue); break; } } //This updates the last column "ExistsInDatabse" based on weather or not the code is found in another table in the database. }
/// <summary>If the number of codes in the code tables (I.e. Snomed, Loinc, Cpt, etc.) are greater than the number we expect then this will set IsInDb=true otherwise false.</summary> private static void updateCodeExistsHelper() { //No need to check RemotingRole; no call to db. if (listt.Count == 0) { return; } //Cache lists of codes. #region Count Variables //Counts from the DB long countCdcDB = -1; long countCdtDB = -1; long countCptDB = -1; long countCvxDB = -1; long countHcpcsDB = -1; long countIcd9DB = -1; long countIcd10DB = -1; long countLoincDB = -1; long countRxNormDB = -1; long countSnomedDB = -1; long countSopDB = -1; //Counts hard-coded from the EhrCodes.Listt. Lowered slightly to give a buffer, in case we decide to remove some codes later. const long countCdcList = 5; const long countCdtList = 10; const long countCptList = 300; const long countCvxList = 5; const long countHcpcsList = 20; const long countIcd9List = 1500; const long countIcd10List = 2000; const long countLoincList = 20; const long countRxNormList = 40; const long countSnomedList = 700; const long countSopList = 100; #endregion for (int i = 0; i < listt.Count; i++) { if (listt[i].IsInDb) { continue; //The codes are already present in the database, so we don't need to check again. } switch (listt[i].CodeSystem) { case "AdministrativeSex": //always "in DB", even though there is no DB table listt[i].IsInDb = true; break; case "CDCREC": if (countCdcDB == -1) { countCdcDB = Cdcrecs.GetCodeCount(); } if (countCdcDB > countCdcList) { listt[i].IsInDb = true; } break; case "CDT": if (countCdtDB == -1) { countCdtDB = ProcedureCodes.GetCodeCount(); } if (countCdtDB > countCdtList) { listt[i].IsInDb = true; } break; case "CPT": if (countCptDB == -1) { countCptDB = Cpts.GetCodeCount(); } if (countCptDB > countCptList) { listt[i].IsInDb = true; } break; case "CVX": if (countCvxDB == -1) { countCvxDB = Cvxs.GetCodeCount(); } if (countCvxDB > countCvxList) { listt[i].IsInDb = true; } break; case "HCPCS": if (countHcpcsDB == -1) { countHcpcsDB = Hcpcses.GetCodeCount(); } if (countHcpcsDB > countHcpcsList) { listt[i].IsInDb = true; } break; case "ICD9CM": if (countIcd9DB == -1) { countIcd9DB = ICD9s.GetCodeCount(); } if (countIcd9DB > countIcd9List) { listt[i].IsInDb = true; } break; case "ICD10CM": if (countIcd10DB == -1) { countIcd10DB = Icd10s.GetCodeCount(); } if (countIcd10DB > countIcd10List) { listt[i].IsInDb = true; } break; case "LOINC": if (countLoincDB == -1) { countLoincDB = Loincs.GetCodeCount(); } if (countLoincDB > countLoincList) { listt[i].IsInDb = true; } break; case "RXNORM": if (countRxNormDB == -1) { countRxNormDB = RxNorms.GetCodeCount(); } if (countRxNormDB > countRxNormList) { listt[i].IsInDb = true; } break; case "SNOMEDCT": if (countSnomedDB == -1) { countSnomedDB = Snomeds.GetCodeCount(); } if (countSnomedDB > countSnomedList) { listt[i].IsInDb = true; } break; case "SOP": if (countSopDB == -1) { countSopDB = Sops.GetCodeCount(); } if (countSopDB > countSopList) { listt[i].IsInDb = true; } break; } } //This updates the last column "ExistsInDatabse" based on weather or not the code is found in another table in the database. }