Exemplo n.º 1
0
        /////<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++;
                }
            }
        }
Exemplo n.º 2
0
        ///<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);
            }
        }