Ejemplo n.º 1
0
 private void FillList()
 {
     Schedule[] SchedListAll = Schedules.RefreshDay(SchedCurDate);
     SchedListDay = Schedules.GetForType(SchedListAll, SchedType, ProvNum);
     SchedDefaults.Refresh();
     SchedDefault[] schedDefForType = SchedDefaults.GetForType(SchedType, ProvNum);
     listTimeBlocks.Items.Clear();
     ALdefaults           = new ArrayList();
     labelDefault.Visible = false;
     if (SchedListDay.Length == 0)
     {
         //show defaults instead of user-entered list
         for (int i = 0; i < schedDefForType.Length; i++)
         {
             if ((int)SchedCurDate.DayOfWeek == schedDefForType[i].DayOfWeek)
             {
                 ALdefaults.Add(schedDefForType[i]);
                 listTimeBlocks.Items.Add(schedDefForType[i].StartTime.ToShortTimeString() + " - "
                                          + schedDefForType[i].StopTime.ToShortTimeString());
             }
         }
         labelDefault.Visible = true;
     }
     else//show the list of user-entered schedule items
     {
         if (SchedListDay.Length == 1 && SchedListDay[0].Status == SchedStatus.Closed)
         {
             listTimeBlocks.Items.Add("Office Closed " + SchedListDay[0].Note);
         }
         else if (SchedListDay.Length == 1 && SchedListDay[0].Status == SchedStatus.Holiday)
         {
             listTimeBlocks.Items.Add("Holiday: " + SchedListDay[0].Note);
         }
         else
         {
             for (int i = 0; i < SchedListDay.Length; i++)
             {
                 listTimeBlocks.Items.Add(SchedListDay[i].StartTime.ToShortTimeString() + " - "
                                          + SchedListDay[i].StopTime.ToShortTimeString());
             }
         }
     }
 }
Ejemplo n.º 2
0
 ///<summary></summary>
 private static bool Overlaps(Schedule sched)
 {
     Schedule[] SchedListDay = Schedules.RefreshDay(sched.SchedDate);
     Schedule[] ListForType  = Schedules.GetForType(SchedListDay, sched.SchedType, sched.ProvNum);
     for (int i = 0; i < ListForType.Length; i++)
     {
         if (ListForType[i].SchedType == ScheduleType.Blockout)
         {
             //skip if blockout, and ops don't interfere
             if (sched.Op != 0 && ListForType[i].Op != 0)                //neither op can be zero, or they will interfere
             {
                 if (sched.Op != ListForType[i].Op)
                 {
                     continue;
                 }
             }
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StartTime.TimeOfDay >= ListForType[i].StartTime.TimeOfDay &&
             sched.StartTime.TimeOfDay < ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StopTime.TimeOfDay > ListForType[i].StartTime.TimeOfDay &&
             sched.StopTime.TimeOfDay <= ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
         if (sched.ScheduleNum != ListForType[i].ScheduleNum &&
             sched.StartTime.TimeOfDay <= ListForType[i].StartTime.TimeOfDay &&
             sched.StopTime.TimeOfDay >= ListForType[i].StopTime.TimeOfDay)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
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);
        }