コード例 #1
0
        public RoomDateViewModel GetRoomByMaxSurgeryTime(ScheduleViewModel scheduleViewModel)
        {
            // Lấy ngày cần lên lịch mổ (mổ bình thường), dạng số giảm dần theo thời gian
            // TODO: List những phòng có thời gian phẫu thuật trễ nhất, giảm dần
            // Chọn các phòng theo ngày

            var result1 = _context.SurgeryShifts
                          .Where(s => (s.EstimatedStartDateTime != null) &&
                                 (UtilitiesDate.ConvertDateToNumber(s.EstimatedEndDateTime.Value) == UtilitiesDate.ConvertDateToNumber(scheduleViewModel.StartAMWorkingHour)))
                          .Select(s => new { s.EstimatedEndDateTime, s.SurgeryRoomId }).ToList();
            // Nhóm các phòng cùng tên
            var result2 = result1.GroupBy(s => s.SurgeryRoomId).ToList();
            // Lấy thời điểm ca mổ gần nhất của phòng
            var result3 = new List <RoomDateViewModel>();

            foreach (var item in result2)
            {
                result3.Add(new RoomDateViewModel()
                {
                    SurgeryRoomId    = int.Parse(item.Key.Value.ToString()),
                    EarlyEndDateTime = item.Max(s => s.EstimatedEndDateTime),
                });
            }
            if (result3 == null || result3.Count == 0)
            {
                return(null);
            }
            result3 = result3.OrderBy(s => s.EarlyEndDateTime).ToList();
            // Lấy phòng hợp lý nhất
            return(result3.First());
        }
コード例 #2
0
        // TODO: Xem lịch theo ngày
        public ICollection <SurgeryShiftViewModel> GetSurgeryShiftsByRoomAndDate(int surgeryRoomId, int dateNumber)
        {
            var results = new List <SurgeryShiftViewModel>();

            foreach (var shift in _context.SurgeryShifts
                     .Where(s => (s.EstimatedStartDateTime != null) &&
                            (UtilitiesDate.ConvertDateToNumber(s.EstimatedStartDateTime.Value) == dateNumber) && //mm/dd/YYYY
                            (s.SurgeryRoomId == surgeryRoomId))
                     .OrderBy(s => s.EstimatedStartDateTime))
            {
                results.Add(new SurgeryShiftViewModel()
                {
                    Id = shift.Id,
                    //CatalogName = shift.SurgeryRoomCatalog.Name,
                    //EstimatedEndDateTime = $"{shift.EstimatedEndDateTime.ToShortDateString()} {shift.EstimatedEndDateTime.ToShortTimeString()}",
                    //EstimatedStartDateTime = $"{shift.EstimatedStartDateTime.ToShortDateString()} {shift.EstimatedStartDateTime.ToShortTimeString()}",
                    PriorityNumber         = shift.PriorityNumber,
                    EstimatedStartDateTime = UtilitiesDate.GetTimeFromDate(shift.EstimatedStartDateTime.Value),
                    EstimatedEndDateTime   = UtilitiesDate.GetTimeFromDate(shift.EstimatedEndDateTime.Value),
                    PatientName            = shift.Patient.FullName,
                    SurgeonNames           = shift.SurgeryShiftSurgeons.Select(s => s.Surgeon.FullName).ToList()
                });
            }
            return(results);
        }
コード例 #3
0
        //public void MakeScheduleList()
        //{
        //    //var result = GetSurgeryShiftsNoSchedule(1);
        //    //foreach (var index in result)
        //    //{
        //    //    MakeSchedule(index);
        //    //}

        //    var result = GetSurgeryShiftsNoSchedule(1).First();
        //    //foreach (var index in result)
        //    //{
        //        MakeSchedule(result);
        //    //}
        //}
        public void MakeSchedule(ScheduleViewModel scheduleViewModel)
        {
            string selectedDay = UtilitiesDate.ConvertDateToString(scheduleViewModel.StartAMWorkingHour);
            // Tìm những phòng còn trống theo ngày
            // Parse số thành giờ: 1.5 => 1h30
            TimeSpan hour        = TimeSpan.FromHours(scheduleViewModel.ExpectedSurgeryDuration);
            int      roomEmptyId = GetEmptyRoomForDate(selectedDay);

            if (roomEmptyId == null || roomEmptyId == 0)
            {
                // Lấy ra cái phòng hợp lý nhất, có ca sớm nhất
                var availableRoom = GetRoomByMaxSurgeryTime(scheduleViewModel);
                if (availableRoom == null)
                {
                } // End If available room
                else
                {
                    DateTime endEstimatedTime = availableRoom.EarlyEndDateTime.Value + hour;
                    if (availableRoom.EarlyEndDateTime.Value >= scheduleViewModel.StartAMWorkingHour && endEstimatedTime <= scheduleViewModel.EndAMWorkingHour) //buổi sáng: thời gian phải <= 11:00
                    {                                                                                                                                           // Khoảng thời gian hợp lý vào buổi sáng
                        InsertDateTimeToSurgeryShift
                            (scheduleViewModel.SurgeryShiftId, availableRoom.EarlyEndDateTime.Value, endEstimatedTime, availableRoom.SurgeryRoomId);
                    }
                    else if (availableRoom.EarlyEndDateTime.Value >= scheduleViewModel.StartPMWorkingHour && endEstimatedTime <= scheduleViewModel.EndPMWorkingHour) //buổi chiều:  >= 13h && <= 17h
                    {                                                                                                                                                // Khoảng thời gian hợp lý vào buổi chiều
                        InsertDateTimeToSurgeryShift
                            (scheduleViewModel.SurgeryShiftId, availableRoom.EarlyEndDateTime.Value, endEstimatedTime, availableRoom.SurgeryRoomId);
                    }
                    else if (endEstimatedTime >= scheduleViewModel.EndAMWorkingHour && endEstimatedTime <= scheduleViewModel.StartPMWorkingHour)
                    {// Nếu thời gian ước tính nằm trong giờ nghỉ trưa thì lấy thời gian đầu của buổi chiều + ExpectedSurgeryDuration
                        endEstimatedTime = scheduleViewModel.StartPMWorkingHour + hour;
                        InsertDateTimeToSurgeryShift
                            (scheduleViewModel.SurgeryShiftId, scheduleViewModel.StartPMWorkingHour, endEstimatedTime, availableRoom.SurgeryRoomId);
                        // Tính sau
                    }
                } // End else available room
            }     // End room Id
            else  // Trường hợp có phòng chưa có ca phẫu thuật nào sẽ add thời gian từ 7:00
            {
                DateTime endEstimatedTime = scheduleViewModel.StartAMWorkingHour + hour;
                InsertDateTimeToSurgeryShift(scheduleViewModel.SurgeryShiftId, scheduleViewModel.StartAMWorkingHour, endEstimatedTime, roomEmptyId);
            }
            // Lấy thời gian sớm nhất + khoảng giờ phẫu thuật = thời gian bắt đầu của ca phẫu thuật tiếp theo
        }