//public CountInTimeFrame hospitalSchedulesWithPatient(DateTime date, string TimeFrame, // int doctorid) //{ // using (CaremeDBContext context = new CaremeDBContext()) // { // DateTime scheduledate = date; // var day = scheduledate.DayOfWeek.ToString(); // CountInTimeFrame citf_data = new CountInTimeFrame(); // citf_data.TimeFrame = TimeFrame; // DateTime? combined = null; // List<tbSchedule> schedules = context.tbSchedules.Where(a => a.IsDeleted != true // && a.DoctorID == doctorid).Where(daysQuery(day)).ToList(); //date // List<HospitalListViewModel> hlistvm = new List<HospitalListViewModel>(); // foreach (var item in schedules) // { // var newdate = scheduledate.ToShortDateString();//tochange // var time = item.Fromtime.Value.ToShortTimeString(); // combined = DateTime.Parse(newdate + " " + time); // HospitalListViewModel hlvm = new HospitalListViewModel(); // hlvm.fromTime = item.Fromtime; // hlvm.toTime = item.Totime; // hlvm.patientCount = context.tbAppointments.Where(a => a.IsDeleted != true // && a.DoctorId == item.DoctorID // && a.HospitalId == item.HospitalID && a.Day == day && a.AppointmentDateTime == combined).Count(); // hlvm.hospitalId = item.HospitalID; // hlvm.hospitalName = item.HospitalName; // hlvm.appointmentDateTime = combined; // hlvm.scheduleID = item.ID; // hlistvm.Add(hlvm); // } // citf_data.hospitalList = hlistvm; // var nextday = date.AddDays(1).Date; // citf_data.totalPatientCount = context.tbAppointments.Where(a => a.IsDeleted != true).Where(a => a.DoctorId == doctorid // && a.Day == day && a.AppointmentDateTime >= date.Date && a.AppointmentDateTime <= nextday).Count(); // return citf_data; // } //} public CountInTimeFrame hospitalSchedulesWithPatient(DateTime date, string TimeFrame, int doctorid) { using (CaremeDBContext context = new CaremeDBContext()) { DateTime scheduledate = date; var day = scheduledate.DayOfWeek.ToString(); CountInTimeFrame citf_data = new CountInTimeFrame(); citf_data.TimeFrame = TimeFrame; DateTime?combined = null; //List<tbSchedule> schedules = context.tbSchedules.Where(a => a.IsDeleted != true // && a.DoctorID == doctorid).Where(daysQuery(day)).ToList(); //date date = date.Date; var dateto = date.AddDays(1); List <tbScheduleData> schedules = context.tbScheduleDatas.Where(a => a.IsDeleted != true && a.DoctorID == doctorid && a.AppointmentDatetime >= date && a.AppointmentDatetime <= dateto).ToList(); List <HospitalListViewModel> hlistvm = new List <HospitalListViewModel>(); foreach (var item in schedules) { //var newdate = scheduledate.ToShortDateString();//tochange //var time = item.Fromtime.Value.ToShortTimeString(); //combined = DateTime.Parse(newdate + " " + time); HospitalListViewModel hlvm = new HospitalListViewModel(); hlvm.fromTime = item.Fromtime; hlvm.toTime = item.Totime; hlvm.patientCount = context.tbAppointments.Where(a => a.IsDeleted != true && a.DoctorId == item.DoctorID && a.HospitalId == item.HospitalID && a.AppointmentDateTime == item.AppointmentDatetime).Count(); hlvm.hospitalId = item.HospitalID; hlvm.hospitalName = item.HospitalName; hlvm.appointmentDateTime = item.AppointmentDatetime; hlvm.scheduleID = item.ID; hlistvm.Add(hlvm); } citf_data.hospitalList = hlistvm; var nextday = date.AddDays(1).Date; citf_data.totalPatientCount = context.tbAppointments.Where(a => a.IsDeleted != true).Where(a => a.DoctorId == doctorid && a.AppointmentDateTime >= date.Date && a.AppointmentDateTime <= nextday).Count(); return(citf_data); } }
public HttpResponseMessage getData(HttpRequestMessage request, int doctorid = 0) { DoctorHomeViewModel homeObj = new DoctorHomeViewModel(); homeObj.doctorid = doctorid; homeObj.doctorName = doctorRepo.GetWithoutTracking().Where(a => a.ID == doctorid).Select(a => a.Name).FirstOrDefault(); DateTime localNow = MyExtension.getLocalTime(DateTime.UtcNow); using (CaremeDBContext context = new CaremeDBContext()) { string timeFrame_Today = "Today"; DateTime today = MyExtension.getLocalTime(DateTime.UtcNow); CountInTimeFrame today_Count = iScheduleService.hospitalSchedulesWithPatient(today, timeFrame_Today, doctorid); string timeFrame_Tomorrow = "Tomorrow"; DateTime tomorrow = today.AddDays(1); CountInTimeFrame tomorrow_Count = iScheduleService.hospitalSchedulesWithPatient(tomorrow, timeFrame_Tomorrow, doctorid); DateTime DFtomorrow = today.AddDays(2); string timeFrame_DFTomorrow = DFtomorrow.Day + " " + DFtomorrow.ToString("MMM"); CountInTimeFrame DFtomorrow_Count = iScheduleService.hospitalSchedulesWithPatient(DFtomorrow, timeFrame_DFTomorrow, doctorid); DateTime TDFtomorrow = today.AddDays(3); string timeFrame_TDFTomorrow = TDFtomorrow.Day + " " + TDFtomorrow.ToString("MMM"); CountInTimeFrame TDFtomorrow_Count = iScheduleService.hospitalSchedulesWithPatient(TDFtomorrow, timeFrame_TDFTomorrow, doctorid); List <CountInTimeFrame> countInTimeframes = new List <CountInTimeFrame>(); countInTimeframes.Add(today_Count); countInTimeframes.Add(tomorrow_Count); countInTimeframes.Add(DFtomorrow_Count); countInTimeframes.Add(TDFtomorrow_Count); homeObj.CountList = countInTimeframes; return(request.CreateResponse <DoctorHomeViewModel>(HttpStatusCode.OK, homeObj)); } }