Example #1
0
 ///<summary>Inserts one Commlog into the database.  Returns the new priKey.</summary>
 public static long Insert(Commlog commlog)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         commlog.CommlogNum = DbHelper.GetNextOracleKey("commlog", "CommlogNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(commlog, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     commlog.CommlogNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(commlog, false));
     }
 }
Example #2
0
        ///<summary>Updates one Commlog in the database.</summary>
        public static void Update(Commlog commlog)
        {
            string command = "UPDATE commlog SET "
                             + "PatNum        =  " + POut.Long(commlog.PatNum) + ", "
                             + "CommDateTime  =  " + POut.DateT(commlog.CommDateTime) + ", "
                             + "CommType      =  " + POut.Long(commlog.CommType) + ", "
                             + "Note          =  " + DbHelper.ParamChar + "paramNote, "
                             + "Mode_         =  " + POut.Int((int)commlog.Mode_) + ", "
                             + "SentOrReceived=  " + POut.Int((int)commlog.SentOrReceived) + ", "
                             + "UserNum       =  " + POut.Long(commlog.UserNum) + ", "
                             + "Signature     =  " + DbHelper.ParamChar + "paramSignature, "
                             + "SigIsTopaz    =  " + POut.Bool(commlog.SigIsTopaz) + ", "
                             //DateTStamp can only be set by MySQL
                             + "DateTimeEnd   =  " + POut.DateT(commlog.DateTimeEnd) + ", "
                             + "CommSource    =  " + POut.Int((int)commlog.CommSource) + ", "
                             + "ProgramNum    =  " + POut.Long(commlog.ProgramNum) + " "
                             + "WHERE CommlogNum = " + POut.Long(commlog.CommlogNum);

            if (commlog.Note == null)
            {
                commlog.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringNote(commlog.Note));

            if (commlog.Signature == null)
            {
                commlog.Signature = "";
            }
            OdSqlParameter paramSignature = new OdSqlParameter("paramSignature", OdDbType.Text, POut.StringParam(commlog.Signature));

            Db.NonQ(command, paramNote, paramSignature);
        }
Example #3
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <Commlog> TableToList(DataTable table)
        {
            List <Commlog> retVal = new List <Commlog>();
            Commlog        commlog;

            foreach (DataRow row in table.Rows)
            {
                commlog                = new Commlog();
                commlog.CommlogNum     = PIn.Long(row["CommlogNum"].ToString());
                commlog.PatNum         = PIn.Long(row["PatNum"].ToString());
                commlog.CommDateTime   = PIn.DateT(row["CommDateTime"].ToString());
                commlog.CommType       = PIn.Long(row["CommType"].ToString());
                commlog.Note           = PIn.String(row["Note"].ToString());
                commlog.Mode_          = (OpenDentBusiness.CommItemMode)PIn.Int(row["Mode_"].ToString());
                commlog.SentOrReceived = (OpenDentBusiness.CommSentOrReceived)PIn.Int(row["SentOrReceived"].ToString());
                commlog.UserNum        = PIn.Long(row["UserNum"].ToString());
                commlog.Signature      = PIn.String(row["Signature"].ToString());
                commlog.SigIsTopaz     = PIn.Bool(row["SigIsTopaz"].ToString());
                commlog.DateTStamp     = PIn.DateT(row["DateTStamp"].ToString());
                commlog.DateTimeEnd    = PIn.DateT(row["DateTimeEnd"].ToString());
                commlog.CommSource     = (OpenDentBusiness.CommItemSource)PIn.Int(row["CommSource"].ToString());
                commlog.ProgramNum     = PIn.Long(row["ProgramNum"].ToString());
                retVal.Add(commlog);
            }
            return(retVal);
        }
Example #4
0
 ///<summary>Inserts one Commlog into the database.  Returns the new priKey.</summary>
 internal static long Insert(Commlog commlog)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         commlog.CommlogNum=DbHelper.GetNextOracleKey("commlog","CommlogNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(commlog,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     commlog.CommlogNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(commlog,false);
     }
 }
Example #5
0
        ///<summary>Sends text message to callfire.  If patNum=0 will not create commlog entry.</summary>
        private bool SendCallFire(long patNum, string wirelessPhone, string message)
        {
            string key = ProgramProperties.GetPropVal(ProgramName.CallFire, "Key From CallFire");
            string msg = wirelessPhone + "," + message.Replace(",", "");     //ph#,msg Commas in msg cause error.

            try {
                CallFireService.SMSService callFire = new CallFireService.SMSService();
                callFire.sendSMSCampaign(
                    key,
                    new string[] { msg },
                    "Open Dental");
            }
            catch (Exception ex) {
                MsgBox.Show(this, "Error sending text message.\r\n\r\n" + ex.Message);
                return(false);
            }
            if (patNum == 0)             //No patient selected, do not make commlog.
            {
                return(true);
            }
            Commlog commlog = new Commlog();

            commlog.CommDateTime   = DateTime.Now;
            commlog.DateTStamp     = DateTime.Now;
            commlog.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.TEXT);
            commlog.Mode_          = CommItemMode.Text;
            commlog.Note           = msg;//phone,note
            commlog.PatNum         = patNum;
            commlog.SentOrReceived = CommSentOrReceived.Sent;
            commlog.UserNum        = Security.CurUser.UserNum;
            commlog.DateTimeEnd    = DateTime.Now;
            Commlogs.Insert(commlog);
            SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, commlog.PatNum, "Insert Text Message");
            return(true);
        }
Example #6
0
 ///<summary>Inserts one Commlog into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(Commlog commlog,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         commlog.CommlogNum=ReplicationServers.GetKey("commlog","CommlogNum");
     }
     string command="INSERT INTO commlog (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="CommlogNum,";
     }
     command+="PatNum,CommDateTime,CommType,Note,Mode_,SentOrReceived,IsStatementSent,UserNum,Signature,SigIsTopaz,DateTimeEnd) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(commlog.CommlogNum)+",";
     }
     command+=
              POut.Long  (commlog.PatNum)+","
         +    POut.DateT (commlog.CommDateTime)+","
         +    POut.Long  (commlog.CommType)+","
         +"'"+POut.String(commlog.Note)+"',"
         +    POut.Int   ((int)commlog.Mode_)+","
         +    POut.Int   ((int)commlog.SentOrReceived)+","
         +    POut.Bool  (commlog.IsStatementSent)+","
         +    POut.Long  (commlog.UserNum)+","
         +"'"+POut.String(commlog.Signature)+"',"
         +    POut.Bool  (commlog.SigIsTopaz)+","
         //DateTStamp can only be set by MySQL
         +    POut.DateT (commlog.DateTimeEnd)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         commlog.CommlogNum=Db.NonQ(command,true);
     }
     return commlog.CommlogNum;
 }
Example #7
0
        public void Reactivations_GetReactivationList_PatientMarkedDoNotContact()
        {
            string  name    = MethodBase.GetCurrentMethod().Name;
            Clinic  clinic  = ClinicT.CreateClinic(name);
            long    provNum = ProviderT.CreateProvider(name);
            Patient pat     = PatientT.CreatePatient(name, provNum, clinic.ClinicNum, TestEmaiAddress, TestPatPhone, ContactMethod.Mail);
            //Patient has not been seen since further in the past than the ReactivationDaysPast preference.
            Procedure proc = ProcedureT.CreateProcedure(pat, "D0120", ProcStat.C, "", 50, procDate: DateTime.Now.AddYears(-3), provNum: provNum);   //3 year old proc
            //Patient has been contacted, and the ReactivationContactInterval has elapsed.
            Commlog comm = new Commlog()
            {
                PatNum         = pat.PatNum,
                CommDateTime   = DateTime.Now.AddYears(-1),
                CommType       = _reactivationCommLogType,
                Mode_          = CommItemMode.Email,
                SentOrReceived = CommSentOrReceived.Sent,
                CommSource     = CommItemSource.ApptReminder,
            };

            comm.CommlogNum = Commlogs.Insert(comm);
            //Patient has been marked "Do Not Contact"
            Reactivations.Insert(new Reactivation()
            {
                PatNum       = pat.PatNum,
                DoNotContact = true,
            });
            DateTime dateSince = DateTime.Today.AddDays(-PrefC.GetInt(PrefName.ReactivationDaysPast));
            DateTime dateStop  = dateSince.AddMonths(-36);
            //Confirm that the patient does not in the Reactivation List
            DataTable tbl = Reactivations.GetReactivationList(dateSince, dateStop, false, false, true, provNum, clinic.ClinicNum, 0, 0
                                                              , ReactivationListSort.LastContacted, RecallListShowNumberReminders.One);

            //No patients in the list
            Assert.AreEqual(0, tbl.Rows.Count);
        }
Example #8
0
        ///<summary></summary>
        public static void Insert(Commlog comm)
        {
            if (PrefB.RandomKeys)
            {
                comm.CommlogNum = MiscData.GetKey("commlog", "CommlogNum");
            }
            string command = "INSERT INTO commlog (";

            if (PrefB.RandomKeys)
            {
                command += "CommlogNum,";
            }
            command += "PatNum,CommDateTime,CommType,Note,Mode_,SentOrReceived,IsStatementSent) VALUES(";
            if (PrefB.RandomKeys)
            {
                command += "'" + POut.PInt(comm.CommlogNum) + "', ";
            }
            command +=
                "'" + POut.PInt(comm.PatNum) + "', "
                + POut.PDateT(comm.CommDateTime) + ", "
                + "'" + POut.PInt(comm.CommType) + "', "
                + "'" + POut.PString(comm.Note) + "', "
                + "'" + POut.PInt((int)comm.Mode_) + "', "
                + "'" + POut.PInt((int)comm.SentOrReceived) + "', "
                + "'" + POut.PBool(comm.IsStatementSent) + "')";
            if (PrefB.RandomKeys)
            {
                General.NonQ(command);
            }
            else
            {
                comm.CommlogNum = General.NonQ(command, true);
            }
        }
Example #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <Commlog> TableToList(DataTable table)
        {
            List <Commlog> retVal = new List <Commlog>();
            Commlog        commlog;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                commlog                 = new Commlog();
                commlog.CommlogNum      = PIn.Long(table.Rows[i]["CommlogNum"].ToString());
                commlog.PatNum          = PIn.Long(table.Rows[i]["PatNum"].ToString());
                commlog.CommDateTime    = PIn.DateT(table.Rows[i]["CommDateTime"].ToString());
                commlog.CommType        = PIn.Long(table.Rows[i]["CommType"].ToString());
                commlog.Note            = PIn.String(table.Rows[i]["Note"].ToString());
                commlog.Mode_           = (CommItemMode)PIn.Int(table.Rows[i]["Mode_"].ToString());
                commlog.SentOrReceived  = (CommSentOrReceived)PIn.Int(table.Rows[i]["SentOrReceived"].ToString());
                commlog.IsStatementSent = PIn.Bool(table.Rows[i]["IsStatementSent"].ToString());
                commlog.UserNum         = PIn.Long(table.Rows[i]["UserNum"].ToString());
                commlog.Signature       = PIn.String(table.Rows[i]["Signature"].ToString());
                commlog.SigIsTopaz      = PIn.Bool(table.Rows[i]["SigIsTopaz"].ToString());
                commlog.DateTStamp      = PIn.DateT(table.Rows[i]["DateTStamp"].ToString());
                commlog.DateTimeEnd     = PIn.DateT(table.Rows[i]["DateTimeEnd"].ToString());
                retVal.Add(commlog);
            }
            return(retVal);
        }
Example #10
0
        ///<summary>Used when printing recall cards to make a commlog entry for everyone at once.</summary>
        public static void InsertForRecallPostcard(int patNum)
        {
            int    recallType = Commlogs.GetTypeAuto(CommItemTypeAuto.RECALL);
            string command;

            if (recallType != 0)
            {
                command = "SELECT COUNT(*) FROM  commlog WHERE ";
                if (FormChooseDatabase.DBtype == DatabaseType.Oracle)
                {
                    command += "TO_DATE(CommDateTime) = " + POut.PDate(MiscData.GetNowDateTime());
                }
                else                  //Assume MySQL
                {
                    command += "DATE(CommDateTime) = CURDATE()";
                }
                command += " AND PatNum=" + POut.PInt(patNum) + " AND CommType=" + POut.PInt(recallType)
                           + " AND Mode_=2 AND SentOrReceived=1";
                if (General.GetCount(command) != "0")
                {
                    return;
                }
            }
            Commlog com = new Commlog();

            com.PatNum         = patNum;
            com.CommDateTime   = DateTime.Now;
            com.CommType       = recallType;
            com.Mode_          = CommItemMode.Mail;
            com.SentOrReceived = CommSentOrReceived.Sent;
            com.Note           = Lan.g("FormRecallList", "Sent recall postcard");
            Insert(com);
        }
Example #11
0
 public FormCommItem(Commlog commlog, bool isPersistent = false)
 {
     InitializeComponent();
     Lan.F(this);
     _isPersistent = isPersistent;
     _commlogCur   = commlog;
     _commlogOld   = commlog.Copy();
 }
Example #12
0
        /// <summary>May be called from other parts of the program without showing this form. You must still create an instance of this form though. Checks CallFire bridge, if it is OK to send a text, etc. (Buttons to load this form are usually  disabled if it is not OK, but this is needed for Confirmations, Recalls, etc.) </summary>
        public void SendText(long patNum, string wirelessPhone, string message, YN txtMsgOk)
        {
            if (Plugins.HookMethod(this, "FormTxtMsgEdit.SendText_Start", patNum, wirelessPhone, message, txtMsgOk))
            {
                return;
            }
            if (wirelessPhone == "")
            {
                MsgBox.Show(this, "Please enter a phone number.");
                return;
            }
            if (!Programs.IsEnabled(ProgramName.CallFire))
            {
                MsgBox.Show(this, "CallFire Program Link must be enabled.");
                return;
            }
            if (txtMsgOk == YN.Unknown && PrefC.GetBool(PrefName.TextMsgOkStatusTreatAsNo))
            {
                MsgBox.Show(this, "It is not OK to text this patient.");
                return;
            }
            if (txtMsgOk == YN.No)
            {
                MsgBox.Show(this, "It is not OK to text this patient.");
                return;
            }
            string key = ProgramProperties.GetPropVal(ProgramName.CallFire, "Key From CallFire");
            string msg = wirelessPhone + "," + message.Replace(",", "");     //ph#,msg Commas in msg cause error.

            try {
                CallFireService.SMSService callFire = new CallFireService.SMSService();
                callFire.sendSMSCampaign(
                    key,
                    new string[] { msg },
                    "Open Dental");
            }
            catch (Exception ex) {
                MsgBox.Show(this, "Error sending text message.\r\n\r\n" + ex.Message);
                return;
            }
            Commlog commlog = new Commlog();

            commlog.CommDateTime   = DateTime.Now;
            commlog.DateTStamp     = DateTime.Now;
            commlog.CommType       = DefC.Short[(int)DefCat.CommLogTypes][0].DefNum; //The first one in the list.  We can enhance later.
            commlog.Mode_          = CommItemMode.Text;
            commlog.Note           = msg;                                            //phone,note
            commlog.PatNum         = patNum;
            commlog.SentOrReceived = CommSentOrReceived.Sent;
            commlog.UserNum        = Security.CurUser.UserNum;
            commlog.DateTimeEnd    = DateTime.Now;
            Commlogs.Insert(commlog);
            SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, commlog.PatNum, "Insert Text Message");
        }
Example #13
0
        ///<summary>Inserts one Commlog into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(Commlog commlog, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO commlog (";

            if (!useExistingPK && isRandomKeys)
            {
                commlog.CommlogNum = ReplicationServers.GetKeyNoCache("commlog", "CommlogNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "CommlogNum,";
            }
            command += "PatNum,CommDateTime,CommType,Note,Mode_,SentOrReceived,UserNum,Signature,SigIsTopaz,DateTimeEnd,CommSource,ProgramNum) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(commlog.CommlogNum) + ",";
            }
            command +=
                POut.Long(commlog.PatNum) + ","
                + POut.DateT(commlog.CommDateTime) + ","
                + POut.Long(commlog.CommType) + ","
                + DbHelper.ParamChar + "paramNote,"
                + POut.Int((int)commlog.Mode_) + ","
                + POut.Int((int)commlog.SentOrReceived) + ","
                + POut.Long(commlog.UserNum) + ","
                + DbHelper.ParamChar + "paramSignature,"
                + POut.Bool(commlog.SigIsTopaz) + ","
                //DateTStamp can only be set by MySQL
                + POut.DateT(commlog.DateTimeEnd) + ","
                + POut.Int((int)commlog.CommSource) + ","
                + POut.Long(commlog.ProgramNum) + ")";
            if (commlog.Note == null)
            {
                commlog.Note = "";
            }
            OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringNote(commlog.Note));

            if (commlog.Signature == null)
            {
                commlog.Signature = "";
            }
            OdSqlParameter paramSignature = new OdSqlParameter("paramSignature", OdDbType.Text, POut.StringParam(commlog.Signature));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramNote, paramSignature);
            }
            else
            {
                commlog.CommlogNum = Db.NonQ(command, true, "CommlogNum", "commlog", paramNote, paramSignature);
            }
            return(commlog.CommlogNum);
        }
Example #14
0
 ///<summary>Returns true if Update(Commlog,Commlog) 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(Commlog commlog, Commlog oldCommlog)
 {
     if (commlog.PatNum != oldCommlog.PatNum)
     {
         return(true);
     }
     if (commlog.CommDateTime != oldCommlog.CommDateTime)
     {
         return(true);
     }
     if (commlog.CommType != oldCommlog.CommType)
     {
         return(true);
     }
     if (commlog.Note != oldCommlog.Note)
     {
         return(true);
     }
     if (commlog.Mode_ != oldCommlog.Mode_)
     {
         return(true);
     }
     if (commlog.SentOrReceived != oldCommlog.SentOrReceived)
     {
         return(true);
     }
     if (commlog.UserNum != oldCommlog.UserNum)
     {
         return(true);
     }
     if (commlog.Signature != oldCommlog.Signature)
     {
         return(true);
     }
     if (commlog.SigIsTopaz != oldCommlog.SigIsTopaz)
     {
         return(true);
     }
     //DateTStamp can only be set by MySQL
     if (commlog.DateTimeEnd != oldCommlog.DateTimeEnd)
     {
         return(true);
     }
     if (commlog.CommSource != oldCommlog.CommSource)
     {
         return(true);
     }
     if (commlog.ProgramNum != oldCommlog.ProgramNum)
     {
         return(true);
     }
     return(false);
 }
Example #15
0
        ///<summary></summary>
        public static void Update(Commlog comm)
        {
            string command = "UPDATE commlog SET "
                             + "PatNum = '" + POut.PInt(comm.PatNum) + "', "
                             + "CommDateTime= " + POut.PDateT(comm.CommDateTime) + ", "
                             + "CommType = '" + POut.PInt((int)comm.CommType) + "', "
                             + "Note = '" + POut.PString(comm.Note) + "', "
                             + "Mode_ = '" + POut.PInt((int)comm.Mode_) + "', "
                             + "SentOrReceived = '" + POut.PInt((int)comm.SentOrReceived) + "' "
                             + "WHERE commlognum = '" + POut.PInt(comm.CommlogNum) + "'";

            General.NonQ(command);
        }
Example #16
0
        public static Commlog CreateCommlog(long patNum, string text          = "", DateTime commDateTime = default(DateTime),
                                            CommSentOrReceived sentOrReceived = CommSentOrReceived.Sent, CommItemMode itemMode = CommItemMode.None)
        {
            Commlog commlog = new Commlog {
                CommDateTime   = commDateTime.Year > 1880 ? commDateTime : DateTime.Now,
                Mode_          = itemMode,
                Note           = text,
                PatNum         = patNum,
                SentOrReceived = sentOrReceived,
            };

            Commlogs.Insert(commlog);
            return(commlog);
        }
Example #17
0
 ///<summary>Inserts one Commlog into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(Commlog commlog)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(commlog, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             commlog.CommlogNum = DbHelper.GetNextOracleKey("commlog", "CommlogNum");                  //Cacheless method
         }
         return(InsertNoCache(commlog, true));
     }
 }
Example #18
0
 public void AutoSaveCommItem(Commlog commlog)
 {
     if (IsNew)
     {
         //Insert
         _view.SetCommlogNum(Commlogs.Insert(commlog));
         SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, commlog.PatNum, "Autosave Insert");
         IsNew = false;
     }
     else
     {
         //Update
         Commlogs.Update(commlog);
     }
 }
Example #19
0
 private void AutoSaveCommItem()
 {
     if (_commlogOld.IsNew)
     {
         //Insert
         Commlogs.Insert(_commlogCur);
         textCommlogNum.Text = this._commlogCur.CommlogNum.ToString();
         SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, _commlogCur.PatNum, "Autosave Insert");
         _commlogCur.IsNew = false;
     }
     else
     {
         //Update
         Commlogs.Update(_commlogCur);
     }
     _commlogOld = _commlogCur.Copy();
 }
Example #20
0
        private static Commlog[] RefreshAndFill(string command)
        {
            DataTable table = General.GetTable(command);

            Commlog[] List = new Commlog[table.Rows.Count];
            for (int i = 0; i < List.Length; i++)
            {
                List[i]                = new Commlog();
                List[i].CommlogNum     = PIn.PInt(table.Rows[i][0].ToString());
                List[i].PatNum         = PIn.PInt(table.Rows[i][1].ToString());
                List[i].CommDateTime   = PIn.PDate(table.Rows[i][2].ToString());
                List[i].CommType       = (CommItemType)PIn.PInt(table.Rows[i][3].ToString());
                List[i].Note           = PIn.PString(table.Rows[i][4].ToString());
                List[i].Mode_          = (CommItemMode)PIn.PInt(table.Rows[i][5].ToString());
                List[i].SentOrReceived = (CommSentOrReceived)PIn.PInt(table.Rows[i][6].ToString());
            }
            return(List);
        }
Example #21
0
        public bool TryGetCommItem(bool showMsg, out Commlog commlog)
        {
            commlog = null;
            if (!ValidateCommlog(showMsg))
            {
                return(false);
            }
            CommItemModel model;

            if (!TryGetModelFromView(out model))
            {
                //Currently the only way for this method to fail is when saving the signature.
                MsgBox.Show(this, "Error saving signature.");
                return(false);
            }
            commlog = model.CommlogCur;
            return(true);
        }
Example #22
0
        ///<summary>Updates one Commlog in the database.</summary>
        public static void Update(Commlog commlog)
        {
            string command = "UPDATE commlog SET "
                             + "PatNum        =  " + POut.Long(commlog.PatNum) + ", "
                             + "CommDateTime  =  " + POut.DateT(commlog.CommDateTime) + ", "
                             + "CommType      =  " + POut.Long(commlog.CommType) + ", "
                             + "Note          = '" + POut.String(commlog.Note) + "', "
                             + "Mode_         =  " + POut.Int((int)commlog.Mode_) + ", "
                             + "SentOrReceived=  " + POut.Int((int)commlog.SentOrReceived) + ", "
                             + "UserNum       =  " + POut.Long(commlog.UserNum) + ", "
                             + "Signature     = '" + POut.String(commlog.Signature) + "', "
                             + "SigIsTopaz    =  " + POut.Bool(commlog.SigIsTopaz) + ", "
                             //DateTStamp can only be set by MySQL
                             + "DateTimeEnd   =  " + POut.DateT(commlog.DateTimeEnd) + " "
                             + "WHERE CommlogNum = " + POut.Long(commlog.CommlogNum);

            Db.NonQ(command);
        }
 private void butStationary_Click(object sender, EventArgs e)
 {
     if (PrefB.GetString("StationaryDocument") == "")
     {
         MsgBox.Show(this, "You must setup your stationary document and word processor path in Setup | Misc");
         return;
     }
     Cursor = Cursors.AppStarting;
     PtLetter_ToClipboard();
     try {
         this.Cursor = Cursors.AppStarting;
         string patFolder = ODFileUtils.CombinePaths(
             FormPath.GetPreferredImagePath(),
             PatCur.ImageFolder.Substring(0, 1),
             PatCur.ImageFolder);
         //string ProgName = @"C:\Program Files\OpenOffice.org 2.0\program\swriter.exe";
         //string ProgName = PrefB.GetString("WordProcessorPath");
         string TheFile = ODFileUtils.CombinePaths(patFolder, "Letter_" + DateTime.Now.ToFileTime() + ".doc");
         try{
             File.Copy(
                 ODFileUtils.CombinePaths(FormPath.GetPreferredImagePath(), PrefB.GetString("StationaryDocument")),
                 TheFile);
             DialogResult = DialogResult.OK;
         }
         catch {
         }
         try {
             Process.Start(TheFile);
         }
         catch {
         }
         this.Cursor = Cursors.Default;
         Commlog CommlogCur = new Commlog();
         CommlogCur.CommDateTime = DateTime.Now;
         CommlogCur.CommType     = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
         CommlogCur.PatNum       = PatCur.PatNum;
         CommlogCur.Note         = Lan.g(this, "Letter sent: See Images for this date.");
         Commlogs.Insert(CommlogCur);
     }
     catch {
         Cursor = Cursors.Default;
         MsgBox.Show(this, "Cannot find stationary document. Or another problem exists.");
     }
 }
Example #24
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
            if (gridBill.SelectedIndices.Length == 0)
            {
                MessageBox.Show(Lan.g(this, "Please select items first."));
                return;
            }
            if (!MsgBox.Show(this, true, "Please be prepared to wait up to ten minutes while all the bills get processed.  Continue?"))
            {
                return;
            }
            Cursor = Cursors.WaitCursor;
            int[] guarNums = new int[gridBill.SelectedIndices.Length];
            for (int i = 0; i < gridBill.SelectedIndices.Length; i++)
            {
                guarNums[i] = AgingList[gridBill.SelectedIndices[i]].PatNum;
            }
            FormRpStatement FormS = new FormRpStatement();

            FormS.LoadAndPrint(guarNums, GeneralNote);
            Cursor = Cursors.Default;
                        #if DEBUG
            FormS.ShowDialog();
                        #endif
            if (MsgBox.Show(this, true, "Printing Statements Complete.  OK to make Commlog entries?"))
            {
                Commlog commlog;
                for (int i = 0; i < guarNums.Length; i++)
                {
                    commlog = new Commlog();
                    commlog.CommDateTime    = DateTime.Now;
                    commlog.CommType        = 0;
                    commlog.SentOrReceived  = CommSentOrReceived.Sent;
                    commlog.Mode_           = CommItemMode.Mail;
                    commlog.IsStatementSent = true;
                    commlog.PatNum          = guarNums[i];         //uaually the guarantor
                    Commlogs.Insert(commlog);
                }
            }
            DialogResult = DialogResult.OK;
        }
Example #25
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<Commlog> TableToList(DataTable table){
			List<Commlog> retVal=new List<Commlog>();
			Commlog commlog;
			for(int i=0;i<table.Rows.Count;i++) {
				commlog=new Commlog();
				commlog.CommlogNum    = PIn.Long  (table.Rows[i]["CommlogNum"].ToString());
				commlog.PatNum        = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				commlog.CommDateTime  = PIn.DateT (table.Rows[i]["CommDateTime"].ToString());
				commlog.CommType      = PIn.Long  (table.Rows[i]["CommType"].ToString());
				commlog.Note          = PIn.String(table.Rows[i]["Note"].ToString());
				commlog.Mode_         = (CommItemMode)PIn.Int(table.Rows[i]["Mode_"].ToString());
				commlog.SentOrReceived= (CommSentOrReceived)PIn.Int(table.Rows[i]["SentOrReceived"].ToString());
				commlog.UserNum       = PIn.Long  (table.Rows[i]["UserNum"].ToString());
				commlog.Signature     = PIn.String(table.Rows[i]["Signature"].ToString());
				commlog.SigIsTopaz    = PIn.Bool  (table.Rows[i]["SigIsTopaz"].ToString());
				commlog.DateTStamp    = PIn.DateT (table.Rows[i]["DateTStamp"].ToString());
				commlog.DateTimeEnd   = PIn.DateT (table.Rows[i]["DateTimeEnd"].ToString());
				retVal.Add(commlog);
			}
			return retVal;
		}
Example #26
0
        ///<summary>Inserts one Commlog into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(Commlog commlog, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                commlog.CommlogNum = ReplicationServers.GetKey("commlog", "CommlogNum");
            }
            string command = "INSERT INTO commlog (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "CommlogNum,";
            }
            command += "PatNum,CommDateTime,CommType,Note,Mode_,SentOrReceived,IsStatementSent,UserNum,Signature,SigIsTopaz,DateTimeEnd) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(commlog.CommlogNum) + ",";
            }
            command +=
                POut.Long(commlog.PatNum) + ","
                + POut.DateT(commlog.CommDateTime) + ","
                + POut.Long(commlog.CommType) + ","
                + "'" + POut.String(commlog.Note) + "',"
                + POut.Int((int)commlog.Mode_) + ","
                + POut.Int((int)commlog.SentOrReceived) + ","
                + POut.Bool(commlog.IsStatementSent) + ","
                + POut.Long(commlog.UserNum) + ","
                + "'" + POut.String(commlog.Signature) + "',"
                + POut.Bool(commlog.SigIsTopaz) + ","
                //DateTStamp can only be set by MySQL
                + POut.DateT(commlog.DateTimeEnd) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                commlog.CommlogNum = Db.NonQ(command, true);
            }
            return(commlog.CommlogNum);
        }
Example #27
0
 ///<summary>Returns true if the commlog was able to save to the database.  Otherwise returns false.
 ///Set showMsg to true to show a meaningful message when the commlog cannot be saved.</summary>
 private bool SaveCommItem(bool showMsg)
 {
     if (!SyncCommlogWithUI(showMsg))
     {
         return(false);
     }
     if (_isPersistent && string.IsNullOrWhiteSpace(_commlogCur.Note))              //in persistent mode, we don't want to save empty commlogs
     {
         return(false);
     }
     if (_commlogOld.IsNew || _isPersistent)
     {
         Commlogs.Insert(_commlogCur);
         _commlogCur.IsNew   = false;
         _commlogOld         = _commlogCur.Copy();
         textCommlogNum.Text = _commlogCur.CommlogNum.ToString();
         SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, _commlogCur.PatNum, "Insert");
         //Post insert persistent user preferences.
         if (_isPersistent)
         {
             if (_userOdPrefClearNote == null || PIn.Bool(_userOdPrefClearNote.ValueString))
             {
                 ClearNote();
             }
             if (_userOdPrefEndDate == null || PIn.Bool(_userOdPrefEndDate.ValueString))
             {
                 ClearDateTimeEnd();
             }
             ODException.SwallowAnyException(() => {
                 FormOpenDental.S_RefreshCurrentModule();
             });
         }
     }
     else
     {
         Commlogs.Update(_commlogCur);
         SecurityLogs.MakeLogEntry(Permissions.CommlogEdit, _commlogCur.PatNum, "");
     }
     return(true);
 }
Example #28
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
            if (textBody.Text == "")
            {
                MsgBox.Show(this, "Letter not allowed to be blank.");
                return;
            }
            pd2                 = new PrintDocument();
            pd2.PrintPage      += new PrintPageEventHandler(this.pd2_PrintPage);
            pd2.OriginAtMargins = true;
            if (!Printers.SetPrinter(pd2, PrintSituation.Default))
            {
                return;
            }
            try{
                pd2.Print();
            }
            catch {
                MessageBox.Show(Lan.g(this, "Printer not available"));
            }
            Commlog CommlogCur = new Commlog();

            CommlogCur.CommDateTime = DateTime.Now;
            CommlogCur.CommType     = CommItemType.Misc;
            CommlogCur.PatNum       = PatCur.PatNum;
            CommlogCur.Note         = "Letter sent";
            if (LetterCur != null)
            {
                CommlogCur.Note += ": " + LetterCur.Description + ". ";
            }
            FormCommItem FormCI = new FormCommItem(CommlogCur);

            FormCI.IsNew = true;
            FormCI.ShowDialog();
            //this window now closes regardless of whether the user saved the comm item.
            DialogResult = DialogResult.OK;
        }
Example #29
0
 ///<summary></summary>
 public FormCommItem(Commlog commlogCur)
 {
     InitializeComponent();
     Lan.F(this);
     CommlogCur = commlogCur;
 }
Example #30
0
		///<summary>Inserts one Commlog into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(Commlog commlog,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				commlog.CommlogNum=ReplicationServers.GetKey("commlog","CommlogNum");
			}
			string command="INSERT INTO commlog (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="CommlogNum,";
			}
			command+="PatNum,CommDateTime,CommType,Note,Mode_,SentOrReceived,UserNum,Signature,SigIsTopaz,DateTimeEnd,IsWebSched) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(commlog.CommlogNum)+",";
			}
			command+=
				     POut.Long  (commlog.PatNum)+","
				+    POut.DateT (commlog.CommDateTime)+","
				+    POut.Long  (commlog.CommType)+","
				+    DbHelper.ParamChar+"paramNote,"
				+    POut.Int   ((int)commlog.Mode_)+","
				+    POut.Int   ((int)commlog.SentOrReceived)+","
				+    POut.Long  (commlog.UserNum)+","
				+"'"+POut.String(commlog.Signature)+"',"
				+    POut.Bool  (commlog.SigIsTopaz)+","
				//DateTStamp can only be set by MySQL
				+    POut.DateT (commlog.DateTimeEnd)+","
				+    POut.Bool  (commlog.IsWebSched)+")";
			if(commlog.Note==null) {
				commlog.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,POut.StringNote(commlog.Note));
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command,paramNote);
			}
			else {
				commlog.CommlogNum=Db.NonQ(command,true,paramNote);
			}
			return commlog.CommlogNum;
		}
Example #31
0
		///<summary>Updates one Commlog 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(Commlog commlog,Commlog oldCommlog){
			string command="";
			if(commlog.PatNum != oldCommlog.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(commlog.PatNum)+"";
			}
			if(commlog.CommDateTime != oldCommlog.CommDateTime) {
				if(command!=""){ command+=",";}
				command+="CommDateTime = "+POut.DateT(commlog.CommDateTime)+"";
			}
			if(commlog.CommType != oldCommlog.CommType) {
				if(command!=""){ command+=",";}
				command+="CommType = "+POut.Long(commlog.CommType)+"";
			}
			if(commlog.Note != oldCommlog.Note) {
				if(command!=""){ command+=",";}
				command+="Note = "+DbHelper.ParamChar+"paramNote";
			}
			if(commlog.Mode_ != oldCommlog.Mode_) {
				if(command!=""){ command+=",";}
				command+="Mode_ = "+POut.Int   ((int)commlog.Mode_)+"";
			}
			if(commlog.SentOrReceived != oldCommlog.SentOrReceived) {
				if(command!=""){ command+=",";}
				command+="SentOrReceived = "+POut.Int   ((int)commlog.SentOrReceived)+"";
			}
			if(commlog.UserNum != oldCommlog.UserNum) {
				if(command!=""){ command+=",";}
				command+="UserNum = "+POut.Long(commlog.UserNum)+"";
			}
			if(commlog.Signature != oldCommlog.Signature) {
				if(command!=""){ command+=",";}
				command+="Signature = '"+POut.String(commlog.Signature)+"'";
			}
			if(commlog.SigIsTopaz != oldCommlog.SigIsTopaz) {
				if(command!=""){ command+=",";}
				command+="SigIsTopaz = "+POut.Bool(commlog.SigIsTopaz)+"";
			}
			//DateTStamp can only be set by MySQL
			if(commlog.DateTimeEnd != oldCommlog.DateTimeEnd) {
				if(command!=""){ command+=",";}
				command+="DateTimeEnd = "+POut.DateT(commlog.DateTimeEnd)+"";
			}
			if(commlog.IsWebSched != oldCommlog.IsWebSched) {
				if(command!=""){ command+=",";}
				command+="IsWebSched = "+POut.Bool(commlog.IsWebSched)+"";
			}
			if(command==""){
				return false;
			}
			if(commlog.Note==null) {
				commlog.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,POut.StringNote(commlog.Note));
			command="UPDATE commlog SET "+command
				+" WHERE CommlogNum = "+POut.Long(commlog.CommlogNum);
			Db.NonQ(command,paramNote);
			return true;
		}
Example #32
0
		///<summary>Updates one Commlog in the database.</summary>
		public static void Update(Commlog commlog){
			string command="UPDATE commlog SET "
				+"PatNum        =  "+POut.Long  (commlog.PatNum)+", "
				+"CommDateTime  =  "+POut.DateT (commlog.CommDateTime)+", "
				+"CommType      =  "+POut.Long  (commlog.CommType)+", "
				+"Note          =  "+DbHelper.ParamChar+"paramNote, "
				+"Mode_         =  "+POut.Int   ((int)commlog.Mode_)+", "
				+"SentOrReceived=  "+POut.Int   ((int)commlog.SentOrReceived)+", "
				+"UserNum       =  "+POut.Long  (commlog.UserNum)+", "
				+"Signature     = '"+POut.String(commlog.Signature)+"', "
				+"SigIsTopaz    =  "+POut.Bool  (commlog.SigIsTopaz)+", "
				//DateTStamp can only be set by MySQL
				+"DateTimeEnd   =  "+POut.DateT (commlog.DateTimeEnd)+", "
				+"IsWebSched    =  "+POut.Bool  (commlog.IsWebSched)+" "
				+"WHERE CommlogNum = "+POut.Long(commlog.CommlogNum);
			if(commlog.Note==null) {
				commlog.Note="";
			}
			OdSqlParameter paramNote=new OdSqlParameter("paramNote",OdDbType.Text,POut.StringNote(commlog.Note));
			Db.NonQ(command,paramNote);
		}
Example #33
0
        private void butPreview_Click(object sender, System.EventArgs e)
        {
#if !DISABLE_MICROSOFT_OFFICE
            if (listLetters.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a letter first.");
                return;
            }
            LetterMerge letterCur = ListForCat[listLetters.SelectedIndex];
            letterCur.ImageFolder = comboImageCategory.SelectedTag <Def>().DefNum;
            string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName);
            string dataFile     = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName);
            if (!File.Exists(templateFile))
            {
                MsgBox.Show(this, "Template file does not exist.");
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            Word.MailMerge wrdMailMerge;
            //Create an instance of Word.
            Word.Application WrdApp;
            try{
                WrdApp = LetterMerges.WordApp;
            }
            catch {
                MsgBox.Show(this, "Error. Is Word installed?");
                return;
            }
            string errorMessage = "";
            //Open a document.
            try {
                Object oName = templateFile;
                wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing,
                                               ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                               ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                wrdDoc.Select();
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error opening document:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            //Attach the data file.
            try {
                wrdMailMerge = wrdDoc.MailMerge;
                wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                wrdMailMerge.Execute(ref oFalse);
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error attaching data file:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            if (letterCur.ImageFolder != 0)           //if image folder exist for this letter, save to AtoZ folder
            //Open document from the atoz folder.
            {
                try {
                    WrdApp.Activate();
                    string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile));
                    Object oFileName    = tempFilePath;
                    WrdApp.ActiveDocument.SaveAs(oFileName);                    //save the document to temp location
                    Document doc       = SaveToImageFolder(tempFilePath, letterCur);
                    string   patFolder = ImageStore.GetPatientFolder(PatCur, ImageStore.GetPreferredAtoZpath());
                    string   fileName  = ImageStore.GetFilePath(doc, patFolder);
                    if (!FileAtoZ.Exists(fileName))
                    {
                        throw new ApplicationException(Lans.g("LetterMerge", "Error opening document" + " " + doc.FileName));
                    }
                    FileAtoZ.StartProcess(fileName);
                    WrdApp.ActiveDocument.Close();                    //Necessary since we created an extra document
                    try {
                        File.Delete(tempFilePath);                    //Clean up the temp file
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                    }
                }
                catch (Exception ex) {
                    FriendlyException.Show(Lan.g(this, "Error saving file to the Image module:") + "\r\n" + ex.Message, ex);
                }
            }
            //Close the original form document since just one record.
            try {
                wrdDoc.Saved = true;
                wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error closing document:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            //At this point, Word remains open with just one new document.
            try {
                WrdApp.Activate();
                if (WrdApp.WindowState == Word.WdWindowState.wdWindowStateMinimize)
                {
                    WrdApp.WindowState = Word.WdWindowState.wdWindowStateMaximize;
                }
            }
            catch (Exception ex) {
                errorMessage = Lan.g(this, "Error showing Microsoft Word:") + "\r\n" + ex.Message;
                MessageBox.Show(errorMessage);
                return;
            }
            wrdMailMerge = null;
            wrdDoc       = null;
            Commlog CommlogCur = new Commlog();
            CommlogCur.CommDateTime   = DateTime.Now;
            CommlogCur.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
            CommlogCur.Mode_          = CommItemMode.Mail;
            CommlogCur.SentOrReceived = CommSentOrReceived.Sent;
            CommlogCur.PatNum         = PatCur.PatNum;
            CommlogCur.Note           = "Letter sent: " + letterCur.Description + ". ";
            CommlogCur.UserNum        = Security.CurUser.UserNum;
            Commlogs.Insert(CommlogCur);
#else
            MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
#endif
            //this window now closes regardless of whether the user saved the comm item.
            DialogResult = DialogResult.OK;
        }
Example #34
0
        private void butPrint_Click(object sender, System.EventArgs e)
        {
#if DISABLE_MICROSOFT_OFFICE
            MessageBox.Show(this, "This version of Open Dental does not support Microsoft Word.");
            return;
#endif
            if (listLetters.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a letter first.");
                return;
            }
            LetterMerge letterCur = ListForCat[listLetters.SelectedIndex];
            letterCur.ImageFolder = comboImageCategory.SelectedTag <Def>().DefNum;
            string templateFile = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.TemplateName);
            string dataFile     = ODFileUtils.CombinePaths(PrefC.GetString(PrefName.LetterMergePath), letterCur.DataFileName);
            if (!File.Exists(templateFile))
            {
                MsgBox.Show(this, "Template file does not exist.");
                return;
            }
            PrintDocument pd = new PrintDocument();
            if (!PrinterL.SetPrinter(pd, PrintSituation.Default, PatCur.PatNum, "Letter merge " + letterCur.Description + " printed"))
            {
                return;
            }
            if (!CreateDataFile(dataFile, letterCur))
            {
                return;
            }
            Word.MailMerge wrdMailMerge;
            //Create an instance of Word.
            Word.Application WrdApp;
            try {
                WrdApp = LetterMerges.WordApp;
            }
            catch {
                MsgBox.Show(this, "Error.  Is MS Word installed?");
                return;
            }
            //Open a document.
            Object oName = templateFile;
            wrdDoc = WrdApp.Documents.Open(ref oName, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            wrdDoc.Select();
            wrdMailMerge = wrdDoc.MailMerge;
            //Attach the data file.
            wrdDoc.MailMerge.OpenDataSource(dataFile, ref oMissing, ref oMissing, ref oMissing,
                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter;
            //WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName;
            //replaced with following 4 lines due to MS bug that changes computer default printer
            object   oWBasic   = WrdApp.WordBasic;
            object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 };
            String[] sWBNames  = new String[] { "Printer", "DoNotSetAsSysDefault" };
            oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames);
            wrdMailMerge.Execute(ref oFalse);
            if (letterCur.ImageFolder != 0)           //if image folder exist for this letter, save to AtoZ folder
            {
                try {
                    wrdDoc.Select();
                    wrdMailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                    wrdMailMerge.Execute(ref oFalse);
                    WrdApp.Activate();
                    string tempFilePath = ODFileUtils.CreateRandomFile(Path.GetTempPath(), GetFileExtensionForWordDoc(templateFile));
                    Object oFileName    = tempFilePath;
                    WrdApp.ActiveDocument.SaveAs(oFileName);                    //save the document
                    WrdApp.ActiveDocument.Close();
                    SaveToImageFolder(tempFilePath, letterCur);
                }
                catch (Exception ex) {
                    FriendlyException.Show(Lan.g(this, "Error saving file to the Image module:") + "\r\n" + ex.Message, ex);
                }
            }
            //Close the original form document since just one record.
            wrdDoc.Saved = true;
            wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            //At this point, Word remains open with no documents.
            WrdApp.WindowState = Word.WdWindowState.wdWindowStateMinimize;
            wrdMailMerge       = null;
            wrdDoc             = null;
            Commlog CommlogCur = new Commlog();
            CommlogCur.CommDateTime   = DateTime.Now;
            CommlogCur.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
            CommlogCur.Mode_          = CommItemMode.Mail;
            CommlogCur.SentOrReceived = CommSentOrReceived.Sent;
            CommlogCur.PatNum         = PatCur.PatNum;
            CommlogCur.Note           = "Letter sent: " + letterCur.Description + ". ";
            CommlogCur.UserNum        = Security.CurUser.UserNum;
            Commlogs.Insert(CommlogCur);
            DialogResult = DialogResult.OK;
        }
        private static void OnCreated(object source, FileSystemEventArgs e)
        {
            //MessageBox.Show("File created.  It will now be deleted.");
            Thread.Sleep(200);            //just to make sure the other process is done writing.
            string[] lines = File.ReadAllLines(e.FullPath);
            File.Delete(e.FullPath);
            if (lines.Length != 1)
            {
                MessageBox.Show(e.FullPath + " was supposed to have exactly one line.  Invalid file.");
                return;
            }
            string rawFieldNames = "PAT_PK,PAT_LOGFK,PAT_LANFK,PAT_TITLE,PAT_FNAME,PAT_MI,PAT_LNAME,PAT_CALLED,PAT_ADDR1,PAT_ADDR2,PAT_CITY,PAT_ST,PAT_ZIP,PAT_HPHN,PAT_WPHN,PAT_EXT,PAT_FAX,PAT_PAGER,PAT_CELL,PAT_EMAIL,PAT_SEX,PAT_EDOCS,PAT_STATUS,PAT_TYPE,PAT_BIRTH,PAT_SSN,PAT_NOCALL,PAT_NOCORR,PAT_DISRES,PAT_LSTUPD,PAT_INSNM,PAT_INSGPL,PAT_INSAD1,PAT_INSAD2,PAT_INSCIT,PAT_INSST,PAT_INSZIP,PAT_INSPHN,PAT_INSEXT,PAT_INSCON,PAT_INSGNO,PAT_EMPNM,PAT_EMPAD1,PAT_EMPAD2,PAT_EMPCIT,PAT_EMPST,PAT_EMPZIP,PAT_EMPPHN,PAT_REFLNM,PAT_REFFNM,PAT_REFMI,PAT_REFPHN,PAT_REFEML,PAT_REFSPE,PAT_NOTES,PAT_NOTE1,PAT_NOTE2,PAT_NOTE3,PAT_NOTE4,PAT_NOTE5,PAT_NOTE6,PAT_NOTE7,PAT_NOTE8,PAT_NOTE9,PAT_NOTE10,PAT_FPSCAN,PAT_PREMED,PAT_MEDS,PAT_FTSTUD,PAT_PTSTUD,PAT_COLLEG,PAT_CHRTNO,PAT_OTHID,PAT_RESPRT,PAT_POLHLD,PAT_CUSCD,PAT_PMPID";

            fieldNames = rawFieldNames.Split(',');
            fieldVals  = lines[0].Split(',');
            if (fieldNames.Length != fieldVals.Length)
            {
                MessageBox.Show(e.FullPath + " contains " + fieldNames.Length.ToString() + " field names, but " + fieldVals.Length.ToString() + " field values.  Invalid file.");
                return;
            }
            for (int i = 0; i < fieldVals.Length; i++)
            {
                fieldVals[i] = fieldVals[i].Replace("\"", "");             //remove quotes
            }
            long patNum = PIn.Long(GetVal("PAT_OTHID"));

            if (patNum == 0)
            {
                MessageBox.Show(patNum.ToString() + " is not a recognized PatNum.");
                return;
            }
            Family fam = Patients.GetFamily(patNum);

            if (fam == null)
            {
                MessageBox.Show("Could not find patient based on PatNum " + patNum.ToString());
                return;
            }
            Patient pat    = fam.GetPatient(patNum);
            Patient patOld = pat.Copy();
            string  txt;
            string  note = "PT Dental import processed.  Some information is shown below which was too complex to import automatically.\r\n";

            txt = GetVal("PAT_FNAME");
            if (txt != "")
            {
                pat.FName = txt;
            }
            txt = GetVal("PAT_MI");
            if (txt != "")
            {
                pat.MiddleI = txt;
            }
            txt = GetVal("PAT_LNAME");
            if (txt != "")
            {
                pat.LName = txt;
            }
            txt = GetVal("PAT_CALLED");
            if (txt != "")
            {
                pat.Preferred = txt;
            }
            txt = GetVal("PAT_ADDR1");
            if (txt != "")
            {
                pat.Address = txt;
            }
            txt = GetVal("PAT_ADDR2");
            if (txt != "")
            {
                pat.Address2 = txt;
            }
            txt = GetVal("PAT_CITY");
            if (txt != "")
            {
                pat.City = txt;
            }
            txt = GetVal("PAT_ST");
            if (txt != "")
            {
                pat.State = txt;
            }
            txt = GetVal("PAT_ZIP");
            if (txt != "")
            {
                pat.Zip = txt;
            }
            txt = GetVal("PAT_HPHN");          //No punct
            if (txt != "")
            {
                pat.HmPhone = TelephoneNumbers.ReFormat(txt);
            }
            txt = GetVal("PAT_WPHN");
            if (txt != "")
            {
                pat.WkPhone = TelephoneNumbers.ReFormat(txt);
            }
            //no matching fields for these three:
            txt = GetVal("PAT_EXT");
            if (txt != "")
            {
                note += "Ph extension: " + txt + "\r\n";
            }
            txt = GetVal("PAT_FAX");
            if (txt != "")
            {
                note += "Fax: " + txt + "\r\n";
            }
            txt = GetVal("PAT_PAGER");
            if (txt != "")
            {
                note += "Pager: " + txt + "\r\n";
            }
            txt = GetVal("PAT_CELL");
            if (txt != "")
            {
                pat.WirelessPhone = TelephoneNumbers.ReFormat(txt);
            }
            txt = GetVal("PAT_EMAIL");
            if (txt != "")
            {
                pat.Email = txt;
            }
            txt = GetVal("PAT_SEX");          //M or F
            if (txt == "M")
            {
                pat.Gender = PatientGender.Male;
            }
            if (txt == "F")
            {
                pat.Gender = PatientGender.Male;
            }
            txt = GetVal("PAT_STATUS");          //our patStatus, Any text allowed
            switch (txt)
            {
            case "Archived": pat.PatStatus = PatientStatus.Archived; break;

            case "Deceased": pat.PatStatus = PatientStatus.Deceased; break;

            //case "Archived": pat.PatStatus=PatientStatus.Deleted; break;
            case "Inactive": pat.PatStatus = PatientStatus.Inactive; break;

            case "NonPatient": pat.PatStatus = PatientStatus.NonPatient; break;

            case "Patient": pat.PatStatus = PatientStatus.Patient; break;
            }
            txt = GetVal("PAT_TYPE");          //our Position, Any text allowed
            switch (txt)
            {
            case "Child": pat.Position = PatientPosition.Child; break;

            case "Divorced": pat.Position = PatientPosition.Divorced; break;

            case "Married": pat.Position = PatientPosition.Married; break;

            case "Single": pat.Position = PatientPosition.Single; break;

            case "Widowed": pat.Position = PatientPosition.Widowed; break;
            }
            txt = GetVal("PAT_BIRTH");          // yyyyMMdd
            if (txt != "")
            {
                pat.Birthdate = PIn.Date(txt);
            }
            txt = GetVal("PAT_SSN");          // No punct
            if (txt != "")
            {
                pat.SSN = txt;
            }
            txt = GetVal("PAT_NOCALL");          // T if no call
            if (txt != "")
            {
                note += "No Call Patient: " + txt + "\r\n";
            }
            txt = GetVal("PAT_NOCORR");          // T/F
            if (txt != "")
            {
                note += "No Correspondence: " + txt + "\r\n";
            }
            txt = GetVal("PAT_NOTES");          // No limits.
            if (txt != "")
            {
                note += txt + "\r\n";
            }
            txt = GetVal("PAT_PREMED");          // F or T
            //I don't like giving the patient control of this field, but I guess the office has the option of not showing this on forms.
            if (txt == "T")
            {
                pat.Premed = true;
            }
            if (txt == "F")
            {
                pat.Premed = false;
            }
            txt = GetVal("PAT_MEDS");          // The meds that they must premedicate with.
            if (txt != "")
            {
                note += "Patient Meds: " + txt + "\r\n";
            }
            string ft = GetVal("PAT_FTSTUD");          // T/F
            string pt = GetVal("PAT_PTSTUD");          //parttime

            if (ft == "T")
            {
                pat.StudentStatus = "F";              //fulltime
            }
            else if (pt == "T")
            {
                pat.StudentStatus = "P";              //parttime
            }
            else if (ft == "F" && pt == "F")
            {
                pat.StudentStatus = "";              //nonstudent
            }
            else if (ft == "F" && pat.StudentStatus == "F")
            {
                pat.StudentStatus = "";
            }
            else if (pt == "F" && pat.StudentStatus == "P")
            {
                pat.StudentStatus = "";
            }
            txt = GetVal("PAT_COLLEG");
            if (txt != "")
            {
                pat.SchoolName = txt;
            }
            txt = GetVal("PAT_CHRTNO");
            //I don't think patient should have control of this field.
            if (txt != "")
            {
                pat.ChartNumber = txt;
            }
            txt = GetVal("PAT_RESPRT");          // Responsible party checkbox T/F
            if (txt == "T" && pat.PatNum != pat.Guarantor)
            {
                note += "Responsible party: True\r\n";
            }
            if (txt == "F" && pat.PatNum == pat.Guarantor)
            {
                note += "Responsible party: False\r\n";
            }
            txt = GetVal("PAT_POLHLD");          // Policy holder checkbox T/F
            if (txt == "T")
            {
                note += "Policy holder: True\r\n";
            }
            if (txt == "F")
            {
                note += "Policy holder: False\r\n";
            }
            txt = GetVal("PAT_INSNM");
            if (txt != "")
            {
                note += "Insurance name: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSGPL");
            if (txt != "")
            {
                note += "Ins group plan name: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSAD1");
            if (txt != "")
            {
                note += "Ins address: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSAD2");
            if (txt != "")
            {
                note += "Ins address2: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSCIT");
            if (txt != "")
            {
                note += "Ins city: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSST");
            if (txt != "")
            {
                note += "Ins state: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSZIP");
            if (txt != "")
            {
                note += "Ins zip: " + txt + "\r\n";
            }
            txt = GetVal("PAT_INSPHN");
            if (txt != "")
            {
                note += "Ins phone: " + TelephoneNumbers.ReFormat(txt) + "\r\n";
            }
            txt = GetVal("PAT_INSGNO");          // Ins group number
            if (txt != "")
            {
                note += "Ins group number: " + txt + "\r\n";
            }
            txt = GetVal("PAT_EMPNM");
            if (txt != "")
            {
                note += "Employer name: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFLNM");
            if (txt != "")
            {
                note += "Referral last name: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFFNM");
            if (txt != "")
            {
                note += "Referral first name: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFMI");
            if (txt != "")
            {
                note += "Referral middle init: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFPHN");
            if (txt != "")
            {
                note += "Referral phone: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFEML");          // Referral source email
            if (txt != "")
            {
                note += "Referral email: " + txt + "\r\n";
            }
            txt = GetVal("PAT_REFSPE");          // Referral specialty. Customizable, so any allowed
            if (txt != "")
            {
                note += "Referral specialty: " + txt + "\r\n";
            }
            Patients.Update(pat, patOld);
            if (File.Exists(dir + "\\" + importMedCsv))
            {
                lines = File.ReadAllLines(dir + "\\" + importMedCsv);
                File.Delete(dir + "\\" + importMedCsv);
                if (lines.Length < 1)
                {
                    MessageBox.Show(e.FullPath + " was supposed to have at least one line.  Invalid file.");
                    return;
                }
                fieldNames = lines[0].Split(',');
                long    diseaseDefNum;
                Disease disease;
                string  diseaseNote;
                for (int i = 1; i < lines.Length; i++)
                {
                    fieldVals   = lines[i].Split(',');
                    txt         = GetVal("PMA_MALDES");
                    diseaseNote = GetVal("PMA_NOTES");
                    if (txt == "")
                    {
                        continue;
                    }
                    diseaseDefNum = DiseaseDefs.GetNumFromName(txt);
                    if (diseaseDefNum == 0)
                    {
                        note += "Disease: " + txt + ", " + diseaseNote + "\r\n";
                    }
                    disease = Diseases.GetSpecificDiseaseForPatient(patNum, diseaseDefNum);
                    if (disease == null)
                    {
                        disease = new Disease();
                        disease.DiseaseDefNum = diseaseDefNum;
                        disease.PatNum        = patNum;
                        disease.PatNote       = diseaseNote;
                        Diseases.Insert(disease);
                    }
                    else
                    {
                        if (txt != "")
                        {
                            if (disease.PatNote != "")
                            {
                                disease.PatNote += "  ";
                            }
                            disease.PatNote += diseaseNote;
                            Diseases.Update(disease);
                        }
                    }
                }
            }
            Commlog comm = new Commlog();

            comm.PatNum         = patNum;
            comm.SentOrReceived = CommSentOrReceived.Received;
            comm.CommDateTime   = DateTime.Now;
            comm.CommType       = Commlogs.GetTypeAuto(CommItemTypeAuto.MISC);
            comm.Mode_          = CommItemMode.None;
            comm.Note           = note;
            comm.UserNum        = Security.CurUser.UserNum;
            Commlogs.Insert(comm);
            MessageBox.Show("PT Dental import complete.");
        }
Example #36
0
        public static bool Trigger <T>(AutomationTrigger trigger, List <string> procCodes, long patNum, long aptNum = 0, T triggerObj = default(T))
        {
            if (patNum == 0)           //Could happen for OpenPatient trigger
            {
                return(false);
            }
            List <Automation> listAutomations = Automations.GetDeepCopy();
            bool automationHappened           = false;

            for (int i = 0; i < listAutomations.Count; i++)
            {
                if (listAutomations[i].Autotrigger != trigger)
                {
                    continue;
                }
                if (trigger == AutomationTrigger.CompleteProcedure || trigger == AutomationTrigger.ScheduleProcedure)
                {
                    if (procCodes == null || procCodes.Count == 0)
                    {
                        continue;                        //fail silently
                    }
                    string[] arrayCodes = listAutomations[i].ProcCodes.Split(',');
                    if (procCodes.All(x => !arrayCodes.Contains(x)))
                    {
                        continue;
                    }
                }
                //matching automation item has been found
                //Get possible list of conditions that exist for this automation item
                List <AutomationCondition> autoConditionsList = AutomationConditions.GetListByAutomationNum(listAutomations[i].AutomationNum);
                if (autoConditionsList.Count > 0 && !CheckAutomationConditions(autoConditionsList, patNum, triggerObj))
                {
                    continue;
                }
                SheetDef          sheetDef;
                Sheet             sheet;
                FormSheetFillEdit FormSF;
                Appointment       aptNew;
                Appointment       aptOld;
                switch (listAutomations[i].AutoAction)
                {
                case AutomationAction.CreateCommlog:
                    if (Plugins.HookMethod(null, "AutomationL.Trigger_CreateCommlog_start", patNum, aptNum, listAutomations[i].CommType,
                                           listAutomations[i].MessageContent, trigger))
                    {
                        automationHappened = true;
                        continue;
                    }
                    Commlog commlogCur = new Commlog();
                    commlogCur.PatNum       = patNum;
                    commlogCur.CommDateTime = DateTime.Now;
                    commlogCur.CommType     = listAutomations[i].CommType;
                    commlogCur.Note         = listAutomations[i].MessageContent;
                    commlogCur.Mode_        = CommItemMode.None;
                    commlogCur.UserNum      = Security.CurUser.UserNum;
                    commlogCur.IsNew        = true;
                    FormCommItem commItemView = new FormCommItem(commlogCur);
                    commItemView.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUp:
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PopUpThenDisable10Min:
                    Plugins.HookAddCode(null, "AutomationL.Trigger_PopUpThenDisable10Min_begin", listAutomations[i], procCodes, patNum);
                    long automationNum      = listAutomations[i].AutomationNum;
                    bool hasAutomationBlock = FormOpenDental.DicBlockedAutomations.ContainsKey(automationNum);
                    if (hasAutomationBlock && FormOpenDental.DicBlockedAutomations[automationNum].ContainsKey(patNum))                             //Automation block exist for current patient.
                    {
                        continue;
                    }
                    if (hasAutomationBlock)
                    {
                        FormOpenDental.DicBlockedAutomations[automationNum].Add(patNum, DateTime.Now.AddMinutes(10)); //Disable for 10 minutes.
                    }
                    else                                                                                              //Add automationNum to higher level dictionary .
                    {
                        FormOpenDental.DicBlockedAutomations.Add(automationNum,
                                                                 new Dictionary <long, DateTime>()
                        {
                            { patNum, DateTime.Now.AddMinutes(10) }                                           //Disable for 10 minutes.
                        });
                    }
                    MessageBox.Show(listAutomations[i].MessageContent);
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintPatientLetter:
                case AutomationAction.ShowExamSheet:
                case AutomationAction.ShowConsentForm:
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintReferralLetter:
                    long referralNum = RefAttaches.GetReferralNum(patNum);
                    if (referralNum == 0)
                    {
                        MsgBox.Show("Automations", "This patient has no referral source entered.");
                        automationHappened = true;
                        continue;
                    }
                    sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                    sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                    SheetParameter.SetParameter(sheet, "PatNum", patNum);
                    SheetParameter.SetParameter(sheet, "ReferralNum", referralNum);
                    //Don't fill these params if the sheet doesn't use them.
                    if (sheetDef.SheetFieldDefs.Any(x =>
                                                    (x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted") ||
                                                    (x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart")))
                    {
                        List <Procedure> listProcs = Procedures.GetCompletedForDateRange(DateTime.Today, DateTime.Today
                                                                                         , listPatNums: new List <long>()
                        {
                            patNum
                        }
                                                                                         , includeNote: true
                                                                                         , includeGroupNote: true
                                                                                         );
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Grid && x.FieldName == "ReferralLetterProceduresCompleted"))
                        {
                            SheetParameter.SetParameter(sheet, "CompletedProcs", listProcs);
                        }
                        if (sheetDef.SheetFieldDefs.Any(x => x.FieldType == SheetFieldType.Special && x.FieldName == "toothChart"))
                        {
                            SheetParameter.SetParameter(sheet, "toothChartImg", SheetPrinting.GetToothChartHelper(patNum, false, listProceduresFilteredOverride: listProcs));
                        }
                    }
                    SheetFiller.FillFields(sheet);
                    SheetUtil.CalculateHeights(sheet);
                    FormSF = new FormSheetFillEdit(sheet);
                    FormSF.ShowDialog();
                    automationHappened = true;
                    continue;

                case AutomationAction.SetApptASAP:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld          = aptNew.Copy();
                    aptNew.Priority = ApptPriority.ASAP;
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.SetApptType:
                    aptNew = Appointments.GetOneApt(aptNum);
                    if (aptNew == null)
                    {
                        MsgBox.Show("Automations", "Invalid appointment for automation.");
                        automationHappened = true;
                        continue;
                    }
                    aptOld = aptNew.Copy();
                    aptNew.AppointmentTypeNum = listAutomations[i].AppointmentTypeNum;
                    AppointmentType aptTypeCur = AppointmentTypes.GetFirstOrDefault(x => x.AppointmentTypeNum == aptNew.AppointmentTypeNum);
                    if (aptTypeCur != null)
                    {
                        aptNew.ColorOverride = aptTypeCur.AppointmentTypeColor;
                        aptNew.Pattern       = AppointmentTypes.GetTimePatternForAppointmentType(aptTypeCur);
                        List <Procedure> listProcs = Appointments.ApptTypeMissingProcHelper(aptNew, aptTypeCur, new List <Procedure>());
                        Procedures.UpdateAptNums(listProcs.Select(x => x.ProcNum).ToList(), aptNew.AptNum, aptNew.AptStatus == ApptStatus.Planned);
                    }
                    Appointments.Update(aptNew, aptOld);                           //Appointments S-Class handles Signalods
                    continue;

                case AutomationAction.PatRestrictApptSchedTrue:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to restrict patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.Upsert(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;

                case AutomationAction.PatRestrictApptSchedFalse:
                    if (!Security.IsAuthorized(Permissions.PatientApptRestrict, true))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientApptRestrict, patNum, "Attempt to allow patient scheduling was blocked due to lack of user permission.");
                        continue;
                    }
                    PatRestrictions.RemovePatRestriction(patNum, PatRestrict.ApptSchedule);
                    automationHappened = true;
                    continue;

                case AutomationAction.PrintRxInstruction:
                    List <RxPat> listRx = (List <RxPat>)(object) triggerObj;
                    if (listRx == null)
                    {
                        //Got here via a pre-existing trigger that doesn't pass in triggerObj.  We now block creation of automation triggers that could get
                        //here via code that does not pass in triggerObj.
                        continue;
                    }
                    //We go through each new Rx where the patient note isn't blank.
                    //There should only usually be one new rx, but we'll loop just in case.
                    foreach (RxPat rx in listRx.Where(x => !string.IsNullOrWhiteSpace(x.PatientInstruction)))
                    {
                        //This logic is an exact copy of FormRxManage.butPrintSelect_Click()'s logic when 1 Rx is selected.
                        //If this is updated, that method needs to be updated as well.
                        sheetDef = SheetDefs.GetSheetDef(listAutomations[i].SheetDefNum);
                        sheet    = SheetUtil.CreateSheet(sheetDef, patNum);
                        SheetParameter.SetParameter(sheet, "RxNum", rx.RxNum);
                        SheetFiller.FillFields(sheet);
                        SheetUtil.CalculateHeights(sheet);
                        FormSF = new FormSheetFillEdit(sheet);
                        FormSF.ShowDialog();
                        automationHappened = true;
                    }
                    continue;

                case AutomationAction.ChangePatStatus:
                    Patient pat    = Patients.GetPat(patNum);
                    Patient patOld = pat.Copy();
                    pat.PatStatus = listAutomations[i].PatStatus;
                    //Don't allow changing status from Archived if this is a merged patient.
                    if (patOld.PatStatus != pat.PatStatus &&
                        patOld.PatStatus == PatientStatus.Archived &&
                        PatientLinks.WasPatientMerged(patOld.PatNum))
                    {
                        MsgBox.Show("FormPatientEdit", "Not allowed to change the status of a merged patient.");
                        continue;
                    }
                    switch (pat.PatStatus)
                    {
                    case PatientStatus.Deceased:
                        if (patOld.PatStatus != PatientStatus.Deceased)
                        {
                            List <Appointment> listFutureAppts = Appointments.GetFutureSchedApts(pat.PatNum);
                            if (listFutureAppts.Count > 0)
                            {
                                string apptDates = string.Join("\r\n", listFutureAppts.Take(10).Select(x => x.AptDateTime.ToString()));
                                if (listFutureAppts.Count > 10)
                                {
                                    apptDates += "(...)";
                                }
                                if (MessageBox.Show(
                                        Lan.g("FormPatientEdit", "This patient has scheduled appointments in the future") + ":\r\n" + apptDates + "\r\n"
                                        + Lan.g("FormPatientEdit", "Would you like to delete them and set the patient to Deceased?"),
                                        Lan.g("FormPatientEdit", "Delete future appointments?"),
                                        MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    foreach (Appointment appt in listFutureAppts)
                                    {
                                        Appointments.Delete(appt.AptNum, true);
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        break;
                    }
                    //Re-activate or disable recalls depending on the the status that the patient is changing to.
                    Patients.UpdateRecalls(pat, patOld, "ChangePatStatus automation");
                    if (Patients.Update(pat, patOld))
                    {
                        SecurityLogs.MakeLogEntry(Permissions.PatientEdit, patNum, "Patient status changed from " + patOld.PatStatus.GetDescription() +
                                                  " to " + listAutomations[i].PatStatus.GetDescription() + " through ChangePatStatus automation.");
                    }
                    automationHappened = true;
                    continue;
                }
            }
            return(automationHappened);
        }
Example #37
0
		///<summary>Updates one Commlog in the database.</summary>
		public static void Update(Commlog commlog){
			string command="UPDATE commlog SET "
				+"PatNum        =  "+POut.Long  (commlog.PatNum)+", "
				+"CommDateTime  =  "+POut.DateT (commlog.CommDateTime)+", "
				+"CommType      =  "+POut.Long  (commlog.CommType)+", "
				+"Note          = '"+POut.String(commlog.Note)+"', "
				+"Mode_         =  "+POut.Int   ((int)commlog.Mode_)+", "
				+"SentOrReceived=  "+POut.Int   ((int)commlog.SentOrReceived)+", "
				+"UserNum       =  "+POut.Long  (commlog.UserNum)+", "
				+"Signature     = '"+POut.String(commlog.Signature)+"', "
				+"SigIsTopaz    =  "+POut.Bool  (commlog.SigIsTopaz)+", "
				//DateTStamp can only be set by MySQL
				+"DateTimeEnd   =  "+POut.DateT (commlog.DateTimeEnd)+" "
				+"WHERE CommlogNum = "+POut.Long(commlog.CommlogNum);
			Db.NonQ(command);
		}
Example #38
0
		///<summary>Updates one Commlog 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(Commlog commlog,Commlog oldCommlog){
			string command="";
			if(commlog.PatNum != oldCommlog.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(commlog.PatNum)+"";
			}
			if(commlog.CommDateTime != oldCommlog.CommDateTime) {
				if(command!=""){ command+=",";}
				command+="CommDateTime = "+POut.DateT(commlog.CommDateTime)+"";
			}
			if(commlog.CommType != oldCommlog.CommType) {
				if(command!=""){ command+=",";}
				command+="CommType = "+POut.Long(commlog.CommType)+"";
			}
			if(commlog.Note != oldCommlog.Note) {
				if(command!=""){ command+=",";}
				command+="Note = '"+POut.String(commlog.Note)+"'";
			}
			if(commlog.Mode_ != oldCommlog.Mode_) {
				if(command!=""){ command+=",";}
				command+="Mode_ = "+POut.Int   ((int)commlog.Mode_)+"";
			}
			if(commlog.SentOrReceived != oldCommlog.SentOrReceived) {
				if(command!=""){ command+=",";}
				command+="SentOrReceived = "+POut.Int   ((int)commlog.SentOrReceived)+"";
			}
			if(commlog.UserNum != oldCommlog.UserNum) {
				if(command!=""){ command+=",";}
				command+="UserNum = "+POut.Long(commlog.UserNum)+"";
			}
			if(commlog.Signature != oldCommlog.Signature) {
				if(command!=""){ command+=",";}
				command+="Signature = '"+POut.String(commlog.Signature)+"'";
			}
			if(commlog.SigIsTopaz != oldCommlog.SigIsTopaz) {
				if(command!=""){ command+=",";}
				command+="SigIsTopaz = "+POut.Bool(commlog.SigIsTopaz)+"";
			}
			//DateTStamp can only be set by MySQL
			if(commlog.DateTimeEnd != oldCommlog.DateTimeEnd) {
				if(command!=""){ command+=",";}
				command+="DateTimeEnd = "+POut.DateT(commlog.DateTimeEnd)+"";
			}
			if(command==""){
				return;
			}
			command="UPDATE commlog SET "+command
				+" WHERE CommlogNum = "+POut.Long(commlog.CommlogNum);
			Db.NonQ(command);
		}