///<summary>Gets time availalbility for appointment searching. Moved to business layer for unit tests. ///Returns the first available time slots for each of the next 10 available days. This means there will only be one time slot per day and ///that time slot will always be the first available time slot within that day regardless of additional time slots being available. ///resultCount defaults to preserve old functionality, the UI only holds 10 but this could be changed.</summary> public static List <ScheduleOpening> GetSearchResults(long aptNum, DateTime dateStart, DateTime dateEnd, List <long> listProvNums, List <long> listOpNums , List <long> listClinicNums, TimeSpan beforeTime, TimeSpan afterTime, long blockoutType = 0, bool hasProvAndBlockout = false, int resultCount = 10) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) //No call to db but designed to save middle tier trips. { return(Meth.GetObject <List <ScheduleOpening> >(MethodBase.GetCurrentMethod(), aptNum, dateStart, dateEnd, listProvNums, listOpNums, listClinicNums , beforeTime, afterTime, blockoutType, hasProvAndBlockout, resultCount)); } //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. if (beforeTime == TimeSpan.FromSeconds(0)) { beforeTime = TimeSpan.FromHours(25); //bigger than any time of day. } ApptSearchData data = GetDataForSearch(aptNum, dateStart, dateEnd, listProvNums, listOpNums, listClinicNums, blockoutType); List <ScheduleOpening> retVal = new List <ScheduleOpening>(); if (data.AppointmentToAdd == null) //appointment was deleted after clicking search. { return(retVal); } DateTime dateEvaluating = data.DateEvaluating; SearchBehaviorCriteria searchType = (SearchBehaviorCriteria)PrefC.GetInt(PrefName.AppointmentSearchBehavior); if (hasProvAndBlockout) //searching for intersection of providers and blockouts get as many results as possible. { while (dateEvaluating < dateEnd) { List <ScheduleOpening> listPotentialTimeAvailable = GetProvAndOpAvailabilityHelper(listProvNums, dateEvaluating, data, searchType, listOpNums , blockoutType); //At this point listPotentialTimeAvailable is already filtered and only contains appt times that match both provider time and operatory time. List <ScheduleOpening> listOpeningsForEntireDay = AddTimesToSearchResultsHelper(listPotentialTimeAvailable, beforeTime, afterTime); retVal.AddRange(listOpeningsForEntireDay); dateEvaluating = dateEvaluating.AddDays(1); } } else { while (retVal.Count < resultCount && dateEvaluating < dateEnd) { List <ScheduleOpening> listPotentialTimeAvailable = GetProvAndOpAvailabilityHelper(listProvNums, dateEvaluating, data, searchType, listOpNums , blockoutType); //At this point listPotentialTimeAvailable is already filtered and only contains appt times that match both provider time and operatory time. ScheduleOpening firstOpeningForDay = AddTimeToSearchResultsHelper(listPotentialTimeAvailable, beforeTime, afterTime); if (firstOpeningForDay != null) { retVal.Add(firstOpeningForDay); } dateEvaluating = dateEvaluating.AddDays(1); } } return(retVal); }
///<summary>Returns the first ScheduleOpening that falls before or after the times passed in. Returns null if none found.</summary> private static ScheduleOpening AddTimeToSearchResultsHelper(List <ScheduleOpening> listApptTimeForBehavior, TimeSpan beforeTime, TimeSpan afterTime) { //No need to check RemotingRole; no call to db. ScheduleOpening firstAvailability = null; listApptTimeForBehavior = listApptTimeForBehavior.OrderBy(x => x.DateTimeAvail).ToList(); for (int i = 0; i < listApptTimeForBehavior.Count; i++) { if (listApptTimeForBehavior[i].DateTimeAvail.TimeOfDay > beforeTime || listApptTimeForBehavior[i].DateTimeAvail.TimeOfDay < afterTime) { continue; } firstAvailability = listApptTimeForBehavior[i]; //add one for this day (only want one time per day). break; } return(firstAvailability); }