Beispiel #1
0
        ///<summary></summary>
        public static List <DateTime> GetSearchResults(long aptNum, DateTime afterDate, List <long> providerNums, int resultCount, TimeSpan beforeTime, TimeSpan afterTime)
        {
            if (beforeTime == TimeSpan.FromSeconds(0))           //if they didn't set a before time, set it to a large timespan so that we can use the same logic for checking appointment times.
            {
                beforeTime = TimeSpan.FromHours(25);             //bigger than any time of day.
            }
            SearchBehaviorCriteria SearchType   = (SearchBehaviorCriteria)PrefC.GetInt(PrefName.AppointmentSearchBehavior);
            List <DateTime>        retVal       = new List <DateTime>();
            DateTime           dayEvaluating    = afterDate.AddDays(1);
            Appointment        appointmentToAdd = Appointments.GetOneApt(aptNum);
            List <DateTime>    potentialProvAppointmentTime;
            List <DateTime>    potentialOpAppointmentTime;
            List <Operatory>   opsListAll                          = Operatories.GetDeepCopy();                 //all operatory Numbers
            List <Schedule>    scheduleListAll                     = Schedules.GetTwoYearPeriod(dayEvaluating); // Schedules for the given day.
            List <Appointment> appointmentListAll                  = Appointments.GetForPeriodList(dayEvaluating, dayEvaluating.AddYears(2));
            List <ScheduleOp>  schedOpListAll                      = ScheduleOps.GetForSchedList(scheduleListAll);
            List <ApptSearchProviderSchedule>  provScheds          = new List <ApptSearchProviderSchedule>();  //Provider Bar, ProviderSched Bar, Date and Provider
            List <ApptSearchOperatorySchedule> operatrorySchedules = new List <ApptSearchOperatorySchedule>(); //filtered based on SearchType
            List <long> operatoryNums = new List <long>();                                                     //more usefull than a list of operatories.

            for (int i = 0; i < opsListAll.Count; i++)
            {
                operatoryNums.Add(opsListAll[i].OperatoryNum);
            }
            while (retVal.Count < resultCount && dayEvaluating < afterDate.AddYears(2))
            {
                potentialOpAppointmentTime = new List <DateTime>();               //clear or create
                //Providers-------------------------------------------------------------------------------------------------------------------------------------
                potentialProvAppointmentTime = new List <DateTime>();             //clear or create
                provScheds = Appointments.GetApptSearchProviderScheduleForProvidersAndDate(providerNums, dayEvaluating, scheduleListAll, appointmentListAll);
                for (int i = 0; i < provScheds.Count; i++)
                {
                    for (int j = 0; j < 288; j++)               //search every 5 minute increment per day
                    {
                        if (j + appointmentToAdd.Pattern.Length > 288)
                        {
                            break;
                        }
                        if (potentialProvAppointmentTime.Contains(dayEvaluating.AddMinutes(j * 5)))
                        {
                            continue;
                        }
                        bool addDateTime = true;
                        for (int k = 0; k < appointmentToAdd.Pattern.Length; k++)
                        {
                            if ((provScheds[i].ProvBar[j + k] == false && appointmentToAdd.Pattern[k] == 'X') || provScheds[i].ProvSchedule[j + k] == false)
                            {
                                addDateTime = false;
                                break;
                            }
                        }
                        if (addDateTime)
                        {
                            potentialProvAppointmentTime.Add(dayEvaluating.AddMinutes(j * 5));
                        }
                    }
                }
                if (SearchType == SearchBehaviorCriteria.ProviderTimeOperatory)               //Handle Operatories here----------------------------------------------------------------------------
                {
                    operatrorySchedules        = GetAllForDate(dayEvaluating, scheduleListAll, appointmentListAll, schedOpListAll, operatoryNums, providerNums);
                    potentialOpAppointmentTime = new List <DateTime>(); //create or clear
                    //for(int j=0;j<operatrorySchedules.Count;j++) {//for each operatory
                    for (int i = 0; i < 288; i++)                       //search every 5 minute increment per day
                    {
                        if (i + appointmentToAdd.Pattern.Length > 288)  //skip if appointment would span across midnight
                        {
                            break;
                        }
                        for (int j = 0; j < operatrorySchedules.Count; j++)                   //for each operatory
                        //if(potentialOpAppointmentTime.Contains(dayEvaluating.AddMinutes(i*5))) {//skip if we already have this dateTime
                        //  break;
                        //}
                        {
                            bool addDateTime = true;
                            for (int k = 0; k < appointmentToAdd.Pattern.Length; k++)                       //check appointment against operatories
                            {
                                if (operatrorySchedules[j].OperatorySched[i + k] == false)
                                {
                                    addDateTime = false;
                                    break;
                                }
                            }
                            if (!addDateTime)
                            {
                                continue;
                            }
                            if (addDateTime)                            // && SearchType==SearchBehaviorCriteria.ProviderTimeOperatory) {//check appointment against providers available for the given operatory
                            {
                                bool provAvail = false;
                                for (int k = 0; k < providerNums.Count; k++)
                                {
                                    if (!operatrorySchedules[j].ProviderNums.Contains(providerNums[k]))
                                    {
                                        continue;
                                    }
                                    provAvail = true;
                                    for (int m = 0; m < appointmentToAdd.Pattern.Length; m++)
                                    {
                                        if ((provScheds[k].ProvBar[i + m] == false && appointmentToAdd.Pattern[m] == 'X') || provScheds[k].ProvSchedule[i + m] == false)                               //if provider bar time slot
                                        {
                                            provAvail = false;
                                            break;
                                        }
                                    }
                                    if (provAvail)                                     //found a provider with an available operatory
                                    {
                                        break;
                                    }
                                }
                                if (provAvail && addDateTime)                                 //operatory and provider are available
                                {
                                    potentialOpAppointmentTime.Add(dayEvaluating.AddMinutes(i * 5));
                                }
                            }
                            else                              //not using SearchBehaviorCriteria.ProviderTimeOperatory
                            {
                                if (addDateTime)
                                {
                                    potentialOpAppointmentTime.Add(dayEvaluating.AddMinutes(i * 5));
                                }
                            }
                        }
                    }
                }
                //At this point the potentialOpAppointmentTime is already filtered and only contains appointment times that match both provider time and operatory time.
                switch (SearchType)
                {
                case SearchBehaviorCriteria.ProviderTime:
                    //Add based on provider bars
                    for (int i = 0; i < potentialProvAppointmentTime.Count; i++)
                    {
                        if (potentialProvAppointmentTime[i].TimeOfDay > beforeTime || potentialProvAppointmentTime[i].TimeOfDay < afterTime)
                        {
                            continue;
                        }
                        retVal.Add(potentialProvAppointmentTime[i]); //add one for this day
                        break;                                       //stop looking through potential times for today.
                    }
                    break;

                case SearchBehaviorCriteria.ProviderTimeOperatory:
                    //add based on provider bar and operatory bar
                    for (int i = 0; i < potentialOpAppointmentTime.Count; i++)
                    {
                        if (potentialOpAppointmentTime[i].TimeOfDay > beforeTime || potentialOpAppointmentTime[i].TimeOfDay < afterTime)
                        {
                            continue;
                        }
                        retVal.Add(potentialOpAppointmentTime[i]); //add one for this day
                        break;                                     //stop looking through potential times for today.
                    }
                    break;
                }
                dayEvaluating = dayEvaluating.AddDays(1);
            }
            return(retVal);
        }