///<summary>Inserts one AllergyDef into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(AllergyDef allergyDef, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO allergydef (";

            if (!useExistingPK && isRandomKeys)
            {
                allergyDef.AllergyDefNum = ReplicationServers.GetKeyNoCache("allergydef", "AllergyDefNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "AllergyDefNum,";
            }
            command += "Description,IsHidden,SnomedType,MedicationNum,UniiCode) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(allergyDef.AllergyDefNum) + ",";
            }
            command +=
                "'" + POut.String(allergyDef.Description) + "',"
                + POut.Bool(allergyDef.IsHidden) + ","
                //DateTStamp can only be set by MySQL
                + POut.Int((int)allergyDef.SnomedType) + ","
                + POut.Long(allergyDef.MedicationNum) + ","
                + "'" + POut.String(allergyDef.UniiCode) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                allergyDef.AllergyDefNum = Db.NonQ(command, true, "AllergyDefNum", "allergyDef");
            }
            return(allergyDef.AllergyDefNum);
        }
Exemple #2
0
 private void FillAlerts()
 {
     RxAlertList = RxAlerts.Refresh(RxDefCur.RxDefNum);
     listAlerts.Items.Clear();
     for (int i = 0; i < RxAlertList.Count; i++)
     {
         if (RxAlertList[i].DiseaseDefNum > 0)
         {
             listAlerts.Items.Add(DiseaseDefs.GetName(RxAlertList[i].DiseaseDefNum));
         }
         if (RxAlertList[i].AllergyDefNum > 0)
         {
             AllergyDef allergyDef = AllergyDefs.GetOne(RxAlertList[i].AllergyDefNum);
             if (allergyDef != null)
             {
                 listAlerts.Items.Add(allergyDef.Description);
             }
         }
         if (RxAlertList[i].MedicationNum > 0)
         {
             Medications.RefreshCache();
             Medication med = Medications.GetMedication(RxAlertList[i].MedicationNum);
             if (med != null)
             {
                 listAlerts.Items.Add(med.MedName);
             }
         }
     }
 }
Exemple #3
0
 ///<summary>Inserts one AllergyDef into the database.  Returns the new priKey.</summary>
 public static long Insert(AllergyDef allergyDef)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         allergyDef.AllergyDefNum = DbHelper.GetNextOracleKey("allergydef", "AllergyDefNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(allergyDef, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     allergyDef.AllergyDefNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(allergyDef, false));
     }
 }
 ///<summary>Returns true if Update(AllergyDef,AllergyDef) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(AllergyDef allergyDef, AllergyDef oldAllergyDef)
 {
     if (allergyDef.Description != oldAllergyDef.Description)
     {
         return(true);
     }
     if (allergyDef.IsHidden != oldAllergyDef.IsHidden)
     {
         return(true);
     }
     //DateTStamp can only be set by MySQL
     if (allergyDef.SnomedType != oldAllergyDef.SnomedType)
     {
         return(true);
     }
     if (allergyDef.MedicationNum != oldAllergyDef.MedicationNum)
     {
         return(true);
     }
     if (allergyDef.UniiCode != oldAllergyDef.UniiCode)
     {
         return(true);
     }
     return(false);
 }
Exemple #5
0
 ///<summary>Inserts one AllergyDef into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(AllergyDef allergyDef,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         allergyDef.AllergyDefNum=ReplicationServers.GetKey("allergydef","AllergyDefNum");
     }
     string command="INSERT INTO allergydef (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="AllergyDefNum,";
     }
     command+="Description,IsHidden,Snomed,MedicationNum) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(allergyDef.AllergyDefNum)+",";
     }
     command+=
          "'"+POut.String(allergyDef.Description)+"',"
         +    POut.Bool  (allergyDef.IsHidden)+","
         //DateTStamp can only be set by MySQL
         +    POut.Int   ((int)allergyDef.Snomed)+","
         +    POut.Long  (allergyDef.MedicationNum)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         allergyDef.AllergyDefNum=Db.NonQ(command,true);
     }
     return allergyDef.AllergyDefNum;
 }
Exemple #6
0
 ///<summary>Inserts one AllergyDef into the database.  Returns the new priKey.</summary>
 internal static long Insert(AllergyDef allergyDef)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         allergyDef.AllergyDefNum=DbHelper.GetNextOracleKey("allergydef","AllergyDefNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(allergyDef,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     allergyDef.AllergyDefNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(allergyDef,false);
     }
 }
Exemple #7
0
        ///<summary>Inserts one AllergyDef into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(AllergyDef allergyDef, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                allergyDef.AllergyDefNum = ReplicationServers.GetKey("allergydef", "AllergyDefNum");
            }
            string command = "INSERT INTO allergydef (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "AllergyDefNum,";
            }
            command += "Description,IsHidden,Snomed,MedicationNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(allergyDef.AllergyDefNum) + ",";
            }
            command +=
                "'" + POut.String(allergyDef.Description) + "',"
                + POut.Bool(allergyDef.IsHidden) + ","
                //DateTStamp can only be set by MySQL
                + POut.Int((int)allergyDef.Snomed) + ","
                + POut.Long(allergyDef.MedicationNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                allergyDef.AllergyDefNum = Db.NonQ(command, true);
            }
            return(allergyDef.AllergyDefNum);
        }
        private void FillForm()
        {
            textMedName.Text = MedicationCur.MedName;
            if (!IsNew)
            {
                textMedName.ReadOnly = true;
            }
            if (MedicationCur.MedicationNum == MedicationCur.GenericNum)
            {
                textGenericName.Text = MedicationCur.MedName;
                textNotes.Text       = MedicationCur.Notes;
                textNotes.ReadOnly   = false;
                Brands = Medications.GetBrands(MedicationCur.MedicationNum);
                comboBrands.Items.Clear();
                comboBrands.Items.AddRange(Brands);
                if (Brands.Length > 0)
                {
                    comboBrands.SelectedIndex = 0;
                }
            }
            else
            {
                textGenericName.Text = Medications.GetMedication(MedicationCur.GenericNum).MedName;
                textNotes.Text       = Medications.GetMedication(MedicationCur.GenericNum).Notes;
                textNotes.ReadOnly   = true;
                Brands = new string[0];
                comboBrands.Visible = false;
                labelBrands.Visible = false;
            }
            _patNameMeds = Medications.GetPatNamesForMed(MedicationCur.MedicationNum);
            comboPatients.Items.Clear();
            comboPatients.Items.AddRange(_patNameMeds);
            if (_patNameMeds.Length > 0)
            {
                comboPatients.SelectedIndex = 0;
            }
            AllergyDef alD = AllergyDefs.GetAllergyDefFromMedication(MedicationCur.MedicationNum);

            if (alD != null)
            {
                _patNameAllergies = Allergies.GetPatNamesForAllergy(alD.AllergyDefNum);
                comboPatientAllergy.Items.Clear();
                comboPatientAllergy.Items.AddRange(_patNameAllergies);
                if (_patNameAllergies.Length > 0)
                {
                    comboPatientAllergy.SelectedIndex = 0;
                }
            }
            if (CultureInfo.CurrentCulture.Name.EndsWith("US"))             //United States
            {
                textRxNormDesc.Text = RxNorms.GetDescByRxCui(MedicationCur.RxCui.ToString());
            }
            else
            {
                labelRxNorm.Visible     = false;
                textRxNormDesc.Visible  = false;
                butRxNormSelect.Visible = false;
            }
        }
        private void butAddNew_Click(object sender, EventArgs e)
        {
            if (gridAllergyImport.SelectedIndices.Length == 0)
            {
                MsgBox.Show(this, "A row must be selected to add");
                return;
            }
            Allergy    al;
            AllergyDef alD;
            AllergyDef alDR      = null;
            int        skipCount = 0;
            bool       isValid;

            for (int i = 0; i < gridAllergyImport.SelectedIndices.Length; i++)
            {
                isValid = true;
                //Since gridAllergyImport and ListAllergyNew are a 1:1 list we can use the selected index position to get our allergy
                al  = ListAllergyNew[gridAllergyImport.SelectedIndices[i]];
                alD = ListAllergyDefNew[gridAllergyImport.SelectedIndices[i]];              //ListAllergyDefNew is also a 1:1 to gridAllergyImport.
                for (int j = 0; j < _listAllergyReconcile.Count; j++)
                {
                    if (_listAllergyReconcile[j].IsNew)
                    {
                        alDR = ListAllergyDefNew[ListAllergyNew.IndexOf(_listAllergyReconcile[j])];
                    }
                    else
                    {
                        alDR = AllergyDefs.GetOne(_listAllergyReconcile[j].AllergyDefNum);
                    }
                    if (alDR == null)
                    {
                        continue;
                    }
                    //if(alDR.SnomedAllergyTo!="" && alDR.SnomedAllergyTo!=null && alDR.SnomedAllergyTo==alD.SnomedAllergyTo) {//TODO: Change to UNII
                    //	isValid=false;
                    //	skipCount++;
                    //	break;
                    //}
                    if (alDR.MedicationNum != 0 && alDR.MedicationNum == alD.MedicationNum)
                    {
                        isValid = false;
                        skipCount++;
                        break;
                    }
                }
                if (isValid)
                {
                    _listAllergyReconcile.Add(al);
                }
            }
            if (skipCount > 0)
            {
                MessageBox.Show(Lan.g(this, " Row(s) skipped because allergy already present in the reconcile list") + ": " + skipCount);
            }
            FillReconcileGrid();
        }
Exemple #10
0
 ///<summary>Converts one AllergyDef object to its mobile equivalent.  Warning! CustomerNum will always be 0.</summary>
 internal static AllergyDefm ConvertToM(AllergyDef allergyDef)
 {
     AllergyDefm allergyDefm=new AllergyDefm();
     //CustomerNum cannot be set.  Remains 0.
     allergyDefm.AllergyDefNum=allergyDef.AllergyDefNum;
     allergyDefm.Description  =allergyDef.Description;
     allergyDefm.Snomed       =allergyDef.Snomed;
     allergyDefm.MedicationNum=allergyDef.MedicationNum;
     return allergyDefm;
 }
Exemple #11
0
        ///<summary>Converts one AllergyDef object to its mobile equivalent.  Warning! CustomerNum will always be 0.</summary>
        internal static AllergyDefm ConvertToM(AllergyDef allergyDef)
        {
            AllergyDefm allergyDefm = new AllergyDefm();

            //CustomerNum cannot be set.  Remains 0.
            allergyDefm.AllergyDefNum = allergyDef.AllergyDefNum;
            allergyDefm.Description   = allergyDef.Description;
            allergyDefm.Snomed        = allergyDef.Snomed;
            allergyDefm.MedicationNum = allergyDef.MedicationNum;
            return(allergyDefm);
        }
        ///<summary>Updates one AllergyDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(AllergyDef allergyDef, AllergyDef oldAllergyDef)
        {
            string command = "";

            if (allergyDef.Description != oldAllergyDef.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(allergyDef.Description) + "'";
            }
            if (allergyDef.IsHidden != oldAllergyDef.IsHidden)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsHidden = " + POut.Bool(allergyDef.IsHidden) + "";
            }
            //DateTStamp can only be set by MySQL
            if (allergyDef.SnomedType != oldAllergyDef.SnomedType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SnomedType = " + POut.Int((int)allergyDef.SnomedType) + "";
            }
            if (allergyDef.MedicationNum != oldAllergyDef.MedicationNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MedicationNum = " + POut.Long(allergyDef.MedicationNum) + "";
            }
            if (allergyDef.UniiCode != oldAllergyDef.UniiCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UniiCode = '" + POut.String(allergyDef.UniiCode) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE allergydef SET " + command
                      + " WHERE AllergyDefNum = " + POut.Long(allergyDef.AllergyDefNum);
            Db.NonQ(command);
            return(true);
        }
Exemple #13
0
        ///<summary>Updates one AllergyDef in the database.</summary>
        internal static void Update(AllergyDef allergyDef)
        {
            string command = "UPDATE allergydef SET "
                             + "Description  = '" + POut.String(allergyDef.Description) + "', "
                             + "IsHidden     =  " + POut.Bool(allergyDef.IsHidden) + ", "
                             //DateTStamp can only be set by MySQL
                             + "Snomed       =  " + POut.Int((int)allergyDef.Snomed) + ", "
                             + "MedicationNum=  " + POut.Long(allergyDef.MedicationNum) + " "
                             + "WHERE AllergyDefNum = " + POut.Long(allergyDef.AllergyDefNum);

            Db.NonQ(command);
        }
Exemple #14
0
 ///<summary>Inserts one AllergyDef into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AllergyDef allergyDef)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(allergyDef, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             allergyDef.AllergyDefNum = DbHelper.GetNextOracleKey("allergydef", "AllergyDefNum");                  //Cacheless method
         }
         return(InsertNoCache(allergyDef, true));
     }
 }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<AllergyDef> TableToList(DataTable table){
			List<AllergyDef> retVal=new List<AllergyDef>();
			AllergyDef allergyDef;
			for(int i=0;i<table.Rows.Count;i++) {
				allergyDef=new AllergyDef();
				allergyDef.AllergyDefNum= PIn.Long  (table.Rows[i]["AllergyDefNum"].ToString());
				allergyDef.Description  = PIn.String(table.Rows[i]["Description"].ToString());
				allergyDef.IsHidden     = PIn.Bool  (table.Rows[i]["IsHidden"].ToString());
				allergyDef.DateTStamp   = PIn.DateT (table.Rows[i]["DateTStamp"].ToString());
				allergyDef.SnomedType   = (SnomedAllergy)PIn.Int(table.Rows[i]["SnomedType"].ToString());
				allergyDef.MedicationNum= PIn.Long  (table.Rows[i]["MedicationNum"].ToString());
				allergyDef.UniiCode     = PIn.String(table.Rows[i]["UniiCode"].ToString());
				retVal.Add(allergyDef);
			}
			return retVal;
		}
Exemple #16
0
        ///<summary>Updates one AllergyDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
        internal static void Update(AllergyDef allergyDef, AllergyDef oldAllergyDef)
        {
            string command = "";

            if (allergyDef.Description != oldAllergyDef.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(allergyDef.Description) + "'";
            }
            if (allergyDef.IsHidden != oldAllergyDef.IsHidden)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsHidden = " + POut.Bool(allergyDef.IsHidden) + "";
            }
            //DateTStamp can only be set by MySQL
            if (allergyDef.Snomed != oldAllergyDef.Snomed)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Snomed = " + POut.Int((int)allergyDef.Snomed) + "";
            }
            if (allergyDef.MedicationNum != oldAllergyDef.MedicationNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MedicationNum = " + POut.Long(allergyDef.MedicationNum) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE allergydef SET " + command
                      + " WHERE AllergyDefNum = " + POut.Long(allergyDef.AllergyDefNum);
            Db.NonQ(command);
        }
Exemple #17
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <AllergyDef> TableToList(DataTable table)
        {
            List <AllergyDef> retVal = new List <AllergyDef>();
            AllergyDef        allergyDef;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                allergyDef = new AllergyDef();
                allergyDef.AllergyDefNum = PIn.Long(table.Rows[i]["AllergyDefNum"].ToString());
                allergyDef.Description   = PIn.String(table.Rows[i]["Description"].ToString());
                allergyDef.IsHidden      = PIn.Bool(table.Rows[i]["IsHidden"].ToString());
                allergyDef.DateTStamp    = PIn.DateT(table.Rows[i]["DateTStamp"].ToString());
                allergyDef.Snomed        = (SnomedAllergy)PIn.Int(table.Rows[i]["Snomed"].ToString());
                allergyDef.MedicationNum = PIn.Long(table.Rows[i]["MedicationNum"].ToString());
                retVal.Add(allergyDef);
            }
            return(retVal);
        }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AllergyDef> TableToList(DataTable table)
        {
            List <AllergyDef> retVal = new List <AllergyDef>();
            AllergyDef        allergyDef;

            foreach (DataRow row in table.Rows)
            {
                allergyDef = new AllergyDef();
                allergyDef.AllergyDefNum = PIn.Long(row["AllergyDefNum"].ToString());
                allergyDef.Description   = PIn.String(row["Description"].ToString());
                allergyDef.IsHidden      = PIn.Bool(row["IsHidden"].ToString());
                allergyDef.DateTStamp    = PIn.DateT(row["DateTStamp"].ToString());
                allergyDef.SnomedType    = (OpenDentBusiness.SnomedAllergy)PIn.Int(row["SnomedType"].ToString());
                allergyDef.MedicationNum = PIn.Long(row["MedicationNum"].ToString());
                allergyDef.UniiCode      = PIn.String(row["UniiCode"].ToString());
                retVal.Add(allergyDef);
            }
            return(retVal);
        }
Exemple #19
0
        private void FillAllergies()
        {
            allergyList = Allergies.GetAll(PatCur.PatNum, checkShowInactiveAllergies.Checked);
            gridAllergies.BeginUpdate();
            gridAllergies.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g("TableAllergies", "Allergy"), 100);

            gridAllergies.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableAllergies", "Reaction"), 180);
            gridAllergies.Columns.Add(col);
            col = new ODGridColumn(Lan.g("TableAllergies", "Status"), 60, HorizontalAlignment.Center);
            gridAllergies.Columns.Add(col);
            gridAllergies.Rows.Clear();
            ODGridRow row;

            for (int i = 0; i < allergyList.Count; i++)
            {
                row = new ODGridRow();
                AllergyDef allergyDef = AllergyDefs.GetOne(allergyList[i].AllergyDefNum);
                row.Cells.Add(allergyDef.Description);
                if (allergyList[i].DateAdverseReaction < DateTime.Parse("1-1-1800"))
                {
                    row.Cells.Add(allergyList[i].Reaction);
                }
                else
                {
                    row.Cells.Add(allergyList[i].Reaction + " " + allergyList[i].DateAdverseReaction.ToShortDateString());
                }
                if (allergyList[i].StatusIsActive)
                {
                    row.Cells.Add("Active");
                }
                else
                {
                    row.Cells.Add("Inactive");
                }
                gridAllergies.Rows.Add(row);
            }
            gridAllergies.EndUpdate();
        }
		///<summary>Updates one AllergyDef in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.</summary>
		public static void Update(AllergyDef allergyDef,AllergyDef oldAllergyDef){
			string command="";
			if(allergyDef.Description != oldAllergyDef.Description) {
				if(command!=""){ command+=",";}
				command+="Description = '"+POut.String(allergyDef.Description)+"'";
			}
			if(allergyDef.IsHidden != oldAllergyDef.IsHidden) {
				if(command!=""){ command+=",";}
				command+="IsHidden = "+POut.Bool(allergyDef.IsHidden)+"";
			}
			//DateTStamp can only be set by MySQL
			if(allergyDef.SnomedType != oldAllergyDef.SnomedType) {
				if(command!=""){ command+=",";}
				command+="SnomedType = "+POut.Int   ((int)allergyDef.SnomedType)+"";
			}
			if(allergyDef.MedicationNum != oldAllergyDef.MedicationNum) {
				if(command!=""){ command+=",";}
				command+="MedicationNum = "+POut.Long(allergyDef.MedicationNum)+"";
			}
			if(allergyDef.UniiCode != oldAllergyDef.UniiCode) {
				if(command!=""){ command+=",";}
				command+="UniiCode = '"+POut.String(allergyDef.UniiCode)+"'";
			}
			if(command==""){
				return;
			}
			command="UPDATE allergydef SET "+command
				+" WHERE AllergyDefNum = "+POut.Long(allergyDef.AllergyDefNum);
			Db.NonQ(command);
		}
		///<summary>Updates one AllergyDef in the database.</summary>
		public static void Update(AllergyDef allergyDef){
			string command="UPDATE allergydef SET "
				+"Description  = '"+POut.String(allergyDef.Description)+"', "
				+"IsHidden     =  "+POut.Bool  (allergyDef.IsHidden)+", "
				//DateTStamp can only be set by MySQL
				+"SnomedType   =  "+POut.Int   ((int)allergyDef.SnomedType)+", "
				+"MedicationNum=  "+POut.Long  (allergyDef.MedicationNum)+", "
				+"UniiCode     = '"+POut.String(allergyDef.UniiCode)+"' "
				+"WHERE AllergyDefNum = "+POut.Long(allergyDef.AllergyDefNum);
			Db.NonQ(command);
		}
        private void butOK_Click(object sender, EventArgs e)
        {
            if (_listAllergyReconcile.Count == 0)
            {
                if (!MsgBox.Show(this, true, "The reconcile list is empty which will cause all existing allergies to be removed.  Continue?"))
                {
                    return;
                }
            }
            Allergy    al;
            AllergyDef alD;
            bool       isActive;

            //Discontinue any current medications that are not present in the reconcile list.
            for (int i = 0; i < _listAllergyCur.Count; i++)       //Start looping through all current allergies
            {
                isActive = false;
                al       = _listAllergyCur[i];
                alD      = AllergyDefs.GetOne(al.AllergyDefNum, _listAllergyDefCur);
                for (int j = 0; j < _listAllergyReconcile.Count; j++)           //Compare each reconcile allergy to the current allergy
                {
                    AllergyDef alDR = AllergyDefs.GetOne(_listAllergyReconcile[j].AllergyDefNum, _listAllergyDefCur);
                    if (_listAllergyReconcile[j].AllergyDefNum == _listAllergyCur[i].AllergyDefNum)                   //Has identical AllergyDefNums
                    {
                        isActive = true;
                        break;
                    }
                    if (alDR == null)
                    {
                        continue;
                    }
                    //if(alDR.SnomedAllergyTo!="" && alDR.SnomedAllergyTo==alD.SnomedAllergyTo) {//TODO: Change to UNII
                    //	isActive=true;
                    //	break;
                    //}
                    if (alDR.MedicationNum != 0 && alDR.MedicationNum == alD.MedicationNum)                 //Has a Snomed code and they are equal
                    {
                        isActive = true;
                        break;
                    }
                }
                if (!isActive)
                {
                    _listAllergyCur[i].StatusIsActive = isActive;
                    Allergies.Update(_listAllergyCur[i]);
                }
            }
            //Always update every current allergy for the patient so that DateTStamp reflects the last reconcile date.
            if (_listAllergyCur.Count > 0)
            {
                Allergies.ResetTimeStamps(_patCur.PatNum, true);
            }
            AllergyDef alDU;
            int        index;

            for (int j = 0; j < _listAllergyReconcile.Count; j++)
            {
                if (!_listAllergyReconcile[j].IsNew)
                {
                    continue;
                }
                index = ListAllergyNew.IndexOf(_listAllergyReconcile[j]);              //Returns -1 if not found.
                if (index < 0)
                {
                    continue;
                }
                //Insert the AllergyDef and Allergy if needed.
                if (ListAllergyDefNew[index].MedicationNum != 0)
                {
                    alDU = AllergyDefs.GetAllergyDefFromMedication(ListAllergyDefNew[index].MedicationNum);
                }
                else
                {
                    alDU = null;                  //remove once UNII is implemented
                    //alDU=AllergyDefs.GetAllergyDefFromCode(ListAllergyDefNew[index].SnomedAllergyTo);//TODO: Change to UNII
                }
                if (alDU == null)               //db is missing the def
                {
                    ListAllergyNew[index].AllergyDefNum = AllergyDefs.Insert(ListAllergyDefNew[index]);
                }
                else
                {
                    ListAllergyNew[index].AllergyDefNum = alDU.AllergyDefNum;                  //Set the allergydefnum on the allergy.
                }
                Allergies.Insert(ListAllergyNew[index]);
            }
            //TODO: Make an allergy measure event if one is needed for MU3.
            //EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent();
            //newMeasureEvent.DateTEvent=DateTime.Now;
            //newMeasureEvent.EventType=EhrMeasureEventType.AllergyReconcile;
            //newMeasureEvent.PatNum=PatCur.PatNum;
            //newMeasureEvent.MoreInfo="";
            //EhrMeasureEvents.Insert(newMeasureEvent);
            for (int inter = 0; inter < _listAllergyReconcile.Count; inter++)
            {
                if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).AllergyCDS)
                {
                    AllergyDef          alDInter = AllergyDefs.GetOne(_listAllergyReconcile[inter].AllergyDefNum);
                    FormCDSIntervention FormCDSI = new FormCDSIntervention();
                    FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(alDInter, _patCur);
                    FormCDSI.ShowIfRequired(false);
                }
            }
            DialogResult = DialogResult.OK;
        }
        private void butAddExist_Click(object sender, EventArgs e)
        {
            if (gridAllergyExisting.SelectedIndices.Length == 0)
            {
                MsgBox.Show(this, "A row must be selected to add");
                return;
            }
            Allergy    al;
            AllergyDef alD;
            int        skipCount = 0;
            bool       isValid;

            for (int i = 0; i < gridAllergyExisting.SelectedIndices.Length; i++)
            {
                isValid = true;
                //Since gridAllergyExisting and _listAllergyCur are a 1:1 list we can use the selected index position to get our allergy
                al  = _listAllergyCur[gridAllergyExisting.SelectedIndices[i]];
                alD = AllergyDefs.GetOne(al.AllergyDefNum, _listAllergyDefCur);
                if (_listAllergyReconcile.Count == 0)
                {
                    _listAllergyReconcile.Add(al);
                    continue;
                }
                for (int j = 0; j < _listAllergyReconcile.Count; j++)
                {
                    if (!_listAllergyReconcile[j].IsNew && _listAllergyReconcile[j].AllergyNum == al.AllergyNum)                   //If not new, then from existing list.  Check allergynums
                    {
                        isValid = false;
                        skipCount++;
                        break;
                    }
                    if (_listAllergyReconcile[j].IsNew)
                    {
                        //This is an allergy that is coming in from and external source.
                        AllergyDef alDN  = null;
                        int        index = ListAllergyNew.IndexOf(_listAllergyReconcile[j]);               //Find the corresponding allergy def by looping through the incoming allergies.
                        if (index == -1)
                        {
                            continue;                            //This should not happen
                        }
                        alDN = ListAllergyDefNew[index];         //Incoming allergy and allergy def lists are 1 to 1 so we can use the same index.
                        if (alDN != null && alDN.MedicationNum == alD.MedicationNum)
                        {
                            isValid = false;
                            skipCount++;
                            break;
                        }
                    }
                    if (al.AllergyDefNum == _listAllergyReconcile[j].AllergyDefNum)
                    {
                        isValid = false;
                        skipCount++;
                        break;
                    }
                    if (!isValid)
                    {
                        break;
                    }
                }
                if (isValid)
                {
                    _listAllergyReconcile.Add(al);
                }
            }
            if (skipCount > 0)
            {
                MessageBox.Show(Lan.g(this, " Row(s) skipped because allergy already present in the reconcile list") + ": " + skipCount);
            }
            FillReconcileGrid();
        }
        private void FillForm()
        {
            textMedName.Text = MedicationCur.MedName;
            if (!IsNew)
            {
                textMedName.ReadOnly = true;
            }
            if (MedicationCur.GenericNum == 0)
            {
                //Probably occurred from a previous bug.  This makes sure we have a generic num that is not 0.
                MedicationCur.GenericNum = MedicationCur.MedicationNum;
                MsgBox.Show(this, "This medication had a missing generic name.  The generic name has been set to the medication name.");
            }
            if (MedicationCur.MedicationNum == MedicationCur.GenericNum)
            {
                textGenericName.Text = MedicationCur.MedName;
                textNotes.Text       = MedicationCur.Notes;
                textNotes.ReadOnly   = false;
                Brands = Medications.GetBrands(MedicationCur.MedicationNum);
                comboBrands.Items.Clear();
                comboBrands.Items.AddRange(Brands);
                if (Brands.Length > 0)
                {
                    comboBrands.SelectedIndex = 0;
                }
            }
            else
            {
                textGenericName.Text = Medications.GetMedication(MedicationCur.GenericNum).MedName;
                textNotes.Text       = Medications.GetMedication(MedicationCur.GenericNum).Notes;
                textNotes.ReadOnly   = true;
                Brands = new string[0];
                comboBrands.Visible = false;
                labelBrands.Visible = false;
            }
            _patNameMeds = Medications.GetPatNamesForMed(MedicationCur.MedicationNum);
            comboPatients.Items.Clear();
            comboPatients.Items.AddRange(_patNameMeds);
            if (_patNameMeds.Length > 0)
            {
                comboPatients.SelectedIndex = 0;
            }
            AllergyDef alD = AllergyDefs.GetAllergyDefFromMedication(MedicationCur.MedicationNum);

            if (alD != null)
            {
                _patNameAllergies = Allergies.GetPatNamesForAllergy(alD.AllergyDefNum);
                comboPatientAllergy.Items.Clear();
                comboPatientAllergy.Items.AddRange(_patNameAllergies);
                if (_patNameAllergies.Length > 0)
                {
                    comboPatientAllergy.SelectedIndex = 0;
                }
            }
            if (CultureInfo.CurrentCulture.Name.EndsWith("US"))             //United States
            {
                textRxNormDesc.Text = RxNorms.GetDescByRxCui(MedicationCur.RxCui.ToString());
            }
            else
            {
                labelRxNorm.Visible     = false;
                textRxNormDesc.Visible  = false;
                butRxNormSelect.Visible = false;
            }
        }
        private void FillReconcileGrid()
        {
            gridAllergyReconcile.BeginUpdate();
            gridAllergyReconcile.Columns.Clear();
            ODGridColumn col = new ODGridColumn("Last Modified", 90, HorizontalAlignment.Center);

            gridAllergyReconcile.Columns.Add(col);
            col = new ODGridColumn("Description", 400);
            gridAllergyReconcile.Columns.Add(col);
            col = new ODGridColumn("Reaction", 300);
            gridAllergyReconcile.Columns.Add(col);
            col = new ODGridColumn("Inactive", 80, HorizontalAlignment.Center);
            gridAllergyReconcile.Columns.Add(col);
            col = new ODGridColumn("Is Incoming", 100, HorizontalAlignment.Center);
            gridAllergyReconcile.Columns.Add(col);
            gridAllergyReconcile.Rows.Clear();
            ODGridRow  row;
            AllergyDef ald = new AllergyDef();

            for (int i = 0; i < _listAllergyReconcile.Count; i++)
            {
                row = new ODGridRow();
                ald = new AllergyDef();
                if (_listAllergyReconcile[i].IsNew)
                {
                    //To find the allergy def for new allergies, get the index of the matching allergy in ListAllergyNew, and use that index in ListAllergyDefNew because they are 1 to 1 lists.
                    ald = ListAllergyDefNew[ListAllergyNew.IndexOf(_listAllergyReconcile[i])];
                }
                for (int j = 0; j < _listAllergyDefCur.Count; j++)
                {
                    if (_listAllergyReconcile[i].AllergyDefNum > 0 && _listAllergyReconcile[i].AllergyDefNum == _listAllergyDefCur[j].AllergyDefNum)
                    {
                        ald = _listAllergyDefCur[j];                      //Gets the allergydef matching the allergy so we can use it to populate the grid
                        break;
                    }
                }
                row.Cells.Add(DateTime.Now.ToShortDateString());
                if (ald.Description == null)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(ald.Description);
                }
                if (_listAllergyReconcile[i].Reaction == null)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(_listAllergyReconcile[i].Reaction);
                }
                if (_listAllergyReconcile[i].StatusIsActive)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add("X");
                }
                row.Cells.Add(_listAllergyReconcile[i].IsNew?"X":"");
                gridAllergyReconcile.Rows.Add(row);
            }
            gridAllergyReconcile.EndUpdate();
        }
        private void FillExistingGrid()
        {
            gridAllergyExisting.BeginUpdate();
            gridAllergyExisting.Columns.Clear();
            ODGridColumn col = new ODGridColumn("Last Modified", 90, HorizontalAlignment.Center);

            gridAllergyExisting.Columns.Add(col);
            col = new ODGridColumn("Description", 200);
            gridAllergyExisting.Columns.Add(col);
            col = new ODGridColumn("Reaction", 100);
            gridAllergyExisting.Columns.Add(col);
            col = new ODGridColumn("Inactive", 80, HorizontalAlignment.Center);
            gridAllergyExisting.Columns.Add(col);
            gridAllergyExisting.Rows.Clear();
            _listAllergyCur = Allergies.GetAll(_patCur.PatNum, false);
            List <long> allergyDefNums = new List <long>();

            for (int h = 0; h < _listAllergyCur.Count; h++)
            {
                if (_listAllergyCur[h].AllergyDefNum > 0)
                {
                    allergyDefNums.Add(_listAllergyCur[h].AllergyDefNum);
                }
            }
            _listAllergyDefCur = AllergyDefs.GetMultAllergyDefs(allergyDefNums);
            ODGridRow  row;
            AllergyDef ald;

            for (int i = 0; i < _listAllergyCur.Count; i++)
            {
                row = new ODGridRow();
                ald = new AllergyDef();
                ald = AllergyDefs.GetOne(_listAllergyCur[i].AllergyDefNum, _listAllergyDefCur);
                row.Cells.Add(_listAllergyCur[i].DateTStamp.ToShortDateString());
                if (ald.Description == null)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(ald.Description);
                }
                if (_listAllergyCur[i].Reaction == null)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add(_listAllergyCur[i].Reaction);
                }
                if (_listAllergyCur[i].StatusIsActive)
                {
                    row.Cells.Add("");
                }
                else
                {
                    row.Cells.Add("X");
                }
                gridAllergyExisting.Rows.Add(row);
            }
            gridAllergyExisting.EndUpdate();
        }
 ///<summary>Inserts one AllergyDef into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AllergyDef allergyDef)
 {
     return(InsertNoCache(allergyDef, false));
 }