Exemplo n.º 1
0
        ///<summary>Gets most of the data necessary to fill the static text fields.</summary>
        public static StaticTextData GetStaticTextData(Patient pat, Family fam, List <long> listProcCodeNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <StaticTextData>(MethodBase.GetCurrentMethod(), pat, fam, listProcCodeNums));
            }
            StaticTextData data = new StaticTextData();

            data.PatNote               = PatientNotes.Refresh(pat.PatNum, pat.Guarantor);
            data.ListRefAttaches       = RefAttaches.Refresh(pat.PatNum);
            data.ListSubs              = InsSubs.RefreshForFam(fam);
            data.ListPlans             = InsPlans.RefreshForSubList(data.ListSubs);
            data.ListPatPlans          = PatPlans.Refresh(pat.PatNum);
            data.ListBenefits          = Benefits.Refresh(data.ListPatPlans, data.ListSubs);
            data.HistList              = ClaimProcs.GetHistList(pat.PatNum, data.ListBenefits, data.ListPatPlans, data.ListPlans, DateTime.Today, data.ListSubs);
            data.ListTreatPlans        = TreatPlans.Refresh(pat.PatNum);
            data.ListRecallsForFam     = Recalls.GetList(fam.ListPats.Select(x => x.PatNum).ToList());
            data.ListAppts             = Appointments.GetListForPat(pat.PatNum);
            data.ListFutureApptsForFam = Appointments.GetFutureSchedApts(fam.ListPats.Select(x => x.PatNum).ToList());
            data.ListDiseases          = Diseases.Refresh(pat.PatNum, true);
            data.ListAllergies         = Allergies.GetAll(pat.PatNum, false);
            data.ListMedicationPats    = MedicationPats.Refresh(pat.PatNum, false);
            data.ListFamPopups         = Popups.GetForFamily(pat);
            data.ListProceduresSome    = Procedures.RefreshForProcCodeNums(pat.PatNum, listProcCodeNums);
            return(data);
        }
Exemplo n.º 2
0
 public static long InsertOrUpdateErxMedication(RxPat rxOld, RxPat rx, long rxCui, string strDrugName, string strGenericName, bool isProv, bool canInsertRx = true)
 {
     if (rxOld == null)
     {
         if (canInsertRx)
         {
             rx.IsNew    = true;               //Might not be necessary, but does not hurt.
             rx.IsErxOld = false;
             SecurityLogs.MakeLogEntry(Permissions.RxCreate, rx.PatNum, "eRx automatically created: " + rx.Drug);
             RxPats.Insert(rx);
         }
     }
     else              //The prescription was already in our database. Update it.
     {
         rx.RxNum = rxOld.RxNum;
         //Preserve the pharmacy on the existing prescription, in case the user set the value manually.
         //We do not pull pharmacy back from eRx yet.
         rx.PharmacyNum = rxOld.PharmacyNum;
         if (rxOld.IsErxOld)
         {
             rx.IsErxOld   = true;
             rx.SendStatus = RxSendStatus.SentElect;                  //To maintain backward compatibility.
         }
         RxPats.Update(rx);
     }
     //If rxCui==0, then third party eRx option (DoseSpot, NewCrop, etc) did not provide an RxCui.
     //Attempt to locate an RxCui using the other provided drug information.  An RxCui is not required for our program.
     //Meds missing an RxCui are not exported in CCD messages.
     if (rxCui == 0 && strDrugName != "")
     {
         List <RxNorm> listRxNorms = RxNorms.GetListByCodeOrDesc(strDrugName, true, true);           //Exact case insensitive match ignoring numbers.
         if (listRxNorms.Count > 0)
         {
             rxCui = PIn.Long(listRxNorms[0].RxCui);
         }
     }
     //If rxCui==0, then third party eRx option (DoseSpot, NewCrop, etc) did not provide an RxCui and we could not locate an RxCui by DrugName
     //Try searching by GenericName.
     if (rxCui == 0 && strGenericName != "")
     {
         List <RxNorm> listRxNorms = RxNorms.GetListByCodeOrDesc(strGenericName, true, true);           //Exact case insensitive match ignoring numbers.
         if (listRxNorms.Count > 0)
         {
             rxCui = PIn.Long(listRxNorms[0].RxCui);
         }
     }
     //If rxCui==0, then third party eRx option (DoseSpot, NewCrop, etc) did not provide an RxCui and we could not
     //locate an RxCui by DrugName or GenericName.
     if (rxCui == 0)
     {
         //We may need to enhance in future to support more advanced RxNorm searches.
         //For example: DrugName=Cafatine, DrugInfo=Cafatine 1 mg-100 mg Tab, GenericName=ergotamine-caffeine.
         //This drug could not be found by DrugName nor GenericName, but could be found when the GenericName was split by non-alpha characters,
         //then the words in the generic name were swapped.
         //Namely, "caffeine ergotamine" is in the RxNorm table.
     }
     //MedicationNum of 0, because we do not want to bloat the medication list in OD.
     //In this special situation, we instead set the MedDescript, RxCui and ErxGuid columns.
     return(MedicationPats.InsertOrUpdateMedOrderForRx(rx, rxCui, isProv));
 }
Exemplo n.º 3
0
        ///<summary>Returns a list of EhrCodes for the specified InterventionCodeSet and ValueSetOID for any medication interventions.  Results will
        ///contain both intervention codes and medication codes that have been used in the last year.</summary>
        public static List <EhrCode> GetForIntervAndMedByUse(InterventionCodeSet codeSet, List <string> listMedValueSetOIDs)
        {
            //get all MedicationPats where the RxCui is one of the RxCui strings for list of ValueSetOIDs provided
            List <string>  listMedPats       = MedicationPats.GetAllForRxCuis(GetForValueSetOIDs(listMedValueSetOIDs, true).Select(x => x.CodeValue).ToList());
            List <string>  listInterventions = Interventions.GetAllForCodeSet(codeSet);
            List <EhrCode> retVal            = new List <EhrCode>();

            foreach (string codeStr in listMedPats.Union(listInterventions))
            {
                EhrCode codeCur = Listt.FirstOrDefault(x => x.CodeValue == codeStr);
                if (codeCur == null)
                {
                    continue;
                }
                retVal.Add(codeCur);
            }
            //we might find the "wrong" ehr code, because a single code may be in multiple code sets. This is still a valid code.
            return(retVal.OrderBy(x => x.Description).ToList());
        }
Exemplo n.º 4
0
        ///<summary>For CPOE.  Used for both manual rx and eRx through NewCrop.  Creates or updates a medical order using the given prescription information.
        ///Since rxCui is not part of the prescription, it must be passed in as a separate parameter.
        ///If isProvOrder is true, then the medical order provNum will be set to the prescription provNum.  If isProvOrder is false, then the medical order provNum will be set to 0.
        ///The MedDescript and NewCropGuid will always be copied from the prescription to the medical order and the medical order MedicationNum will be set to 0.
        ///This method return the medOrderNum for the new/updated medicationPat. Unlike most medical orders this does not create an entry in the medical order table.</summary>
        public static long InsertOrUpdateMedOrderForRx(RxPat rxPat, long rxCui, bool isProvOrder)
        {
            long          medOrderNum;
            MedicationPat medOrder = new MedicationPat();          //The medication order corresponding to the prescription.

            medOrder.DateStart   = rxPat.RxDate;
            medOrder.DateStop    = rxPat.RxDate.AddDays(7);       //Is there a way to easily calculate this information from the prescription information? The medical order will be inactive after this date.
            medOrder.MedDescript = rxPat.Drug;
            medOrder.RxCui       = rxCui;
            medOrder.NewCropGuid = rxPat.NewCropGuid;
            medOrder.PatNote     = rxPat.Sig;
            medOrder.PatNum      = rxPat.PatNum;
            if (isProvOrder)
            {
                medOrder.ProvNum = rxPat.ProvNum;
                medOrder.IsCpoe  = true;
            }
            MedicationPat medOrderOld = null;

            if (!String.IsNullOrEmpty(rxPat.NewCropGuid))              //This check prevents an extra db call when the order is being created for a prescription written from inside of OD manually instead of using NewCrop.
            {
                medOrderOld = MedicationPats.GetMedicationOrderByNewCropGuid(rxPat.NewCropGuid);
            }
            if (medOrderOld == null)
            {
                medOrder.IsNew = true;              //Might not be necessary, but does not hurt.
                medOrderNum    = MedicationPats.Insert(medOrder);
            }
            else              //The medication order was already in our database. Update it.
            {
                medOrder.MedicationPatNum = medOrderOld.MedicationPatNum;
                MedicationPats.Update(medOrder);
                medOrderNum = medOrder.MedicationPatNum;
            }
            return(medOrderNum);
        }
Exemplo n.º 5
0
        ///<summary></summary>
        public static List <EduResource> GenerateForPatient(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <EduResource> >(MethodBase.GetCurrentMethod(), patNum));
            }
            List <Disease>       diseaseList        = Diseases.Refresh(patNum);
            List <MedicationPat> medicationPatList  = MedicationPats.Refresh(patNum, false);
            List <LabResult>     labResultList      = LabResults.GetAllForPatient(patNum);
            List <EduResource>   eduResourceListAll = Crud.EduResourceCrud.SelectMany("SELECT * FROM eduresource");
            List <EduResource>   retVal             = new List <EduResource>();

            for (int i = 0; i < eduResourceListAll.Count; i++)
            {
                if (eduResourceListAll[i].DiseaseDefNum != 0)
                {
                    for (int j = 0; j < diseaseList.Count; j++)
                    {
                        if (eduResourceListAll[i].DiseaseDefNum == diseaseList[j].DiseaseDefNum)
                        {
                            retVal.Add(eduResourceListAll[i]);
                        }
                    }
                }
                else if (eduResourceListAll[i].Icd9Num != 0)               //checks against same list as Diseases/Problems
                {
                    for (int j = 0; j < diseaseList.Count; j++)
                    {
                        if (eduResourceListAll[i].Icd9Num == diseaseList[j].ICD9Num)
                        {
                            retVal.Add(eduResourceListAll[i]);
                        }
                    }
                }
                else if (eduResourceListAll[i].MedicationNum != 0)
                {
                    for (int j = 0; j < medicationPatList.Count; j++)
                    {
                        if (eduResourceListAll[i].MedicationNum == medicationPatList[j].MedicationNum)
                        {
                            retVal.Add(eduResourceListAll[i]);
                        }
                    }
                }
                else if (eduResourceListAll[i].LabResultID != "")
                {
                    for (int j = 0; j < labResultList.Count; j++)
                    {
                        if (eduResourceListAll[i].LabResultID != labResultList[j].TestID)
                        {
                            continue;
                        }
                        if (eduResourceListAll[i].LabResultCompare.StartsWith("<"))
                        {
                            //PIn.Int not used because blank not allowed.
                            try{
                                if (int.Parse(labResultList[j].ObsValue) < int.Parse(eduResourceListAll[i].LabResultCompare.Substring(1)))
                                {
                                    retVal.Add(eduResourceListAll[i]);
                                }
                            }
                            catch {
                                //This could only happen if the validation in either input didn't work.
                            }
                        }
                        else if (eduResourceListAll[i].LabResultCompare.StartsWith(">"))
                        {
                            try {
                                if (int.Parse(labResultList[j].ObsValue) > int.Parse(eduResourceListAll[i].LabResultCompare.Substring(1)))
                                {
                                    retVal.Add(eduResourceListAll[i]);
                                }
                            }
                            catch {
                                //This could only happen if the validation in either input didn't work.
                            }
                        }
                    }
                }
            }
            return(retVal);
        }
Exemplo n.º 6
0
        ///<summary></summary>
        public static List <EduResource> GenerateForPatient(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <EduResource> >(MethodBase.GetCurrentMethod(), patNum));
            }
            List <Disease>         diseaseList        = Diseases.Refresh(patNum);
            List <MedicationPat>   medicationPatList  = MedicationPats.Refresh(patNum, false);
            List <LabResult>       labResultList      = LabResults.GetAllForPatient(patNum);
            List <EhrLabResult>    listEhrLabResults  = EhrLabResults.GetAllForPatient(patNum);
            List <EduResource>     eduResourceListAll = Crud.EduResourceCrud.SelectMany("SELECT * FROM eduresource");
            List <EhrMeasureEvent> listTobaccoEvents  = EhrMeasureEvents.RefreshByType(patNum, EhrMeasureEventType.TobaccoUseAssessed)
                                                        .FindAll(x => x.CodeSystemResult == "SNOMEDCT");
            List <EduResource> retVal = new List <EduResource>();

            eduResourceListAll.FindAll(x => x.DiseaseDefNum != 0 && diseaseList.Any(y => y.DiseaseDefNum == x.DiseaseDefNum)).ForEach(x => retVal.Add(x));
            eduResourceListAll.FindAll(x => x.MedicationNum != 0 &&
                                       medicationPatList.Any(y => y.MedicationNum == x.MedicationNum ||
                                                             (y.MedicationNum == 0 && Medications.GetMedication(x.MedicationNum).RxCui == y.RxCui)))
            .ForEach(x => retVal.Add(x));
            eduResourceListAll.FindAll(x => x.SmokingSnoMed != "" && listTobaccoEvents.Any(y => y.CodeValueResult == x.SmokingSnoMed)).ForEach(x => retVal.Add(x));
            foreach (EduResource resourceCur in eduResourceListAll.Where(x => x.LabResultID != ""))
            {
                foreach (LabResult labResult in labResultList.Where(x => x.TestID == resourceCur.LabResultID))
                {
                    if (resourceCur.LabResultCompare.StartsWith("<"))
                    {
                        //PIn.Int not used because blank not allowed.
                        try{
                            if (int.Parse(labResult.ObsValue) < int.Parse(resourceCur.LabResultCompare.Substring(1)))
                            {
                                retVal.Add(resourceCur);
                            }
                        }
                        catch {
                            //This could only happen if the validation in either input didn't work.
                        }
                    }
                    else if (resourceCur.LabResultCompare.StartsWith(">"))
                    {
                        try {
                            if (int.Parse(labResult.ObsValue) > int.Parse(resourceCur.LabResultCompare.Substring(1)))
                            {
                                retVal.Add(resourceCur);
                            }
                        }
                        catch {
                            //This could only happen if the validation in either input didn't work.
                        }
                    }
                }                                                                                                                         //end LabResultList
                foreach (EhrLabResult ehrLabResult in listEhrLabResults.Where(x => x.ObservationIdentifierID == resourceCur.LabResultID)) //matches loinc only.
                {
                    if (retVal.Contains(resourceCur))
                    {
                        continue;                        //already added from loop above.
                    }
                    retVal.Add(resourceCur);
                }                //end EhrLabResults
            }
            return(retVal);
        }
Exemplo n.º 7
0
        ///<summary>This is the first step of automation, this checks to see if the new object matches one of the trigger conditions. </summary>
        /// <param name="triggerObject">Can be DiseaseDef, ICD9, Icd10, Snomed, Medication, RxNorm, Cvx, AllerfyDef, EHRLabResult, Patient, or VitalSign.</param>
        /// <param name="PatCur">Triggers and intervention are currently always dependant on current patient. </param>
        /// <returns>Returns a dictionary keyed on triggers and a list of all the objects that the trigger matched on. Should be used to generate CDS intervention message and later be passed to FormInfobutton for knowledge request.</returns>
        public static List <CDSIntervention> TriggerMatch(object triggerObject, Patient PatCur)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <List <CDSIntervention> >(MethodBase.GetCurrentMethod(), triggerObject, PatCur));
            }
            //Dictionary<string,List<object>> retVal=new Dictionary<string,List<object>>();
            List <CDSIntervention> retVal = new List <CDSIntervention>();
            //Define objects to be used in matching triggers.
            DiseaseDef   diseaseDef;
            ICD9         icd9;
            Icd10        icd10;
            Snomed       snomed;
            Medication   medication;
            RxNorm       rxNorm;
            Cvx          cvx;
            AllergyDef   allergyDef;
            EhrLabResult ehrLabResult;
            Patient      pat;
            Vitalsign    vitalsign;
            string       triggerObjectMessage = "";
            string       command = "";

            switch (triggerObject.GetType().Name)
            {
            case "DiseaseDef":
                diseaseDef = (DiseaseDef)triggerObject;
                command    = "SELECT * FROM ehrtrigger"
                             + " WHERE ProblemDefNumList LIKE '% " + POut.String(diseaseDef.DiseaseDefNum.ToString()) + " %'";      // '% <code> %' so that we can get exact matches.
                if (diseaseDef.ICD9Code != "")
                {
                    command += " OR ProblemIcd9List LIKE '% " + POut.String(diseaseDef.ICD9Code) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.ICD9Code + "(Icd9)  " + ICD9s.GetByCode(diseaseDef.ICD9Code).Description + "\r\n";
                }
                if (diseaseDef.Icd10Code != "")
                {
                    command += " OR ProblemIcd10List LIKE '% " + POut.String(diseaseDef.Icd10Code) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.Icd10Code + "(Icd10)  " + Icd10s.GetByCode(diseaseDef.Icd10Code).Description + "\r\n";
                }
                if (diseaseDef.SnomedCode != "")
                {
                    command += " OR ProblemSnomedList LIKE '% " + POut.String(diseaseDef.SnomedCode) + " %'";
                    triggerObjectMessage += "  -" + diseaseDef.SnomedCode + "(Snomed)  " + Snomeds.GetByCode(diseaseDef.SnomedCode).Description + "\r\n";
                }
                break;

            case "ICD9":
                icd9 = (ICD9)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE Icd9List LIKE '% " + POut.String(icd9.ICD9Code) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Icd10":
                icd10 = (Icd10)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE Icd10List LIKE '% " + POut.String(icd10.Icd10Code) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Snomed":
                snomed = (Snomed)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE SnomedList LIKE '% " + POut.String(snomed.SnomedCode) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Medication":
                medication           = (Medication)triggerObject;
                triggerObjectMessage = "  - " + medication.MedName + (medication.RxCui == 0?"":" (RxCui:" + RxNorms.GetByRxCUI(medication.RxCui.ToString()).RxCui + ")") + "\r\n";
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE MedicationNumList LIKE '% " + POut.String(medication.MedicationNum.ToString()) + " %'";         // '% <code> %' so that we can get exact matches.
                if (medication.RxCui != 0)
                {
                    command += " OR RxCuiList LIKE '% " + POut.String(medication.RxCui.ToString()) + " %'";                      // '% <code> %' so that we can get exact matches.
                }
                break;

            case "RxNorm":
                rxNorm = (RxNorm)triggerObject;
                triggerObjectMessage = "  - " + rxNorm.Description + "(RxCui:" + rxNorm.RxCui + ")\r\n";
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE RxCuiList LIKE '% " + POut.String(rxNorm.RxCui) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "Cvx":
                cvx = (Cvx)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE CvxList LIKE '% " + POut.String(cvx.CvxCode) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "AllergyDef":
                allergyDef = (AllergyDef)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger"
                          + " WHERE AllergyDefNumList LIKE '% " + POut.String(allergyDef.AllergyDefNum.ToString()) + " %'";         // '% <code> %' so that we can get exact matches.
                break;

            case "EhrLabResult":                    //match loinc only, no longer
                ehrLabResult = (EhrLabResult)triggerObject;
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger WHERE "
                          + "(LabLoincList LIKE '% " + ehrLabResult.ObservationIdentifierID + " %'"                  //LOINC may be in one of two fields
                          + "OR LabLoincList LIKE '% " + ehrLabResult.ObservationIdentifierIDAlt + " %')";           //LOINC may be in one of two fields
                break;

            case "Patient":
                pat = (Patient)triggerObject;
                List <string> triggerNums = new List <string>();
                //TODO: TriggerObjectMessage
                command = "SELECT * FROM ehrtrigger WHERE DemographicsList !=''";
                List <EhrTrigger> triggers = Crud.EhrTriggerCrud.SelectMany(command);
                for (int i = 0; i < triggers.Count; i++)
                {
                    string[] arrayDemoItems = triggers[i].DemographicsList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < arrayDemoItems.Length; j++)
                    {
                        switch (arrayDemoItems[j].Split(',')[0])
                        {
                        case "age":
                            int val = PIn.Int(Regex.Match(arrayDemoItems[j], @"\d+").Value);
                            if (arrayDemoItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (val == pat.Age)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayDemoItems[j].Contains("<"))
                            {
                                if (pat.Age < val)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayDemoItems[j].Contains(">"))
                            {
                                if (pat.Age > val)
                                {
                                    triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            //should never happen, age element didn't contain a comparator
                            break;

                        case "gender":
                            if (arrayDemoItems[j].Split(',')[0].StartsWith(pat.Gender.ToString()))
                            {
                                triggerNums.Add(triggers[i].EhrTriggerNum.ToString());
                            }
                            break;

                        default:
                            break;                                            //should never happen
                        }
                    }
                }
                triggerNums.Add("-1");                        //to ensure the querry is valid.
                command = "SELECT * FROM ehrTrigger WHERE EhrTriggerNum IN (" + String.Join(",", triggerNums) + ")";
                break;

            case "Vitalsign":
                List <string> trigNums = new List <string>();
                vitalsign = (Vitalsign)triggerObject;
                command   = "SELECT * FROM ehrtrigger WHERE VitalLoincList !=''";
                List <EhrTrigger> triggersVit = Crud.EhrTriggerCrud.SelectMany(command);
                for (int i = 0; i < triggersVit.Count; i++)
                {
                    string[] arrayVitalItems = triggersVit[i].VitalLoincList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < arrayVitalItems.Length; j++)
                    {
                        double val = PIn.Double(Regex.Match(arrayVitalItems[j], @"\d+(.(\d+))*").Value);                             //decimal value w or w/o decimal.
                        switch (arrayVitalItems[j].Split(',')[0])
                        {
                        case "height":
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (vitalsign.Height == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (vitalsign.Height < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (vitalsign.Height > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            //should never happen, Height element didn't contain a comparator
                            break;

                        case "weight":
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (vitalsign.Weight == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (vitalsign.Weight < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (vitalsign.Weight > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            break;

                        case "BMI":
                            float BMI = Vitalsigns.CalcBMI(vitalsign.Weight, vitalsign.Height);
                            if (arrayVitalItems[j].Contains("="))                                             //=, >=, or <=
                            {
                                if (BMI == val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains("<"))
                            {
                                if (BMI < val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            if (arrayVitalItems[j].Contains(">"))
                            {
                                if (BMI > val)
                                {
                                    trigNums.Add(triggersVit[i].EhrTriggerNum.ToString());
                                    break;
                                }
                            }
                            break;

                        case "BP":
                            //TODO
                            break;
                        }                //end switch
                    }
                }                        //End Triggers Vit
                trigNums.Add("-1");      //to ensure the querry is valid.
                command = "SELECT * FROM ehrTrigger WHERE EhrTriggerNum IN (" + String.Join(",", trigNums) + ")";
                break;

            default:
                //command="SELECT * FROM ehrtrigger WHERE false";//should not return any results.
                return(null);

                                        #if DEBUG
                throw new Exception(triggerObject.GetType().ToString() + " object not implemented as intervention trigger yet. Add to the list above to handle.");
                                        #endif
                //break;
            }
            List <EhrTrigger> listEhrTriggers = Crud.EhrTriggerCrud.SelectMany(command);
            if (listEhrTriggers.Count == 0)
            {
                return(null);               //no triggers matched.
            }
            //Check for MatchCardinality.One type triggers.----------------------------------------------------------------------------
            for (int i = 0; i < listEhrTriggers.Count; i++)
            {
                if (listEhrTriggers[i].Cardinality != MatchCardinality.One)
                {
                    continue;
                }
                string triggerMessage = listEhrTriggers[i].Description + ":\r\n"; //Example:"Patient over 55:\r\n"
                triggerMessage += triggerObjectMessage;                           //Example:"  -Patient Age 67\r\n"
                List <object> ListObjectMatches = new List <object>();
                ListObjectMatches.Add(triggerObject);
                CDSIntervention cdsi = new CDSIntervention();
                cdsi.EhrTrigger          = listEhrTriggers[i];
                cdsi.InterventionMessage = triggerMessage;
                cdsi.TriggerObjects      = ListObjectMatches;
                retVal.Add(cdsi);
            }
            //Fill object lists to be checked-------------------------------------------------------------------------------------------------
            List <Allergy>    ListAllergy    = Allergies.GetAll(PatCur.PatNum, false);
            List <Disease>    ListDisease    = Diseases.Refresh(PatCur.PatNum, true);
            List <DiseaseDef> ListDiseaseDef = new List <DiseaseDef>();
            List <EhrLab>     ListEhrLab     = EhrLabs.GetAllForPat(PatCur.PatNum);
            //List<EhrLabResult> ListEhrLabResults=null;//Lab results are stored in a list in the EhrLab object.
            List <MedicationPat> ListMedicationPat = MedicationPats.Refresh(PatCur.PatNum, false);
            List <AllergyDef>    ListAllergyDef    = new List <AllergyDef>();
            for (int i = 0; i < ListAllergy.Count; i++)
            {
                ListAllergyDef.Add(AllergyDefs.GetOne(ListAllergy[i].AllergyDefNum));
            }
            for (int i = 0; i < ListDisease.Count; i++)
            {
                ListDiseaseDef.Add(DiseaseDefs.GetItem(ListDisease[i].DiseaseDefNum));
            }
            for (int i = 0; i < listEhrTriggers.Count; i++)
            {
                if (listEhrTriggers[i].Cardinality == MatchCardinality.One)
                {
                    continue;                    //we handled these above.
                }
                string triggerMessage = listEhrTriggers[i].Description + ":\r\n";
                triggerMessage += triggerObjectMessage;
                List <object> ListObjectMatches = new List <object>();            //Allergy, Disease, LabPanels, MedicationPat, Patient, VaccinePat
                ListObjectMatches.Add(triggerObject);
                //Allergy-----------------------------------------------------------------------------------------------------------------------
                //allergy.snomedreaction
                //allergy.AllergyDefNum>>AllergyDef.SnomedType
                //allergy.AllergyDefNum>>AllergyDef.SnomedAllergyTo
                //allergy.AllergyDefNum>>AllergyDef.MedicationNum>>Medication.RxCui
                //Disease-----------------------------------------------------------------------------------------------------------------------
                //Disease.DiseaseDefNum>>DiseaseDef.ICD9Code
                //Disease.DiseaseDefNum>>DiseaseDef.SnomedCode
                //Disease.DiseaseDefNum>>DiseaseDef.Icd10Code
                //LabPanels---------------------------------------------------------------------------------------------------------------------
                //LabPanel.LabPanelNum<<LabResult.TestId (Loinc)
                //LabPanel.LabPanelNum<<LabResult.ObsValue (Loinc)
                //LabPanel.LabPanelNum<<LabResult.ObsRange (Loinc)
                //MedicationPat-----------------------------------------------------------------------------------------------------------------
                //MedicationPat.RxCui
                //MedicationPat.MedicationNum>>Medication.RxCui
                //Patient>>Demographics---------------------------------------------------------------------------------------------------------
                //Patient.Gender
                //Patient.Birthdate (Loinc age?)
                //Patient.SmokingSnoMed
                //RxPat-------------------------------------------------------------------------------------------------------------------------
                //Do not check RxPat. It is useless.
                //VaccinePat--------------------------------------------------------------------------------------------------------------------
                //VaccinePat.VaccineDefNum>>VaccineDef.CVXCode
                //VitalSign---------------------------------------------------------------------------------------------------------------------
                //VitalSign.Height (Loinc)
                //VitalSign.Weight (Loinc)
                //VitalSign.BpSystolic (Loinc)
                //VitalSign.BpDiastolic (Loinc)
                //VitalSign.WeightCode (Snomed)
                //VitalSign.PregDiseaseNum (Snomed)
                //Use object matches to check if required conditions are met-------------------------------------------------------------------------------
                switch (listEhrTriggers[i].Cardinality)
                {
                case MatchCardinality.One:
                    //should never get here, handled above.
                    continue;

                case MatchCardinality.OneOfEachCategory:                        //falls through to two or more, but then branches at the end of the case statement.
                case MatchCardinality.TwoOrMore:
                    //if(ListObjectMatches.Count<2) {
                    //	continue;//Must match at least two objects for this category.
                    //}
                    //Medication
                    for (int m = 0; m < ListMedicationPat.Count; m++)
                    {
                        if (listEhrTriggers[i].MedicationNumList.Contains(" " + ListMedicationPat[m].MedicationNum + " "))
                        {
                            ListObjectMatches.Add(ListMedicationPat[m]);
                            continue;
                        }
                        if (ListMedicationPat[m].RxCui != 0 &&
                            listEhrTriggers[i].RxCuiList.Contains(" " + ListMedicationPat[m].RxCui + " "))
                        {
                            ListObjectMatches.Add(ListMedicationPat[m]);
                            continue;
                        }
                    }
                    //Allergy
                    for (int a = 0; a < ListAllergy.Count; a++)
                    {
                        if (listEhrTriggers[i].AllergyDefNumList.Contains(" " + ListAllergy[a].AllergyDefNum + " "))
                        {
                            ListObjectMatches.Add(AllergyDefs.GetOne(ListAllergy[a].AllergyDefNum));
                            triggerMessage += "  -(Allergy) " + AllergyDefs.GetOne(ListAllergy[a].AllergyDefNum).Description + "\r\n";
                            continue;
                        }
                    }
                    //Problem
                    for (int d = 0; d < ListDiseaseDef.Count; d++)
                    {
                        if (ListDiseaseDef[d].ICD9Code != "" &&
                            listEhrTriggers[i].ProblemIcd9List.Contains(" " + ListDiseaseDef[d].ICD9Code + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(ICD9) " + ICD9s.GetByCode(ListDiseaseDef[d].ICD9Code).Description + "\r\n";
                            continue;
                        }
                        if (ListDiseaseDef[d].Icd10Code != "" &&
                            listEhrTriggers[i].ProblemIcd10List.Contains(" " + ListDiseaseDef[d].Icd10Code + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Icd10) " + Icd10s.GetByCode(ListDiseaseDef[d].Icd10Code).Description + "\r\n";
                            continue;
                        }
                        if (ListDiseaseDef[d].SnomedCode != "" &&
                            listEhrTriggers[i].ProblemSnomedList.Contains(" " + ListDiseaseDef[d].SnomedCode + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Snomed) " + Snomeds.GetByCode(ListDiseaseDef[d].SnomedCode).Description + "\r\n";
                            continue;
                        }
                        if (listEhrTriggers[i].ProblemDefNumList.Contains(" " + ListDiseaseDef[d].DiseaseDefNum + " "))
                        {
                            ListObjectMatches.Add(ListDiseaseDef[d]);
                            triggerMessage += "  -(Problem Def) " + ListDiseaseDef[d].DiseaseName + "\r\n";
                            continue;
                        }
                    }
                    //Vital
                    //TODO
                    //Age
                    //TODO
                    //Gender
                    //TODO
                    //Lab Result
                    for (int l = 0; l < ListEhrLab.Count; l++)
                    {
                        for (int r = 0; r < ListEhrLab[l].ListEhrLabResults.Count; r++)
                        {
                            if (listEhrTriggers[i].LabLoincList.Contains(" " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID + " ") ||
                                listEhrTriggers[i].LabLoincList.Contains(" " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt + " "))
                            {
                                ListObjectMatches.Add(ListEhrLab[l].ListEhrLabResults[r]);
                                if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")                                       //should almost always be the case.
                                {
                                    triggerMessage += "  -(LOINC) " + Loincs.GetByCode(ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID).NameShort + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")
                                {
                                    triggerMessage += "  -(LOINC) " + Loincs.GetByCode(ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt).NameShort + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierText != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierText + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextAlt != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextAlt + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierID + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierIDAlt + "\r\n";
                                }
                                else if (ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextOriginal != "")
                                {
                                    triggerMessage += "  -(LOINC) " + ListEhrLab[l].ListEhrLabResults[r].ObservationIdentifierTextOriginal + "\r\n";
                                }
                                else
                                {
                                    triggerMessage += "  -(LOINC) Unknown code.\r\n";                                          //should never happen.
                                }
                                continue;
                            }
                        }
                    }
                    ListObjectMatches = RemoveDuplicateObjectsHelper(ListObjectMatches);
                    if (listEhrTriggers[i].Cardinality == MatchCardinality.TwoOrMore && ListObjectMatches.Count < 2)
                    {
                        continue;                                //next trigger, do not add to retVal
                    }
                    if (listEhrTriggers[i].Cardinality == MatchCardinality.OneOfEachCategory && !OneOfEachCategoryHelper(listEhrTriggers[i], ListObjectMatches))
                    {
                        continue;
                    }
                    break;

                case MatchCardinality.All:
                    bool          allConditionsMet = true;
                    List <string> MatchedCodes     = getCodesFromListHelper(ListObjectMatches);                     //new List<string>();
                    //Match all Icd9Codes-------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayIcd9Codes = listEhrTriggers[i].ProblemIcd9List.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayIcd9Codes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayIcd9Codes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all Icd10Codes------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayIcd10Codes = listEhrTriggers[i].ProblemIcd10List.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayIcd10Codes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayIcd10Codes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all SnomedCodes-----------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arraySnomedCodes = listEhrTriggers[i].ProblemSnomedList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arraySnomedCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arraySnomedCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger
                    }
                    //Match all CvxCodes--------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayCvxCodes = listEhrTriggers[i].CvxList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayCvxCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayCvxCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger, do not add to retval
                    }
                    //Match all LoincCodes------------------------------------------------------------------------------------------------------------------------------------------------
                    string[] arrayLoincCodes = listEhrTriggers[i].LabLoincList.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    for (int c = 0; c < arrayLoincCodes.Length; c++)
                    {
                        if (MatchedCodes.Contains(arrayLoincCodes[i]))
                        {
                            continue;                                    //found required code
                        }
                        //required code not found, set allConditionsMet to false and continue to next trigger
                        allConditionsMet = false;
                        break;
                    }
                    if (!allConditionsMet)
                    {
                        continue;                                //next trigger, do not add to retval
                    }
                    //TODO:with values
                    //Match all Vitals----------------------------------------------------------------------------------------------------------------------------------------------------
                    //TODO:with values
                    //Match all Demographics---------------------------------------------------------------------------------------------------------------------------------------------
                    //if(listEhrTriggers[i].DemographicAgeGreaterThan!=0){
                    //	if(PatCur.Birthdate.Year>1880 && PatCur.Birthdate.AddYears(listEhrTriggers[i].DemographicAgeGreaterThan)>DateTime.Now){//patient too young
                    //		continue;//next trigger
                    //	}
                    //}
                    //if(listEhrTriggers[i].DemographicAgeLessThan!=0){
                    //	if(PatCur.Birthdate.Year>1880 && PatCur.Birthdate.AddYears(listEhrTriggers[i].DemographicAgeGreaterThan)<DateTime.Now){//patient too old
                    //		continue;//next trigger
                    //	}
                    //}
                    //if(listEhrTriggers[i].DemographicGender!=""){
                    //	if(!listEhrTriggers[i].DemographicGender.Contains(PatCur.Gender.ToString())){//Patient Gender not in gender list of trigger
                    //		continue;//next trigger
                    //	}
                    //}
                    //TODO: construct trigger message using all the codes in the trigger.
                    break;
                }                //end switch trigger cardinality
                //retVal.Add(triggerMessage,ListObjectMatches);
                CDSIntervention cdsi = new CDSIntervention();
                cdsi.EhrTrigger          = listEhrTriggers[i];
                cdsi.InterventionMessage = triggerMessage;
                cdsi.TriggerObjects      = ListObjectMatches;
                retVal.Add(cdsi);
            }            //end triggers
            return(retVal);
        }
Exemplo n.º 8
0
        ///<summary>For CPOE.  Used for both manual rx and eRx through NewCrop.  Creates or updates a medical order using the given prescription information.
        ///Since rxCui is not part of the prescription, it must be passed in as a separate parameter.
        ///If isProvOrder is true, then the medical order provNum will be set to the prescription provNum.  If isProvOrder is false, then the medical order provNum will be set to 0.
        ///The MedDescript and ErxGuid will always be copied from the prescription to the medical order and the medical order MedicationNum will be set to 0.
        ///This method return the medOrderNum for the new/updated medicationPat. Unlike most medical orders this does not create an entry in the medical order table.</summary>
        public static long InsertOrUpdateMedOrderForRx(RxPat rxPat, long rxCui, bool isProvOrder)
        {
            long          medOrderNum;
            MedicationPat medOrderOld = null;

            if (!string.IsNullOrWhiteSpace(rxPat.ErxGuid))             //This check prevents an extra db call when making a new prescription manually inside OD.
            {
                medOrderOld = MedicationPats.GetMedicationOrderByErxIdAndPat(rxPat.ErxGuid, rxPat.PatNum);
            }
            MedicationPat medOrder = null;          //The medication order corresponding to the prescription.

            if (medOrderOld == null)
            {
                medOrder = new MedicationPat();
            }
            else
            {
                medOrder = medOrderOld.Clone();              //Maintain primary key and medicationnum for the update below.
            }
            medOrder.DateStart = rxPat.RxDate;
            int numDays = PrefC.GetInt(PrefName.MedDefaultStopDays);

            if (numDays != 0)
            {
                medOrder.DateStop = rxPat.RxDate.AddDays(numDays);
            }
            medOrder.MedDescript = rxPat.Drug;
            medOrder.RxCui       = rxCui;
            if (rxCui != 0)
            {
                //The customer may not have a medication entered for this RxCui the first few times they get this particular medication back from eRx.
                //Once the customer adds the medication to their medication list, then we can automatically attach the order to the medication.
                //The reason we decided not to automatically create the medication if one does not already exist is because we do not want to
                //accidentally bloat the medication list, if for example, the user has the medication entered but has not set the RxCui on it yet.
                List <Medication> listMeds = Medications.GetAllMedsByRxCui(rxCui);
                if (listMeds.Count > 0)
                {
                    medOrder.MedicationNum = listMeds[0].MedicationNum;
                }
            }
            medOrder.ErxGuid = rxPat.ErxGuid;
            medOrder.PatNote = rxPat.Sig;
            medOrder.PatNum  = rxPat.PatNum;
            if (isProvOrder)
            {
                medOrder.ProvNum = rxPat.ProvNum;
                medOrder.IsCpoe  = true;
            }
            if (medOrderOld == null)
            {
                medOrder.IsNew = true;              //Might not be necessary, but does not hurt.
                medOrderNum    = MedicationPats.Insert(medOrder);
                //If the ErxGuid has not been set, and it is a new medication, set the ErxGuid so that the medication can be sent to DoseSpot
                if (Erx.IsManualRx(rxPat.ErxGuid))
                {
                    try {
                        int medPatNumAsInt = (int)medOrderNum;
                        rxPat.ErxGuid = Erx.OpenDentalErxPrefix + medPatNumAsInt;
                        RxPats.Update(rxPat);
                    }
                    catch (Exception ex) {
                        //If we cannot downgrade a long to an int for the ErxGuid we can simply ignore trying to update the rxPat.
                        //This is because this medication would never be sent to eRx because we would attempt this downgrade again in the exact same manner.
                        ex.DoNothing();
                    }
                }
            }
            else              //The medication order was already in our database. Update it.
            {
                medOrder.MedicationPatNum = medOrderOld.MedicationPatNum;
                MedicationPats.Update(medOrder, false);               //Don't ErxGuid here, it was already purposefully set above.
                medOrderNum = medOrder.MedicationPatNum;
            }
            return(medOrderNum);
        }
Exemplo n.º 9
0
        ///<summary>Runs the required queries to populate the necessary StaticTextData fields corresponding to staticTextDependencies.</summary>
        private void LoadData(StaticTextFieldDependency staticTextDependencies, Patient pat, Family fam, List <long> listProcCodeNums)
        {
            bool isMiddleTier = (RemotingClient.RemotingRole == RemotingRole.ServerWeb);

            System.Diagnostics.Stopwatch timer = null;
            if (ODBuild.IsDebug())
            {
                timer = new System.Diagnostics.Stopwatch();
                timer.Start();
            }
            if (staticTextDependencies.HasFlag(StaticTextFieldDependency.Pat))
            {
                //patient should already be loaded.
            }
            if (fam == null && staticTextDependencies.HasFlag(StaticTextFieldDependency.Fam))
            {
                fam = Patients.GetFamily(pat.PatNum);
            }
            if (PatNote == null)
            {
                if (staticTextDependencies.HasFlag(StaticTextFieldDependency.PatNote))
                {
                    PatNote = PatientNotes.Refresh(pat.PatNum, pat.Guarantor);
                }
                else
                {
                    PatNote = new PatientNote();
                }
            }
            bool IsQueryNeeded <T>(ref List <T> list, StaticTextFieldDependency dependency)
            {
                if (list == null || (isMiddleTier && list.Count == 0))             //Middle Tier deserializes null lists to empty lists.
                {
                    if (staticTextDependencies.HasFlag(dependency))
                    {
                        return(true);
                    }
                    else
                    {
                        list = new List <T>();
                    }
                }
                return(false);
            }

            if (IsQueryNeeded(ref ListRefAttaches, StaticTextFieldDependency.ListRefAttaches))
            {
                ListRefAttaches = RefAttaches.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListInsSubs, StaticTextFieldDependency.ListInsSubs))
            {
                ListInsSubs = InsSubs.RefreshForFam(fam);
            }
            if (IsQueryNeeded(ref ListInsPlans, StaticTextFieldDependency.ListInsPlans))
            {
                ListInsPlans = InsPlans.RefreshForSubList(ListInsSubs);
            }
            if (IsQueryNeeded(ref ListPatPlans, StaticTextFieldDependency.ListPatPlans))
            {
                ListPatPlans = PatPlans.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListBenefits, StaticTextFieldDependency.ListBenefits))
            {
                ListBenefits = Benefits.Refresh(ListPatPlans, ListInsSubs);
            }
            if (IsQueryNeeded(ref HistList, StaticTextFieldDependency.HistList))
            {
                HistList = ClaimProcs.GetHistList(pat.PatNum, ListBenefits, ListPatPlans, ListInsPlans, DateTime.Today, ListInsSubs);
            }
            if (IsQueryNeeded(ref ListTreatPlans, StaticTextFieldDependency.ListTreatPlans))
            {
                ListTreatPlans = TreatPlans.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListRecallsForFam, StaticTextFieldDependency.ListRecallsForFam))
            {
                ListRecallsForFam = Recalls.GetList(fam.ListPats.Select(x => x.PatNum).ToList());
            }
            if (IsQueryNeeded(ref ListAppts, StaticTextFieldDependency.ListAppts))
            {
                ListAppts = Appointments.GetListForPat(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListFutureApptsForFam, StaticTextFieldDependency.ListFutureApptsForFam))
            {
                ListFutureApptsForFam = Appointments.GetFutureSchedApts(fam.ListPats.Select(x => x.PatNum).ToList());
            }
            if (IsQueryNeeded(ref ListDiseases, StaticTextFieldDependency.ListDiseases))
            {
                ListDiseases = Diseases.Refresh(pat.PatNum, true);
            }
            if (IsQueryNeeded(ref ListAllergies, StaticTextFieldDependency.ListAllergies))
            {
                ListAllergies = Allergies.GetAll(pat.PatNum, false);
            }
            if (IsQueryNeeded(ref ListMedicationPats, StaticTextFieldDependency.ListMedicationPats))
            {
                ListMedicationPats = MedicationPats.Refresh(pat.PatNum, false);
            }
            if (IsQueryNeeded(ref ListFamPopups, StaticTextFieldDependency.ListFamPopups))
            {
                ListFamPopups = Popups.GetForFamily(pat);
            }
            if (IsQueryNeeded(ref ListProceduresSome, StaticTextFieldDependency.ListProceduresSome))
            {
                ListProceduresSome = Procedures.RefreshForProcCodeNums(pat.PatNum, listProcCodeNums);
            }
            if (IsQueryNeeded(ref ListProceduresPat, StaticTextFieldDependency.ListProceduresPat))
            {
                ListProceduresPat = Procedures.Refresh(pat.PatNum);
            }
            if (IsQueryNeeded(ref ListPlannedAppts, StaticTextFieldDependency.ListPlannedAppts))
            {
                ListPlannedAppts = new List <PlannedAppt>();
                PlannedAppt plannedAppt = PlannedAppts.GetOneOrderedByItemOrder(pat.PatNum);
                if (plannedAppt != null)
                {
                    ListPlannedAppts.Add(plannedAppt);
                }
            }
            if (ODBuild.IsDebug())
            {
                timer.Stop();
                Console.WriteLine("Static text field query time (ms): " + timer.ElapsedMilliseconds);
            }
        }