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()); }
// 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); }