Example #1
0
        ///<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 ImportLoinc(string tempFileName, ProgressArgs progress, ref bool quit)
        {
            if (tempFileName == null)
            {
                return;
            }
            HashSet <string> codeHash = new HashSet <string>(Loincs.GetAllCodes());

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayLoinc;
            Loinc    loinc = new Loinc();

            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);
                }
                arrayLoinc = lines[i].Split('\t');
                if (codeHash.Contains(arrayLoinc[0]))                 //code already exists
                {
                    continue;
                }
                loinc.LoincCode               = arrayLoinc[0];
                loinc.Component               = arrayLoinc[1];
                loinc.PropertyObserved        = arrayLoinc[2];
                loinc.TimeAspct               = arrayLoinc[3];
                loinc.SystemMeasured          = arrayLoinc[4];
                loinc.ScaleType               = arrayLoinc[5];
                loinc.MethodType              = arrayLoinc[6];
                loinc.StatusOfCode            = arrayLoinc[7];
                loinc.NameShort               = arrayLoinc[8];
                loinc.ClassType               = arrayLoinc[9];
                loinc.UnitsRequired           = arrayLoinc[10] == "Y";
                loinc.OrderObs                = arrayLoinc[11];
                loinc.HL7FieldSubfieldID      = arrayLoinc[12];
                loinc.ExternalCopyrightNotice = arrayLoinc[13];
                loinc.NameLongCommon          = arrayLoinc[14];
                loinc.UnitsUCUM               = arrayLoinc[15];
                loinc.RankCommonTests         = PIn.Int(arrayLoinc[16]);
                loinc.RankCommonOrders        = PIn.Int(arrayLoinc[17]);
                Loincs.Insert(loinc);
            }
        }
Example #2
0
        ///<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 ImportLoinc(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated,
                                       bool updateExisting)
        {
            if (tempFileName == null)
            {
                return;
            }
            Dictionary <string, Loinc> dictLoincs = Loincs.GetAll().ToDictionary(x => x.LoincCode, x => x);

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayLoinc;
            Loinc    oldLoinc = new Loinc();
            Loinc    newLoinc = new Loinc();

            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);
                }
                arrayLoinc                       = lines[i].Split('\t');
                newLoinc.LoincCode               = arrayLoinc[0];
                newLoinc.Component               = arrayLoinc[1];
                newLoinc.PropertyObserved        = arrayLoinc[2];
                newLoinc.TimeAspct               = arrayLoinc[3];
                newLoinc.SystemMeasured          = arrayLoinc[4];
                newLoinc.ScaleType               = arrayLoinc[5];
                newLoinc.MethodType              = arrayLoinc[6];
                newLoinc.StatusOfCode            = arrayLoinc[7];
                newLoinc.NameShort               = arrayLoinc[8];
                newLoinc.ClassType               = arrayLoinc[9];
                newLoinc.UnitsRequired           = arrayLoinc[10] == "Y";
                newLoinc.OrderObs                = arrayLoinc[11];
                newLoinc.HL7FieldSubfieldID      = arrayLoinc[12];
                newLoinc.ExternalCopyrightNotice = arrayLoinc[13];
                newLoinc.NameLongCommon          = arrayLoinc[14];
                newLoinc.UnitsUCUM               = arrayLoinc[15];
                newLoinc.RankCommonTests         = PIn.Int(arrayLoinc[16]);
                newLoinc.RankCommonOrders        = PIn.Int(arrayLoinc[17]);
                if (dictLoincs.ContainsKey(arrayLoinc[0]))                 //code already exists; arrayLoinc[0]==Loinc Code
                {
                    oldLoinc = dictLoincs[arrayLoinc[0]];
                    if (updateExisting &&
                        (oldLoinc.LoincCode != arrayLoinc[0] ||
                         oldLoinc.Component != arrayLoinc[1] ||
                         oldLoinc.PropertyObserved != arrayLoinc[2] ||
                         oldLoinc.TimeAspct != arrayLoinc[3] ||
                         oldLoinc.SystemMeasured != arrayLoinc[4] ||
                         oldLoinc.ScaleType != arrayLoinc[5] ||
                         oldLoinc.MethodType != arrayLoinc[6] ||
                         oldLoinc.StatusOfCode != arrayLoinc[7] ||
                         oldLoinc.NameShort != arrayLoinc[8] ||
                         oldLoinc.ClassType != arrayLoinc[9] ||
                         oldLoinc.UnitsRequired != (arrayLoinc[10] == "Y") ||
                         oldLoinc.OrderObs != arrayLoinc[11] ||
                         oldLoinc.HL7FieldSubfieldID != arrayLoinc[12] ||
                         oldLoinc.ExternalCopyrightNotice != arrayLoinc[13] ||
                         oldLoinc.NameLongCommon != arrayLoinc[14] ||
                         oldLoinc.UnitsUCUM != arrayLoinc[15] ||
                         oldLoinc.RankCommonTests != PIn.Int(arrayLoinc[16]) ||
                         oldLoinc.RankCommonOrders != PIn.Int(arrayLoinc[17])))
                    {
                        Loincs.Update(newLoinc);
                        numCodesUpdated++;
                    }
                    continue;
                }
                Loincs.Insert(newLoinc);
                numCodesImported++;
            }
        }