Esempio n. 1
0
 public async Task <DoctorWorkingTime> GetAvailableWorkingTimeAsync(Guid id, DateTime date, FilterWorktime filter)
 {
     return(await _unitOfWork.DoctorRepository.GetAvailableWorkingTimeAsync(id, date, filter));
 }
Esempio n. 2
0
        public async Task <DoctorWorkingTime> GetAvailableWorkingTimeAsync(Guid id, DateTime date, FilterWorktime filter)
        {
            var doctorTime = await Context.Doctors
                             .IncludeMultiple(x => x.Appointments, x => x.WorkingSchedules, x => x.NoAttendances)
                             .Where(x => x.IsActive && x.Id == id)
                             .Select(x => new DoctorTimeProjection
            {
                WorkingHoursInDay = x.WorkingSchedules
                                    .Where(ws => ws.IsActive && date.Date >= ws.FromDate.Date)
                                    .Select(ws => ws.Hours.ToWorkingTimes(date.DayOfWeek))
                                    .FirstOrDefault(),
                TimeOffInDay = x.NoAttendances
                               .Where(na => na.IsActive && date.IsBetween(na.FromDate.Date, na.ToDate.Date))
                               .Select(na => TimeRangeUtils.GetTimeRange(na.FromDate, na.ToDate, date))
                               .ToArray(),
                TimeBusyInDay = x.Appointments
                                .Where(a => a.IsActive && a.Status != (int)AppointmentStatus.Cancelled && a.DoctorId == id && a.AppointmentDate.Date == date.Date)
                                .Select(a => new TimeRange(a.AppointmentDate.TimeOfDay, a.AppointmentDate.AddMinutes(a.TotalMinutes).TimeOfDay))
                                .ToArray()
            })
                             .FirstOrDefaultAsync();

            var result = new DoctorWorkingTime
            {
                DoctorId     = id,
                WorkingTimes = doctorTime.WorkingHoursInDay
                               .ConvertArray(wh =>
                                             TimeRangeUtils.GetTimeFrame(wh, doctorTime.TimeOffInDay, doctorTime.TimeBusyInDay, new TimeRange(filter.TimeFrom ?? new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 59))))
                               .ToSingleArray()
            };

            if (filter.ServiceDuration.GetValueOrDefault() > 0)
            {
                result.WorkingTimes = result.WorkingTimes.Where(worktime => TimeRangeUtils.IsServiceTime(worktime, filter.ServiceDuration.Value, result.WorkingTimes)).ToArray();
            }

            return(result);
        }