示例#1
0
 ///<summary>Returns serialized DbInfo object as JSON string of database info from both the preference table and non preferernce table info.</summary>
 private string GetDbInfoJSON(long patNum, string moduleName)
 {
     _info = new BugSubmission.SubmissionInfo();
     try {
         //This list is not in a separate method because we want to ensure that future development related to bug submissions don't try to make assumptions
         //on which preferences are in an object at any given time.
         //Ex.  Let's say in version 17.4, the list doesn't contain the payplan version preference, but 17.5 does.
         //If we called the method that retrieves the used preferences from WebServiceMainHQ which in this example is on version 17.5,
         // it would think all bugsubmission rows contain the payplan version preference when that is not the case.
         List <PrefName> listPrefs = new List <PrefName>()
         {
             PrefName.AtoZfolderUsed,
             PrefName.ClaimSnapshotEnabled,
             PrefName.ClaimSnapshotRunTime,
             PrefName.ClaimSnapshotTriggerType,
             PrefName.CorruptedDatabase,
             PrefName.DataBaseVersion,
             PrefName.EasyNoClinics,
             PrefName.LanguageAndRegion,
             PrefName.MySqlVersion,
             PrefName.PayPlansVersion,
             PrefName.ProcessSigsIntervalInSecs,
             PrefName.ProgramVersionLastUpdated,
             PrefName.ProgramVersion,
             PrefName.RandomPrimaryKeys,
             PrefName.RegistrationKey,
             PrefName.RegistrationKeyIsDisabled,
             PrefName.ReplicationFailureAtServer_id,
             PrefName.ReportingServerCompName,
             PrefName.ReportingServerDbName,
             PrefName.ReportingServerMySqlUser,
             PrefName.ReportingServerMySqlPassHash,
             PrefName.ReportingServerURI,
             PrefName.WebServiceServerName
         };
         foreach (PrefName pref in listPrefs)
         {
             _info.DictPrefValues[pref] = Prefs.GetOne(pref).ValueString;
         }
         _info.CountClinics            = Clinics.GetCount();
         _info.EnabledPlugins          = Programs.GetWhere(x => x.Enabled && !string.IsNullOrWhiteSpace(x.PluginDllName)).Select(x => x.ProgName).ToList();
         _info.ClinicNumCur            = Clinics.ClinicNum;
         _info.UserNumCur              = Security.CurUser.UserNum;
         _info.PatientNumCur           = patNum;
         _info.IsOfficeOnReplication   = (ReplicationServers.GetCount() > 0 ? true : false);
         _info.IsOfficeUsingMiddleTier = (RemotingClient.RemotingRole == RemotingRole.ClientWeb ? true : false);
         _info.WindowsVersion          = MiscData.GetOSVersionInfo();
         _info.CompName = Environment.MachineName;
         List <UpdateHistory> listHist = UpdateHistories.GetPreviouUpdateHistories(2);                       //Ordered by newer versions first.
         _info.PreviousUpdateVersion = listHist.Count == 2 ? listHist[1].ProgramVersion : "";                //Show the previous version they updated from
         _info.PreviousUpdateTime    = listHist.Count > 0 ? listHist[0].DateTimeUpdated : DateTime.MinValue; //Show when they updated to the current version.
         _info.ModuleNameCur         = moduleName;
         _info.DatabaseName          = DataConnection.GetDatabaseName();
     }
     catch (Exception ex) {
         ex.DoNothing();
     }
     return(JsonConvert.SerializeObject(_info));
 }
        ///<summary>Inserts a healthy heartbeat.</summary>
        public static void InsertHeartbeatForService(eServiceCode serviceCode)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), serviceCode);
                return;
            }
            AlertItems.DeleteFor(AlertType.EConnectorDown);
            string command = "SELECT * FROM eservicesignal WHERE ServiceCode=" + POut.Int((int)serviceCode)
                             + " AND Severity IN ("
                             + POut.Int((int)eServiceSignalSeverity.NotEnabled) + ","
                             + POut.Int((int)eServiceSignalSeverity.Working) + ","
                             + POut.Int((int)eServiceSignalSeverity.Critical)
                             + ") ORDER BY SigDateTime DESC " + DbHelper.LimitWhere(1);//only select not enabled, working, and critical statuses.
            EServiceSignal eServiceSignalLast = Crud.EServiceSignalCrud.SelectOne(command);
            DateTime       dtNow = MiscData.GetNowDateTime();

            //If initializing or changing state to working from not working, insert two signals; An anchor and a rolling timestamp.
            if (eServiceSignalLast == null || eServiceSignalLast.Severity != eServiceSignalSeverity.Working)          //First ever heartbeat or critical which was not previously critical.
            {
                if (eServiceSignalLast != null && eServiceSignalLast.Severity == eServiceSignalSeverity.Critical
                    //Do not create a signal if the eConnector was stopped because of an update
                    && (eServiceSignalLast.SigDateTime > UpdateHistories.GetLastUpdateHistory().DateTimeUpdated ||
                        UpdateHistories.GetLastUpdateHistory().DateTimeUpdated.AddMinutes(10) < dtNow))
                {
                    //Changing from critical to working so alert user that this change took place and tell them how long we were in critical state.
                    //Insert() will also insert Alert.
                    Insert(new EServiceSignal()
                    {
                        ServiceCode = (int)serviceCode, Severity = eServiceSignalSeverity.Error, SigDateTime = dtNow, IsProcessed = false, Description = "Listener was critical for " + DateTime.Now.Subtract(eServiceSignalLast.SigDateTime).ToStringHmm()
                    });
                }
                Insert(new EServiceSignal()
                {
                    ServiceCode = (int)serviceCode, Severity = eServiceSignalSeverity.Working, SigDateTime = dtNow, IsProcessed = true, Description = "Heartbeat Anchor"
                });                                                                                                                                                                                     //anchor heartbeat
                Insert(new EServiceSignal()
                {
                    ServiceCode = (int)serviceCode, Severity = eServiceSignalSeverity.Working, SigDateTime = dtNow.AddSeconds(1), IsProcessed = true, Description = "Heartbeat"
                });                                                                                                                                                                                            //rolling heartbeat
                return;
            }
            eServiceSignalLast.SigDateTime = dtNow;
            Update(eServiceSignalLast);
        }
示例#3
0
        ///<summary>Returns the earliest datetime that a version was reached. If that version has not been reached, returns the MinDate.</summary>
        public static DateTime GetDateForVersion(Version version)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                //This line is necessary because Version stores unspecified fields as -1. When Newtonsoft.Json tries to serialize it, it fails because none
                //of the arguments to the constructor are allowed to be negative.
                version = new Version(Math.Max(version.Major, 0), Math.Max(version.Minor, 0), Math.Max(version.Build, 0), Math.Max(version.Revision, 0));
                return(Meth.GetObject <DateTime>(MethodBase.GetCurrentMethod(), version));
            }
            List <UpdateHistory> listUpdates = UpdateHistories.GetAll();

            foreach (UpdateHistory update in listUpdates)
            {
                if (new Version(update.ProgramVersion) >= version)
                {
                    return(update.DateTimeUpdated);
                }
            }
            //The earliest version was later than the version passed in.
            return(new DateTime(1, 1, 1));
        }
示例#4
0
 /// <summary>Runs repeating charges for the date passed in, usually today. Can't use 'out' variables because this runs over Middle Tier.</summary>
 public static RepeatChargeResult RunRepeatingCharges(DateTime dateRun)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         return(Meth.GetObject <RepeatChargeResult>(MethodBase.GetCurrentMethod(), dateRun));
     }
     Prefs.UpdateDateT(PrefName.RepeatingChargesBeginDateTime, dateRun);
     try {
         RepeatChargeResult  result = new RepeatChargeResult();
         List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();
         if (PrefC.IsODHQ)
         {
             //Remove all eService repeating charges.
             //EService charges have already been calculated and stored in EServiceBilling table. Add those here.
             List <string> listEServiceCodes = EServiceCodeLink.GetProcCodesForAll();
             listRepeatingCharges.RemoveAll(x => listEServiceCodes.Contains(x.ProcCode));
             result.ProceduresAddedCount += EServiceBillings.AddEServiceRepeatingChargesHelper(dateRun).Count;
         }
         DateTime startedUsingFKs = UpdateHistories.GetDateForVersion(new Version("16.1.0.0"));              //We started using FKs from procs to repeat charges in 16.1.
         foreach (RepeatCharge repeatCharge in listRepeatingCharges)
         {
             if (!repeatCharge.IsEnabled || (repeatCharge.DateStop.Year > 1880 && repeatCharge.DateStop.AddMonths(3) < dateRun))
             {
                 continue;                        //This repeating charge is too old to possibly create a new charge. Not precise but greatly reduces calls to DB.
                 //We will filter by more stringently on the DateStop later on.
             }
             long codeNum = ProcedureCodes.GetCodeNum(repeatCharge.ProcCode);
             //Must contain all procedures that affect the date range.
             DateTime         procRangeStart    = repeatCharge.DateStart.AddMonths(-1);       //Minus 1 month to catch accounts that have changed their billing date
             List <Procedure> listExistingProcs = Procedures.GetCompletedForDateRange(procRangeStart, dateRun,
                                                                                      new List <long> {
                 codeNum
             },
                                                                                      new List <long> {
                 repeatCharge.PatNum
             });
             for (int j = listExistingProcs.Count - 1; j >= 0; j--)               //iterate backwards to remove elements
             {
                 Procedure proc = listExistingProcs[j];
                 if (((proc.RepeatChargeNum == repeatCharge.RepeatChargeNum)                      //Check the procedure's FK first
                      //Use the old logic without matching FKs only if the procedure was added before updating to 16.1
                      //Match patnum, codenum, fee, year, and month (IsRepeatDateHelper uses special logic to determine correct month)
                      //Procedures with the ProcDate prior to the RepeatCharge.StartDate should not be considered as valid procedures
                      //associated to the current repeat charge.
                      || ((proc.ProcDate < startedUsingFKs || startedUsingFKs.Year < 1880) &&
                          proc.PatNum == repeatCharge.PatNum &&
                          proc.CodeNum == codeNum &&
                          proc.ProcFee.IsEqual(repeatCharge.ChargeAmt))) &&
                     (proc.ProcDate >= repeatCharge.DateStart ||                           //Consider procedures that fall on or after the repeat charge start date.
                      proc.ProcDate.Day != repeatCharge.DateStart.Day)) //Consider procs only when days are not the same. Catches procs that have changed their billing date
                 {
                     continue;                                          //This existing procedure needs to be counted for this repeat charge.
                 }
                 listExistingProcs.RemoveAt(j);                         //Removing so that another repeat charge of the same code, date, and amount will be added.
             }
             List <DateTime> listBillingDates;                          //This list will have 1 or 2 dates where a repeating charge might be added
             if (PrefC.GetBool(PrefName.BillingUseBillingCycleDay))
             {
                 listBillingDates = GetBillingDatesHelper(repeatCharge.DateStart, repeatCharge.DateStop, dateRun, listExistingProcs, repeatCharge,
                                                          Patients.GetPat(repeatCharge.PatNum).BillingCycleDay);
             }
             else
             {
                 listBillingDates = GetBillingDatesHelper(repeatCharge.DateStart, repeatCharge.DateStop, dateRun, listExistingProcs, repeatCharge);
             }
             listBillingDates.RemoveAll(x => x.Date > DateTime.Today.Date && !PrefC.GetBool(PrefName.FutureTransDatesAllowed));
             //If any billing dates have not been filtered out, add a repeating charge on those dates
             foreach (DateTime billingDate in listBillingDates)
             {
                 Procedure    procAdded       = AddRepeatingChargeHelper(repeatCharge, billingDate, dateRun);
                 List <Claim> listClaimsAdded = new List <Claim>();
                 if (repeatCharge.CreatesClaim && !ProcedureCodes.GetProcCode(repeatCharge.ProcCode).NoBillIns)
                 {
                     listClaimsAdded = AddClaimsHelper(repeatCharge, procAdded);
                 }
                 result.ProceduresAddedCount++;
                 result.ClaimsAddedCount += listClaimsAdded.Count;
             }
         }
         return(result);
     }
     finally {
         Prefs.UpdateString(PrefName.RepeatingChargesBeginDateTime, "");
     }
 }
示例#5
0
 /// <summary>Runs repeating charges for the date passed in, usually today. Can't use 'out' variables because this runs over Middle Tier.</summary>
 public static RepeatChargeResult RunRepeatingCharges(DateTime dateRun)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         return(Meth.GetObject <RepeatChargeResult>(MethodBase.GetCurrentMethod(), dateRun));
     }
     Prefs.UpdateDateT(PrefName.RepeatingChargesBeginDateTime, dateRun);
     try {
         RepeatChargeResult  result = new RepeatChargeResult();
         List <RepeatCharge> listRepeatingCharges = RepeatCharges.Refresh(0).ToList();
         if (PrefC.IsODHQ)
         {
             //Remove all eService repeating charges.
             //EService charges have already been calculated and stored in EServiceBilling table. Add those here.
             List <string> listEServiceCodes = EServiceCodeLink.GetProcCodesForAll();
             listRepeatingCharges.RemoveAll(x => listEServiceCodes.Contains(x.ProcCode));
             result.ProceduresAddedCount += EServiceBillings.AddEServiceRepeatingChargesHelper(dateRun).Count;
         }
         //Must contain all procedures that affect the date range, safe to contain too many, bad to contain too few.
         List <Procedure> listExistingProcs = Procedures.GetCompletedForDateRange(dateRun.AddMonths(-3), dateRun.AddDays(1),
                                                                                  listRepeatingCharges.Select(x => x.ProcCode).Distinct().Select(x => ProcedureCodes.GetProcCode(x).CodeNum).ToList());
         DateTime startedUsingFKs = UpdateHistories.GetDateForVersion(new Version("16.1.0.0"));              //We started using FKs from procs to repeat charges in 16.1.
         foreach (RepeatCharge repeatCharge in listRepeatingCharges)
         {
             if (!repeatCharge.IsEnabled || (repeatCharge.DateStop.Year > 1880 && repeatCharge.DateStop.AddMonths(3) < dateRun))
             {
                 continue;                        //This repeating charge is too old to possibly create a new charge. Not precise but greatly reduces calls to DB.
                 //We will filter by more stringently on the DateStop later on.
             }
             Patient         pat = null;
             List <DateTime> listBillingDates;                   //This list will have 1 or 2 dates where a repeating charge might be added
             if (PrefC.GetBool(PrefName.BillingUseBillingCycleDay))
             {
                 pat = Patients.GetPat(repeatCharge.PatNum);
                 listBillingDates = GetBillingDatesHelper(repeatCharge.DateStart, repeatCharge.DateStop, dateRun, pat.BillingCycleDay);
             }
             else
             {
                 listBillingDates = GetBillingDatesHelper(repeatCharge.DateStart, repeatCharge.DateStop, dateRun);
             }
             long codeNum = ProcedureCodes.GetCodeNum(repeatCharge.ProcCode);
             //Remove billing dates if there is a procedure from this repeat charge in that month and year
             for (int i = listBillingDates.Count - 1; i >= 0; i--)             //iterate backwards to remove elements
             {
                 DateTime billingDate = listBillingDates[i];
                 for (int j = listExistingProcs.Count - 1; j >= 0; j--)                 //iterate backwards to remove elements
                 {
                     Procedure proc = listExistingProcs[j];
                     if ((proc.RepeatChargeNum == repeatCharge.RepeatChargeNum &&                       //Check the procedure's FK first
                          IsRepeatDateHelper(repeatCharge, billingDate, proc.ProcDate, pat))
                         //Use the old logic without matching FKs only if the procedure was added before updating to 16.1
                         //Match patnum, codenum, fee, year, and month (IsRepeatDateHelper uses special logic to determine correct month)
                         || ((proc.ProcDate < startedUsingFKs || startedUsingFKs.Year < 1880) &&
                             proc.PatNum == repeatCharge.PatNum &&
                             proc.CodeNum == codeNum &&
                             IsRepeatDateHelper(repeatCharge, billingDate, proc.ProcDate, pat) &&
                             proc.ProcFee.IsEqual(repeatCharge.ChargeAmt)))
                     {
                         //This is a match to an existing procedure.
                         listBillingDates.RemoveAt(i);         //Removing so that a procedure will not get added on this date.
                         listExistingProcs.RemoveAt(j);        //Removing so that another repeat charge of the same code, date, and amount will be added.
                         break;                                //Go to the next billing date
                     }
                 }
             }
             //If any billing dates have not been filtered out, add a repeating charge on those dates
             foreach (DateTime billingDate in listBillingDates)
             {
                 Procedure    procAdded       = AddRepeatingChargeHelper(repeatCharge, billingDate, dateRun);
                 List <Claim> listClaimsAdded = new List <Claim>();
                 if (repeatCharge.CreatesClaim && !ProcedureCodes.GetProcCode(repeatCharge.ProcCode).NoBillIns)
                 {
                     listClaimsAdded = AddClaimsHelper(repeatCharge, procAdded);
                 }
                 result.ProceduresAddedCount++;
                 result.ClaimsAddedCount += listClaimsAdded.Count;
             }
         }
         return(result);
     }
     finally {
         Prefs.UpdateString(PrefName.RepeatingChargesBeginDateTime, "");
     }
 }