Esempio n. 1
0
        ///<summary>Called after file is downloaded.  Throws exceptions.</summary>
        //public static void ImportAdministrativeSex(string tempFileName) ... not necessary.

        ///<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 ImportCdcrec(string tempFileName, ProgressArgs progress, ref bool quit)
        {
            if (tempFileName == null)
            {
                return;
            }
            HashSet <string> codeHash = new HashSet <string>(Cdcrecs.GetAllCodes());

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayCDCREC;
            Cdcrec   cdcrec = new Cdcrec();

            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);
                }
                arrayCDCREC = lines[i].Split('\t');
                if (codeHash.Contains(arrayCDCREC[0]))                 //code already existed
                {
                    continue;
                }
                cdcrec.CdcrecCode       = arrayCDCREC[0];
                cdcrec.HeirarchicalCode = arrayCDCREC[1];
                cdcrec.Description      = arrayCDCREC[2];
                Cdcrecs.Insert(cdcrec);
            }
        }
Esempio n. 2
0
        ///<summary>Inserts or Deletes neccesary PatientRace entries for the specified patient given the list of PatRaces provided.</summary>
        public static void Reconcile(long patNum, List <PatRace> listPatRaces)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), patNum, listPatRaces);
                return;
            }
            string command;

            if (listPatRaces.Count == 0)                                                 //DELETE all for the patient if listPatRaces is empty.
            {
                command = "DELETE FROM patientrace WHERE PatNum = " + POut.Long(patNum); //Can't use CRUD layer here because there might be multiple races for one patient.
                Db.NonQ(command);
                return;
            }
            List <PatientRace> listPatientRaces;           //Rename this variable and the listPatRaces variable so it is easier to indicate which is the "selected" list and which is the db list.

            command          = "SELECT * FROM patientrace WHERE PatNum = " + POut.Long(patNum);
            listPatientRaces = Crud.PatientRaceCrud.SelectMany(command);
            //delete excess rows
            for (int i = 0; i < listPatientRaces.Count; i++)
            {
                if (!listPatRaces.Contains((PatRace)listPatientRaces[i].Race))                 //if there is a PatientRace row that does not match the new list of PatRaces, delete it
                {
                    Crud.PatientRaceCrud.Delete(listPatientRaces[i].PatientRaceNum);
                }
            }
            //insert new rows
            for (int i = 0; i < listPatRaces.Count; i++)
            {
                bool insertNeeded = true;
                for (int j = 0; j < listPatientRaces.Count; j++)
                {
                    if (listPatRaces[i] == listPatientRaces[j].Race)
                    {
                        insertNeeded = false;
                    }
                }
                if (insertNeeded)
                {
                    PatientRace pr = new PatientRace();
                    pr.PatNum     = patNum;
                    pr.Race       = listPatRaces[i];
                    pr.CdcrecCode = Cdcrecs.GetByPatRace(listPatRaces[i]);
                    Crud.PatientRaceCrud.Insert(pr);
                }
                //next PatRace
            }
            //return;
        }
Esempio n. 3
0
        /////<summary>Called after file is downloaded.  Throws exceptions.</summary>
        //public static void ImportAdministrativeSex(string tempFileName) ... not necessary.

        ///<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 ImportCdcrec(string tempFileName, ProgressArgs progress, ref bool quit, ref int numCodesImported, ref int numCodesUpdated,
                                        bool updateExisting)
        {
            if (tempFileName == null)
            {
                return;
            }
            Dictionary <string, Cdcrec> dictCdcrecs = Cdcrecs.GetAll().ToDictionary(x => x.CdcrecCode, x => x);

            string[] lines = File.ReadAllLines(tempFileName);
            string[] arrayCDCREC;
            Cdcrec   cdcrec = new Cdcrec();

            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);
                }
                arrayCDCREC = lines[i].Split('\t');
                if (dictCdcrecs.ContainsKey(arrayCDCREC[0]))                 //code already exists
                {
                    cdcrec = dictCdcrecs[arrayCDCREC[0]];
                    if (updateExisting &&
                        (cdcrec.HeirarchicalCode != arrayCDCREC[1] ||
                         cdcrec.Description != arrayCDCREC[2]))
                    {
                        cdcrec.HeirarchicalCode = arrayCDCREC[1];
                        cdcrec.Description      = arrayCDCREC[2];
                        Cdcrecs.Update(cdcrec);
                        numCodesUpdated++;
                    }
                    continue;
                }
                cdcrec.CdcrecCode       = arrayCDCREC[0];
                cdcrec.HeirarchicalCode = arrayCDCREC[1];
                cdcrec.Description      = arrayCDCREC[2];
                Cdcrecs.Insert(cdcrec);
                numCodesImported++;
            }
        }
Esempio n. 4
0
        /// <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.
        }
Esempio n. 5
0
        /// <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.
        }