///<summary>Inserts one FHIRContactPoint into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(FHIRContactPoint fHIRContactPoint, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                fHIRContactPoint.FHIRContactPointNum = ReplicationServers.GetKey("fhircontactpoint", "FHIRContactPointNum");
            }
            string command = "INSERT INTO fhircontactpoint (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "FHIRContactPointNum,";
            }
            command += "FHIRSubscriptionNum,ContactSystem,ContactValue,ContactUse,ItemOrder,DateStart,DateEnd) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(fHIRContactPoint.FHIRContactPointNum) + ",";
            }
            command +=
                POut.Long(fHIRContactPoint.FHIRSubscriptionNum) + ","
                + POut.Int((int)fHIRContactPoint.ContactSystem) + ","
                + "'" + POut.String(fHIRContactPoint.ContactValue) + "',"
                + POut.Int((int)fHIRContactPoint.ContactUse) + ","
                + POut.Int(fHIRContactPoint.ItemOrder) + ","
                + POut.Date(fHIRContactPoint.DateStart) + ","
                + POut.Date(fHIRContactPoint.DateEnd) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                fHIRContactPoint.FHIRContactPointNum = Db.NonQ(command, true, "FHIRContactPointNum", "fHIRContactPoint");
            }
            return(fHIRContactPoint.FHIRContactPointNum);
        }
 ///<summary>Returns true if Update(FHIRContactPoint,FHIRContactPoint) 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(FHIRContactPoint fHIRContactPoint, FHIRContactPoint oldFHIRContactPoint)
 {
     if (fHIRContactPoint.FHIRSubscriptionNum != oldFHIRContactPoint.FHIRSubscriptionNum)
     {
         return(true);
     }
     if (fHIRContactPoint.ContactSystem != oldFHIRContactPoint.ContactSystem)
     {
         return(true);
     }
     if (fHIRContactPoint.ContactValue != oldFHIRContactPoint.ContactValue)
     {
         return(true);
     }
     if (fHIRContactPoint.ContactUse != oldFHIRContactPoint.ContactUse)
     {
         return(true);
     }
     if (fHIRContactPoint.ItemOrder != oldFHIRContactPoint.ItemOrder)
     {
         return(true);
     }
     if (fHIRContactPoint.DateStart.Date != oldFHIRContactPoint.DateStart.Date)
     {
         return(true);
     }
     if (fHIRContactPoint.DateEnd.Date != oldFHIRContactPoint.DateEnd.Date)
     {
         return(true);
     }
     return(false);
 }
 ///<summary>Inserts one FHIRContactPoint into the database.  Returns the new priKey.</summary>
 public static long Insert(FHIRContactPoint fHIRContactPoint)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         fHIRContactPoint.FHIRContactPointNum = DbHelper.GetNextOracleKey("fhircontactpoint", "FHIRContactPointNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(fHIRContactPoint, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     fHIRContactPoint.FHIRContactPointNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(fHIRContactPoint, false));
     }
 }
        ///<summary>Updates one FHIRContactPoint in the database.</summary>
        public static void Update(FHIRContactPoint fHIRContactPoint)
        {
            string command = "UPDATE fhircontactpoint SET "
                             + "FHIRSubscriptionNum=  " + POut.Long(fHIRContactPoint.FHIRSubscriptionNum) + ", "
                             + "ContactSystem      =  " + POut.Int((int)fHIRContactPoint.ContactSystem) + ", "
                             + "ContactValue       = '" + POut.String(fHIRContactPoint.ContactValue) + "', "
                             + "ContactUse         =  " + POut.Int((int)fHIRContactPoint.ContactUse) + ", "
                             + "ItemOrder          =  " + POut.Int(fHIRContactPoint.ItemOrder) + ", "
                             + "DateStart          =  " + POut.Date(fHIRContactPoint.DateStart) + ", "
                             + "DateEnd            =  " + POut.Date(fHIRContactPoint.DateEnd) + " "
                             + "WHERE FHIRContactPointNum = " + POut.Long(fHIRContactPoint.FHIRContactPointNum);

            Db.NonQ(command);
        }
 ///<summary>Inserts one FHIRContactPoint into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FHIRContactPoint fHIRContactPoint)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(fHIRContactPoint, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             fHIRContactPoint.FHIRContactPointNum = DbHelper.GetNextOracleKey("fhircontactpoint", "FHIRContactPointNum");                  //Cacheless method
         }
         return(InsertNoCache(fHIRContactPoint, true));
     }
 }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <FHIRContactPoint> TableToList(DataTable table)
        {
            List <FHIRContactPoint> retVal = new List <FHIRContactPoint>();
            FHIRContactPoint        fHIRContactPoint;

            foreach (DataRow row in table.Rows)
            {
                fHIRContactPoint = new FHIRContactPoint();
                fHIRContactPoint.FHIRContactPointNum = PIn.Long(row["FHIRContactPointNum"].ToString());
                fHIRContactPoint.FHIRSubscriptionNum = PIn.Long(row["FHIRSubscriptionNum"].ToString());
                fHIRContactPoint.ContactSystem       = (OpenDentBusiness.ContactPointSystem)PIn.Int(row["ContactSystem"].ToString());
                fHIRContactPoint.ContactValue        = PIn.String(row["ContactValue"].ToString());
                fHIRContactPoint.ContactUse          = (OpenDentBusiness.ContactPointUse)PIn.Int(row["ContactUse"].ToString());
                fHIRContactPoint.ItemOrder           = PIn.Int(row["ItemOrder"].ToString());
                fHIRContactPoint.DateStart           = PIn.Date(row["DateStart"].ToString());
                fHIRContactPoint.DateEnd             = PIn.Date(row["DateEnd"].ToString());
                retVal.Add(fHIRContactPoint);
            }
            return(retVal);
        }
        ///<summary>Updates one FHIRContactPoint 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(FHIRContactPoint fHIRContactPoint, FHIRContactPoint oldFHIRContactPoint)
        {
            string command = "";

            if (fHIRContactPoint.FHIRSubscriptionNum != oldFHIRContactPoint.FHIRSubscriptionNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FHIRSubscriptionNum = " + POut.Long(fHIRContactPoint.FHIRSubscriptionNum) + "";
            }
            if (fHIRContactPoint.ContactSystem != oldFHIRContactPoint.ContactSystem)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ContactSystem = " + POut.Int((int)fHIRContactPoint.ContactSystem) + "";
            }
            if (fHIRContactPoint.ContactValue != oldFHIRContactPoint.ContactValue)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ContactValue = '" + POut.String(fHIRContactPoint.ContactValue) + "'";
            }
            if (fHIRContactPoint.ContactUse != oldFHIRContactPoint.ContactUse)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ContactUse = " + POut.Int((int)fHIRContactPoint.ContactUse) + "";
            }
            if (fHIRContactPoint.ItemOrder != oldFHIRContactPoint.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(fHIRContactPoint.ItemOrder) + "";
            }
            if (fHIRContactPoint.DateStart.Date != oldFHIRContactPoint.DateStart.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateStart = " + POut.Date(fHIRContactPoint.DateStart) + "";
            }
            if (fHIRContactPoint.DateEnd.Date != oldFHIRContactPoint.DateEnd.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateEnd = " + POut.Date(fHIRContactPoint.DateEnd) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE fhircontactpoint SET " + command
                      + " WHERE FHIRContactPointNum = " + POut.Long(fHIRContactPoint.FHIRContactPointNum);
            Db.NonQ(command);
            return(true);
        }
 ///<summary>Inserts one FHIRContactPoint into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FHIRContactPoint fHIRContactPoint)
 {
     return(InsertNoCache(fHIRContactPoint, false));
 }