Пример #1
0
        ///<summary>Tests to see if this appointment will create a double booking. Returns arrayList with no items in it if no double bookings for this appt.  But if double booking, then it returns an arrayList of adacodes which would be double booked.  You must supply the appointment being scheduled as well as a list of all appointments for that day.  The list can include the appointment being tested if user is moving it to a different time on the same day.  The ProcsForOne list of procedures needs to contain the procedures for the apt becauese procsMultApts won't necessarily, especially if it's a planned appt on the pinboard.</summary>
        public static ArrayList GetDoubleBookedCodes(Appointment apt, Appointment[] dayList, Procedure[] procsMultApts, Procedure[] procsForOne)
        {
            ArrayList retVal = new ArrayList();          //ADAcodes
            //figure out which provider we are testing for
            int provNum;

            if (apt.IsHygiene)
            {
                provNum = apt.ProvHyg;
            }
            else
            {
                provNum = apt.ProvNum;
            }
            //compute the starting row of this appt
            int convertToY = (int)(((double)apt.AptDateTime.Hour * (double)60
                                    / (double)PrefB.GetInt("AppointmentTimeIncrement")
                                    + (double)apt.AptDateTime.Minute
                                    / (double)PrefB.GetInt("AppointmentTimeIncrement")
                                    ) * (double)ContrApptSheet.Lh * ContrApptSheet.RowsPerIncr);
            int    startIndex = convertToY / ContrApptSheet.Lh;     //rounds down
            string pattern    = ContrApptSingle.GetPatternShowing(apt.Pattern);
            //keep track of which rows in the entire day would be occupied by provider time for this appt
            ArrayList aptProvTime = new ArrayList();

            for (int k = 0; k < pattern.Length; k++)
            {
                if (pattern.Substring(k, 1) == "X")
                {
                    aptProvTime.Add(startIndex + k);                  //even if it extends past midnight, we don't care
                }
            }
            //Now, loop through all the other appointments for the day, and see if any would overlap this one
            bool overlaps;

            Procedure[] procs;
            bool        doubleBooked = false;   //applies to all appts, not just one at a time.

            for (int i = 0; i < dayList.Length; i++)
            {
                if (dayList[i].AptNum == apt.AptNum)              //ignore current apt in its old location
                {
                    continue;
                }
                //ignore other providers
                if (dayList[i].IsHygiene && dayList[i].ProvHyg != provNum)
                {
                    continue;
                }
                if (!dayList[i].IsHygiene && dayList[i].ProvNum != provNum)
                {
                    continue;
                }
                if (dayList[i].AptStatus == ApptStatus.Broken)              //ignore broken appts
                {
                    continue;
                }
                //calculate starting row
                //this math is copied from another section of the program, so it's sloppy. Safer than trying to rewrite it:
                convertToY = (int)(((double)dayList[i].AptDateTime.Hour * (double)60
                                    / (double)PrefB.GetInt("AppointmentTimeIncrement")
                                    + (double)dayList[i].AptDateTime.Minute
                                    / (double)PrefB.GetInt("AppointmentTimeIncrement")
                                    ) * (double)ContrApptSheet.Lh * ContrApptSheet.RowsPerIncr);
                startIndex = convertToY / ContrApptSheet.Lh;            //rounds down
                pattern    = ContrApptSingle.GetPatternShowing(dayList[i].Pattern);
                //now compare it to apt
                overlaps = false;
                for (int k = 0; k < pattern.Length; k++)
                {
                    if (pattern.Substring(k, 1) == "X")
                    {
                        if (aptProvTime.Contains(startIndex + k))
                        {
                            overlaps     = true;
                            doubleBooked = true;
                        }
                    }
                }
                if (overlaps)
                {
                    //we need to add all ADACodes for this appt to retVal
                    procs = Procedures.GetProcsOneApt(dayList[i].AptNum, procsMultApts);
                    for (int j = 0; j < procs.Length; j++)
                    {
                        retVal.Add(procs[j].ADACode);
                    }
                }
            }
            //now, retVal contains all double booked procs except for this appt
            //need to all procs for this appt.
            if (doubleBooked)
            {
                for (int j = 0; j < procsForOne.Length; j++)
                {
                    retVal.Add(procsForOne[j].ADACode);
                }
            }
            return(retVal);
        }
Пример #2
0
        ///<summary>Used by appt search function.  Returns the next available time for the appointment.  Starts searching on lastSlot, which can be tonight at midnight for the first search.  Then, each subsequent search will start at the time of the previous search plus the length of the appointment.  Provider array cannot be length 0.  Might return array of 0 if it goes more than 1 year into the future.</summary>
        public static DateTime[] GetSearchResults(Appointment apt, DateTime afterDate, int[] providers, int resultCount,
                                                  TimeSpan beforeTime, TimeSpan afterTime)
        {
            DateTime dayEvaluating = afterDate.AddDays(1);

            Appointment[] aptList;                     //list of appointments for one day
            ArrayList     ALresults = new ArrayList(); //result Date/Times
            TimeSpan      timeFound;
            int           hourFound;

            int[][]  provBar      = new int[providers.Length][];    //dim 1 is for each provider.  Dim 2is the 10min increment
            bool[][] provBarSched = new bool[providers.Length][];   //keeps track of the schedule of each provider. True means open, false is closed.
            int      aptProv;
            string   pattern;
            int      startIndex;
            int      provIndex;       //the index of a provider within providers

            Schedule[] schedDay;      //all schedule items for a given day.
            bool       provHandled;
            bool       aptIsMatch = false;

            //int afterIndex=0;//GetProvBarIndex(afterTime);
            //int beforeIndex=0;//GetProvBarIndex(beforeTime);
            while (ALresults.Count < resultCount &&      //stops when the specified number of results are retrieved
                   dayEvaluating < afterDate.AddYears(1))
            {
                for (int i = 0; i < providers.Length; i++)
                {
                    provBar[i]      = new int[24 * ContrApptSheet.RowsPerHr];           //[144]; or 24*6
                    provBarSched[i] = new bool[24 * ContrApptSheet.RowsPerHr];
                }
                //get appointments for one day
                aptList = Refresh(dayEvaluating);
                //fill provBar
                for (int i = 0; i < aptList.Length; i++)
                {
                    if (aptList[i].IsHygiene)
                    {
                        aptProv = aptList[i].ProvHyg;
                    }
                    else
                    {
                        aptProv = aptList[i].ProvNum;
                    }
                    provIndex = -1;
                    for (int p = 0; p < providers.Length; p++)
                    {
                        if (providers[p] == aptProv)
                        {
                            provIndex = p;
                            break;
                        }
                    }
                    if (provIndex == -1)
                    {
                        continue;
                    }
                    pattern    = ContrApptSingle.GetPatternShowing(aptList[i].Pattern);
                    startIndex = (int)(((double)aptList[i].AptDateTime.Hour * (double)60 / (double)PrefB.GetInt("AppointmentTimeIncrement")
                                        + (double)aptList[i].AptDateTime.Minute / (double)PrefB.GetInt("AppointmentTimeIncrement"))
                                       * (double)ContrApptSheet.Lh * ContrApptSheet.RowsPerIncr)
                                 / ContrApptSheet.Lh;              //rounds down
                    for (int k = 0; k < pattern.Length; k++)
                    {
                        if (pattern.Substring(k, 1) == "X")
                        {
                            provBar[provIndex][startIndex + k]++;
                        }
                    }
                }
                //for(int i=0;i<provBar[0].Length;i++){
                //	Debug.Write(provBar[0][i].ToString());
                //}
                //Debug.WriteLine("");
                //handle all schedules by setting element of provBarSched to true if provider schedule shows open.
                schedDay = Schedules.RefreshDay(dayEvaluating);
                for (int p = 0; p < providers.Length; p++)
                {
                    provHandled = false;
                    //schedule for prov
                    for (int i = 0; i < schedDay.Length; i++)
                    {
                        if (schedDay[i].SchedType != ScheduleType.Provider)
                        {
                            continue;
                        }
                        if (providers[p] != schedDay[i].ProvNum)
                        {
                            continue;
                        }
                        if (schedDay[i].Status == SchedStatus.Closed || schedDay[i].Status == SchedStatus.Holiday)
                        {
                            provHandled = true;                          //all elements remain false.
                            break;
                        }
                        SetProvBarSched(ref provBarSched[p], schedDay[i].StartTime, schedDay[i].StopTime);
                        provHandled = true;
                    }
                    if (provHandled)
                    {
                        continue;
                    }
                    //schedDefault for prov
                    for (int i = 0; i < SchedDefaults.List.Length; i++)
                    {
                        if (SchedDefaults.List[i].DayOfWeek != (int)dayEvaluating.DayOfWeek)
                        {
                            continue;
                        }
                        if (SchedDefaults.List[i].SchedType != ScheduleType.Provider)
                        {
                            continue;
                        }
                        if (providers[p] != SchedDefaults.List[i].ProvNum)
                        {
                            continue;
                        }
                        SetProvBarSched(ref provBarSched[p], SchedDefaults.List[i].StartTime, SchedDefaults.List[i].StopTime);
                        provHandled = true;
                    }
                    if (provHandled)
                    {
                        continue;
                    }
                    //schedule for practice
                    for (int i = 0; i < schedDay.Length; i++)
                    {
                        if (schedDay[i].SchedType != ScheduleType.Practice)
                        {
                            continue;
                        }
                        if (schedDay[i].Status == SchedStatus.Closed || schedDay[i].Status == SchedStatus.Holiday)
                        {
                            provHandled = true;                          //all elements remain false.
                            break;
                        }
                        SetProvBarSched(ref provBarSched[p], schedDay[i].StartTime, schedDay[i].StopTime);
                        provHandled = true;
                    }
                    if (provHandled)
                    {
                        continue;
                    }
                    //SchedDefault for practice
                    for (int i = 0; i < SchedDefaults.List.Length; i++)
                    {
                        if (SchedDefaults.List[i].DayOfWeek != (int)dayEvaluating.DayOfWeek)
                        {
                            continue;
                        }
                        if (SchedDefaults.List[i].SchedType != ScheduleType.Practice)
                        {
                            continue;
                        }
                        SetProvBarSched(ref provBarSched[p], SchedDefaults.List[i].StartTime, SchedDefaults.List[i].StopTime);
                    }
                }
                //step through day, one increment at a time, looking for a slot
                pattern   = ContrApptSingle.GetPatternShowing(apt.Pattern);
                timeFound = new TimeSpan(0);
                for (int i = 0; i < provBar[0].Length; i++)          //144 if using 10 minute increments
                {
                    for (int p = 0; p < providers.Length; p++)
                    {
                        //assume apt will be placed here
                        aptIsMatch = true;
                        //test all apt increments for prov closed. If any found, continue
                        for (int a = 0; a < pattern.Length; a++)
                        {
                            if (provBarSched[p].Length < i + a + 1 || !provBarSched[p][i + a])
                            {
                                aptIsMatch = false;
                                break;
                            }
                        }
                        if (!aptIsMatch)
                        {
                            continue;
                        }
                        //test all apt increments with an X for not scheduled. If scheduled, continue.
                        for (int a = 0; a < pattern.Length; a++)
                        {
                            if (pattern.Substring(a, 1) == "X" && (provBar[p].Length < i + a + 1 || provBar[p][i + a] > 0))
                            {
                                aptIsMatch = false;
                                break;
                            }
                        }
                        if (!aptIsMatch)
                        {
                            continue;
                        }
                        //convert to valid time
                        hourFound = (int)((double)(i) / 60 * PrefB.GetInt("AppointmentTimeIncrement"));
                        timeFound = new TimeSpan(
                            hourFound,
                            //minutes. eg. (13-(2*60/10))*10
                            (int)((i - ((double)hourFound * 60 / (double)PrefB.GetInt("AppointmentTimeIncrement")))
                                  * PrefB.GetInt("AppointmentTimeIncrement")),
                            0);
                        //make sure it's after the time restricted
                        //Debug.WriteLine(timeFound.ToString()+"  "+afterTime.ToString());
                        //apt.AptDateTime.TimeOfDay+"  "+afterTime.ToString());
                        if (afterTime != TimeSpan.Zero && timeFound < afterTime)
                        {
                            aptIsMatch = false;
                            continue;
                        }
                        if (beforeTime != TimeSpan.Zero && timeFound > beforeTime)
                        {
                            aptIsMatch = false;
                            continue;
                        }
                        //match found
                        ALresults.Add(dayEvaluating + timeFound);
                    }                    //for p
                    if (aptIsMatch)
                    {
                        break;
                    }
                }
                dayEvaluating = dayEvaluating.AddDays(1);              //move to the next day
            }
            DateTime[] retVal = new DateTime[ALresults.Count];
            ALresults.CopyTo(retVal);
            return(retVal);
        }