Пример #1
0
 ///<summary>Inserts one RxNorm into the database.  Returns the new priKey.</summary>
 public static long Insert(RxNorm rxNorm)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         rxNorm.RxNormNum = DbHelper.GetNextOracleKey("rxnorm", "RxNormNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(rxNorm, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     rxNorm.RxNormNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(rxNorm, false));
     }
 }
Пример #2
0
 ///<summary>Inserts one RxNorm into the database.  Returns the new priKey.</summary>
 internal static long Insert(RxNorm rxNorm)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         rxNorm.RxNormNum=DbHelper.GetNextOracleKey("rxnorm","RxNormNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(rxNorm,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     rxNorm.RxNormNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(rxNorm,false);
     }
 }
Пример #3
0
 ///<summary>Inserts one RxNorm into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(RxNorm rxNorm,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         rxNorm.RxNormNum=ReplicationServers.GetKey("rxnorm","RxNormNum");
     }
     string command="INSERT INTO rxnorm (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="RxNormNum,";
     }
     command+="RxCui,MmslCode,Description) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(rxNorm.RxNormNum)+",";
     }
     command+=
          "'"+POut.String(rxNorm.RxCui)+"',"
         +"'"+POut.String(rxNorm.MmslCode)+"',"
         +"'"+POut.String(rxNorm.Description)+"')";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         rxNorm.RxNormNum=Db.NonQ(command,true);
     }
     return rxNorm.RxNormNum;
 }
Пример #4
0
        ///<summary>Inserts one RxNorm into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(RxNorm rxNorm, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                rxNorm.RxNormNum = ReplicationServers.GetKey("rxnorm", "RxNormNum");
            }
            string command = "INSERT INTO rxnorm (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "RxNormNum,";
            }
            command += "RxCui,MmslCode,Description) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(rxNorm.RxNormNum) + ",";
            }
            command +=
                "'" + POut.String(rxNorm.RxCui) + "',"
                + "'" + POut.String(rxNorm.MmslCode) + "',"
                + "'" + POut.String(rxNorm.Description) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                rxNorm.RxNormNum = Db.NonQ(command, true);
            }
            return(rxNorm.RxNormNum);
        }
Пример #5
0
 private void butOK_Click(object sender, EventArgs e)
 {
     if (gridMain.GetSelectedIndex() < 0)
     {
         MsgBox.Show(this, "Please select an item first.");
         return;
     }
     SelectedRxNorm = rxList[gridMain.GetSelectedIndex()];
     DialogResult   = DialogResult.OK;
 }
Пример #6
0
        ///<summary>Updates one RxNorm in the database.</summary>
        internal static void Update(RxNorm rxNorm)
        {
            string command = "UPDATE rxnorm SET "
                             + "RxCui      = '" + POut.String(rxNorm.RxCui) + "', "
                             + "MmslCode   = '" + POut.String(rxNorm.MmslCode) + "', "
                             + "Description= '" + POut.String(rxNorm.Description) + "' "
                             + "WHERE RxNormNum = " + POut.Long(rxNorm.RxNormNum);

            Db.NonQ(command);
        }
Пример #7
0
 private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
 {
     if (!IsSelectionMode)
     {
         return;
     }
     SelectedRxNorm      = rxList[e.Row];
     ListSelectedRxNorms = new List <RxNorm>();
     ListSelectedRxNorms.Add(rxList[e.Row]);
     DialogResult = DialogResult.OK;
 }
Пример #8
0
 public override IDocEntity SaveChanges(bool ignoreCache, DocConstantPermission permission)
 {
     BioPortal = BioPortal?.TrimAndPruneSpaces();
     CUI       = CUI?.TrimAndPruneSpaces();
     MedDRA    = MedDRA?.TrimAndPruneSpaces();
     Name      = Name?.TrimAndPruneSpaces();
     RxNorm    = RxNorm?.TrimAndPruneSpaces();
     SNOWMED   = SNOWMED?.TrimAndPruneSpaces();
     TUI       = TUI?.TrimAndPruneSpaces();
     URI       = URI?.TrimAndPruneSpaces();
     return(base.SaveChanges(ignoreCache, permission));
 }
Пример #9
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<RxNorm> TableToList(DataTable table){
			List<RxNorm> retVal=new List<RxNorm>();
			RxNorm rxNorm;
			for(int i=0;i<table.Rows.Count;i++) {
				rxNorm=new RxNorm();
				rxNorm.RxNormNum  = PIn.Long  (table.Rows[i]["RxNormNum"].ToString());
				rxNorm.RxCui      = PIn.String(table.Rows[i]["RxCui"].ToString());
				rxNorm.MmslCode   = PIn.String(table.Rows[i]["MmslCode"].ToString());
				rxNorm.Description= PIn.String(table.Rows[i]["Description"].ToString());
				retVal.Add(rxNorm);
			}
			return retVal;
		}
Пример #10
0
 ///<summary>Inserts one RxNorm into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(RxNorm rxNorm)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(rxNorm, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             rxNorm.RxNormNum = DbHelper.GetNextOracleKey("rxnorm", "RxNormNum");                  //Cacheless method
         }
         return(InsertNoCache(rxNorm, true));
     }
 }
Пример #11
0
 private void butOK_Click(object sender, EventArgs e)
 {
     if (gridMain.GetSelectedIndex() < 0)
     {
         MsgBox.Show(this, "Please select an item first.");
         return;
     }
     SelectedRxNorm      = rxList[gridMain.GetSelectedIndex()];
     ListSelectedRxNorms = new List <RxNorm>();
     for (int i = 0; i < gridMain.SelectedIndices.Length; i++)
     {
         ListSelectedRxNorms.Add(rxList[gridMain.SelectedIndices[i]]);
     }
     DialogResult = DialogResult.OK;
 }
Пример #12
0
        ///<summary>Updates one RxNorm in the database.</summary>
        public static void Update(RxNorm rxNorm)
        {
            string command = "UPDATE rxnorm SET "
                             + "RxCui      = '" + POut.String(rxNorm.RxCui) + "', "
                             + "MmslCode   = '" + POut.String(rxNorm.MmslCode) + "', "
                             + "Description=  " + DbHelper.ParamChar + "paramDescription "
                             + "WHERE RxNormNum = " + POut.Long(rxNorm.RxNormNum);

            if (rxNorm.Description == null)
            {
                rxNorm.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(rxNorm.Description));

            Db.NonQ(command, paramDescription);
        }
Пример #13
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <RxNorm> TableToList(DataTable table)
        {
            List <RxNorm> retVal = new List <RxNorm>();
            RxNorm        rxNorm;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                rxNorm             = new RxNorm();
                rxNorm.RxNormNum   = PIn.Long(table.Rows[i]["RxNormNum"].ToString());
                rxNorm.RxCui       = PIn.String(table.Rows[i]["RxCui"].ToString());
                rxNorm.MmslCode    = PIn.String(table.Rows[i]["MmslCode"].ToString());
                rxNorm.Description = PIn.String(table.Rows[i]["Description"].ToString());
                retVal.Add(rxNorm);
            }
            return(retVal);
        }
Пример #14
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <RxNorm> TableToList(DataTable table)
        {
            List <RxNorm> retVal = new List <RxNorm>();
            RxNorm        rxNorm;

            foreach (DataRow row in table.Rows)
            {
                rxNorm             = new RxNorm();
                rxNorm.RxNormNum   = PIn.Long(row["RxNormNum"].ToString());
                rxNorm.RxCui       = PIn.String(row["RxCui"].ToString());
                rxNorm.MmslCode    = PIn.String(row["MmslCode"].ToString());
                rxNorm.Description = PIn.String(row["Description"].ToString());
                retVal.Add(rxNorm);
            }
            return(retVal);
        }
Пример #15
0
 ///<summary>Returns true if Update(RxNorm,RxNorm) 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(RxNorm rxNorm, RxNorm oldRxNorm)
 {
     if (rxNorm.RxCui != oldRxNorm.RxCui)
     {
         return(true);
     }
     if (rxNorm.MmslCode != oldRxNorm.MmslCode)
     {
         return(true);
     }
     if (rxNorm.Description != oldRxNorm.Description)
     {
         return(true);
     }
     return(false);
 }
Пример #16
0
        ///<summary>Updates one RxNorm 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(RxNorm rxNorm, RxNorm oldRxNorm)
        {
            string command = "";

            if (rxNorm.RxCui != oldRxNorm.RxCui)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RxCui = '" + POut.String(rxNorm.RxCui) + "'";
            }
            if (rxNorm.MmslCode != oldRxNorm.MmslCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MmslCode = '" + POut.String(rxNorm.MmslCode) + "'";
            }
            if (rxNorm.Description != oldRxNorm.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = " + DbHelper.ParamChar + "paramDescription";
            }
            if (command == "")
            {
                return(false);
            }
            if (rxNorm.Description == null)
            {
                rxNorm.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(rxNorm.Description));

            command = "UPDATE rxnorm SET " + command
                      + " WHERE RxNormNum = " + POut.Long(rxNorm.RxNormNum);
            Db.NonQ(command, paramDescription);
            return(true);
        }
Пример #17
0
        ///<summary>Inserts the new medication and returns it.</summary>
        public static Medication CreateMedication(string medName = "", string rxCui = "")
        {
            Medication medication = new Medication();

            medication.MedName = medName;
            if (medication.MedName == "")
            {
                medication.MedName = "Med_" + MiscUtils.CreateRandomAlphaNumericString(8);
            }
            medication.RxCui = PIn.Long(rxCui, false);
            if (medication.RxCui != 0 && RxNorms.GetByRxCUI(rxCui) == null)
            {
                RxNorm rxNorm = new RxNorm();
                rxNorm.RxCui       = rxCui;
                rxNorm.Description = medication.MedName;
                RxNorms.Insert(rxNorm);
            }
            Medications.Insert(medication);
            return(medication);
        }
Пример #18
0
        ///<summary>Inserts one RxNorm into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(RxNorm rxNorm, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO rxnorm (";

            if (!useExistingPK && isRandomKeys)
            {
                rxNorm.RxNormNum = ReplicationServers.GetKeyNoCache("rxnorm", "RxNormNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "RxNormNum,";
            }
            command += "RxCui,MmslCode,Description) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(rxNorm.RxNormNum) + ",";
            }
            command +=
                "'" + POut.String(rxNorm.RxCui) + "',"
                + "'" + POut.String(rxNorm.MmslCode) + "',"
                + DbHelper.ParamChar + "paramDescription)";
            if (rxNorm.Description == null)
            {
                rxNorm.Description = "";
            }
            OdSqlParameter paramDescription = new OdSqlParameter("paramDescription", OdDbType.Text, POut.StringParam(rxNorm.Description));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramDescription);
            }
            else
            {
                rxNorm.RxNormNum = Db.NonQ(command, true, "RxNormNum", "rxNorm", paramDescription);
            }
            return(rxNorm.RxNormNum);
        }
Пример #19
0
        ///<summary>Updates one RxNorm 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(RxNorm rxNorm, RxNorm oldRxNorm)
        {
            string command = "";

            if (rxNorm.RxCui != oldRxNorm.RxCui)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RxCui = '" + POut.String(rxNorm.RxCui) + "'";
            }
            if (rxNorm.MmslCode != oldRxNorm.MmslCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MmslCode = '" + POut.String(rxNorm.MmslCode) + "'";
            }
            if (rxNorm.Description != oldRxNorm.Description)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Description = '" + POut.String(rxNorm.Description) + "'";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE rxnorm SET " + command
                      + " WHERE RxNormNum = " + POut.Long(rxNorm.RxNormNum);
            Db.NonQ(command);
        }
Пример #20
0
 ///<summary>Inserts one RxNorm into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(RxNorm rxNorm)
 {
     return(InsertNoCache(rxNorm, false));
 }
Пример #21
0
        //private void butRxNorm_Click(object sender,EventArgs e) {
        //	//if(!MsgBox.Show(this,MsgBoxButtons.OKCancel,"This will ")) {
        //	//	return;
        //	//}
        //	Cursor=Cursors.WaitCursor;
        //	RxNorms.CreateFreshRxNormTableFromZip();
        //	Cursor=Cursors.Default;
        //	MsgBox.Show(this,"done");
        //	//just making sure it worked:
        //	/*
        //	RxNorm rxNorm=RxNorms.GetOne(1);
        //	MsgBox.Show(this,rxNorm.RxNormNum+" "+rxNorm.RxCui+" "+rxNorm.MmslCode+" "+rxNorm.Description);
        //	MsgBox.Show(this,RxNorms.GetMmslCodeByRxCui("1000005")+" <-- should be 26420");
        //	MsgBox.Show(this,RxNorms.GetMmslCodeByRxCui("1000002")+" <-- should be blank");*/
        //}

        private void butNone_Click(object sender, EventArgs e)
        {
            SelectedRxNorm      = new RxNorm();
            ListSelectedRxNorms = new List <RxNorm>();
            DialogResult        = DialogResult.OK;
        }
Пример #22
0
		///<summary>Updates one RxNorm 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(RxNorm rxNorm,RxNorm oldRxNorm){
			string command="";
			if(rxNorm.RxCui != oldRxNorm.RxCui) {
				if(command!=""){ command+=",";}
				command+="RxCui = '"+POut.String(rxNorm.RxCui)+"'";
			}
			if(rxNorm.MmslCode != oldRxNorm.MmslCode) {
				if(command!=""){ command+=",";}
				command+="MmslCode = '"+POut.String(rxNorm.MmslCode)+"'";
			}
			if(rxNorm.Description != oldRxNorm.Description) {
				if(command!=""){ command+=",";}
				command+="Description = '"+POut.String(rxNorm.Description)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE rxnorm SET "+command
				+" WHERE RxNormNum = "+POut.Long(rxNorm.RxNormNum);
			Db.NonQ(command);
			return true;
		}
Пример #23
0
		///<summary>Updates one RxNorm in the database.</summary>
		public static void Update(RxNorm rxNorm){
			string command="UPDATE rxnorm SET "
				+"RxCui      = '"+POut.String(rxNorm.RxCui)+"', "
				+"MmslCode   = '"+POut.String(rxNorm.MmslCode)+"', "
				+"Description= '"+POut.String(rxNorm.Description)+"' "
				+"WHERE RxNormNum = "+POut.Long(rxNorm.RxNormNum);
			Db.NonQ(command);
		}
Пример #24
0
 private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
 {
     SelectedRxNorm = rxList[e.Row];
     DialogResult   = DialogResult.OK;
 }
Пример #25
0
        private void FillGridInterventions()
        {
            gridInterventions.BeginUpdate();
            gridInterventions.Columns.Clear();
            gridInterventions.Columns.Add(new ODGridColumn("Date", 70));
            gridInterventions.Columns.Add(new ODGridColumn("Type", 150));
            gridInterventions.Columns.Add(new ODGridColumn("Description", 160));
            gridInterventions.Columns.Add(new ODGridColumn("Declined", 60)
            {
                TextAlign = HorizontalAlignment.Center
            });
            gridInterventions.Columns.Add(new ODGridColumn("Documentation", 140));
            gridInterventions.Rows.Clear();
            //build list of rows of CessationInterventions and CessationMedications so we can order the list by date and type before filling the grid
            List <ODGridRow> listRows = new List <ODGridRow>();
            ODGridRow        row;

            #region CessationInterventions
            List <Intervention> listInterventions = Interventions.Refresh(PatCur.PatNum, InterventionCodeSet.TobaccoCessation);
            foreach (Intervention iCur in listInterventions)
            {
                row = new ODGridRow();
                row.Cells.Add(iCur.DateEntry.ToShortDateString());
                string type     = InterventionCodeSet.TobaccoCessation.ToString() + " Counseling";
                string descript = "";
                switch (iCur.CodeSystem)
                {
                case "CPT":
                    Cpt cptCur = Cpts.GetByCode(iCur.CodeValue);
                    descript = cptCur != null?cptCur.Description:"";
                    break;

                case "SNOMEDCT":
                    Snomed sCur = Snomeds.GetByCode(iCur.CodeValue);
                    descript = sCur != null?sCur.Description:"";
                    break;

                case "RXNORM":
                    //if the user checks the "Patient Declined" checkbox, we enter the tobacco cessation medication as an intervention that was declined
                    type = InterventionCodeSet.TobaccoCessation.ToString() + " Medication";
                    RxNorm rCur = RxNorms.GetByRxCUI(iCur.CodeValue);
                    descript = rCur != null?rCur.Description:"";
                    break;
                }
                row.Cells.Add(type);
                row.Cells.Add(descript);
                row.Cells.Add(iCur.IsPatDeclined?"X":"");
                row.Cells.Add(iCur.Note);
                row.Tag = iCur;
                listRows.Add(row);
            }
            #endregion
            #region CessationMedications
            //Tobacco Use Cessation Pharmacotherapy Value Set
            string[] arrayRxCuiStrings = EhrCodes.GetForValueSetOIDs(new List <string> {
                "2.16.840.1.113883.3.526.3.1190"
            }, true)
                                         .Select(x => x.CodeValue).ToArray();
            //arrayRxCuiStrings will contain 41 RxCui strings for tobacco cessation medications if those exist in the rxnorm table
            List <MedicationPat> listMedPats = MedicationPats.Refresh(PatCur.PatNum, true).FindAll(x => arrayRxCuiStrings.Contains(x.RxCui.ToString()));
            foreach (MedicationPat medPatCur in listMedPats)
            {
                row = new ODGridRow();
                List <string> listMedDates = new List <string>();
                if (medPatCur.DateStart.Year > 1880)
                {
                    listMedDates.Add(medPatCur.DateStart.ToShortDateString());
                }
                if (medPatCur.DateStop.Year > 1880)
                {
                    listMedDates.Add(medPatCur.DateStop.ToShortDateString());
                }
                if (listMedDates.Count == 0)
                {
                    listMedDates.Add(medPatCur.DateTStamp.ToShortDateString());
                }
                row.Cells.Add(string.Join(" - ", listMedDates));
                row.Cells.Add(InterventionCodeSet.TobaccoCessation.ToString() + " Medication");
                row.Cells.Add(RxNorms.GetDescByRxCui(medPatCur.RxCui.ToString()));
                row.Cells.Add(medPatCur.PatNote);
                row.Tag = medPatCur;
                listRows.Add(row);
            }
            #endregion
            listRows.OrderBy(x => PIn.Date(x.Cells[0].Text))            //rows ordered by date, oldest first
            .ThenBy(x => x.Cells[3].Text != "")
            //interventions at the top, declined med interventions below normal interventions
            .ThenBy(x => x.Tag.GetType().Name != "Intervention" || ((Intervention)x.Tag).CodeSystem == "RXNORM").ToList()
            .ForEach(x => gridInterventions.Rows.Add(x));                    //then add rows to gridInterventions
            gridInterventions.EndUpdate();
        }
Пример #26
0
 ///<summary>Inserts one RxNorm into the database.  Returns the new priKey.</summary>
 public static long Insert(RxNorm rxNorm)
 {
     return(Insert(rxNorm, false));
 }