Пример #1
0
        ///<summary>Returns definitions that are associated to the defCat, fKey, and defLinkType passed in.</summary>
        public static List <Def> GetDefsByDefLinkFKey(DefCat defCat, long fKey, DefLinkType defLinkType)
        {
            //No need to check RemotingRole; no call to db.
            List <DefLink> listDefLinks = DefLinks.GetDefLinksByType(defLinkType).FindAll(x => x.FKey == fKey);

            return(Defs.GetDefs(defCat, listDefLinks.Select(x => x.DefNum).Distinct().ToList()));
        }
Пример #2
0
        ///<summary>Sets the FieldName for each SheetFieldDef in sheetDef.SheetFieldDefs to the Def.DefNum defined as the Patient Image definition.
        ///Defaults to the first definition in the Image category if Patient Image is not defined.
        ///This is necessary because the resource for the internal sheet likely does not contain a valid Def primary key.</summary>
        public static void SetPatImageFieldNames(SheetDef sheetDef)
        {
            //We need to figure out which Image Category should be used for any PatImage SheetFieldDefs.
            List <Def> listImageDefs = Defs.GetDefsForCategory(DefCat.ImageCats, true);
            long       defNum        = 0;
            //A user can define a specific image category as being the Patient Picture definition, see FormDefEditImages.butOK_Click().
            //SheetFieldDef.FieldName corresponds to Def.DefNum for a PatImage type SheetFieldDef.
            Def def = listImageDefs.FirstOrDefault(x => x.ItemValue.Contains("P"));

            if (def == null)
            {
                def = listImageDefs.FirstOrDefault(); //Default to the first image category definition if one isn't defined as the Patient Image definition.
            }
            if (def == null)                          //No Image Category definitions setup.
            {
                defNum = 0;
            }
            else
            {
                defNum = def.DefNum;
            }
            foreach (SheetFieldDef sheetFieldDef in sheetDef.SheetFieldDefs)
            {
                if (sheetFieldDef.FieldType != SheetFieldType.PatImage)
                {
                    continue;
                }
                sheetFieldDef.FieldName = POut.Long(defNum);
            }
        }
Пример #3
0
        ///<summary>Returns empty string if no match found.</summary>
        public static string GetValue(DefCat myCat, long myDefNum)
        {
            //No need to check RemotingRole; no call to db.
            Def def = Defs.GetDefsForCategory(myCat).LastOrDefault(x => x.DefNum == myDefNum);

            return(def == null ? "" : def.ItemValue);
        }
Пример #4
0
        ///<summary>Grouped by Category.  Used only in FormRpProcCodes.</summary>
        public static ProcedureCode[] GetProcList(Def[][] arrayDefs = null)
        {
            //No need to check RemotingRole; no call to db.
            List <ProcedureCode> retVal = new List <ProcedureCode>();

            Def[] array = null;
            if (arrayDefs == null)
            {
                array = Defs.GetDefsForCategory(DefCat.ProcCodeCats, true).ToArray();
            }
            else
            {
                array = arrayDefs[(int)DefCat.ProcCodeCats];
            }
            List <ProcedureCode> listProcedureCodes = GetListDeep();

            for (int j = 0; j < arrayDefs[(int)DefCat.ProcCodeCats].Length; j++)
            {
                for (int k = 0; k < listProcedureCodes.Count; k++)
                {
                    if (arrayDefs[(int)DefCat.ProcCodeCats][j].DefNum == listProcedureCodes[k].ProcCat)
                    {
                        retVal.Add(listProcedureCodes[k].Copy());
                    }
                }
            }
            return(retVal.ToArray());
        }
Пример #5
0
        ///<summary>Returns a string that can be used for securitylog entries.</summary>
        public static string GetSecuritylogEntryText(Payment paymentNew, Payment paymentOld, bool isNew, List <Def> listPayTypes = null)
        {
            string secLogText;

            if (listPayTypes == null)
            {
                listPayTypes = Defs.GetDefsForCategory(DefCat.PaymentTypes);
            }
            string clinicAbbrNew = Clinics.GetAbbr(paymentNew.ClinicNum);

            if (isNew)
            {
                secLogText = $"Payment created for {Patients.GetLim(paymentNew.PatNum).GetNameLF()} with payment type '" +
                             GetPaymentTypeDesc(paymentNew, listPayTypes) + "'";
                if (!string.IsNullOrEmpty(clinicAbbrNew))
                {
                    secLogText += $", clinic '{clinicAbbrNew}'";
                }
                secLogText += $", amount '{paymentNew.PayAmt.ToString("c")}'";
            }
            else
            {
                secLogText  = $"Payment edited for {Patients.GetLim(paymentNew.PatNum).GetNameLF()}";
                secLogText += SecurityLogEntryTextHelper(paymentNew.PayAmt.ToString("c"), paymentOld.PayAmt.ToString("c"), "amount");
                secLogText += SecurityLogEntryTextHelper(clinicAbbrNew, Clinics.GetAbbr(paymentOld.ClinicNum), "clinic");
                secLogText += SecurityLogEntryTextHelper(paymentNew.PayDate.ToShortDateString(), paymentOld.PayDate.ToShortDateString(), "payment date");
                secLogText += SecurityLogEntryTextHelper(GetPaymentTypeDesc(paymentNew, listPayTypes), GetPaymentTypeDesc(paymentOld, listPayTypes), "payment type");
            }
            return(secLogText);
        }
Пример #6
0
        ///<summary>Supply the index of the cat within Defs.Short.</summary>
        public static List <LetterMerge> GetListForCat(int catIndex)
        {
            //No need to check RemotingRole; no call to db.
            long defNum = Defs.GetDefsForCategory(DefCat.LetterMergeCats, true)[catIndex].DefNum;

            return(GetWhere(x => x.Category == defNum));
        }
Пример #7
0
        ///<summary>Returns a DefNum for the special image category specified.  Returns 0 if no match found.</summary>
        public static long GetImageCat(ImageCategorySpecial specialCat)
        {
            //No need to check RemotingRole; no call to db.
            Def def = Defs.GetDefsForCategory(DefCat.ImageCats, true).FirstOrDefault(x => x.ItemValue.Contains(specialCat.ToString()));

            return(def == null ? 0 : def.DefNum);
        }
Пример #8
0
        ///<summary>Returns the named def.  If it can't find the name, then it returns the first def in the category.</summary>
        public static long GetByExactNameNeverZero(DefCat myCat, string itemName)
        {
            //No need to check RemotingRole; no call to db.
            List <Def> listDefs = Defs.GetDefsForCategory(myCat);
            Def        def;

            //We have been getting bug submissions from customers where listDefs will be null (e.g. DefCat.ProviderSpecialties cat itemName "General")
            //Therefore, we should check for null or and entirely empty category first before looking for a match.
            if (listDefs == null || listDefs.Count == 0)
            {
                //There are no defs for the category passed in, create one because this method should never return zero.
                def           = new Def();
                def.Category  = myCat;
                def.ItemOrder = 0;
                def.ItemName  = itemName;
                Defs.Insert(def);
                Defs.RefreshCache();
                return(def.DefNum);
            }
            //From this point on, we know our list of definitions contains at least one def.
            def = listDefs.FirstOrDefault(x => x.ItemName == itemName);
            if (def != null)
            {
                return(def.DefNum);
            }
            //Couldn't find a match so return the first definition from our list as a last resort.
            return(listDefs[0].DefNum);
        }
Пример #9
0
        ///<summary>Returns Color.White if no match found.</summary>
        public static Color GetColor(DefCat myCat, long myDefNum)
        {
            //No need to check RemotingRole; no call to db.
            Def def = Defs.GetDefsForCategory(myCat).LastOrDefault(x => x.DefNum == myDefNum);

            return(def == null ? Color.White : def.ItemColor);
        }
Пример #10
0
 ///<summary>Returns the payment type string for the payment.</summary>
 public static string GetPaymentTypeDesc(Payment payment, List <Def> listPayTypes = null)
 {
     if (listPayTypes == null)
     {
         listPayTypes = Defs.GetDefsForCategory(DefCat.PaymentTypes);
     }
     return(payment.PayType == 0 ? "Income Transfer" : Defs.GetName(DefCat.PaymentTypes, payment.PayType, listPayTypes));
 }
Пример #11
0
 ///<summary>Compares two procedures and returns the order they should appear based on status, priority, toothrange, toothnum, then proccode.
 ///Uses the same logic as the other CompareProcedures but takes Procedure objects instead of DataRows.
 ///Only used for the Appointment Edit window currently.</summary>
 public static int CompareProcedures(Procedure x, Procedure y)
 {
     //first by status
     if (x.ProcStatus != y.ProcStatus)
     {
         //Cn,TP,R,EO,C,EC,D
         //EC procs will draw on top of C procs of same date in the 3D tooth chart,
         //but this is not a problem since C procs should always have a later date than EC procs.
         //EC must come after C so that group notes will come after their procedures in Progress Notes.
         int             xIdx, yIdx;
         List <ProcStat> sortOrder = new List <ProcStat>
         {                //The order of statuses in this list is very important and determines the sort order for procedures.
             ProcStat.TPi,
             ProcStat.Cn,
             ProcStat.TP,
             ProcStat.R,
             ProcStat.EO,
             ProcStat.C,
             ProcStat.EC,
             ProcStat.D
         };
         xIdx = sortOrder.IndexOf(x.ProcStatus);
         yIdx = sortOrder.IndexOf(y.ProcStatus);
         return(xIdx.CompareTo(yIdx));
     }
     //by priority
     if (x.Priority != y.Priority)           //if priorities are different
     {
         if (x.Priority == 0)
         {
             return(1);                           //x is greater than y. Priorities always come first.
         }
         if (y.Priority == 0)
         {
             return(-1);                           //x is less than y. Priorities always come first.
         }
         return(Defs.GetOrder(DefCat.TxPriorities, x.Priority).CompareTo(Defs.GetOrder(DefCat.TxPriorities, y.Priority)));
     }
     //priorities are the same, so sort by toothrange
     if (x.ToothRange != y.ToothRange)
     {
         //empty toothranges come before filled toothrange values
         return(x.ToothRange.CompareTo(y.ToothRange));
     }
     //toothranges are the same (usually empty), so compare toothnumbers
     if (x.ToothNum != y.ToothNum)
     {
         //this also puts invalid or empty toothnumbers before the others.
         return(Tooth.ToInt(x.ToothNum).CompareTo(Tooth.ToInt(y.ToothNum)));
     }
     //priority and toothnums are the same, so sort by proccode.
     if (x.CodeNum != y.CodeNum)
     {
         return(ProcedureCodes.GetProcCode(x.CodeNum).ProcCode.CompareTo(ProcedureCodes.GetProcCode(y.CodeNum).ProcCode));
     }
     //if everything else is the same, sort by ProcNum so sort is deterministic
     return(x.ProcNum.CompareTo(y.ProcNum));
 }
Пример #12
0
        ///<summary>Gets list of all appointment type specific DefLinks associated to the WebSchedNewPatApptTypes definition category.</summary>
        public static List <DefLink> GetDefLinksForWebSchedNewPatApptApptTypes()
        {
            //No need to check RemotingRole; no call to db.
            //Get all definitions that are associated to the WebSchedNewPatApptTypes category that are linked to an operatory.
            List <Def> listWSNPAATDefs = Defs.GetDefsForCategory(DefCat.WebSchedNewPatApptTypes);         //Cannot hide defs of this category at this time.

            //Return all of the deflinks that are of type Operatory in order to get the operatory specific deflinks.
            return(DefLinks.GetDefLinksByTypeAndDefs(DefLinkType.AppointmentType, listWSNPAATDefs.Select(x => x.DefNum).ToList()));
        }
Пример #13
0
        ///<summary></summary>
        public static void SetOrder(int mySelNum, int myItemOrder, Def[] list)
        {
            //No need to check RemotingRole; no call to db.
            Def def = list[mySelNum];

            def.ItemOrder = myItemOrder;
            //Cur=temp;
            Defs.Update(def);
        }
Пример #14
0
        ///<summary>Returns true if there are any entries in definition that do not have a Category named "General".
        ///Returning false means the user has ProcButtonCategory customizations.</summary>
        public static bool HasCustomCategories()
        {
            List <Def> listDefs = Defs.GetDefsForCategory(DefCat.ProcButtonCats);

            foreach (Def defCur in listDefs)
            {
                if (!defCur.ItemName.Equals("General"))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #15
0
        ///<summary>Returns 0 if it can't find the named def.  If the name is blank, then it returns the first def in the category.</summary>
        public static long GetByExactName(DefCat myCat, string itemName)
        {
            //No need to check RemotingRole; no call to db.
            List <Def> listDefs = Defs.GetDefsForCategory(myCat);

            //jsalmon - The following line doesn't make much sense because the def list could be empty but this is preserving old behavior...
            if (itemName == "")
            {
                return(listDefs[0].DefNum);               //return the first one in the list
            }
            Def def = listDefs.FirstOrDefault(x => x.ItemName == itemName);

            return(def == null ? 0 : def.DefNum);
        }
Пример #16
0
        public static DataTable GetActiveJobsForUser(long UserNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), UserNum));
            }
            string command = "SELECT Priority, DateTimeEntry AS 'Date Entered', PhaseCur AS 'Phase', Title"
                             + " FROM job"
                             + " WHERE UserNumEngineer=" + UserNum + " AND PhaseCur NOT IN"
                             + "('" + POut.String(JobStatus.Complete.ToString()) + "','" + POut.String(JobStatus.Cancelled.ToString()) + "','"
                             + POut.String(JobStatus.Documentation.ToString()) + "')"
                             + " AND Priority!='" + POut.Long(Defs.GetDefsForCategory(DefCat.JobPriorities, true).First(x => x.ItemValue.Contains("OnHold")).DefNum) + "'";

            return(Db.GetTable(command));
        }
Пример #17
0
 ///<summary>Construct a payplanproductionentry for an UNATTACHED adjustment (attached adjustments get treated as procedures).</summary>
 public PayPlanProductionEntry(Adjustment adj, PayPlanLink credit)
 {
     ProductionTag   = adj;
     LinkedCredit    = credit;
     ProductionDate  = adj.AdjDate;
     PriKey          = adj.AdjNum;
     ProvNum         = adj.ProvNum;
     ClinicNum       = adj.ClinicNum;
     PatNum          = adj.PatNum;
     AmountOriginal  = (decimal)adj.AdjAmt;
     AmountOverride  = (decimal)credit.AmountOverride;
     AmountRemaining = (AmountOverride == 0)?AmountOriginal:AmountOverride;        //Gets set when calculating
     CreditDate      = credit.SecDateTEntry;
     Description     = $"Adjustment - {Defs.GetName(DefCat.AdjTypes,adj.AdjType)}";
     LinkType        = PayPlanLinkType.Adjustment;
 }
Пример #18
0
        ///<Summary>Returns a defnum.  If no match, then it returns the first one in the list in that category.
        ///If there are no defs in the category, 0 is returned.</Summary>
        public static long GetTypeAuto(CommItemTypeAuto typeauto)
        {
            //No need to check RemotingRole; no call to db.
            List <Def> listDefs = Defs.GetDefsForCategory(DefCat.CommLogTypes);
            Def        def      = listDefs.FirstOrDefault(x => x.ItemValue == typeauto.ToString());

            if (def != null)
            {
                return(def.DefNum);
            }
            if (listDefs.Count > 0)
            {
                return(listDefs[0].DefNum);
            }
            return(0);
        }
Пример #19
0
        ///<summary>Returns the Provider Taxonomy code for the given specialty. Always 10 characters, validated.</summary>
        public static string GetTaxonomy(Provider provider)
        {
            if (provider.TaxonomyCodeOverride != "")
            {
                return(provider.TaxonomyCodeOverride);
            }
            string spec     = "1223G0001X";      //general
            Def    provSpec = Defs.GetDef(DefCat.ProviderSpecialties, provider.Specialty);

            if (provSpec == null)
            {
                return(spec);
            }
            switch (provSpec.ItemName)
            {
            case "General": spec = "1223G0001X"; break;

            case "Hygienist": spec = "124Q00000X"; break;

            case "PublicHealth": spec = "1223D0001X"; break;

            case "Endodontics": spec = "1223E0200X"; break;

            case "Pathology": spec = "1223P0106X"; break;

            case "Radiology": spec = "1223X0008X"; break;

            case "Surgery": spec = "1223S0112X"; break;

            case "Ortho": spec = "1223X0400X"; break;

            case "Pediatric": spec = "1223P0221X"; break;

            case "Perio": spec = "1223P0300X"; break;

            case "Prosth": spec = "1223P0700X"; break;

            case "Denturist": spec = "122400000X"; break;

            case "Assistant": spec = "126800000X"; break;

            case "LabTech": spec = "126900000X"; break;
            }
            return(spec);
        }
Пример #20
0
        ///<summary></summary>
        public static DataTable GetForClaim(long claimNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), claimNum));
            }
            DataTable table = new DataTable();
            DataRow   row;

            table.Columns.Add("amount");
            table.Columns.Add("payType");
            table.Columns.Add("BankBranch");
            table.Columns.Add("ClaimPaymentNum");
            table.Columns.Add("checkDate");
            table.Columns.Add("CheckNum");
            table.Columns.Add("Note");
            List <DataRow> rows    = new List <DataRow>();
            string         command = "SELECT BankBranch,claimpayment.ClaimPaymentNum,CheckNum,CheckDate,"
                                     + "SUM(claimproc.InsPayAmt) amount,Note,PayType "
                                     + "FROM claimpayment,claimproc "
                                     + "WHERE claimpayment.ClaimPaymentNum = claimproc.ClaimPaymentNum "
                                     + "AND claimproc.ClaimNum = '" + POut.Long(claimNum) + "' "
                                     + "GROUP BY claimpayment.ClaimPaymentNum, BankBranch, CheckDate, CheckNum, Note, PayType";
            DataTable rawT = Db.GetTable(command);
            DateTime  date;

            for (int i = 0; i < rawT.Rows.Count; i++)
            {
                row                    = table.NewRow();
                row["amount"]          = PIn.Double(rawT.Rows[i]["amount"].ToString()).ToString("F");
                row["payType"]         = Defs.GetName(DefCat.InsurancePaymentType, PIn.Long(rawT.Rows[i]["PayType"].ToString()));
                row["BankBranch"]      = rawT.Rows[i]["BankBranch"].ToString();
                row["ClaimPaymentNum"] = rawT.Rows[i]["ClaimPaymentNum"].ToString();
                date                   = PIn.Date(rawT.Rows[i]["CheckDate"].ToString());
                row["checkDate"]       = date.ToShortDateString();
                row["CheckNum"]        = rawT.Rows[i]["CheckNum"].ToString();
                row["Note"]            = rawT.Rows[i]["Note"].ToString();
                rows.Add(row);
            }
            for (int i = 0; i < rows.Count; i++)
            {
                table.Rows.Add(rows[i]);
            }
            return(table);
        }
Пример #21
0
        public static JobLog MakeLogEntryForPriority(Job jobNew, Job jobOld)
        {
            string note   = "Job Priority was changed from " + Defs.GetName(DefCat.JobPriorities, jobOld.Priority) + " to " + Defs.GetName(DefCat.JobPriorities, jobNew.Priority) + ".";
            JobLog jobLog = new JobLog()
            {
                JobNum          = jobOld.JobNum,
                UserNumChanged  = Security.CurUser.UserNum,
                UserNumExpert   = jobOld.UserNumExpert,
                UserNumEngineer = jobOld.UserNumEngineer,
                Title           = jobOld.Title,
                Description     = note,
                TimeEstimate    = TimeSpan.FromHours(jobNew.HoursEstimate)
            };

            JobLogs.Insert(jobLog);
            JobNotifications.UpsertAllNotifications(jobNew, Security.CurUser.UserNum, JobNotificationChanges.PriorityChange);
            return(JobLogs.GetOne(jobLog.JobLogNum));           //to get new timestamp.
        }
Пример #22
0
        ///<summary>Any filenames mentioned in the fileList which are not attached to the given patient are properly attached to that patient. Returns the total number of documents that were newly attached to the patient.</summary>
        public static int InsertMissing(Patient patient, List <string> fileList)
        {
            //No need to check RemotingRole; no call to db.
            int       countAdded = 0;
            DataTable table      = Documents.GetFileNamesForPatient(patient.PatNum);

            for (int j = 0; j < fileList.Count; j++)
            {
                string fileName = Path.GetFileName(fileList[j]);
                if (!IsAcceptableFileName(fileName))
                {
                    continue;
                }
                bool inList = false;
                for (int i = 0; i < table.Rows.Count && !inList; i++)
                {
                    inList = (table.Rows[i]["FileName"].ToString() == fileName);
                }
                if (!inList)                //OD found new images in the patient's folder that aren't part of the DB.
                {
                    Document doc = new Document();
                    if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
                    {
                        doc.DateCreated = File.GetLastWriteTime(fileList[j]);
                    }
                    else                      //Cloud
                    {
                        doc.DateCreated = DateTime.Now;
                    }
                    DateTime datePrevious = doc.DateTStamp;
                    doc.Description = fileName;
                    doc.DocCategory = Defs.GetFirstForCategory(DefCat.ImageCats, true).DefNum;
                    doc.FileName    = fileName;
                    doc.PatNum      = patient.PatNum;
                    Insert(doc, patient);
                    countAdded++;
                    string docCat = Defs.GetDef(DefCat.ImageCats, doc.DocCategory).ItemName;
                    SecurityLogs.MakeLogEntry(Permissions.ImageEdit, patient.PatNum, Lans.g("ContrImages", "Document Created: A file") + ", " + doc.FileName + ", "
                                              + Lans.g("ContrImages", "placed into the patient's AtoZ images folder from outside of the program was detected and a record automatically inserted into the first image category") + ", " + docCat, doc.DocNum, datePrevious);
                }
            }
            return(countAdded);
        }
Пример #23
0
        ///<summary>Will return null if no picture for this patient.</summary>
        public static Document GetPatPictFromDb(long patNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetObject <Document>(MethodBase.GetCurrentMethod(), patNum));
            }
            //first establish which category pat pics are in
            long defNumPicts = 0;

            Def[] defs = Defs.GetDefsForCategory(DefCat.ImageCats, true).ToArray();
            for (int i = 0; i < defs.Length; i++)
            {
                if (Regex.IsMatch(defs[i].ItemValue, @"P"))
                {
                    defNumPicts = defs[i].DefNum;
                    break;
                }
            }
            if (defNumPicts == 0)          //no category set for picts
            {
                return(null);
            }
            //then find, limit 1 to get the most recent
            string command = "SELECT * FROM document "
                             + "WHERE document.PatNum=" + POut.Long(patNum)
                             + " AND document.DocCategory=" + POut.Long(defNumPicts)
                             + " ORDER BY DateCreated DESC";

            command = DbHelper.LimitOrderBy(command, 1);
            DataTable table = Db.GetTable(command);

            Document[] pictureDocs = Fill(table);
            if (pictureDocs == null || pictureDocs.Length < 1)        //no pictures
            {
                return(null);
            }
            return(pictureDocs[0]);
        }
Пример #24
0
 ///<summary>Returns the named def.  If it can't find the name, then it returns the first def in the category.</summary>
 public static long GetByExactNameNeverZero(DefCat myCat, string itemName)
 {
     if (itemName == "")
     {
         return(DefC.Long[(int)myCat][0].DefNum);               //return the first one in the list
     }
     for (int i = 0; i < DefC.Long[(int)myCat].GetLength(0); i++)
     {
         if (DefC.Long[(int)myCat][i].ItemName == itemName)
         {
             return(DefC.Long[(int)myCat][i].DefNum);
         }
     }
     if (DefC.Long[(int)myCat].Length == 0)
     {
         Def def = new Def();
         def.Category  = myCat;
         def.ItemOrder = 0;
         def.ItemName  = itemName;
         Defs.Insert(def);
         Defs.RefreshCache();
     }
     return(DefC.Long[(int)myCat][0].DefNum);           //return the first one in the list
 }
Пример #25
0
        ///<summary>Update Appointment.Confirmed. Returns true if update was allowed. Returns false if it was prevented.</summary>
        public static bool UpdateAppointmentConfirmationStatus(long aptNum, long confirmDefNum, string commaListOfExcludedDefNums)
        {
            Appointment aptCur = Appointments.GetOneApt(aptNum);

            if (aptCur == null)
            {
                return(false);
            }
            List <long> preventChangeFrom = commaListOfExcludedDefNums.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();

            if (preventChangeFrom.Contains(aptCur.Confirmed))              //This appointment is in a confirmation state that can no longer be updated.
            {
                return(false);
            }
            //Keep the update small.
            Appointment aptOld = aptCur.Copy();

            aptCur.Confirmed = confirmDefNum;
            Appointments.Update(aptCur, aptOld);           //Appointments S-Class handles Signalods
            SecurityLogs.MakeLogEntry(Permissions.ApptConfirmStatusEdit, aptCur.PatNum, "Appointment confirmation status changed from "
                                      + Defs.GetName(DefCat.ApptConfirmed, aptOld.Confirmed) + " to " + Defs.GetName(DefCat.ApptConfirmed, aptCur.Confirmed)
                                      + " due to an eConfirmation.", aptCur.AptNum, LogSources.AutoConfirmations, aptOld.DateTStamp);
            return(true);
        }
Пример #26
0
        public static DataTable GetData(long feeSchedNum, long clinicNum, long provNum, bool isCategories, bool includeBlanks)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), feeSchedNum, clinicNum, provNum, isCategories, includeBlanks));
            }
            DataTable data   = GetDataSet(feeSchedNum, clinicNum, provNum);
            DataTable retVal = new DataTable("ProcCodes");

            if (isCategories)
            {
                retVal.Columns.Add(new DataColumn("Category"));
            }
            retVal.Columns.Add(new DataColumn("Code"));
            retVal.Columns.Add(new DataColumn("Desc"));
            retVal.Columns.Add(new DataColumn("Abbr"));
            retVal.Columns.Add(new DataColumn("Fee"));
            List <ProcedureCode> listProcCodes = new List <ProcedureCode>();

            if (isCategories)
            {
                Def[][] arrayDefs = ReportsComplex.RunFuncOnReportServer(() => Defs.GetArrayShortNoCache());
                listProcCodes = ReportsComplex.RunFuncOnReportServer(() => ProcedureCodes.GetProcList(arrayDefs))
                                .OrderBy(x => x.ProcCat).ThenBy(x => x.ProcCode).ToList();         //Ordered by category
            }
            else
            {
                listProcCodes = ReportsComplex.RunFuncOnReportServer(() => ProcedureCodes.GetAllCodes());               //Ordered by ProcCode, used for the non-category version of the report if they want blanks.
            }
            bool       isFound;
            List <Def> listDefs = Defs.GetDefsNoCache(DefCat.ProcCodeCats);

            for (int i = 0; i < listProcCodes.Count; i++)
            {
                isFound = false;
                DataRow row = retVal.NewRow();
                if (isCategories)
                {
                    //reports should no longer use the cache.
                    Def def = listDefs.FirstOrDefault(x => x.DefNum == listProcCodes[i].ProcCat);
                    row[0] = def == null ? "" : def.ItemName;
                    row[1] = listProcCodes[i].ProcCode;
                    row[2] = listProcCodes[i].Descript;
                    row[3] = listProcCodes[i].AbbrDesc;
                }
                else
                {
                    row[0] = listProcCodes[i].ProcCode;
                    row[1] = listProcCodes[i].Descript;
                    row[2] = listProcCodes[i].AbbrDesc;
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    if (data.Rows[j]["ProcCode"].ToString() == listProcCodes[i].ProcCode)
                    {
                        isFound = true;
                        double amt = PIn.Double(data.Rows[j]["Amount"].ToString());
                        if (isCategories)
                        {
                            if (amt == -1)
                            {
                                row[4]  = "";
                                isFound = false;
                            }
                            else
                            {
                                row[4] = amt.ToString("n");
                            }
                        }
                        else
                        {
                            if (amt == -1)
                            {
                                row[3]  = "";
                                isFound = false;
                            }
                            else
                            {
                                row[3] = amt.ToString("n");
                            }
                        }
                        break;
                    }
                }
                if (includeBlanks && !isFound)
                {
                    retVal.Rows.Add(row);                     //Including a row that has a blank fee.
                }
                else if (isFound)
                {
                    retVal.Rows.Add(row);
                }
                //All other rows (empty rows where we don't want blanks) are not added to the dataset.
            }
            return(retVal);
        }
Пример #27
0
        ///<summary>If not using clinics, or for all clinics with clinics enabled, supply an empty list of clinicNums.  If the user is restricted, for all
        ///clinics supply only those clinics for which the user has permission to access, otherwise it will be run for all clinics.</summary>
        public static DataTable GetPatTable(DateTime dateFrom, DateTime dateTo, List <long> listProvNums, List <long> listClinicNums, List <long> listPatientTypes,
                                            bool hasAllProvs, bool hasAllClinics, bool hasPatientTypes, bool isGroupedByPatient, bool isUnearnedIncluded, bool doShowProvSeparate,
                                            bool doShowHiddenTPUnearned)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), dateFrom, dateTo, listProvNums, listClinicNums, listPatientTypes, hasAllProvs, hasAllClinics,
                                     hasPatientTypes, isGroupedByPatient, isUnearnedIncluded, doShowProvSeparate, doShowHiddenTPUnearned));
            }
            //reports should no longer use the cache
            bool        hasClinicsEnabled         = ReportsComplex.RunFuncOnReportServer(() => Prefs.HasClinicsEnabledNoCache);
            List <long> listHiddenUnearnedDefNums = new List <long>();

            if (!doShowHiddenTPUnearned)
            {
                listHiddenUnearnedDefNums = ReportsComplex.RunFuncOnReportServer(() =>
                                                                                 Defs.GetDefsNoCache(DefCat.PaySplitUnearnedType).FindAll(x => !string.IsNullOrEmpty(x.ItemValue)).Select(x => x.DefNum).ToList()
                                                                                 );
            }
            //patient payments-----------------------------------------------------------------------------------------
            //the selected columns have to remain in this order due to the way the report complex populates the returned sheet
            string queryPat = "SELECT payment.PayDate DatePay,"
                              + "MAX(" + DbHelper.Concat("patient.LName", "', '", "patient.FName", "' '", "patient.MiddleI") + ") lfname,GROUP_CONCAT(DISTINCT provider.Abbr),";

            if (hasClinicsEnabled)
            {
                queryPat += "clinic.Abbr clinicAbbr,";
            }
            queryPat += "payment.CheckNum,SUM(COALESCE(paysplit.SplitAmt,0)) amt,payment.PayNum,ItemName,payment.PayType "
                        + "FROM payment "
                        + "LEFT JOIN paysplit ON payment.PayNum=paysplit.PayNum "
                        + "LEFT JOIN patient ON payment.PatNum=patient.PatNum "
                        + "LEFT JOIN provider ON paysplit.ProvNum=provider.ProvNum "
                        + "LEFT JOIN definition ON payment.PayType=definition.DefNum ";
            if (hasClinicsEnabled)
            {
                queryPat += "LEFT JOIN clinic ON clinic.ClinicNum=paysplit.ClinicNum ";
            }
            queryPat += "WHERE payment.PayDate BETWEEN " + POut.Date(dateFrom) + " AND " + POut.Date(dateTo) + " ";
            if (hasClinicsEnabled && listClinicNums.Count > 0)
            {
                queryPat += "AND paysplit.ClinicNum IN(" + string.Join(",", listClinicNums.Select(x => POut.Long(x))) + ") ";
            }
            if (!hasAllProvs && listProvNums.Count > 0)
            {
                queryPat += "AND paysplit.ProvNum IN(" + string.Join(",", listProvNums.Select(x => POut.Long(x))) + ") ";
            }
            if (!hasPatientTypes && listPatientTypes.Count > 0)
            {
                queryPat += "AND payment.PayType IN (" + string.Join(",", listPatientTypes.Select(x => POut.Long(x))) + ") ";
            }
            if (!isUnearnedIncluded)             //UnearnedType of 0 means the paysplit is NOT unearned
            {
                queryPat += "AND paysplit.UnearnedType=0 ";
            }
            else if (listHiddenUnearnedDefNums.Count > 0 && !doShowHiddenTPUnearned)           //Include unearned but not of the TP type.
            {
                queryPat += $"AND paysplit.UnearnedType NOT IN ({string.Join(",",listHiddenUnearnedDefNums)}) ";
            }
            queryPat += "GROUP BY payment.PayNum,payment.PayDate,payment.CheckNum,definition.ItemName,payment.PayType ";
            if (doShowProvSeparate)
            {
                queryPat += ",provider.ProvNum ";
            }
            if (hasClinicsEnabled)
            {
                queryPat += ",clinic.Abbr ";
            }
            if (isGroupedByPatient)
            {
                queryPat += ",patient.PatNum ";
            }
            queryPat += "ORDER BY payment.PayType,payment.PayDate,lfname";
            if (!hasPatientTypes && listPatientTypes.Count == 0)
            {
                queryPat = DbHelper.LimitOrderBy(queryPat, 0);
            }
            return(ReportsComplex.RunFuncOnReportServer(() => Db.GetTable(queryPat)));
        }
Пример #28
0
        public static string GetChangesDescription(TaskHist taskCur, TaskHist taskNext)
        {
            if (taskCur.Descript.StartsWith("This task was cut from task list ") || taskCur.Descript.StartsWith("This task was copied from task "))
            {
                return(taskCur.Descript);
            }
            if (taskCur.DateTimeEntry == DateTime.MinValue)
            {
                return(Lans.g("TaskHists", "New task."));
            }
            StringBuilder strb = new StringBuilder();

            strb.Append("");
            if (taskNext.TaskListNum != taskCur.TaskListNum)
            {
                string   descOne  = Lans.g("TaskHists", "(DELETED)");
                string   descTwo  = Lans.g("TaskHists", "(DELETED)");
                TaskList taskList = TaskLists.GetOne(taskCur.TaskListNum);
                if (taskList != null)
                {
                    descOne = taskList.Descript;
                }
                taskList = TaskLists.GetOne(taskNext.TaskListNum);
                if (taskList != null)
                {
                    descTwo = taskList.Descript;
                }
                strb.Append(Lans.g("TaskHists", "Task list changed from") + " " + descOne + " " + Lans.g("TaskHists", "to") + " " + descTwo + ".\r\n");
            }
            if (taskNext.ObjectType != taskCur.ObjectType)
            {
                strb.Append(Lans.g("TaskHists", "Task attachment changed from") + " "
                            + taskCur.ObjectType.ToString() + " " + Lans.g("TaskHists", "to") + " " + taskNext.ObjectType.ToString() + ".\r\n");
            }
            if (taskNext.KeyNum != taskCur.KeyNum)
            {
                strb.Append(Lans.g("TaskHists", "Task account attachment changed.") + "\r\n");
            }
            if (taskNext.Descript != taskCur.Descript && !taskNext.Descript.StartsWith("This task was cut from task list ") &&
                !taskNext.Descript.StartsWith("This task was copied from task "))
            {
                //We change the description of a task when it is cut/copied.
                //This prevents the history grid from showing a description changed when it wasn't changed by the user.
                strb.Append(Lans.g("TaskHists", "Task description changed.") + "\r\n");
            }
            if (taskNext.TaskStatus != taskCur.TaskStatus)
            {
                strb.Append(Lans.g("TaskHists", "Task status changed from") + " "
                            + taskCur.TaskStatus.ToString() + " " + Lans.g("TaskHists", "to") + " " + taskNext.TaskStatus.ToString() + ".\r\n");
            }
            if (taskNext.DateTimeEntry != taskCur.DateTimeEntry)
            {
                strb.Append(Lans.g("TaskHists", "Task date added changed from") + " "
                            + taskCur.DateTimeEntry.ToString()
                            + " " + Lans.g("TaskHists", "to") + " "
                            + taskNext.DateTimeEntry.ToString() + ".\r\n");
            }
            if (taskNext.UserNum != taskCur.UserNum)
            {
                strb.Append(Lans.g("TaskHists", "Task author changed from ")
                            + Userods.GetUser(taskCur.UserNum).UserName
                            + " " + Lans.g("TaskHists", "to") + " "
                            + Userods.GetUser(taskNext.UserNum).UserName + ".\r\n");
            }
            if (taskNext.DateTimeFinished != taskCur.DateTimeFinished)
            {
                strb.Append(Lans.g("TaskHists", "Task date finished changed from") + " "
                            + taskCur.DateTimeFinished.ToString()
                            + " " + Lans.g("TaskHists", "to") + " "
                            + taskNext.DateTimeFinished.ToString() + ".\r\n");
            }
            if (taskNext.PriorityDefNum != taskCur.PriorityDefNum)
            {
                strb.Append(Lans.g("TaskHists", "Task priority changed from") + " "
                            + Defs.GetDef(DefCat.TaskPriorities, taskCur.PriorityDefNum).ItemName
                            + " " + Lans.g("TaskHists", "to") + " "
                            + Defs.GetDef(DefCat.TaskPriorities, taskNext.PriorityDefNum).ItemName + ".\r\n");
            }
            if (taskCur.IsNoteChange)              //Using taskOld because the notes changed from the old one to the new one.
            {
                strb.Append(Lans.g("TaskHists", "Task notes changed."));
            }
            return(strb.ToString());
        }
Пример #29
0
        ///<summary>For orderBy, use 0 for BillingType and 1 for PatientName.</summary>
        public static DataTable GetBilling(bool isSent, int orderBy, DateTime dateFrom, DateTime dateTo, List <long> clinicNums)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                return(Meth.GetTable(MethodBase.GetCurrentMethod(), isSent, orderBy, dateFrom, dateTo, clinicNums));
            }
            DataTable table = new DataTable();
            DataRow   row;

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("amountDue");
            table.Columns.Add("balTotal");
            table.Columns.Add("billingType");
            table.Columns.Add("insEst");
            table.Columns.Add("IsSent");
            table.Columns.Add("lastStatement");
            table.Columns.Add("mode");
            table.Columns.Add("name");
            table.Columns.Add("PatNum");
            table.Columns.Add("payPlanDue");
            table.Columns.Add("StatementNum");
            table.Columns.Add("SuperFamily");
            table.Columns.Add("ClinicNum");
            string command = "SELECT guar.BalTotal,patient.BillingType,patient.FName,guar.InsEst,statement.IsSent,"
                             + "IFNULL(MAX(s2.DateSent)," + POut.Date(DateTime.MinValue) + ") LastStatement,"
                             + "patient.LName,patient.MiddleI,statement.Mode_,guar.PayPlanDue,patient.Preferred,"
                             + "statement.PatNum,statement.StatementNum,statement.SuperFamily,patient.ClinicNum "
                             + "FROM statement "
                             + "LEFT JOIN patient ON statement.PatNum=patient.PatNum "
                             + "LEFT JOIN patient guar ON guar.PatNum=patient.Guarantor "
                             + "LEFT JOIN statement s2 ON s2.PatNum=patient.PatNum "
                             + "AND s2.IsSent=1 ";

            if (PrefC.GetBool(PrefName.BillingIgnoreInPerson))
            {
                command += "AND s2.Mode_ !=1 ";
            }
            if (orderBy == 0)          //BillingType
            {
                command += "LEFT JOIN definition ON patient.BillingType=definition.DefNum ";
            }
            command += "WHERE statement.IsSent=" + POut.Bool(isSent) + " ";
            //if(dateFrom.Year>1800){
            command += "AND statement.DateSent>=" + POut.Date(dateFrom) + " ";      //greater than midnight this morning
            //}
            //if(dateFrom.Year>1800){
            command += "AND statement.DateSent<" + POut.Date(dateTo.AddDays(1)) + " ";      //less than midnight tonight
            //}
            if (clinicNums.Count > 0)
            {
                command += "AND patient.ClinicNum IN (" + string.Join(",", clinicNums) + ") ";
            }
            command += "GROUP BY guar.BalTotal,patient.BillingType,patient.FName,guar.InsEst,statement.IsSent,"
                       + "patient.LName,patient.MiddleI,statement.Mode_,guar.PayPlanDue,patient.Preferred,"
                       + "statement.PatNum,statement.StatementNum,statement.SuperFamily ";
            if (orderBy == 0)          //BillingType
            {
                command += "ORDER BY definition.ItemOrder,patient.LName,patient.FName,patient.MiddleI,guar.PayPlanDue";
            }
            else
            {
                command += "ORDER BY patient.LName,patient.FName";
            }
            DataTable      rawTable = Db.GetTable(command);
            double         balTotal;
            double         insEst;
            double         payPlanDue;
            DateTime       lastStatement;
            List <Patient> listFamilyGuarantors;

            foreach (DataRow rawRow in rawTable.Rows)
            {
                row = table.NewRow();
                if (rawRow["SuperFamily"].ToString() == "0")               //not a super statement, just get bal info from guarantor
                {
                    balTotal   = PIn.Double(rawRow["BalTotal"].ToString());
                    insEst     = PIn.Double(rawRow["InsEst"].ToString());
                    payPlanDue = PIn.Double(rawRow["PayPlanDue"].ToString());
                }
                else                  //super statement, add all guar positive balances to get bal total for super family
                {
                    listFamilyGuarantors = Patients.GetSuperFamilyGuarantors(PIn.Long(rawRow["SuperFamily"].ToString())).FindAll(x => x.HasSuperBilling);
                    //exclude fams with neg balances in the total for super family stmts (per Nathan 5/25/2016)
                    if (PrefC.GetBool(PrefName.BalancesDontSubtractIns))
                    {
                        listFamilyGuarantors = listFamilyGuarantors.FindAll(x => x.BalTotal > 0);
                        insEst = 0;
                    }
                    else
                    {
                        listFamilyGuarantors = listFamilyGuarantors.FindAll(x => (x.BalTotal - x.InsEst) > 0);
                        insEst = listFamilyGuarantors.Sum(x => x.InsEst);
                    }
                    balTotal   = listFamilyGuarantors.Sum(x => x.BalTotal);
                    payPlanDue = listFamilyGuarantors.Sum(x => x.PayPlanDue);
                }
                row["amountDue"]   = (balTotal - insEst).ToString("F");
                row["balTotal"]    = balTotal.ToString("F");;
                row["billingType"] = Defs.GetName(DefCat.BillingTypes, PIn.Long(rawRow["BillingType"].ToString()));
                if (insEst == 0)
                {
                    row["insEst"] = "";
                }
                else
                {
                    row["insEst"] = insEst.ToString("F");
                }
                row["IsSent"] = rawRow["IsSent"].ToString();
                lastStatement = PIn.Date(rawRow["LastStatement"].ToString());
                if (lastStatement.Year < 1880)
                {
                    row["lastStatement"] = "";
                }
                else
                {
                    row["lastStatement"] = lastStatement.ToShortDateString();
                }
                row["mode"]   = Lans.g("enumStatementMode", ((StatementMode)PIn.Int(rawRow["Mode_"].ToString())).ToString());
                row["name"]   = Patients.GetNameLF(rawRow["LName"].ToString(), rawRow["FName"].ToString(), rawRow["Preferred"].ToString(), rawRow["MiddleI"].ToString());
                row["PatNum"] = rawRow["PatNum"].ToString();
                if (payPlanDue == 0)
                {
                    row["payPlanDue"] = "";
                }
                else
                {
                    row["payPlanDue"] = payPlanDue.ToString("F");
                }
                row["StatementNum"] = rawRow["StatementNum"].ToString();
                row["SuperFamily"]  = rawRow["SuperFamily"].ToString();
                row["ClinicNum"]    = rawRow["ClinicNum"].ToString();
                table.Rows.Add(row);
            }
            return(table);
        }
Пример #30
0
        ///<summary>Sends an SFTP message to TSI to suspend the account for the guarantor passed in.  Returns empty string if successful.
        ///Returns a translated error message that should be displayed to the user if anything goes wrong.</summary>
        public static string SuspendGuar(Patient guar)
        {
            PatAging patAging = Patients.GetAgingListFromGuarNums(new List <long>()
            {
                guar.PatNum
            }).FirstOrDefault();

            if (patAging == null)           //this would only happen if the patient was not in the db??, just in case
            {
                return(Lans.g("TsiTransLogs", "An error occurred when trying to send a suspend message to TSI."));
            }
            long    clinicNum = (PrefC.HasClinicsEnabled?guar.ClinicNum:0);
            Program prog      = Programs.GetCur(ProgramName.Transworld);

            if (prog == null)           //shouldn't be possible, the program link should always exist, just in case
            {
                return(Lans.g("TsiTransLogs", "The Transworld program link does not exist.  Contact support."));
            }
            Dictionary <long, List <ProgramProperty> > dictAllProps = ProgramProperties.GetForProgram(prog.ProgramNum)
                                                                      .GroupBy(x => x.ClinicNum)
                                                                      .ToDictionary(x => x.Key, x => x.ToList());

            if (dictAllProps.Count == 0)           //shouldn't be possible, there should always be a set of props for ClinicNum 0 even if disabled, just in case
            {
                return(Lans.g("TsiTransLogs", "The Transworld program link is not setup properly."));
            }
            if (PrefC.HasClinicsEnabled && !dictAllProps.ContainsKey(clinicNum) && dictAllProps.ContainsKey(0))
            {
                clinicNum = 0;
            }
            string clinicDesc = clinicNum == 0?"Headquarters":Clinics.GetDesc(clinicNum);

            if (!dictAllProps.ContainsKey(clinicNum) ||
                !ValidateClinicSftpDetails(dictAllProps[clinicNum], true))                    //the props should be valid, but this will test the connection using the props
            {
                return(Lans.g("TsiTransLogs", "The Transworld program link is not enabled") + " "
                       + (PrefC.HasClinicsEnabled?(Lans.g("TsiTransLogs", "for the guarantor's clinic") + ", " + clinicDesc + ", "):"")
                       + Lans.g("TsiTransLogs", "or is not setup properly."));
            }
            List <ProgramProperty> listProps = dictAllProps[clinicNum];
            long newBillType = PrefC.GetLong(PrefName.TransworldPaidInFullBillingType);

            if (newBillType == 0 || Defs.GetDef(DefCat.BillingTypes, newBillType) == null)
            {
                return(Lans.g("TsiTransLogs", "The default paid in full billing type is not set.  An automated suspend message cannot be sent until the "
                              + "default paid in full billing type is set in the Transworld program link")
                       + (PrefC.HasClinicsEnabled?(" " + Lans.g("TsiTransLogs", "for the guarantor's clinic") + ", " + clinicDesc):"") + ".");
            }
            string clientId = "";

            if (patAging.ListTsiLogs.Count > 0)
            {
                clientId = patAging.ListTsiLogs[0].ClientId;
            }
            if (string.IsNullOrEmpty(clientId))
            {
                clientId = listProps.Find(x => x.PropertyDesc == "ClientIdAccelerator")?.PropertyValue;
            }
            if (string.IsNullOrEmpty(clientId))
            {
                clientId = listProps.Find(x => x.PropertyDesc == "ClientIdCollection")?.PropertyValue;
            }
            if (string.IsNullOrEmpty(clientId))
            {
                return(Lans.g("TsiTransLogs", "There is no client ID in the Transworld program link")
                       + (PrefC.HasClinicsEnabled?(" " + Lans.g("TsiTransLogs", "for the guarantor's clinic") + ", " + clinicDesc):"") + ".");
            }
            string sftpAddress = listProps.Find(x => x.PropertyDesc == "SftpServerAddress")?.PropertyValue ?? "";
            int    sftpPort;

            if (!int.TryParse(listProps.Find(x => x.PropertyDesc == "SftpServerPort")?.PropertyValue ?? "", out sftpPort))
            {
                sftpPort = 22;              //default to port 22
            }
            string userName     = listProps.Find(x => x.PropertyDesc == "SftpUsername")?.PropertyValue ?? "";
            string userPassword = listProps.Find(x => x.PropertyDesc == "SftpPassword")?.PropertyValue ?? "";

            if (new[] { sftpAddress, userName, userPassword }.Any(x => string.IsNullOrEmpty(x)))
            {
                return(Lans.g("TsiTransLogs", "The SFTP address, username, or password for the Transworld program link") + " "
                       + (PrefC.HasClinicsEnabled?(Lans.g("TsiTransLogs", "for the guarantor's clinic") + ", " + clinicDesc + ", "):"") + Lans.g("TsiTransLogs", "is blank."));
            }
            string msg = TsiMsgConstructor.GenerateUpdate(patAging.PatNum, clientId, TsiTransType.SS, 0.00, patAging.AmountDue);

            try {
                byte[]          fileContents = Encoding.ASCII.GetBytes(TsiMsgConstructor.GetUpdateFileHeader() + "\r\n" + msg);
                TaskStateUpload state        = new Sftp.Upload(sftpAddress, userName, userPassword, sftpPort)
                {
                    Folder        = "/xfer/incoming",
                    FileName      = "TsiUpdates_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".txt",
                    FileContent   = fileContents,
                    HasExceptions = true
                };
                state.Execute(false);
            }
            catch (Exception ex) {
                return(Lans.g("TsiTransLogs", "There was an error sending the update message to Transworld")
                       + (PrefC.HasClinicsEnabled?(" " + Lans.g("TsiTransLogs", "using the program properties for the guarantor's clinic") + ", " + clinicDesc):"") + ".\r\n"
                       + ex.Message);
            }
            //Upload was successful
            TsiTransLog log = new TsiTransLog()
            {
                PatNum    = patAging.PatNum,
                UserNum   = Security.CurUser.UserNum,
                TransType = TsiTransType.SS,
                //TransDateTime=DateTime.Now,//set on insert, not editable by user
                //DemandType=TsiDemandType.Accelerator,//only valid for placement msgs
                //ServiceCode=TsiServiceCode.Diplomatic,//only valid for placement msgs
                ClientId       = clientId,
                TransAmt       = 0.00,
                AccountBalance = patAging.AmountDue,
                FKeyType       = TsiFKeyType.None, //only used for account trans updates
                FKey           = 0,                //only used for account trans updates
                RawMsgText     = msg,
                ClinicNum      = clinicNum
                                 //,TransJson=""//only valid for placement msgs
            };

            TsiTransLogs.Insert(log);
            //update family billing type to the paid in full billing type pref
            Patients.UpdateFamilyBillingType(newBillType, patAging.PatNum);
            return("");
        }