Beispiel #1
0
        /// <summary>
        /// از تاریخ و ساعت مشخص شده شروع می کند و اولین بازه زمانی خالی را برای ارایه موردنظر پیدا می کند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="From_DateTime">تاریخ</param>
        /// <param name="StartTime">ساعت</param>
        /// <returns></returns>
        public TimePeriodModel Find_First_Empty_TimePeriod_From_DateTime(ServiceSupply serviceSupply, DateTime from, ShiftCenterService polyclinicHealthService)
        {
            if (!serviceSupply.IsAvailable)
            {
                return(null);
            }

            var availableEmptyPeriodsByPercent = new List <TimePeriodModel>();

            var startReservationDate = serviceSupply.StartReservationDate > from ? serviceSupply.StartReservationDate : from;
            var lastDay = startReservationDate.AddDays(serviceSupply.ShiftCenter.ActiveDaysAhead);

            for (var dt = startReservationDate.Date; dt <= lastDay.Date; dt = dt.AddDays(1))
            {
                var schedules = _serviceSupplyManager.GetSchedulesByDate(serviceSupply, dt, polyclinicHealthService);
                if (schedules != null && schedules.Count > 0)
                {
                    foreach (var schedule in schedules)
                    {
                        var result = Calculate_Available_Empty_TimePeriods_By_Percent(serviceSupply, schedule.Start_DateTime, polyclinicHealthService);

                        if (result != null && result.Count() > 0)
                        {
                            return(result.FirstOrDefault(x => x.StartDateTime >= DateTime.Now));
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// از همین الان شروع می کند و اولین بازه زمانی خالی را برای ارایه پیدا می کند و بر می گرداند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <returns></returns>
        public TimePeriodModel FindFirstEmptyTimePeriodFromNow(ServiceSupply serviceSupply, ShiftCenterService polyclinicHealthService)
        {
            if (!serviceSupply.IsAvailable)
            {
                return(null);
            }

            var startReservationDate = serviceSupply.StartReservationDate > DateTime.Now ? serviceSupply.StartReservationDate : DateTime.Now;
            var lastDay = startReservationDate.AddDays(serviceSupply.ShiftCenter.ActiveDaysAhead);

            for (var dt = startReservationDate.Date; dt <= lastDay.Date; dt = dt.AddDays(1))
            {
                //var schedules = GetSchedulesByDate(serviceSupply, dt, polyclinicHealthService);
                //if (schedules != null && schedules.Count > 0)
                //{
                //    foreach (var schedule in schedules)
                //    {
                var result = Calculate_Available_Empty_TimePeriods_By_Percent(serviceSupply, dt, polyclinicHealthService);

                if (result != null && result.Count() > 0)
                {
                    return(result.FirstOrDefault(x => x.StartDateTime >= DateTime.Now));
                }
                //}
                //}
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// بدست آوردن پیش نیاز پزشک برای یک تاریخی
        /// </summary>
        /// <param name="datetime"></param>
        /// <param name="serviceSupply"></param>
        /// <returns></returns>
        public PrerequisiteType getPrerequsite(DateTime datetime, ServiceSupply serviceSupply)
        {
            var prerequsite = PrerequisiteType.WithoutPrerequisite;

            var specialSchedule = serviceSupply.Schedules.FirstOrDefault(x => x.IsAvailable && x.Start_DateTime.ToShortDateString() == datetime.ToShortDateString());

            if (specialSchedule != null && specialSchedule.Prerequisite != null)
            {
                prerequsite = specialSchedule.Prerequisite;
            }
            else
            {
                var shift = 0; //Mornig
                if (datetime.Hour >= Defaults.EveningStart.Hour && datetime.Hour <= Defaults.EveningEnd.Hour)
                {
                    shift = 1; //Evening
                }
                var plan = serviceSupply.UsualSchedulePlans.FirstOrDefault(x => x.Shift == (ScheduleShift)shift && x.DayOfWeek == datetime.DayOfWeek);
                if (plan != null)
                {
                    prerequsite = plan.Prerequisite;
                }
            }

            return(prerequsite);
        }
        public async Task <ServiceSupply> GetServiceSupplyForAreaAsync(int id)
        {
            if (id == 0)
            {
                return(null);
            }

            ServiceSupply serviceSupply = null;

            switch (_workContext.LoginAs)
            {
            case LoginAs.ADMIN:
                serviceSupply = await GetServiceSupplyByIdAsync(id);

                break;

            case LoginAs.CLINICMANAGER:
                serviceSupply = GetServiceSupplyByIdForClinic(_workContext.WorkingArea.Id, id);
                break;

            case LoginAs.POLYCLINICMANAGER:
            case LoginAs.BEAUTYCENTERMANAGER:
                serviceSupply = GetServiceSupplyByIdForPolyClinic(_workContext.WorkingArea.Id, id);
                break;

            default:
                break;
            }

            return(serviceSupply);
        }
        public virtual void UpdateServiceSupply(ServiceSupply serviceSupply)
        {
            if (serviceSupply == null)
            {
                throw new ArgumentNullException("serviceSupply");
            }

            _serviceSupplyRepository.Update(serviceSupply);
        }
Beispiel #6
0
        /// <summary>
        /// در تاریخ موردنظر اولین بازه زمانی خالی را برای ارایه موردنظر بدست می آورد
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="Date">تاریخ</param>
        /// <returns></returns>
        public TimePeriodModel FindFirstEmptyTimePeriodInDate(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
        {
            var emptyPeriods = Calculate_Available_Empty_TimePeriods_By_Percent(serviceSupply, Date, polyclinicHealthService);

            if (emptyPeriods != null && emptyPeriods.Count() > 0)
            {
                return(emptyPeriods.FirstOrDefault());
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// لیست همه بازه های زمانی قابل رزرو و رزرو شده و یا در حال رزرو را بر می گرداند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="Date">تاریخ - روز</param>
        /// <returns></returns>
        public IEnumerable <TimePeriodModel> Calculate_All_TimePeriods(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
        {
            var BookableTimePeriods = Calculate_Bookable_TimePeriods(serviceSupply, Date, polyclinicHealthService);

            if (BookableTimePeriods != null && BookableTimePeriods.Count() >= 1)
            {
                // This is necessary
                BookableTimePeriods = BookableTimePeriods.ToList();

                var appointments = Get_All_Appointments(serviceSupply, Date).ToList();

                var inProgressAppointments = Calculate_InProgressAppointments_TimePriods(serviceSupply, Date).ToList();

                if ((appointments == null || appointments.Count <= 0) &&
                    (inProgressAppointments == null || inProgressAppointments.Count <= 0))
                {
                    return(BookableTimePeriods);
                }

                if (appointments != null && appointments.Count >= 1)
                {
                    foreach (var pa in appointments)
                    {
                        foreach (var bookable in BookableTimePeriods)
                        {
                            if (bookable.StartDateTime == pa.Start_DateTime && bookable.Type != TimePeriodType.InProgressAppointment)
                            {
                                BookableTimePeriods.ElementAt(BookableTimePeriods.IndexOf(bookable)).Type = pa.OfferId == null ? TimePeriodType.Appointment : TimePeriodType.OfferAppointment;
                                break;
                            }
                        }
                    }
                }

                if (inProgressAppointments != null && inProgressAppointments.Count >= 1)
                {
                    foreach (var ipa in inProgressAppointments)
                    {
                        foreach (var bookable in BookableTimePeriods)
                        {
                            if (bookable.StartDateTime == ipa.StartDateTime && bookable.Type != TimePeriodType.Appointment)
                            {
                                BookableTimePeriods.ElementAt(BookableTimePeriods.IndexOf(bookable)).Type = TimePeriodType.InProgressAppointment;
                            }
                        }
                    }
                }

                return(BookableTimePeriods.OrderBy(x => x.StartDateTime));
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// این متد مشخص میکند که آیا پزشکی که سرویس ارایه میدهد برای همه زمانبندی هایش پیش نیاز تعریف شده است یا نه؟
        /// </summary>
        /// <param name="serviceSupply">پزشکی که در مطبی سرویس ارایه می دهد</param>
        /// <returns></returns>
        public bool IsNeedPrerequsiteForAllTimes(ServiceSupply serviceSupply)
        {
            var haveUsuals = (from u in serviceSupply.UsualSchedulePlans
                              where u.Prerequisite != PrerequisiteType.WithoutPrerequisite
                              select u).Count() >= 1;

            var haveSchedules = (from s in serviceSupply.Schedules
                                 where s.IsAvailable && s.Prerequisite != null && s.Prerequisite != PrerequisiteType.WithoutPrerequisite
                                 select s).ToList().Count >= 1;

            return(haveUsuals || haveSchedules);
        }
Beispiel #9
0
        /// <summary>
        /// مشخص می کند که آیا بازه زمانی موردنظر برای ارایه خالی است یا نه؟
        /// </summary>
        /// <param name="serviceSupply">ارایه</param>
        /// <param name="datetime">تاریخ و زمان</param>
        /// <returns></returns>
        public bool IsEmptyTimePeriod(ServiceSupply serviceSupply, TimePeriodModel timePriod, ShiftCenterService polyclinicHealthService)
        {
            var founded = Calculate_Empty_TimePeriods(serviceSupply, timePriod.StartDateTime, polyclinicHealthService)
                          .Where(x => x.StartDateTime == timePriod.StartDateTime && x.EndDateTime == timePriod.EndDateTime).FirstOrDefault();

            if (founded == null)
            {
                return(false);
            }

            return(true);
        }
Beispiel #10
0
        public IEnumerable <TimePeriodModel> CalculateFinalBookableTimePeriods(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
        {
            var allTimePeriods = Calculate_All_TimePeriods(serviceSupply, Date, polyclinicHealthService);

            if (allTimePeriods != null && allTimePeriods.Count() > 0)
            {
                var finalBookables = allTimePeriods.Where(x => x.Type == TimePeriodType.InProgressAppointment && x.StartDateTime >= DateTime.Now).OrderBy(x => x.StartDateTime);

                return(finalBookables);
            }

            return(null);
        }
        public bool HaveWorkingSchedules(ServiceSupply serviceSupply, DateTime Date, int shift)
        {
            var specialSchedules = new List <Schedule>();

            var specialNotAvailables = serviceSupply.Schedules.Where(x => x.Start_DateTime.Date == Date.Date &&
                                                                     !x.IsAvailable &&
                                                                     ((x.Start_DateTime.Hour == 06 && x.End_DateTime.Hour == 23) || (Utils.GetScheduleShift(x.Start_DateTime, x.End_DateTime) == (ScheduleShift)shift))
                                                                     ).ToList();

            if (specialNotAvailables.Count > 0)
            {
                return(false);
            }

            switch (shift)
            {
            case 0:     //Morning
                specialSchedules = serviceSupply.Schedules.Where(x => x.Start_DateTime.Date == Date.Date && (Utils.GetScheduleShift(x.Start_DateTime, x.End_DateTime) == ScheduleShift.Morning) && x.IsAvailable).ToList();
                break;

            case 1:     //Evening
                specialSchedules = serviceSupply.Schedules.Where(x => x.Start_DateTime.Date == Date.Date && (Utils.GetScheduleShift(x.Start_DateTime, x.End_DateTime) == ScheduleShift.Evening) && x.IsAvailable).ToList();
                break;
            }

            if (specialSchedules.Count > 0)
            {
                return(true);
            }
            else
            {
                //باید مطمین شویم که تاریخ موردنظر جزو روزهای تعطیل نمی باشد
                //var isVocation = IsSystemVocationDay(Date) || serviceSupply.PoliClinic.PoliClinicVocationDays.Count(x => x.Date.Date == Date.Date) >= 1;

                if (/*IsSystemVocationDay(Date) ||*/ IsLocalVocationDay(Date, serviceSupply))
                {
                    return(false);
                }

                var usualDayPlan = serviceSupply.UsualSchedulePlans.FirstOrDefault(x => x.Shift == (ScheduleShift)shift && x.DayOfWeek == Date.DayOfWeek);

                if (usualDayPlan == null)
                {
                    return(false);
                }

                return(true);
            }
        }
        public IList <Schedule> GetSchedulesByDateWithoutFilter(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyClinicHealthService)
        {
            //بررسی می کنیم که آیا زمانبندی دستی  و منحصربفرد برای تاریخ موردنظر تعریف شده است یا نه؟
            var specialSchedules = serviceSupply.Schedules.Where(x => x.Start_DateTime.Date == Date.Date && x.ShiftCenterServiceId == polyClinicHealthService.Id && x.IsAvailable).ToList();

            if (specialSchedules.Count > 0)
            {
                return(specialSchedules);
            }
            else
            {
                //باید مطمین شویم که تاریخ موردنظر جزو روزهای تعطیل نمی باشد
                //var isVocation = IsSystemVocationDay(Date) || serviceSupply.PoliClinic.PoliClinicVocationDays.Count(x => x.Date.Date == Date.Date) >= 1;

                if (/*IsSystemVocationDay(Date) ||*/ IsLocalVocationDay(Date, serviceSupply))
                {
                    return(null);
                }

                var usualDayPlans = serviceSupply.UsualSchedulePlans.Where(x => x.DayOfWeek == Date.DayOfWeek && x.ShiftCenterServiceId == polyClinicHealthService.Id).ToList();

                if (usualDayPlans.Count == 0)
                {
                    return(null);
                }

                var usualSchedules = new List <Schedule>();
                foreach (var plan in usualDayPlans)
                {
                    usualSchedules.Add(new Schedule
                    {
                        CreatedAt            = DateTime.Now,
                        DayOfWeek            = plan.DayOfWeek.ToString(),
                        Description_Ku       = "",
                        IsAvailable          = serviceSupply.IsAvailable,
                        MaxCount             = plan.MaxCount,
                        Shift                = plan.Shift,
                        ShiftCenterServiceId = plan.ShiftCenterServiceId,
                        ServiceSupply        = serviceSupply,
                        ServiceSupplyId      = serviceSupply.Id,
                        Start_DateTime       = DateTime.Parse(Date.ToShortDateString() + " " + plan.StartTime),
                        End_DateTime         = DateTime.Parse(Date.ToShortDateString() + " " + plan.EndTime)
                    });
                }

                return(usualSchedules);
            }
        }
        /// <summary>
        /// Determine if a Date is vocation day or not
        /// </summary>
        /// <param name="date">specified date</param>
        /// <returns>true or false</returns>
        //public bool IsSystemVocationDay(DateTime date)
        //{
        //    //only we need date and not time
        //    //Linq to entities dont support .Date or .ToShortDateString()
        //    var _date = date.Date;
        //    using (var context = new BanobatDbContext())
        //    {
        //        return context.VocationDays.FirstOrDefault(x => x.Date == _date) != null;
        //    }
        //}


        public bool IsLocalVocationDay(DateTime date, ServiceSupply serviceSupply)
        {
            if (serviceSupply.ShiftCenter.IsIndependent)
            {
                if (serviceSupply.ShiftCenter.Vocations == null)
                {
                    return(false);
                }

                return(serviceSupply.ShiftCenter.Vocations.Where(v => date.Date >= v.F.Date && date.Date <= v.T.Date).Count() > 0);
            }
            else if (serviceSupply.ShiftCenter.Clinic.IsIndependent)
            {
                var isPolyclinicVocation = false;
                var isClinicVocation     = false;

                if (serviceSupply.ShiftCenter.Vocations != null)
                {
                    isPolyclinicVocation = serviceSupply.ShiftCenter.Vocations.Where(v => date.Date >= v.F.Date && date.Date <= v.T.Date).Count() > 0;
                }

                if (serviceSupply.ShiftCenter.Clinic.Vocations != null)
                {
                    isClinicVocation = serviceSupply.ShiftCenter.Clinic.Vocations.Where(v => date.Date >= v.F.Date && date.Date <= v.T.Date).Count() > 0;
                }

                return(isPolyclinicVocation || isClinicVocation);
            }
            else
            {
                var isPolyclinicVocation = false;
                var isClinicVocation     = false;

                if (serviceSupply.ShiftCenter.Vocations != null)
                {
                    isPolyclinicVocation = serviceSupply.ShiftCenter.Vocations.Where(v => date.Date >= v.F.Date && date.Date <= v.T.Date).Count() > 0;
                }

                if (serviceSupply.ShiftCenter.Clinic.Vocations != null)
                {
                    isClinicVocation = serviceSupply.ShiftCenter.Clinic.Vocations.Where(v => date.Date >= v.F.Date && date.Date <= v.T.Date).Count() > 0;
                }

                return(isPolyclinicVocation || isClinicVocation);
            }
        }
Beispiel #14
0
        /// <summary>
        /// این متد لیست همه بازه های زمانی که قابلیت رزرو دارند را برای یک ارایه در یک تاریخ محاسبه و بر می گرداند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="Date">تاریخ - روز</param>
        /// <returns>لیست بازه های زمانی دارای قابلیت رزرو</returns>
        public IList <TimePeriodModel> Calculate_Bookable_TimePeriods(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
        {
            var BookableTimes = new List <TimePeriodModel>();

            var nonBreakTimes = _serviceSupplyManager.Get_Non_Break_Times(serviceSupply, Date, polyclinicHealthService);

            if (nonBreakTimes != null && nonBreakTimes.Count() >= 1)
            {
                foreach (var item in nonBreakTimes)
                {
                    for (var dt = item.StartDateTime; dt <= item.EndDateTime; dt = dt.AddMinutes(item.Duration))
                    {
                        var tpEndTime = dt.AddMinutes(item.Duration);
                        if (tpEndTime <= item.EndDateTime)
                        {
                            BookableTimes.Add(new TimePeriodModel
                            {
                                StartDateTime = dt,
                                EndDateTime   = tpEndTime,
                                Duration      = item.Duration,
                                Type          = TimePeriodType.Empty
                            });
                        }
                        else
                        {
                            var tpStartTime = tpEndTime.AddMinutes(-item.Duration);

                            if (tpStartTime > item.StartDateTime && tpStartTime < item.EndDateTime)
                            {
                                BookableTimes.Add(new TimePeriodModel
                                {
                                    StartDateTime = tpStartTime,
                                    EndDateTime   = item.EndDateTime,
                                    Duration      = item.Duration,
                                    Type          = TimePeriodType.Empty
                                });
                            }
                        }
                    }
                }
                return(BookableTimes.OrderBy(x => x.StartDateTime).ToList());
            }

            return(null);
        }
Beispiel #15
0
        public DoctorTimePeriods FindFirstDateEmptyTimePeriodsFromNow(ServiceSupply serviceSupply, ShiftCenterService polyclinicHealthService)
        {
            if (!serviceSupply.IsAvailable)
            {
                return new DoctorTimePeriods {
                           TimePeriods = new List <TimePeriodModel>(), HasOffers = false
                }
            }
            ;

            var startReservationDate = serviceSupply.StartReservationDate > DateTime.Now ? serviceSupply.StartReservationDate : DateTime.Now;
            var lastDay = startReservationDate.AddDays(serviceSupply.ShiftCenter.ActiveDaysAhead);

            for (var dt = startReservationDate.Date; dt <= lastDay.Date; dt = dt.AddDays(1))
            {
                var result = Calculate_Available_Empty_TimePeriods_By_Percent(serviceSupply, dt, polyclinicHealthService);

                if (result != null && result.Any())
                {
                    // TODO: We can check here if doctor has offer for this date or not
                    // Then get offer here and calculate all time periods include offers

                    var hasOffer = serviceSupply.Offers.Any(x => x.StartDateTime.Value.Date == dt.Date);

                    var turns = result.Where(x => x.StartDateTime >= DateTime.Now);

                    if (serviceSupply.ReservationType == ReservationType.Selective)
                    {
                        return(new DoctorTimePeriods {
                            TimePeriods = turns.ToList(), HasOffers = hasOffer
                        });
                    }
                    else
                    {
                        return(new DoctorTimePeriods {
                            TimePeriods = turns.Take(1).ToList(), HasOffers = hasOffer
                        });
                    }
                }
            }

            return(new DoctorTimePeriods {
                TimePeriods = new List <TimePeriodModel>(), HasOffers = false
            });
        }
Beispiel #16
0
        public void EnsureHasSchedule(ServiceSupply serviceSupply, int centerServiceId, DateTime start, DateTime end, bool passIfNoSchedules = false)
        {
            // Ensure doctor has schedule for requested date/time
            var schedule = serviceSupply.Schedules.Where(x => x.ShiftCenterServiceId == centerServiceId && x.Start_DateTime <= start && x.End_DateTime >= end).FirstOrDefault();

            if (schedule == null)
            {
                var hasSchedule = false;

                var turnShift = getScheduleShift(start, end);

                var generalSchedules = serviceSupply.UsualSchedulePlans.Where(x => x.ShiftCenterServiceId == centerServiceId && x.DayOfWeek == start.DayOfWeek && x.Shift == turnShift).ToList();

                if (generalSchedules.Any())
                {
                    foreach (var item in generalSchedules)
                    {
                        var scheduleStartTime = DateTime.Parse($"{start.ToShortDateString()} {item.StartTime}");
                        var scheduleEndTime   = DateTime.Parse($"{start.ToShortDateString()} {item.EndTime}");
                        if (scheduleStartTime <= start && scheduleEndTime >= start)
                        {
                            hasSchedule = true;
                            break;
                        }
                    }
                    if (!hasSchedule)
                    {
                        throw new AwroNoreException(Messages.WorkingScheduleNotFoundForThisTime);
                    }
                }
                else
                {
                    if (!passIfNoSchedules)
                    {
                        throw new AwroNoreException(Messages.WorkingScheduleNotFoundForThisTime);
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// از یک تاریخ تا تاریخ دیگری اولین بازه زمانی خالی را برای ارایه پیدا می کند
        /// </summary>
        /// <param name="serviceSupply"></param>
        /// <param name="From_DateTime"></param>
        /// <param name="To_DateTime"></param>
        /// <returns></returns>
        public TimePeriodModel Find_First_Empty_TimePeriod_FromDateTime_ToDateTime(ServiceSupply serviceSupply, DateTime From_DateTime, DateTime To_DateTime, ShiftCenterService polyclinicHealthService)
        {
            var BRH = serviceSupply.ShiftCenter.BookingRestrictionHours;

            if (From_DateTime >= To_DateTime)
            {
                throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
            }

            if (From_DateTime < DateTime.Now)
            {
                throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
            }


            for (var dt = From_DateTime; dt <= To_DateTime || dt.ToShortDateString().Trim() == To_DateTime.ToShortDateString().Trim(); dt = dt.AddDays(1))
            {
                var schedules = _serviceSupplyManager.GetSchedulesByDate(serviceSupply, dt, polyclinicHealthService);
                foreach (var schedule in schedules)
                {
                    //اگر در روز مورد نظر وضعیت زمانبندی برابر در دسترس باشد
                    if (schedule != null && (schedule.Start_DateTime - DateTime.Now).TotalHours > BRH && schedule.IsAvailable)
                    {
                        var timePeriods = Calculate_Available_Empty_TimePeriods_By_Percent(serviceSupply, dt, polyclinicHealthService).ToList();
                        foreach (var item in timePeriods)
                        {
                            if (item != null && (item.StartDateTime >= From_DateTime && item.EndDateTime <= To_DateTime))
                            {
                                return(item);
                            }
                        }
                    }
                }
            }

            return(null);
        }
 /// <summary>
 /// Get all inprogress appointments from redis client pool for specific service supply in selected date
 /// </summary>
 /// <param name="serviceSupply"></param>
 /// <param name="Date"></param>
 /// <returns></returns>
 public IEnumerable <IPAModel> GetAll(ServiceSupply serviceSupply, DateTime Date)
 {
     return(GetAll().Where(x => x.ServiceSupplyId == serviceSupply.Id && x.StartDateTime.ToShortDateString() == Date.ToShortDateString()).OrderBy(x => x.StartDateTime));
 }
        public async Task <BookingAppointmentResult> BookAppointmentAsync(
            ServiceSupply serviceSupply,
            PatientModel patinetModel,
            string Date,
            string StartTime,
            string EndTime,
            bool _existUser,
            PaymentStatus paymentStatus,
            ShiftCenterService polyclinicHealthService,
            ReservationChannel channel,
            Lang requestLang,
            int?offerId = null)
        {
            var resultMessage = Messages.ErrorOccuredWhileFinalBookTurn;

            try
            {
                if (serviceSupply == null)
                {
                    throw new ArgumentNullException(nameof(serviceSupply));
                }

                if (string.IsNullOrEmpty(Date) || string.IsNullOrEmpty(StartTime) || string.IsNullOrEmpty(EndTime))
                {
                    throw new ArgumentNullException("Date");
                }

                var tmpStatus = paymentStatus == PaymentStatus.NotPayed ? AppointmentStatus.Unknown : AppointmentStatus.Pending;

                var startDateTime = DateTime.Parse(Date + " " + StartTime);

                var endDateTime = DateTime.Parse(Date + " " + EndTime);

                var date = DateTime.Parse(Date).Date;

                long   appointmentId = -1;
                string trackingCode  = string.Empty;

                var strategy = _dbContext.Database.CreateExecutionStrategy();
                await strategy.ExecuteAsync(async() =>
                {
                    using (var transaction = _dbContext.Database.BeginTransaction())
                    {
                        try
                        {
                            if (offerId != null)
                            {
                                var offer = await _dbContext.Offers.FindAsync(offerId.Value);

                                if (offer == null)
                                {
                                    throw new AwroNoreException("Offer Not Found");
                                }

                                if (offer.RemainedCount <= 0)
                                {
                                    throw new AwroNoreException("All Offer Appointments Are Reserved");
                                }

                                offer.RemainedCount -= 1;

                                _dbContext.Entry(offer).State = EntityState.Modified;

                                await _dbContext.SaveChangesAsync();
                            }

                            #region book appointment for new user
                            if (!_existUser)
                            {
                                var patientUser = new Person
                                {
                                    NamePrefix      = patinetModel.NamePrefix,
                                    FirstName       = patinetModel.FirstName,
                                    SecondName      = patinetModel.SecondName,
                                    ThirdName       = patinetModel.ThirdName,
                                    Age             = patinetModel.Age,
                                    Gender          = patinetModel.Gender,
                                    Mobile          = patinetModel.Mobile,
                                    ZipCode         = patinetModel.ZipCode,
                                    Address         = patinetModel.Address,
                                    Description     = patinetModel.Description,
                                    CreatedAt       = DateTime.Now,
                                    IsApproved      = true,
                                    IsDeleted       = false,
                                    CreatorRole     = Shared.Enums.LoginAs.UNKNOWN,
                                    CreationPlaceId = null
                                };

                                _dbContext.Persons.Add(patientUser);

                                _dbContext.SaveChanges();

                                // TODO:
                                // var createUser = userManager.Create(patientUser, patinetModel.Password);

                                //if (createUser.Succeeded)
                                //{
                                //    var assignPatientRole = userManager.AddToRole(patientUser.Id, UsersRoleName.Patient.ToString());
                                //    if (!assignPatientRole.Succeeded)
                                //    {
                                //        throw new Exception(Messages.ErrorOccuredWhileAssignRole);
                                //    }
                                //}

                                _dbContext.PatientPersonInfo.Add(new PatientPersonInfo
                                {
                                    PersonId  = patientUser.Id,
                                    CreatedAt = DateTime.Now
                                });

                                #region Set Patient Insurance
                                int?_patientInsuranceId = null;

                                if (patinetModel.InsuranceId != 0 && patinetModel.InsuranceNumber != null)
                                {
                                    var _patientInsurance = new PatientInsurance
                                    {
                                        UserPatientId            = patientUser.Id,
                                        ServiceSupplyInsuranceId = patinetModel.InsuranceId,
                                        InsuranceNumber          = patinetModel.InsuranceNumber,
                                        CreatedAt = DateTime.Now
                                    };
                                    _dbContext.PatientInsurances.Add(_patientInsurance);
                                    _dbContext.SaveChanges();
                                    _patientInsuranceId = _patientInsurance.Id;
                                }
                                #endregion

                                var finalBookabeTimePeriods = _doctorServiceManager.CalculateFinalBookableTimePeriods(serviceSupply, startDateTime, polyclinicHealthService);

                                if (finalBookabeTimePeriods == null || finalBookabeTimePeriods.Count() <= 0)
                                {
                                    throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
                                }

                                var ipaTimePeriod = finalBookabeTimePeriods.FirstOrDefault(f => f.StartDateTime == startDateTime && f.EndDateTime == endDateTime && f.Type == TimePeriodType.InProgressAppointment);

                                if (ipaTimePeriod == null)
                                {
                                    throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
                                }

                                trackingCode = await _appointmentService.GenerateUniqueTrackingNumberAsync();

                                var appointment = new Appointment
                                {
                                    UniqueTrackingCode   = trackingCode,
                                    Book_DateTime        = DateTime.Now,
                                    Start_DateTime       = startDateTime,
                                    End_DateTime         = endDateTime,
                                    Description          = " ",
                                    Status               = tmpStatus,
                                    ServiceSupplyId      = serviceSupply.Id,
                                    PersonId             = patientUser.Id,
                                    PatientInsuranceId   = _patientInsuranceId,
                                    IsAnnounced          = false,
                                    Paymentstatus        = paymentStatus,
                                    IsDeleted            = false,
                                    ShiftCenterServiceId = polyclinicHealthService.Id,
                                    ReservationChannel   = channel,
                                    CreatedAt            = DateTime.Now,
                                    OfferId              = offerId,
                                    RequestLang          = requestLang
                                };
                                _dbContext.Appointments.Add(appointment);
                                _dbContext.SaveChanges();

                                #region Send SMS notification
                                if (channel != ReservationChannel.Kiosk)
                                {
                                    try
                                    {
                                        var doctor_name       = serviceSupply.Person.FullName;
                                        var persian_dayOfWeek = Utils.ConvertDayOfWeek(startDateTime.DayOfWeek.ToString());
                                        var day_number        = startDateTime.ToShortDateString().Split('/')[2];
                                        var persian_month     = Utils.GetMonthName(startDateTime);
                                        var year_number       = startDateTime.ToShortDateString().Split('/')[0];
                                        var time = startDateTime.ToShortTimeString();

                                        var smsBody = $"{Messages.YourAppointmentForDoctor} { doctor_name} ، { persian_dayOfWeek} { day_number} { persian_month} {year_number} ،{Global.Hour}: {time}";

                                        if (channel == ReservationChannel.ClinicManagerSection)
                                        {
                                            smsBody = smsBody = "Turn for doctor  " + doctor_name + ", " + persian_dayOfWeek + " " + day_number + " " + persian_month + " " + year_number;
                                        }

                                        string[] recepient = { $"964{patinetModel.Mobile}" };

                                        if (serviceSupply.ShiftCenter.IsIndependent)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }
                                        else if (serviceSupply.ShiftCenter.Clinic != null && serviceSupply.ShiftCenter.Clinic.IsIndependent)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }
                                        else if (serviceSupply.ShiftCenter.Clinic != null && serviceSupply.ShiftCenter.Clinic.Hospital != null)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }

                                        _plivoService.SendMessage(recepient.ToList(), smsBody);

                                        _dbContext.Entry(appointment).State = EntityState.Modified;

                                        appointment.IsAnnounced = true;
                                    }
                                    catch
                                    {
                                    }
                                }
                                #endregion

                                _iPAsManager.Delete(serviceSupply.Id, startDateTime);

                                _dbContext.SaveChanges();

                                appointmentId = appointment.Id;
                            }
                            #endregion

                            #region book appointment for existing user
                            else if (_existUser == true)
                            {
                                var user = await _dbContext.Persons.FirstOrDefaultAsync(u => u.Mobile == patinetModel.Mobile);
                                if (user == null)
                                {
                                    throw new EntityNotFoundException();
                                }

                                // TODO
                                //if (!userManager.IsInRole(user.Id, UsersRoleName.Patient.ToString()))
                                //{
                                //    var assignPatientRole = userManager.AddToRole(user.Id, UsersRoleName.Patient.ToString());
                                //    if (!assignPatientRole.Succeeded)
                                //    {
                                //        throw new Exception(Messages.ErrorOccuredWhileAssignRole);
                                //    }
                                //}

                                if (user.PatientPersonInfo == null)
                                {
                                    _dbContext.PatientPersonInfo.Add(new PatientPersonInfo
                                    {
                                        PersonId  = user.Id,
                                        CreatedAt = DateTime.Now
                                    });
                                }

                                #region Set Patient Insurance
                                //Check if user already used current insurance name and number
                                int?patientInsuranId = null;
                                if (patinetModel.InsuranceId != 0 && patinetModel.InsuranceNumber != null)
                                {
                                    var oldInsurance = user.PatientPersonInfo.PatientInsurances.FirstOrDefault(pi => pi.InsuranceNumber == patinetModel.InsuranceNumber && pi.ServiceSupplyInsuranceId == patinetModel.InsuranceId);
                                    if (oldInsurance == null)
                                    {
                                        var _patientInsurance = new PatientInsurance
                                        {
                                            UserPatientId            = user.Id,
                                            ServiceSupplyInsuranceId = patinetModel.InsuranceId,
                                            InsuranceNumber          = patinetModel.InsuranceNumber,
                                            CreatedAt = DateTime.Now
                                        };
                                        _dbContext.PatientInsurances.Add(_patientInsurance);
                                        _dbContext.SaveChanges();
                                        patientInsuranId = _patientInsurance.Id;
                                    }
                                    else
                                    {
                                        patientInsuranId = oldInsurance.Id;
                                    }
                                }
                                #endregion

                                var finalBookabeTimePeriods = _doctorServiceManager.CalculateFinalBookableTimePeriods(serviceSupply, startDateTime, polyclinicHealthService);

                                if (finalBookabeTimePeriods == null || finalBookabeTimePeriods.Count() <= 0)
                                {
                                    throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
                                }

                                var ipaTimePeriod = finalBookabeTimePeriods.FirstOrDefault(f => f.StartDateTime == startDateTime && f.EndDateTime == endDateTime && f.Type == TimePeriodType.InProgressAppointment);

                                if (ipaTimePeriod == null)
                                {
                                    throw new Exception(Messages.ValidEmptyTimePeriodNotFound);
                                }

                                trackingCode = await _appointmentService.GenerateUniqueTrackingNumberAsync();

                                var appointment = new Appointment
                                {
                                    UniqueTrackingCode   = trackingCode,
                                    Book_DateTime        = DateTime.Now,
                                    Start_DateTime       = startDateTime,
                                    End_DateTime         = endDateTime,
                                    Description          = " ",
                                    Status               = tmpStatus,
                                    ServiceSupplyId      = serviceSupply.Id,
                                    PersonId             = user.Id,
                                    PatientInsuranceId   = patientInsuranId,
                                    IsAnnounced          = false,
                                    Paymentstatus        = paymentStatus,
                                    IsDeleted            = false,
                                    ShiftCenterServiceId = polyclinicHealthService.Id,
                                    ReservationChannel   = channel,
                                    CreatedAt            = DateTime.Now,
                                    OfferId              = offerId,
                                    RequestLang          = requestLang
                                };

                                _dbContext.Appointments.Add(appointment);
                                _dbContext.SaveChanges();

                                #region Send SMS notification
                                if (channel != ReservationChannel.Kiosk)
                                {
                                    try
                                    {
                                        var doctor_name       = serviceSupply.Person.FullName;
                                        var persian_dayOfWeek = Utils.ConvertDayOfWeek(startDateTime.DayOfWeek.ToString());
                                        var day_number        = startDateTime.ToShortDateString().Split('/')[2];
                                        var persian_month     = Utils.GetMonthName(startDateTime);
                                        var year_number       = startDateTime.ToShortDateString().Split('/')[0];
                                        var time = startDateTime.ToShortTimeString();

                                        var smsBody = $"{Messages.YourAppointmentForDoctor} { doctor_name} ، { persian_dayOfWeek} { day_number} { persian_month} {year_number} ،{Global.Hour}: {time}";

                                        if (channel == ReservationChannel.ClinicManagerSection)
                                        {
                                            smsBody = smsBody = "Turn for doctor  " + doctor_name + ", " + persian_dayOfWeek + " " + day_number + " " + persian_month + " " + year_number;
                                        }

                                        string[] recepient = { $"964{patinetModel.Mobile}" };

                                        if (serviceSupply.ShiftCenter.IsIndependent)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }
                                        else if (serviceSupply.ShiftCenter.Clinic != null && serviceSupply.ShiftCenter.Clinic.IsIndependent)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }
                                        else if (serviceSupply.ShiftCenter.Clinic != null && serviceSupply.ShiftCenter.Clinic.Hospital != null)
                                        {
                                            if (Lng == Lang.KU)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ku != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ku;
                                                }
                                            }
                                            else if (Lng == Lang.AR)
                                            {
                                                if (serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ar != null)
                                                {
                                                    smsBody = serviceSupply.ShiftCenter.Clinic.Hospital.FinalBookSMSMessage_Ar;
                                                }
                                            }
                                        }

                                        _plivoService.SendMessage(recepient.ToList(), smsBody);

                                        _dbContext.Entry(appointment).State = EntityState.Modified;

                                        appointment.IsAnnounced = true;
                                    }
                                    catch
                                    {
                                    }
                                }
                                #endregion

                                _iPAsManager.Delete(serviceSupply.Id, startDateTime);

                                _dbContext.SaveChanges();

                                appointmentId = appointment.Id;
                            }
                            #endregion

                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            throw ex;
                        }
                    }
                });

                return(new BookingAppointmentResult
                {
                    Status = BookingAppointmentStatus.Success,
                    Message = Messages.TurnBookedFinally,
                    AppointmentId = appointmentId,
                    TrackingCode = trackingCode
                });
            }
            catch (Exception ex)
            {
                resultMessage = ex.Message;
            }
            return(new BookingAppointmentResult
            {
                Status = BookingAppointmentStatus.Failure,
                Message = resultMessage
            });
        }
Beispiel #20
0
        public async Task <IActionResult> GetZipFile([FromBody] RegisterDownloadAppModel inputModel)
        {
            HttpContext.Response.ContentType = ContentType;

            byte[] resultFileBytes = null;

            // Center & Person Data
            #region Validations
            if (string.IsNullOrEmpty(inputModel.Mobile))
            {
                throw new Exception("Mobile is not valid");
            }

            if (inputModel.Mobile.Length > 10)
            {
                inputModel.Mobile = inputModel.Mobile.Substring(inputModel.Mobile.Length - 10);
            }
            else if (inputModel.Mobile.Length < 10)
            {
                inputModel.Mobile = inputModel.Mobile.PadLeft(10, '0');
            }

            var isMobileValid = long.TryParse(inputModel.Mobile, out long mobileNumber);

            if (!isMobileValid)
            {
                throw new AwroNoreException("Mobile is not valid");
            }

            var existPerson = await _dbContext.Persons.FirstOrDefaultAsync(x => x.Mobile == inputModel.Mobile);

            var existCenter = await _dbContext.ShiftCenters.FirstOrDefaultAsync(x => x.Type == inputModel.CenterType && x.Name == inputModel.PoliClinicName && x.Name_Ku == inputModel.PoliClinicName && x.Name_Ar == inputModel.PoliClinicName && x.CityId == inputModel.CityId);

            var phones = new List <ShiftCenterPhoneModel>
            {
                new ShiftCenterPhoneModel
                {
                    PhoneNumber = inputModel.Mobile
                }
            };
            #endregion

            var strategy = _dbContext.Database.CreateExecutionStrategy();
            await strategy.ExecuteAsync(async() =>
            {
                using (var transaction = _dbContext.Database.BeginTransaction())
                {
                    // DB operations
                    // TODO: Add db operations here (Create person & Center)
                    #region ShiftCenter
                    var center = existCenter;
                    if (center == null)
                    {
                        center = new ShiftCenter
                        {
                            Type                     = inputModel.CenterType,
                            Name                     = inputModel.PoliClinicName,
                            Name_Ku                  = inputModel.PoliClinicName,
                            Name_Ar                  = inputModel.PoliClinicName,
                            Description              = inputModel.Description,
                            Description_Ku           = inputModel.Description,
                            Description_Ar           = inputModel.Description,
                            CityId                   = inputModel.CityId,
                            Address                  = inputModel.PoliClinicAddress,
                            Address_Ku               = inputModel.PoliClinicAddress,
                            Address_Ar               = inputModel.PoliClinicAddress,
                            IsIndependent            = true,
                            ClinicId                 = null,
                            BookingRestrictionHours  = 0,
                            CreatedAt                = DateTime.Now,
                            PhoneNumbers             = phones,
                            IsApproved               = false,
                            IsDeleted                = false,
                            ActiveDaysAhead          = 30,
                            AutomaticScheduleEnabled = false,
                            FinalBookMessage         = "",
                            FinalBookMessage_Ar      = "",
                            FinalBookMessage_Ku      = "",
                            FinalBookSMSMessage      = "",
                            FinalBookSMSMessage_Ar   = "",
                            FinalBookSMSMessage_Ku   = "",
                            Notification             = "Offline",
                            Notification_Ar          = "",
                            Notification_Ku          = "",
                            PrescriptionPath         = "",
                            Location                 = new NetTopologySuite.Geometries.Point(0.0, 0.0)
                            {
                                SRID = 4326 // Set the SRID (spatial reference system id) to 4326, which is the spatial reference system used by Google maps (WGS84)
                            },
                        };

                        await _dbContext.ShiftCenters.AddAsync(center);

                        await _dbContext.SaveChangesAsync();
                    }

                    var person = existPerson;
                    if (person == null)
                    {
                        person = new Person
                        {
                            Mobile          = inputModel.Mobile,
                            MobileConfirmed = false,
                            FirstName       = inputModel.FirstName,
                            FirstName_Ku    = inputModel.FirstName,
                            FirstName_Ar    = inputModel.FirstName,
                            SecondName      = inputModel.SecondName,
                            SecondName_Ku   = inputModel.SecondName,
                            SecondName_Ar   = inputModel.SecondName,
                            ThirdName       = inputModel.ThirdName,
                            ThirdName_Ku    = inputModel.ThirdName,
                            ThirdName_Ar    = inputModel.ThirdName,
                            UniqueId        = await _personService.GenerateUniqueIdAsync(),
                            Avatar          = null,
                            Age             = 0,
                            Gender          = inputModel.Gender,
                            BloodType       = Core.Enums.BloodType.Unknown,
                            IsApproved      = true,
                            IsEmployee      = true,
                            IsDeleted       = false,
                            Birthdate       = DateTime.Now,
                            Address         = "",
                            CreatedAt       = DateTime.Now,
                            CreationPlaceId = null,
                            CreatorRole     = Shared.Enums.LoginAs.UNKNOWN,
                            Email           = inputModel.Email,
                            Description     = "",
                            Weight          = 0,
                            Height          = 0,
                            ZipCode         = "",
                            IdNumber        = "",
                            Language        = null,
                            MarriageStatus  = null
                        };

                        await _dbContext.Persons.AddAsync(person);

                        await _dbContext.SaveChangesAsync();
                    }
                    #endregion

                    #region ShiftCenter Person
                    var centerPerson = await _dbContext.ShiftCenterPersons.FirstOrDefaultAsync(x => x.PersonId == person.Id && x.ShiftCenterId == center.Id);
                    if (centerPerson == null)
                    {
                        centerPerson = new ShiftCenterPersons
                        {
                            IsManager     = true,
                            PersonId      = person.Id,
                            ShiftCenterId = center.Id,
                            CreatedAt     = DateTime.Now
                        };

                        await _dbContext.ShiftCenterPersons.AddAsync(centerPerson);

                        await _dbContext.SaveChangesAsync();
                    }
                    #endregion

                    #region Service Supply
                    var serviceSupply = await _dbContext.ServiceSupplies.FirstOrDefaultAsync(x => x.PersonId == person.Id && x.ShiftCenterId == center.Id);
                    if (serviceSupply == null)
                    {
                        serviceSupply = new ServiceSupply
                        {
                            Duration                            = 5,
                            ShiftCenterId                       = center.Id,
                            ReservationType                     = ReservationType.Selective,
                            PersonId                            = person.Id,
                            OnlineReservationPercent            = 100,
                            IsAvailable                         = false,
                            StartReservationDate                = DateTime.Now,
                            VisitPrice                          = 0,
                            PrePaymentPercent                   = 0,
                            PaymentType                         = PaymentType.Free,
                            ReservationRangeStartPoint          = 0,
                            ReservationRangeEndPointPosition    = Position.AFTER,
                            ReservationRangeEndPointDiffMinutes = 30,
                            RankScore                           = 0,
                            CreatedAt                           = DateTime.Now,
                            Notification                        = "",
                            Notification_Ar                     = "",
                            Notification_Ku                     = "",
                            PrescriptionPath                    = ""
                        };

                        _dbContext.ServiceSupplies.Add(serviceSupply);

                        await _dbContext.SaveChangesAsync();

                        await _dbContext.ServiceSupplyInfo.AddAsync(new ServiceSupplyInfo
                        {
                            ServiceSupplyId      = serviceSupply.Id,
                            MedicalCouncilNumber = "",
                            AcceptionDate        = DateTime.Now,
                            Bio            = "",
                            Bio_Ar         = "",
                            Bio_Ku         = "",
                            Website        = "",
                            Description    = "#Requested",
                            Description_Ar = "#Requested",
                            Description_Ku = "#Requested",
                            Picture        = "",
                            IsDeleted      = false,
                            WorkExperience = 0,
                            CreatedAt      = DateTime.Now
                        });

                        await _dbContext.SaveChangesAsync();
                    }
                    #endregion

                    #region Prescription File
                    var destinationDirPath = $"wwwroot\\uploaded\\prescriptions\\shiftcenters\\{center.Id}\\{serviceSupply.Id}";

                    var fullDestinationDirPath = Path.Combine(_hostingEnvironment.ContentRootPath, destinationDirPath);

                    if (!Directory.Exists(fullDestinationDirPath))
                    {
                        Directory.CreateDirectory(fullDestinationDirPath);
                    }

                    _dbContext.Entry(serviceSupply).State = EntityState.Modified;

                    serviceSupply.PrescriptionPath = Path.Combine(destinationDirPath, $"prescript_{serviceSupply.Id}.mrt");

                    await _dbContext.SaveChangesAsync();

                    var destinationPrescriptPath = Path.Combine(_hostingEnvironment.ContentRootPath, serviceSupply.PrescriptionPath);

                    if (!System.IO.File.Exists(destinationPrescriptPath))
                    {
                        // Remove all existing files
                        try
                        {
                            DirectoryInfo di = new DirectoryInfo("fullDestinationDirPath");

                            foreach (FileInfo file in di.GetFiles())
                            {
                                file.Delete();
                            }
                        }
                        catch
                        {
                            // Ignored
                        }
                        try
                        {
                            System.IO.File.Copy(BasePrescriptFullPath, destinationPrescriptPath, true);
                        }
                        catch
                        {
                            throw new AwroNoreException("Can not copy prescription file. please try again");
                        }
                    }
                    #endregion

                    // HTTP operations
                    #region Identity User
                    var userDTO = new UserDTO
                    {
                        UserName         = inputModel.Username,
                        Email            = inputModel.Email,
                        IsSystemUser     = false,
                        Mobile           = inputModel.Mobile,
                        Password         = inputModel.Password,
                        TwoFactorEnabled = false,
                        UserProfile      = new UserProfileDTO
                        {
                            CenterId         = center.Id,
                            PersonId         = person.Id,
                            ServiceSupplyIds = new List <int> {
                                serviceSupply.Id
                            },
                            LoginAs = SystemRoles.GetLoginAs(Role)
                        },
                        Roles = new List <string> {
                            Role
                        }
                    };

                    var(_, isSucceeded, message, _, _) = await _identityService.PostCreateAsync("user", userDTO);

                    // if (!isSucceeded) throw new AwroNoreException(message);
                    #endregion

                    // IO operations
                    #region Zip Archive Operations
                    using (FileStream zipToOpen = new FileStream(ZipFilePath, FileMode.Open))
                    {
                        using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                        {
                            // Delete old readme file
                            var item = archive.Entries.FirstOrDefault(x => x.FullName == ReadmeFileName);
                            if (item != null)
                            {
                                item.Delete();
                            }

                            // Create new readme file
                            var readmeEntry = archive.CreateEntry(ReadmeFileName);

                            // Read new file and write data
                            using (Stream writer = readmeEntry.Open())
                            {
                                var xmlSerializer = new XmlSerializer(typeof(RegisterOfflineResult));

                                var resultModel = new RegisterOfflineResult
                                {
                                    Doctor = _mapper.Map <RegisterOfflineData>(inputModel)
                                };

                                xmlSerializer.Serialize(writer, resultModel);
                            }
                        }
                    }

                    resultFileBytes = await System.IO.File.ReadAllBytesAsync(ZipFilePath);
                    #endregion

                    transaction.Commit();
                }
            });

            // Create result file
            var result = new FileContentResult(resultFileBytes, ContentType)
            {
                FileDownloadName = $"{Path.GetFileName(ZipFilePath)}"
            };

            return(result);
        }
Beispiel #21
0
        public void SetManualSchedule(ServiceSupply serviceSupply, ManualScheduleModel scheduleModel, out List <Appointment> pendingAppoints)
        {
            if (scheduleModel.StartDateTime == null || scheduleModel.EndDateTime == null)
            {
                throw new Exception(Messages.PlsEnterStartEndDateTime);
            }

            pendingAppoints = new List <Appointment>();

            if (!scheduleModel.IsAvailable && scheduleModel.AllDay)
            {
                var pendingList = _appointmentService.GetPendingAppointmentsForServiceSupplyInManualSchedule(serviceSupply.Id, scheduleModel.StartDateTime, scheduleModel.EndDateTime);
                pendingAppoints.AddRange(pendingList);
            }

            if (!pendingAppoints.Any())
            {
                if (scheduleModel.AllDay)
                {
                    var schedules = _scheduleService.GetManualSchedulesForServiceSupplyInDate(serviceSupply.Id, scheduleModel.StartDateTime);
                    if (schedules.Count <= 0)
                    {
                        if (!scheduleModel.IsAvailable)
                        {
                            _scheduleService.InsertSchedule(new Schedule
                            {
                                Start_DateTime       = scheduleModel.StartDateTime,
                                End_DateTime         = scheduleModel.EndDateTime,
                                IsAvailable          = scheduleModel.IsAvailable,
                                DayOfWeek            = scheduleModel.StartDateTime.DayOfWeek.ToString(),
                                ServiceSupplyId      = serviceSupply.Id,
                                Description_Ku       = scheduleModel.StartDateTime.DayOfWeek + scheduleModel.StartDateTime.ToShortDateString(),
                                CreatedAt            = DateTime.Now,
                                ShiftCenterServiceId = 1
                            });
                        }
                    }
                    else
                    {
                        if (schedules.Count == 1)
                        {
                            var _schedule = schedules.FirstOrDefault();
                            if (_schedule.Start_DateTime.Hour == 06 && _schedule.End_DateTime.Hour == 23)
                            {
                                if (scheduleModel.IsAvailable)
                                {
                                    _scheduleService.DeleteSchedule(_schedule);
                                }
                            }
                            else
                            {
                                _schedule.IsAvailable = scheduleModel.IsAvailable;
                                _scheduleService.UpdateSchedule(_schedule);
                            }
                        }
                        else
                        {
                            foreach (var item in schedules)
                            {
                                item.IsAvailable = scheduleModel.IsAvailable;
                                _scheduleService.UpdateSchedule(item);
                            }
                        }
                    }
                }
                else
                {
                    var preSchedule = _scheduleService.GetSingleManualScheduleForServiceSupply(serviceSupply.Id, scheduleModel.StartDateTime, scheduleModel.HealthServiceId);

                    var isValidSchedule = IsValidScheduleTimes(out string message, scheduleModel.StartDateTime, scheduleModel.EndDateTime, serviceSupply, preSchedule);
                    if (!isValidSchedule)
                    {
                        throw new AwroNoreException(message);
                    }

                    var schedule = new Schedule
                    {
                        Start_DateTime       = scheduleModel.StartDateTime,
                        End_DateTime         = scheduleModel.EndDateTime,
                        ShiftCenterServiceId = scheduleModel.HealthServiceId,
                        Prerequisite         = scheduleModel.Prerequisite,
                        IsAvailable          = scheduleModel.IsAvailable,
                        MaxCount             = scheduleModel.MaxCount,
                        Shift           = getScheduleShift(scheduleModel.StartDateTime, scheduleModel.EndDateTime),
                        DayOfWeek       = scheduleModel.StartDateTime.DayOfWeek.ToString(),
                        ServiceSupplyId = serviceSupply.Id,
                        Description_Ku  = scheduleModel.StartDateTime.DayOfWeek + scheduleModel.StartDateTime.ToShortDateString(),
                        CreatedAt       = DateTime.Now
                    };

                    _scheduleService.InsertSchedule(schedule);
                }
            }
        }
Beispiel #22
0
        private bool IsValidScheduleTimes(out string message,
                                          DateTime start,
                                          DateTime end,
                                          ServiceSupply serviceSupply,
                                          Schedule preSchedule = null)
        {
            message = string.Empty;
            var result = true;

            try
            {
                //اگر زمان شروع کوچکتر از زمان پایان نباشد
                if (start >= end)
                {
                    throw new Exception(Messages.ScheduleStartMustSmallerThanEnd);
                }

                //زمان شروع زمانبندی نباید کوچکتر از زمان حال حاضر باشد
                if (start < DateTime.Now)
                {
                    throw new ScheduleForPastException(start.ToShortTimeString());
                }

                //زمان شروع زمانبندی نباید در محدوده ساعات محدودیت رزرو نوبت باشد
                if ((start - DateTime.Now).TotalHours < serviceSupply.ShiftCenter.BookingRestrictionHours)
                {
                    throw new Exception(Messages.ScheduleStartNotValidForBHR);
                }

                if (start < serviceSupply.StartReservationDate)
                {
                    throw new Exception(Messages.ScheduleStartSmallerThanDoctorTurningStart);
                }

                if (_serviceSupplyManager.IsLocalVocationDay(start, serviceSupply) /* || _serviceSupplyManager.IsSystemVocationDay(start)*/)
                {
                    throw new ScheduleForVocationDayException(start.ToShortDateString());
                }

                if (preSchedule != null)
                {
                    if (start < preSchedule.Start_DateTime && (end > preSchedule.Start_DateTime && end < preSchedule.End_DateTime))
                    {
                        throw new Exception(Messages.ScheduleHasInterferesWithPreviews);
                    }
                    if ((start > preSchedule.Start_DateTime && start < preSchedule.End_DateTime) && end > preSchedule.End_DateTime)
                    {
                        throw new Exception(Messages.ScheduleHasInterferesWithPreviews);
                    }
                    if ((start > preSchedule.Start_DateTime && start < preSchedule.End_DateTime) && (end > preSchedule.Start_DateTime && end < preSchedule.End_DateTime))
                    {
                        throw new Exception(Messages.ScheduleHasInterferesWithPreviews);
                    }
                }
            }
            catch (Exception e)
            {
                message = e.Message;
                result  = false;
            }

            return(result);
        }
Beispiel #23
0
        /// <summary>
        /// محاسبه بازه های زمانی در دسترس و محدود کردن تعداد آنها بر اساس درصد رزرو آنلاین
        /// </summary>
        /// <param name="serviceSupply"></param>
        /// <param name="Date"></param>
        /// <returns></returns>
        public IEnumerable <TimePeriodModel> Calculate_Available_Empty_TimePeriods_By_Percent(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
        {
            if (!serviceSupply.IsAvailable)
            {
                return(null);
            }

            var finalPercentPeriods = new List <TimePeriodModel>();

            var allTimePeriods = Calculate_All_TimePeriods(serviceSupply, Date, polyclinicHealthService);

            if (allTimePeriods != null && allTimePeriods.Count() > 0)
            {
                if (serviceSupply.OnlineReservationPercent < 100)
                {
                    var schedules = _serviceSupplyManager.GetSchedulesByDate(serviceSupply, Date, polyclinicHealthService);
                    foreach (var schedule in schedules)
                    {
                        for (var dt = schedule.Start_DateTime; dt <= schedule.End_DateTime; dt = dt.AddHours(1))
                        {
                            var hourPeriods = allTimePeriods.Where(x => x.StartDateTime >= dt && x.EndDateTime <= dt.AddHours(1)).ToList();
                            if (hourPeriods != null && hourPeriods.Count >= 1)
                            {
                                var hourPeriodsByPercentCount = serviceSupply.OnlineReservationPercent * hourPeriods.Count / 100;
                                if (hourPeriodsByPercentCount > 0)
                                {
                                    for (var i = 0; i < hourPeriodsByPercentCount; i++)
                                    {
                                        finalPercentPeriods.Add(hourPeriods.ElementAt(i));
                                    }
                                }
                            }
                        }
                        return(finalPercentPeriods.Where(x => x.Type == TimePeriodType.Empty && x.StartDateTime >= DateTime.Now).OrderBy(x => x.StartDateTime));
                    }
                }
                return(allTimePeriods.Where(x => x.Type == TimePeriodType.Empty && x.StartDateTime >= DateTime.Now).OrderBy(x => x.StartDateTime));
            }
            return(null);
        }
        /// <summary>
        /// این متد برای یک تاریخ مشخص همه بازه های زمانی که پزشک می تواند سرویس ارایه دهد را محاسبه می کند
        /// بازه های زمانی غیراستراحت را محاسبه می کند
        /// </summary>
        /// <param name="supply">ارایه</param>
        /// <param name="Date">تاریخ موردنظر</param>
        /// <returns>لیست بازه های زمانی با قابلیت ارایه سرویس</returns>
        public IEnumerable <TimePeriodModel> Get_Non_Break_Times(ServiceSupply supply, DateTime Date, ShiftCenterService polyclinicHealthService, bool applyLimits = true)
        {
            IList <Schedule> schedules;

            if (applyLimits)
            {
                schedules = GetSchedulesByDate(supply, Date, polyclinicHealthService);
            }
            else
            {
                schedules = GetSchedulesByDateWithoutFilter(supply, Date, polyclinicHealthService);
            }

            if (schedules != null && schedules.Count > 0)
            {
                var nonBreaks = new List <TimePeriodModel>();
                var _duration = supply.Duration;

                foreach (var item in schedules)
                {
                    if (item.MaxCount > 0)
                    {
                        var appointsForSchedule = supply.Appointments.Where(a => a.Start_DateTime >= item.Start_DateTime && a.End_DateTime <= item.End_DateTime && (a.ShiftCenterService == null || (polyclinicHealthService != null && a.ShiftCenterServiceId == polyclinicHealthService.Id)) && !a.IsDeleted);
                        if (appointsForSchedule.Count() > 0)
                        {
                            var firstAppoint = appointsForSchedule.FirstOrDefault();
                            _duration = (int)(firstAppoint.End_DateTime - firstAppoint.Start_DateTime).TotalMinutes;
                        }
                        else
                        {
                            var _maxCount = item.MaxCount;
                            var manualSchedulesForOtherHealthServices = (from ms in supply.Schedules
                                                                         where ms.Start_DateTime == item.Start_DateTime &&
                                                                         ms.End_DateTime == item.End_DateTime &&
                                                                         ms.ShiftCenterServiceId != item.ShiftCenterServiceId
                                                                         select ms).ToList();
                            if (manualSchedulesForOtherHealthServices.Count > 0)
                            {
                                foreach (var ms in manualSchedulesForOtherHealthServices)
                                {
                                    _maxCount += ms.MaxCount;
                                }
                            }
                            else
                            {
                                var shift = Utils.GetScheduleShift(item.Start_DateTime, item.End_DateTime);

                                var usualSchedulesForOtherHelathServices = (from us in supply.UsualSchedulePlans
                                                                            where us.Shift == shift &&
                                                                            us.DayOfWeek == item.Start_DateTime.DayOfWeek &&
                                                                            us.StartTime == item.Start_DateTime.ToShortTimeString() &&
                                                                            us.EndTime == item.End_DateTime.ToShortTimeString() &&
                                                                            us.ShiftCenterServiceId != item.ShiftCenterServiceId
                                                                            select us).ToList();

                                foreach (var us in usualSchedulesForOtherHelathServices)
                                {
                                    _maxCount += us.MaxCount;
                                }
                            }
                            _duration = (int)Math.Ceiling(((item.End_DateTime - item.Start_DateTime).TotalMinutes) / _maxCount);
                        }
                    }

                    nonBreaks.Add(new TimePeriodModel
                    {
                        StartDateTime = item.Start_DateTime,
                        EndDateTime   = item.End_DateTime,
                        Duration      = _duration,
                        Type          = TimePeriodType.Empty
                    });
                }

                return(nonBreaks.OrderBy(x => x.StartDateTime));
            }
            return(null);
        }
        public IList <Schedule> FilterAndGetValidSchedules(ServiceSupply serviceSupply, List <Schedule> schedules, ShiftCenterService healthService)
        {
            var validSchedules = new List <Schedule>();

            // Policlinic Booking Restriction Hours
            var BRH = serviceSupply.ShiftCenter.BookingRestrictionHours;

            var startReservationDate = serviceSupply.StartReservationDate > DateTime.Now ? serviceSupply.StartReservationDate : DateTime.Now;
            var lastDay = startReservationDate.AddDays(serviceSupply.ShiftCenter.ActiveDaysAhead);

            var startPoint       = serviceSupply.ReservationRangeStartPoint;
            var endPoint         = serviceSupply.ReservationRangeEndPointDiffMinutes;
            var endPointPosition = serviceSupply.ReservationRangeEndPointPosition;

            foreach (var schedule in schedules)
            {
                if (schedule.Start_DateTime.Date < startReservationDate.Date || schedule.Start_DateTime.Date > lastDay.Date)
                {
                    continue;
                }
                //===========================================================
                //برای روز آخر میخواهیم که نوبت دهی از ساعت 8 به بعد شروع شود
                if (schedule.Start_DateTime.Date == lastDay.Date)
                {
                    var reservationStartTimeForLastDay = DateTime.Parse(DateTime.Now.ToShortDateString() + " 08:00:00");
                    if (DateTime.Now < reservationStartTimeForLastDay)
                    {
                        continue;
                    }
                }
                //===========================================================
                //محدوده ای برای نوبت دهی در نظر گرفته نشده است
                if (startPoint == null && endPoint == null)
                {
                    if ((schedule.Start_DateTime - DateTime.Now).TotalHours <= BRH)
                    {
                        continue;
                    }
                }
                else
                {
                    //شروع نوبت دهی همزمان با شروع ویزیت
                    if (startPoint == 0)
                    {
                        if (DateTime.Now < schedule.Start_DateTime)
                        {
                            continue;
                        }
                    }
                    //Diff Minutes before visit time
                    if (startPoint > 0)
                    {
                        if ((schedule.Start_DateTime - DateTime.Now).TotalMinutes > startPoint)
                        {
                            continue;
                        }
                    }
                    //پایان نوبت دهی تا انتهای زمان ویزیت
                    if (endPoint == -1)
                    {
                        if (DateTime.Now > schedule.End_DateTime)
                        {
                            continue;
                        }
                    }
                    //پایان نوبت دهی تا شروع زمان ویزیت
                    if (endPoint == 0)
                    {
                        if (DateTime.Now >= schedule.Start_DateTime)
                        {
                            continue;
                        }
                    }
                    //پایان نوبت دهی مدتی قبل یا بعد از شروع ویزیت
                    if (endPoint > 0)
                    {
                        var endPointTime = DateTime.Now;
                        //پایان قبل از شروع ویزیت
                        if (endPointPosition == Position.BEFORE)
                        {
                            endPointTime = schedule.Start_DateTime.AddMinutes(-endPoint);
                        }
                        else if (endPointPosition == Position.AFTER)
                        {
                            endPointTime = schedule.Start_DateTime.AddMinutes(endPoint);
                        }

                        if (DateTime.Now > endPointTime)
                        {
                            continue;
                        }
                    }
                }

                //Check remained free appoints for polyclinic health service
                var appints = healthService != null ?
                              (from a in serviceSupply.Appointments
                               where (a.ShiftCenterService == null || a.ShiftCenterServiceId == healthService.Id) &&
                               a.Start_DateTime.Date == schedule.Start_DateTime.Date &&
                               a.Start_DateTime >= schedule.Start_DateTime &&
                               a.End_DateTime <= schedule.End_DateTime &&
                               !a.IsDeleted
                               select a).ToList()
                    :
                              (from a in serviceSupply.Appointments
                               where a.Start_DateTime.Date == schedule.Start_DateTime.Date &&
                               a.Start_DateTime >= schedule.Start_DateTime &&
                               a.End_DateTime <= schedule.End_DateTime &&
                               !a.IsDeleted
                               select a).ToList();

                if (schedule.MaxCount - appints.Count <= 0)
                {
                    continue;
                }

                validSchedules.Add(schedule);
            }

            return(validSchedules.Count > 0 ? validSchedules : null);
        }
Beispiel #26
0
 /// <summary>
 /// همه بازه های زمانی خالی مربوط به ارایه در تاریخ مشخص شده را بر می گرداند
 /// </summary>
 /// <param name="serviceSupply">ارایه موردنظر</param>
 /// <param name="Date">تاریخ</param>
 /// <returns></returns>
 public IEnumerable <TimePeriodModel> Calculate_Empty_TimePeriods(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
 {
     return(Calculate_All_TimePeriods(serviceSupply, Date, polyclinicHealthService).Where(x => x.Type == TimePeriodType.Empty));
 }
Beispiel #27
0
        /// <summary>
        /// همه بازه های زمانی با نوع قرار ملاقات را برای ارایه مورد نظر در تاریخ مشخص شده محاسبه می کند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="Date">تاریخ (فقط روز) ساعت لازم نیست</param>
        /// <returns>لیست بازه های زمانی با نوع قرار ملاقات</returns>
        public IEnumerable <TimePeriodModel> Calculate_PendingAppointment_TimePeriods(ServiceSupply serviceSupply, DateTime Date)
        {
            //همه قرارهای انجام نشده و منتظر انجام را بدست می آوریم
            var pendingAppointments =
                Get_All_Appointments_By_Status(serviceSupply, Date, AppointmentStatus.Pending)
                .Where(x => x.Start_DateTime >= DateTime.Now);

            var result = pendingAppointments.Select(item => new TimePeriodModel
            {
                StartDateTime = item.Start_DateTime,
                EndDateTime   = item.End_DateTime,
                Type          = TimePeriodType.Appointment,
                Duration      = serviceSupply.Duration
            }).OrderBy(x => x.StartDateTime);

            return(result);
        }
Beispiel #28
0
        /// <summary>
        /// لیست همه بازه های زمانی قفل شده و در حال رزرو را برای ارایه موردنظر را در تاریخ مشخص شده بر می گرداند
        /// </summary>
        /// <param name="serviceSupply">ارایه موردنظر</param>
        /// <param name="Date">تاریخ - روز</param>
        /// <returns>لیست بازه های زمانی در حال رزرو</returns>
        public IEnumerable <TimePeriodModel> Calculate_InProgressAppointments_TimePriods(ServiceSupply serviceSupply, DateTime Date)
        {
            var InProgressAppointments = _iPAsManager.GetAll(serviceSupply, Date);

            var result = InProgressAppointments.Select(item => new TimePeriodModel
            {
                StartDateTime = item.StartDateTime,
                EndDateTime   = item.EndDateTime,
                Type          = TimePeriodType.InProgressAppointment,
                Duration      = serviceSupply.Duration
            }).OrderBy(x => x.StartDateTime);

            return(result);
        }
Beispiel #29
0
 /// <summary>
 /// همه قرارهای ملاقات یک ارایه را برای یک تاریخ مشخص بر اساس نوع قرارملاقات بر می گرداند
 /// </summary>
 /// <param name="serviceSupply">ارایه موردنظر</param>
 /// <param name="Date">تاریخ (فقط روز) و ساعت لازم نیست</param>
 /// <param name="status">نوع قرار ملاقاتی که می خواهیم</param>
 /// <returns></returns>
 public IEnumerable <Appointment> Get_All_Appointments_By_Status(ServiceSupply serviceSupply, DateTime Date, AppointmentStatus status)
 {
     return(serviceSupply.Appointments
            .Where(x => x.Start_DateTime.Date == Date.Date && x.Status == status && !x.IsDeleted)
            .OrderBy(x => x.Start_DateTime));
 }
Beispiel #30
0
 /// <summary>
 /// همه بازه های زمانی در دسترس و قابل استفاده را بر می گرداند
 /// </summary>
 /// <param name="serviceSupply">ارایه موردنظر</param>
 /// <param name="Date">تاریخ</param>
 /// <returns>لیست بازه های زمانی در دسترس و قابل استفاده</returns>
 public IEnumerable <TimePeriodModel> Calculate_Available_Empty_TimePeriods(ServiceSupply serviceSupply, DateTime Date, ShiftCenterService polyclinicHealthService)
 {
     return
         (Calculate_Empty_TimePeriods(serviceSupply, Date, polyclinicHealthService)
          .Where(x => x.StartDateTime >= DateTime.Now));
 }