public IActionResult Complete(int insuranceId, int doctorId) { ShiftPlan shiftplan = GetShiftPlanFromDoctorId(doctorId); // Lấy mã phòng Room room = _context.Rooms.Where(r => r.Id == shiftplan.Room_Id).FirstOrDefault(); string roomshortcode = room.ShortCode; // Lấy tên bác sĩ Doctor doc = _context.Doctors.Where(d => d.Id == doctorId).FirstOrDefault(); string doctorname = doc.NameLast + " " + doc.NameMiddle + " " + doc.NameFirst; // Lấy tên khoa string facultyname = _context.Faculties.Where(f => f.Id == doc.Faculty_Id).FirstOrDefault().Name; // Lấy số thứ tự //nullhere int waitnumber = 0; var ifnull = _context.WaitingLines.Where(w => w.Room_Id == room.Id).LastOrDefault(); if (ifnull == null) { waitnumber = 1; } else { waitnumber = ifnull.Number + 1; } // Thêm vào hàng chờ WaitingLine new_wait = new WaitingLine() { Room_Id = room.Id, Patient_Id = _context.Patients.Where(p => p.Insurance_Id == insuranceId).FirstOrDefault().Id, Number = waitnumber }; _context.WaitingLines.Add(new_wait); _context.SaveChanges(); VictimCompleteViewModel vm = new VictimCompleteViewModel() { RoomShortCode = roomshortcode, DoctorName = doctorname, FacultyName = facultyname, WaitNumber = waitnumber }; return(View(vm)); }
public IActionResult waitingline([FromBody] int stt) { var per = new PercriptionViewModel(); DateTime datenow = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")); DateTime hournow = DateTime.Parse(DateTime.Now.ToString("HH:mm:ss")); var dr = HttpContext.Session.Get <Doctor>("doctor"); var shiftplan = _context.ShiftPlans.Where(r => r.Doctor_Id == dr.Id && DateTime.Parse(r.DateStart.ToString("yyyy-MM-dd")) <= datenow && DateTime.Parse(r.DateEnd.ToString("yyyy-MM-dd")) >= datenow); var shiftPl = new ShiftPlan(); foreach (var sp in shiftplan) { var shift = _context.Shifts.Where(s => s.Id == sp.Shift_Id).FirstOrDefault(); if (shift.TimeStart <= hournow && shift.TimeEnd >= hournow) { shiftPl = sp; } } var waitinginroom = _context.WaitingLines.Where(s => s.Room_Id == shiftPl.Room_Id); var waitingpa = waitinginroom.Where(p => p.Number == stt + 1).FirstOrDefault(); var pa = _context.Patients.Where(p => p.Id == waitingpa.Patient_Id).FirstOrDefault(); return(Ok(pa)); }
// Return a shiftplans public ShiftPlan GetShiftPlanFromDoctorId(int doctorId) { if (IsInShift(doctorId) == true) { ShiftPlan result = new ShiftPlan(); int now_to_int = (DateTime.Now.Hour * 60) + DateTime.Now.Minute; // Lấy lịch trực của bác sĩ trong ngày List <ShiftPlan> plans = new List <ShiftPlan>(); foreach (ShiftPlan sp in _context.ShiftPlans.ToList()) { int nowD = DateTime.Now.Day; int nowM = DateTime.Now.Month; if (nowM == sp.DateStart.Month) { if (sp.DateStart.Day <= nowD && sp.DateEnd.Day >= nowD && sp.Doctor_Id == doctorId) { plans.Add(sp); } } } foreach (ShiftPlan plan in plans) { Shift shift = _context.Shifts.Where(sp => sp.Id == plan.Shift_Id).FirstOrDefault(); int start_to_int = (shift.TimeStart.Hour * 60 + shift.TimeStart.Minute); int end_to_int = (shift.TimeEnd.Hour * 60 + shift.TimeEnd.Minute); if (start_to_int <= now_to_int && end_to_int > now_to_int) { result = plan; } } return(result); } return(null); }
public CustomList <ShiftPlan> GetAllShiftPlan() { return(ShiftPlan.GetAllShiftPlan()); }