Exemple #1
0
        public HttpResponseMessage statuschange(HttpRequestMessage request, int id, string statuschange = null)
        {
            // tbAppointment appointment = new tbAppointment();
            tbAppointment UpdatedAppointment = null;

            tbAppointment appointment = appointmentRepo.Get().Where(a => a.ID == id).FirstOrDefault();

            appointment.Status = statuschange;
            UpdatedAppointment = appointmentRepo.UpdatewithObj(appointment);
            List <tbAppointment> appointments = appointmentRepo.Get().Where(a => a.Status == "ACCEPTED" && a.Counter < appointment.Counter).ToList();
            string time1 = appointment.AppointmentDateTime.Value.ToLongTimeString();

            //tbAppointment mama = appointmentRepo.Get().Where(a => a.ID == 4).FirstOrDefault();
            //string time2 = mama.AppointmentDateTime.Value.ToLongTimeString();
            //TimeSpan duration = DateTime.Parse(time1).Subtract(DateTime.Parse(time2));
            foreach (var acceptlist in appointments)
            {
                string   time2    = acceptlist.AppointmentDateTime.Value.ToLongTimeString();
                TimeSpan duration = DateTime.Parse(time1).Subtract(DateTime.Parse(time2));
                TimeSpan comTime  = new TimeSpan(01, 00, 00);
                if (duration >= comTime)
                {
                    acceptlist.Status = "CANCEL";
                    appointmentRepo.UpdatewithObj(acceptlist);
                }
                //  string t1 = "01:00:00";
                //   TimeSpan t2 = DateTime.Parse(t1);
                // if (duration.ToString().Equals(t1))
                //{
                //     acceptlist.Status = "CANCEL";
                //      appointmentRepo.UpdatewithObj(acceptlist);
                //  }
            }
            return(request.CreateResponse <tbAppointment>(HttpStatusCode.OK, UpdatedAppointment));
        }
        public HttpResponseMessage changestatus(HttpRequestMessage request, int id, string status)
        {
            bool          result      = false;
            tbAppointment appointment = appointmentRepo.Get().Where(a => a.ID == id).FirstOrDefault();

            if (appointment != null)
            {
                if (status == "BOOKED")
                {
                    appointment.Status     = null;
                    appointment.IsWaiting  = true;
                    appointment.IsApproved = true;
                }
                else if (status == "WAITING")
                {
                    appointment.Status    = status;
                    appointment.IsWaiting = true; //updated
                }
                else if (status == "CHECKIN")
                {
                    appointment.IsWaiting = true;
                    appointment.IsCheckIn = true;
                    appointment.Status    = status;
                }
                else if (status == "CHECKOUT")
                {
                    appointment.IsWaiting = true;
                    appointment.IsCheckIn = true;
                    appointment.Status    = status;
                }
                else if (status == "CANCEL")
                {
                    appointment.Status       = "CANCEL";
                    appointment.IsDelByAdmin = true;
                    appointment.IsWaiting    = false;
                    appointment.IsCheckIn    = false;
                }
                else if (status == "SKIP")
                {
                    if (appointment.SkipCount == null)
                    {
                        appointment.SkipCount   = 1;
                        appointment.Position   += 5;
                        appointment.CreatedTime = DateTime.UtcNow.getLocalTime();
                    }
                    else
                    {
                        appointment.Status       = "CANCEL";
                        appointment.IsDelByAdmin = true;
                    }
                }

                result = appointmentRepo.UpdatewithObj(appointment) != null ? true : false;
            }
            return(request.CreateResponse <bool>(HttpStatusCode.OK, result));
        }
        public HttpResponseMessage Create(HttpRequestMessage request, PatientAppointmentViewModel patient)
        {
            PatientAppointmentViewModel pavm = new PatientAppointmentViewModel();

            tbPatient     UpdatedEntity      = null;
            tbAppointment UpdatedAppointment = null;

            if (iBookingService.checkBookingAvailable(patient.appointment.ScheduleDataID ?? 0) == true)
            {
                if (patient.patient.ID > 0)
                {
                    UpdatedEntity = patientRepo.UpdatewithObj(patient.patient);
                }
                else
                {
                    if (patient.patient.MsgrID != null)
                    {
                        tbPatient oldPatient = patientRepo.Get().Where(a => a.MsgrID == patient.patient.MsgrID && a.IsDeleted != true).FirstOrDefault();
                        if (oldPatient != null)
                        {
                            oldPatient.MsgrName = patient.patient.MsgrName;
                            oldPatient.Name     = patient.patient.Name;
                            oldPatient.Phone    = patient.patient.Phone;
                            oldPatient.Problem  = patient.patient.Problem;
                            oldPatient.Gender   = patient.patient.Gender;
                            oldPatient.Age      = patient.patient.Age;
                            oldPatient.Address  = patient.patient.Address;
                            UpdatedEntity       = patientRepo.UpdatewithObj(oldPatient);
                        }
                        else
                        {
                            // UpdatedEntity = new tbPatient();
                            patient.patient.IsDeleted  = false;
                            patient.patient.Accesstime = MyExtension.getLocalTime(DateTime.UtcNow);
                            UpdatedEntity = patientRepo.AddWithGetObj(patient.patient);
                        }
                    }
                    else
                    {
                        // UpdatedEntity = new tbPatient();
                        patient.patient.IsDeleted  = false;
                        patient.patient.Accesstime = MyExtension.getLocalTime(DateTime.UtcNow);
                        UpdatedEntity = patientRepo.AddWithGetObj(patient.patient);
                    }
                }

                tbAppointment appointment = appRepo.GetWithoutTracking().Where(a => a.IsDeleted != true && a.PatientId == UpdatedEntity.ID).FirstOrDefault();
                if (appointment != null)
                {
                    appointment.PatientId   = UpdatedEntity.ID;
                    appointment.PatientName = UpdatedEntity.Name;
                    appointment.PatientAge  = UpdatedEntity.Age;
                    appointment.DoctorName  = dbContext.tbDoctors.Where(a => a.IsDeleted != true && a.ID == patient.appointment.DoctorId).Select(a => a.Name).FirstOrDefault();
                    appointment             = appRepo.UpdatewithObj(appointment);
                }
                else
                {
                    var scheduledata = dbContext.tbScheduleDatas.Where(a => a.IsDeleted != true && a.ID == patient.appointment.ScheduleDataID).FirstOrDefault();

                    int counter  = dbContext.tbAppointments.Where(a => a.ScheduleDataID == scheduledata.ID).Count();
                    int?position = dbContext.tbAppointments.Where(a => a.ScheduleDataID == scheduledata.ID).Max(a => a.Position);
                    // patient.appointment = new tbAppointment();
                    patient.appointment.PatientId   = UpdatedEntity.ID;
                    patient.appointment.PatientName = UpdatedEntity.Name;
                    patient.appointment.PatientAge  = UpdatedEntity.Age;
                    patient.appointment.Status      = "BOOKED";
                    patient.appointment.Counter     = counter + 1;
                    if (position == null)
                    {
                        patient.appointment.Position = counter + 1;
                    }
                    else
                    {
                        patient.appointment.Position = position + 1;
                    }
                    //patient.appointment.HospitalId =
                    //patient.appointment.HospitalName =
                    //    patient.appointment.Day = patient.appointment.AppointmentDateTime.Value.DayOfWeek.ToString();
                    patient.appointment.IsDeleted    = false;
                    patient.appointment.Accesstime   = MyExtension.getLocalTime(DateTime.UtcNow);
                    patient.appointment.HospitalName = dbContext.tbHospitals.Where(a => a.IsDeleted != true && a.ID == patient.appointment.HospitalId).Select(a => a.Name).FirstOrDefault();
                    //   patient.appointment.DoctorName = dbContext.tbDoctors.Where(a => a.IsDeleted != true && a.ID == patient.appointment.DoctorId).Select(a => a.Name).FirstOrDefault();
                    UpdatedAppointment = appRepo.AddWithGetObj(patient.appointment);

                    var doc = docRepo.Get().Where(a => a.ID == patient.appointment.DoctorId && a.IsDeleted != true).FirstOrDefault();

                    FCMViewModel fcm = new FCMViewModel();
                    fcm.to = doc.UserToken;

                    fcmdata fcmdata = new fcmdata();
                    fcmdata.body     = "1 patient is waiting";
                    fcmdata.doctorId = doc.ID;
                    fcmdata.title    = "Booking notification";
                    fcmdata.type     = "1001";
                    fcm.data         = fcmdata;
                    FCMRequestHelper.sendTokenMessage(fcm);
                }
            }

            pavm.patient     = UpdatedEntity;
            pavm.appointment = UpdatedAppointment;

            return(request.CreateResponse <PatientAppointmentViewModel>(HttpStatusCode.OK, pavm));
        }
Exemple #4
0
        public HttpResponseMessage newstatuschange(HttpRequestMessage request, int id, string statuschange = null, int pagesize = 10, int page = 1)
        {
            // tbAppointment appointment = new tbAppointment();
            tbAppointment UpdatedAppointment = null;

            tbAppointment appointment = appointmentRepo.Get().Where(a => a.ID == id).FirstOrDefault();

            if (statuschange == "BOOKED")
            {
                appointment.Status     = null;
                appointment.IsWaiting  = true;
                appointment.IsApproved = true;
            }
            else if (statuschange == "WAITING")
            {
                appointment.Status = null;
                //     appointment.IsWaiting = false; //updated
                appointment.IsCheckIn = true;
            }
            else if (statuschange == "CHECKIN")
            {
                //   appointment.IsWaiting = false; //updated
                //   appointment.IsCheckIn = false;
                appointment.Status = "CHECKOUT";
            }
            else if (statuschange == "CANCEL")
            {
                appointment.Status       = "CANCEL";
                appointment.IsDelByAdmin = true;
            }
            else if (statuschange == "SKIP")
            {
                if (appointment.SkipCount == null)
                {
                    appointment.SkipCount   = 1;
                    appointment.Position   += 5;
                    appointment.CreatedTime = MyExtension.getLocalTime(DateTime.UtcNow);
                }
                else
                {
                    appointment.Status       = "CANCEL";
                    appointment.IsDelByAdmin = true;
                }
            }

            UpdatedAppointment = appointmentRepo.UpdatewithObj(appointment);
            List <tbAppointment> result = appointmentRepo.Get().Where(a => a.Status != "CHECKOUT" && a.Status != "CANCEL").ToList();

            //return request.CreateResponse<List<tbAppointment>>(HttpStatusCode.OK, appointments);
            var totalCount = result.Count();
            var totalpages = (int)Math.Ceiling((double)totalCount / pagesize);
            var dataList   = result.OrderBy(a => a.IsEmergency).OrderBy(a => a.Accesstime).OrderBy(a => a.Position)
                             .Skip(pagesize * (page - 1)).Take(pagesize);
            PagedListServer <tbAppointment> model = new PagedListServer <tbAppointment>();

            model.Results    = dataList.ToList();
            model.TotalCount = totalCount;
            model.TotalPages = totalpages;
            dbContext.Dispose();
            return(request.CreateResponse <PagedListServer <tbAppointment> >(HttpStatusCode.OK, model));
        }