///<summary>When appt is null you must provide aptNum and HistApptAction will be set to deleted.</summary> public static void CreateHistoryEntry(Appointment appt, HistAppointmentAction action, long aptNum = 0) { HistAppointment hist = new HistAppointment(); hist.HistUserNum = Security.CurUser.UserNum; hist.ApptSource = Security.CurUser.EServiceType; hist.HistApptAction = action; if (appt != null) //Null if deleted { hist.SetAppt(appt); } else { hist.AptNum = aptNum; hist.HistApptAction = HistAppointmentAction.Deleted; } HistAppointments.Insert(hist); }
///<summary>When appt is null you must provide aptNum and HistApptAction will be set to deleted.</summary> public static void CreateHistoryEntry(Appointment appt, HistAppointmentAction action, long aptNum = 0) { if (Security.CurUser == null) { return; //There is no user currently logged on so do not create a HistAppointment. } HistAppointment hist = new HistAppointment(); hist.HistUserNum = Security.CurUser.UserNum; hist.ApptSource = Security.CurUser.EServiceType; hist.HistApptAction = action; if (appt != null) //Null if deleted { hist.SetAppt(appt); } else { hist.AptNum = aptNum; hist.HistApptAction = HistAppointmentAction.Deleted; } HistAppointments.Insert(hist); }
///<summary>Calculates the time available to verify based on a variety of patient and appointment factors. ///Looks at Appointment date, appointment creation date, last verification date, next scheduled verification, insurance renewal ///</summary> public static InsVerify SetTimeAvailableForVerify(InsVerify insVer, PlanToVerify planType, int appointmentScheduledDays, int insBenefitEligibilityDays, int patientEnrollmentDays) { //DateAppointmentScheduled-DateAppointmentCreated DateTime dateTimeLatestApptScheduling; //DateAppointmentScheduled-appointmentScheduledDays (default is 7) DateTime dateTimeUntilAppt; //DateTime the appointment takes place. DateTime dateTimeAppointment; //DateTime the patient was scheduled to be re-verified DateTime dateTimeScheduledReVerify; //DateTime verification last took place. Will be 01/01/0001 if verification has never happened. DateTime dateTimeLastVerified; //DateTime the insurance renewal month rolls over. //The month the renewal takes place is stored in the database. If the month is 0, then it is actually january. //It is the first day of the given month at midnight, or (Month#)/01/(year) @ 00:00AM. //Set to max val by default in case the PrefName.InsVerifyFutureDateBenefitYear=false. //Since max val is later in time than the appointment time, it will be ignored. DateTime dateBenifitRenewalNeeded = DateTime.MaxValue; #region Appointment Dates dateTimeAppointment = insVer.AppointmentDateTime; dateTimeUntilAppt = insVer.AppointmentDateTime.AddDays(-appointmentScheduledDays); //Calculate when the appointment was put into it's current time slot. //This will be the earliest datetime where the scheduled appointment time is what it is now List <HistAppointment> listHistAppt = HistAppointments.GetForApt(insVer.AptNum); listHistAppt.RemoveAll(x => x.AptDateTime.Date != insVer.AppointmentDateTime.Date); listHistAppt = listHistAppt.Where(x => x.AptStatus == ApptStatus.Scheduled).OrderBy(x => x.AptDateTime).ToList(); if (listHistAppt.Count > 0) { //If the appointment was moved to the current date after the (Apt.DateTime-appointmentScheduledDays), //we only had (Apt.DateTime-listHistAppt.First().HistDateTstamp) days instead of (appointmentScheduledDays) dateTimeLatestApptScheduling = listHistAppt.First().HistDateTStamp; } else { //Just in case there's no history for an appointment for some reason. //Shouldn't happen because a log entry is created when the appointment is created. //Use the date the appointment was created. This is better than nothing and should never happen anyways. dateTimeLatestApptScheduling = Appointments.GetOneApt(insVer.AptNum).SecDateEntry; } #endregion Appointment Dates #region Insurance Verification dateTimeLastVerified = insVer.DateLastVerified; //Add defined number of days to date last verified to calculate when the next verification date should have started. if (planType == PlanToVerify.InsuranceBenefits) { if (insVer.DateLastVerified == DateTime.MinValue) //If it's the min value, the insurance has never been verified. { dateTimeScheduledReVerify = insVer.DateTimeEntry; } else { dateTimeScheduledReVerify = insVer.DateLastVerified.AddDays(insBenefitEligibilityDays); } } else //PlanToVerify.PatientEligibility { if (insVer.DateLastVerified == DateTime.MinValue) { dateTimeScheduledReVerify = insVer.DateTimeEntry; } else { dateTimeScheduledReVerify = insVer.DateLastVerified.AddDays(patientEnrollmentDays); } } #endregion insurance verification #region Benifit Renewal if (PrefC.GetBool(PrefName.InsVerifyFutureDateBenefitYear)) { InsPlan insPlan = InsPlans.GetPlan(insVer.PlanNum, null); //Setup the month renew dates. Need all 3 years in case the appointment verify window crosses over a year //e.g. Appt verify date: 12/30/2016 and Appt Date: 1/6/2017 DateTime dateTimeOldestRenewal = new DateTime(DateTime.Now.Year - 1, Math.Max((byte)1, insPlan.MonthRenew), 1); DateTime dateTimeMiddleRenewal = new DateTime(DateTime.Now.Year, Math.Max((byte)1, insPlan.MonthRenew), 1); DateTime dateTimeNewestRenewal = new DateTime(DateTime.Now.Year + 1, Math.Max((byte)1, insPlan.MonthRenew), 1); //We want to find the date closest to the appointment date without going past it. if (dateTimeMiddleRenewal > dateTimeAppointment) { dateBenifitRenewalNeeded = dateTimeOldestRenewal; } else { if (dateTimeNewestRenewal > dateTimeAppointment) { dateBenifitRenewalNeeded = dateTimeMiddleRenewal; } else { dateBenifitRenewalNeeded = dateTimeNewestRenewal; } } } #endregion Benifit Renewal DateTime dateTimeAbleToVerify = VerifyDateCalulation(dateTimeUntilAppt, dateTimeLatestApptScheduling, dateTimeScheduledReVerify, dateBenifitRenewalNeeded); insVer.HoursAvailableForVerification = insVer.AppointmentDateTime.Subtract(dateTimeAbleToVerify).TotalHours; return(insVer); }