///<summary>Inserts one EhrLabSpecimen into the database. Returns the new priKey.</summary> public static long Insert(EhrLabSpecimen ehrLabSpecimen) { if (DataConnection.DBtype == DatabaseType.Oracle) { ehrLabSpecimen.EhrLabSpecimenNum = DbHelper.GetNextOracleKey("ehrlabspecimen", "EhrLabSpecimenNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(ehrLabSpecimen, true)); } catch (Oracle.ManagedDataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { ehrLabSpecimen.EhrLabSpecimenNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(ehrLabSpecimen, false)); } }
///<summary>Inserts one EhrLabSpecimen into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(EhrLabSpecimen ehrLabSpecimen) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(ehrLabSpecimen, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { ehrLabSpecimen.EhrLabSpecimenNum = DbHelper.GetNextOracleKey("ehrlabspecimen", "EhrLabSpecimenNum"); //Cacheless method } return(InsertNoCache(ehrLabSpecimen, true)); } }
///<summary>Returns true if Update(EhrLabSpecimen,EhrLabSpecimen) 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(EhrLabSpecimen ehrLabSpecimen, EhrLabSpecimen oldEhrLabSpecimen) { if (ehrLabSpecimen.EhrLabNum != oldEhrLabSpecimen.EhrLabNum) { return(true); } if (ehrLabSpecimen.SetIdSPM != oldEhrLabSpecimen.SetIdSPM) { return(true); } if (ehrLabSpecimen.SpecimenTypeID != oldEhrLabSpecimen.SpecimenTypeID) { return(true); } if (ehrLabSpecimen.SpecimenTypeText != oldEhrLabSpecimen.SpecimenTypeText) { return(true); } if (ehrLabSpecimen.SpecimenTypeCodeSystemName != oldEhrLabSpecimen.SpecimenTypeCodeSystemName) { return(true); } if (ehrLabSpecimen.SpecimenTypeIDAlt != oldEhrLabSpecimen.SpecimenTypeIDAlt) { return(true); } if (ehrLabSpecimen.SpecimenTypeTextAlt != oldEhrLabSpecimen.SpecimenTypeTextAlt) { return(true); } if (ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt != oldEhrLabSpecimen.SpecimenTypeCodeSystemNameAlt) { return(true); } if (ehrLabSpecimen.SpecimenTypeTextOriginal != oldEhrLabSpecimen.SpecimenTypeTextOriginal) { return(true); } if (ehrLabSpecimen.CollectionDateTimeStart != oldEhrLabSpecimen.CollectionDateTimeStart) { return(true); } if (ehrLabSpecimen.CollectionDateTimeEnd != oldEhrLabSpecimen.CollectionDateTimeEnd) { return(true); } return(false); }
///<summary>Updates one EhrLabSpecimen in the database.</summary> public static void Update(EhrLabSpecimen ehrLabSpecimen) { string command = "UPDATE ehrlabspecimen SET " + "EhrLabNum = " + POut.Long(ehrLabSpecimen.EhrLabNum) + ", " + "SetIdSPM = " + POut.Long(ehrLabSpecimen.SetIdSPM) + ", " + "SpecimenTypeID = '" + POut.String(ehrLabSpecimen.SpecimenTypeID) + "', " + "SpecimenTypeText = '" + POut.String(ehrLabSpecimen.SpecimenTypeText) + "', " + "SpecimenTypeCodeSystemName = '" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName) + "', " + "SpecimenTypeIDAlt = '" + POut.String(ehrLabSpecimen.SpecimenTypeIDAlt) + "', " + "SpecimenTypeTextAlt = '" + POut.String(ehrLabSpecimen.SpecimenTypeTextAlt) + "', " + "SpecimenTypeCodeSystemNameAlt= '" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt) + "', " + "SpecimenTypeTextOriginal = '" + POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal) + "', " + "CollectionDateTimeStart = '" + POut.String(ehrLabSpecimen.CollectionDateTimeStart) + "', " + "CollectionDateTimeEnd = '" + POut.String(ehrLabSpecimen.CollectionDateTimeEnd) + "' " + "WHERE EhrLabSpecimenNum = " + POut.Long(ehrLabSpecimen.EhrLabSpecimenNum); Db.NonQ(command); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<EhrLabSpecimen> TableToList(DataTable table){ List<EhrLabSpecimen> retVal=new List<EhrLabSpecimen>(); EhrLabSpecimen ehrLabSpecimen; for(int i=0;i<table.Rows.Count;i++) { ehrLabSpecimen=new EhrLabSpecimen(); ehrLabSpecimen.EhrLabSpecimenNum = PIn.Long (table.Rows[i]["EhrLabSpecimenNum"].ToString()); ehrLabSpecimen.EhrLabNum = PIn.Long (table.Rows[i]["EhrLabNum"].ToString()); ehrLabSpecimen.SetIdSPM = PIn.Long (table.Rows[i]["SetIdSPM"].ToString()); ehrLabSpecimen.SpecimenTypeID = PIn.String(table.Rows[i]["SpecimenTypeID"].ToString()); ehrLabSpecimen.SpecimenTypeText = PIn.String(table.Rows[i]["SpecimenTypeText"].ToString()); ehrLabSpecimen.SpecimenTypeCodeSystemName = PIn.String(table.Rows[i]["SpecimenTypeCodeSystemName"].ToString()); ehrLabSpecimen.SpecimenTypeIDAlt = PIn.String(table.Rows[i]["SpecimenTypeIDAlt"].ToString()); ehrLabSpecimen.SpecimenTypeTextAlt = PIn.String(table.Rows[i]["SpecimenTypeTextAlt"].ToString()); ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt= PIn.String(table.Rows[i]["SpecimenTypeCodeSystemNameAlt"].ToString()); ehrLabSpecimen.SpecimenTypeTextOriginal = PIn.String(table.Rows[i]["SpecimenTypeTextOriginal"].ToString()); ehrLabSpecimen.CollectionDateTimeStart = PIn.String(table.Rows[i]["CollectionDateTimeStart"].ToString()); ehrLabSpecimen.CollectionDateTimeEnd = PIn.String(table.Rows[i]["CollectionDateTimeEnd"].ToString()); retVal.Add(ehrLabSpecimen); } return retVal; }
///<summary>Inserts one EhrLabSpecimen into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(EhrLabSpecimen ehrLabSpecimen, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO ehrlabspecimen ("; if (!useExistingPK && isRandomKeys) { ehrLabSpecimen.EhrLabSpecimenNum = ReplicationServers.GetKeyNoCache("ehrlabspecimen", "EhrLabSpecimenNum"); } if (isRandomKeys || useExistingPK) { command += "EhrLabSpecimenNum,"; } command += "EhrLabNum,SetIdSPM,SpecimenTypeID,SpecimenTypeText,SpecimenTypeCodeSystemName,SpecimenTypeIDAlt,SpecimenTypeTextAlt,SpecimenTypeCodeSystemNameAlt,SpecimenTypeTextOriginal,CollectionDateTimeStart,CollectionDateTimeEnd) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(ehrLabSpecimen.EhrLabSpecimenNum) + ","; } command += POut.Long(ehrLabSpecimen.EhrLabNum) + "," + POut.Long(ehrLabSpecimen.SetIdSPM) + "," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeID) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeText) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeIDAlt) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeTextAlt) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt) + "'," + "'" + POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal) + "'," + "'" + POut.String(ehrLabSpecimen.CollectionDateTimeStart) + "'," + "'" + POut.String(ehrLabSpecimen.CollectionDateTimeEnd) + "')"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { ehrLabSpecimen.EhrLabSpecimenNum = Db.NonQ(command, true, "EhrLabSpecimenNum", "ehrLabSpecimen"); } return(ehrLabSpecimen.EhrLabSpecimenNum); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <EhrLabSpecimen> TableToList(DataTable table) { List <EhrLabSpecimen> retVal = new List <EhrLabSpecimen>(); EhrLabSpecimen ehrLabSpecimen; foreach (DataRow row in table.Rows) { ehrLabSpecimen = new EhrLabSpecimen(); ehrLabSpecimen.EhrLabSpecimenNum = PIn.Long(row["EhrLabSpecimenNum"].ToString()); ehrLabSpecimen.EhrLabNum = PIn.Long(row["EhrLabNum"].ToString()); ehrLabSpecimen.SetIdSPM = PIn.Long(row["SetIdSPM"].ToString()); ehrLabSpecimen.SpecimenTypeID = PIn.String(row["SpecimenTypeID"].ToString()); ehrLabSpecimen.SpecimenTypeText = PIn.String(row["SpecimenTypeText"].ToString()); ehrLabSpecimen.SpecimenTypeCodeSystemName = PIn.String(row["SpecimenTypeCodeSystemName"].ToString()); ehrLabSpecimen.SpecimenTypeIDAlt = PIn.String(row["SpecimenTypeIDAlt"].ToString()); ehrLabSpecimen.SpecimenTypeTextAlt = PIn.String(row["SpecimenTypeTextAlt"].ToString()); ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt = PIn.String(row["SpecimenTypeCodeSystemNameAlt"].ToString()); ehrLabSpecimen.SpecimenTypeTextOriginal = PIn.String(row["SpecimenTypeTextOriginal"].ToString()); ehrLabSpecimen.CollectionDateTimeStart = PIn.String(row["CollectionDateTimeStart"].ToString()); ehrLabSpecimen.CollectionDateTimeEnd = PIn.String(row["CollectionDateTimeEnd"].ToString()); retVal.Add(ehrLabSpecimen); } return(retVal); }
///<summary>Inserts one EhrLabSpecimen into the database. Returns the new priKey.</summary> public static long Insert(EhrLabSpecimen ehrLabSpecimen){ if(DataConnection.DBtype==DatabaseType.Oracle) { ehrLabSpecimen.EhrLabSpecimenNum=DbHelper.GetNextOracleKey("ehrlabspecimen","EhrLabSpecimenNum"); int loopcount=0; while(loopcount<100){ try { return Insert(ehrLabSpecimen,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ ehrLabSpecimen.EhrLabSpecimenNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(ehrLabSpecimen,false); } }
///<summary>Updates one EhrLabSpecimen 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(EhrLabSpecimen ehrLabSpecimen, EhrLabSpecimen oldEhrLabSpecimen) { string command = ""; if (ehrLabSpecimen.EhrLabNum != oldEhrLabSpecimen.EhrLabNum) { if (command != "") { command += ","; } command += "EhrLabNum = " + POut.Long(ehrLabSpecimen.EhrLabNum) + ""; } if (ehrLabSpecimen.SetIdSPM != oldEhrLabSpecimen.SetIdSPM) { if (command != "") { command += ","; } command += "SetIdSPM = " + POut.Long(ehrLabSpecimen.SetIdSPM) + ""; } if (ehrLabSpecimen.SpecimenTypeID != oldEhrLabSpecimen.SpecimenTypeID) { if (command != "") { command += ","; } command += "SpecimenTypeID = '" + POut.String(ehrLabSpecimen.SpecimenTypeID) + "'"; } if (ehrLabSpecimen.SpecimenTypeText != oldEhrLabSpecimen.SpecimenTypeText) { if (command != "") { command += ","; } command += "SpecimenTypeText = '" + POut.String(ehrLabSpecimen.SpecimenTypeText) + "'"; } if (ehrLabSpecimen.SpecimenTypeCodeSystemName != oldEhrLabSpecimen.SpecimenTypeCodeSystemName) { if (command != "") { command += ","; } command += "SpecimenTypeCodeSystemName = '" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName) + "'"; } if (ehrLabSpecimen.SpecimenTypeIDAlt != oldEhrLabSpecimen.SpecimenTypeIDAlt) { if (command != "") { command += ","; } command += "SpecimenTypeIDAlt = '" + POut.String(ehrLabSpecimen.SpecimenTypeIDAlt) + "'"; } if (ehrLabSpecimen.SpecimenTypeTextAlt != oldEhrLabSpecimen.SpecimenTypeTextAlt) { if (command != "") { command += ","; } command += "SpecimenTypeTextAlt = '" + POut.String(ehrLabSpecimen.SpecimenTypeTextAlt) + "'"; } if (ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt != oldEhrLabSpecimen.SpecimenTypeCodeSystemNameAlt) { if (command != "") { command += ","; } command += "SpecimenTypeCodeSystemNameAlt = '" + POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt) + "'"; } if (ehrLabSpecimen.SpecimenTypeTextOriginal != oldEhrLabSpecimen.SpecimenTypeTextOriginal) { if (command != "") { command += ","; } command += "SpecimenTypeTextOriginal = '" + POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal) + "'"; } if (ehrLabSpecimen.CollectionDateTimeStart != oldEhrLabSpecimen.CollectionDateTimeStart) { if (command != "") { command += ","; } command += "CollectionDateTimeStart = '" + POut.String(ehrLabSpecimen.CollectionDateTimeStart) + "'"; } if (ehrLabSpecimen.CollectionDateTimeEnd != oldEhrLabSpecimen.CollectionDateTimeEnd) { if (command != "") { command += ","; } command += "CollectionDateTimeEnd = '" + POut.String(ehrLabSpecimen.CollectionDateTimeEnd) + "'"; } if (command == "") { return(false); } command = "UPDATE ehrlabspecimen SET " + command + " WHERE EhrLabSpecimenNum = " + POut.Long(ehrLabSpecimen.EhrLabSpecimenNum); Db.NonQ(command); return(true); }
///<summary>Inserts one EhrLabSpecimen into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(EhrLabSpecimen ehrLabSpecimen) { return(InsertNoCache(ehrLabSpecimen, false)); }
///<summary>Inserts one EhrLabSpecimen into the database. Provides option to use the existing priKey.</summary> public static long Insert(EhrLabSpecimen ehrLabSpecimen,bool useExistingPK){ if(!useExistingPK && PrefC.RandomKeys) { ehrLabSpecimen.EhrLabSpecimenNum=ReplicationServers.GetKey("ehrlabspecimen","EhrLabSpecimenNum"); } string command="INSERT INTO ehrlabspecimen ("; if(useExistingPK || PrefC.RandomKeys) { command+="EhrLabSpecimenNum,"; } command+="EhrLabNum,SetIdSPM,SpecimenTypeID,SpecimenTypeText,SpecimenTypeCodeSystemName,SpecimenTypeIDAlt,SpecimenTypeTextAlt,SpecimenTypeCodeSystemNameAlt,SpecimenTypeTextOriginal,CollectionDateTimeStart,CollectionDateTimeEnd) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(ehrLabSpecimen.EhrLabSpecimenNum)+","; } command+= POut.Long (ehrLabSpecimen.EhrLabNum)+"," + POut.Long (ehrLabSpecimen.SetIdSPM)+"," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeID)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeText)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeIDAlt)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeTextAlt)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt)+"'," +"'"+POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal)+"'," +"'"+POut.String(ehrLabSpecimen.CollectionDateTimeStart)+"'," +"'"+POut.String(ehrLabSpecimen.CollectionDateTimeEnd)+"')"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { ehrLabSpecimen.EhrLabSpecimenNum=Db.NonQ(command,true); } return ehrLabSpecimen.EhrLabSpecimenNum; }
///<summary>Updates one EhrLabSpecimen 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(EhrLabSpecimen ehrLabSpecimen,EhrLabSpecimen oldEhrLabSpecimen){ string command=""; if(ehrLabSpecimen.EhrLabNum != oldEhrLabSpecimen.EhrLabNum) { if(command!=""){ command+=",";} command+="EhrLabNum = "+POut.Long(ehrLabSpecimen.EhrLabNum)+""; } if(ehrLabSpecimen.SetIdSPM != oldEhrLabSpecimen.SetIdSPM) { if(command!=""){ command+=",";} command+="SetIdSPM = "+POut.Long(ehrLabSpecimen.SetIdSPM)+""; } if(ehrLabSpecimen.SpecimenTypeID != oldEhrLabSpecimen.SpecimenTypeID) { if(command!=""){ command+=",";} command+="SpecimenTypeID = '"+POut.String(ehrLabSpecimen.SpecimenTypeID)+"'"; } if(ehrLabSpecimen.SpecimenTypeText != oldEhrLabSpecimen.SpecimenTypeText) { if(command!=""){ command+=",";} command+="SpecimenTypeText = '"+POut.String(ehrLabSpecimen.SpecimenTypeText)+"'"; } if(ehrLabSpecimen.SpecimenTypeCodeSystemName != oldEhrLabSpecimen.SpecimenTypeCodeSystemName) { if(command!=""){ command+=",";} command+="SpecimenTypeCodeSystemName = '"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName)+"'"; } if(ehrLabSpecimen.SpecimenTypeIDAlt != oldEhrLabSpecimen.SpecimenTypeIDAlt) { if(command!=""){ command+=",";} command+="SpecimenTypeIDAlt = '"+POut.String(ehrLabSpecimen.SpecimenTypeIDAlt)+"'"; } if(ehrLabSpecimen.SpecimenTypeTextAlt != oldEhrLabSpecimen.SpecimenTypeTextAlt) { if(command!=""){ command+=",";} command+="SpecimenTypeTextAlt = '"+POut.String(ehrLabSpecimen.SpecimenTypeTextAlt)+"'"; } if(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt != oldEhrLabSpecimen.SpecimenTypeCodeSystemNameAlt) { if(command!=""){ command+=",";} command+="SpecimenTypeCodeSystemNameAlt = '"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt)+"'"; } if(ehrLabSpecimen.SpecimenTypeTextOriginal != oldEhrLabSpecimen.SpecimenTypeTextOriginal) { if(command!=""){ command+=",";} command+="SpecimenTypeTextOriginal = '"+POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal)+"'"; } if(ehrLabSpecimen.CollectionDateTimeStart != oldEhrLabSpecimen.CollectionDateTimeStart) { if(command!=""){ command+=",";} command+="CollectionDateTimeStart = '"+POut.String(ehrLabSpecimen.CollectionDateTimeStart)+"'"; } if(ehrLabSpecimen.CollectionDateTimeEnd != oldEhrLabSpecimen.CollectionDateTimeEnd) { if(command!=""){ command+=",";} command+="CollectionDateTimeEnd = '"+POut.String(ehrLabSpecimen.CollectionDateTimeEnd)+"'"; } if(command==""){ return false; } command="UPDATE ehrlabspecimen SET "+command +" WHERE EhrLabSpecimenNum = "+POut.Long(ehrLabSpecimen.EhrLabSpecimenNum); Db.NonQ(command); return true; }
///<summary>Updates one EhrLabSpecimen in the database.</summary> public static void Update(EhrLabSpecimen ehrLabSpecimen){ string command="UPDATE ehrlabspecimen SET " +"EhrLabNum = "+POut.Long (ehrLabSpecimen.EhrLabNum)+", " +"SetIdSPM = "+POut.Long (ehrLabSpecimen.SetIdSPM)+", " +"SpecimenTypeID = '"+POut.String(ehrLabSpecimen.SpecimenTypeID)+"', " +"SpecimenTypeText = '"+POut.String(ehrLabSpecimen.SpecimenTypeText)+"', " +"SpecimenTypeCodeSystemName = '"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemName)+"', " +"SpecimenTypeIDAlt = '"+POut.String(ehrLabSpecimen.SpecimenTypeIDAlt)+"', " +"SpecimenTypeTextAlt = '"+POut.String(ehrLabSpecimen.SpecimenTypeTextAlt)+"', " +"SpecimenTypeCodeSystemNameAlt= '"+POut.String(ehrLabSpecimen.SpecimenTypeCodeSystemNameAlt)+"', " +"SpecimenTypeTextOriginal = '"+POut.String(ehrLabSpecimen.SpecimenTypeTextOriginal)+"', " +"CollectionDateTimeStart = '"+POut.String(ehrLabSpecimen.CollectionDateTimeStart)+"', " +"CollectionDateTimeEnd = '"+POut.String(ehrLabSpecimen.CollectionDateTimeEnd)+"' " +"WHERE EhrLabSpecimenNum = "+POut.Long(ehrLabSpecimen.EhrLabSpecimenNum); Db.NonQ(command); }