public async Task <IActionResult> CreateClient(Appointment appointment)
        {
            var client = _clientRepository.GetClientByUserEmail(User.Identity.Name);

            appointment.ClientId    = client.Id;
            appointment.Id          = 0;
            appointment.IsConfirmed = false;
            await _appointmentRepository.CreateAsync(appointment);

            return(RedirectToAction("CreateClient", "Appointments"));
        }
예제 #2
0
        public async Task <IActionResult> Schedule(AppointmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Doctor = await _doctorRepository.GetDoctorByIdAsync(model.DoctorId);

                    model.Owner = await _ownerRepository.GetOwnerWithUserByIdAsync(model.OwnerId);

                    model.Pet = await _petRepository.GetByIdWithIncludesAsync(model.PetId);

                    var appointment = _converterHelper.ToAppointment(model, true);

                    appointment.CreatedBy = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                    await _appointmentRepository.CreateAsync(appointment);

                    return(RedirectToAction(nameof(MyAppointments)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }

            model.Doctors = _doctorRepository.GetComboDoctors();
            model.Pets    = _petRepository.GetComboPets(model.OwnerId);

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = new Appointment
                {
                    Start    = model.Day + new TimeSpan(0, model.AppointmentTime, 0),
                    AnimalId = model.AnimalId,
                    DoctorId = model.DoctorId
                };

                await _appointmentRepository.CreateAsync(entity);

                ViewBag.Message = "Appointment Successfully Requested";
                return(View(model));
            }

            model.Specialities = _comboHelper.GetComboSpecialities();
            model.Rooms        = await _comboHelper.GetComboRoomsAsync(model.SpecialityId);

            model.Doctors = await _comboHelper.GetComboDoctorsAsync(model.RoomId);

            model.AvailableHours = _comboHelper.GetComboAvailableAppointment(new List <Appointment>(), new TimeSpan());
            return(View(model));
        }
        public async Task ScheduleAsync(AppointmentId appointmentId, DoctorId doctorId, PatientId patientId, DateTime requestedAppointmentAt, AppointmentDuration requestedAppointmentDuration,
                                        CancellationToken cancellationToken = default)
        {
            if (requestedAppointmentAt < _systemClockService.UtcNow.DateTime)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it occurs in the past.");
            }

            var doctor = await _doctorRepository.GetByIdAsync(doctorId, cancellationToken);

            if (doctor == null)
            {
                throw new EntityNotFoundException("The requested doctor was not found.");
            }

            var patient = await _patientRepository.GetByIdAsync(patientId, cancellationToken);

            if (patient == null)
            {
                throw new EntityNotFoundException("The requested patient was not found.");
            }

            // Does the requested appointment occur during the doctor's availability?

            var doctorAvailabilities = await _doctorAvailabilityRepository.GetAllForDoctorAsync(doctorId, cancellationToken);

            var doctorIsAvailable = doctorAvailabilities.Any(a =>
                                                             a.DayOfWeek == requestedAppointmentAt.DayOfWeek &&                            // Occurs on an available day of the week
                                                             a.StartsAt <= requestedAppointmentAt.TimeOfDay && // After that day of the week's start time
                                                             a.EndsAt >= requestedAppointmentAt.TimeOfDay + requestedAppointmentDuration); // And ends before that day of the week's end time

            if (!doctorIsAvailable)
            {
                throw new DomainValidationException("The appointment could not be scheduled because it is outside of the doctor's availability.");
            }

            // Determine if there are any scheduling conflicts.
            // Algorithm description: Two time periods overlap if each one starts before the other one ends.

            var doctorAppointments = await _appointmentRepository.GetAllUpcomingForDoctorAsync(doctorId, cancellationToken);

            var doctorHasConflictingAppointment = doctorAppointments.Any(existingAppointment =>
                                                                         requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                         existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (doctorHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the doctor has a conflicting appointment.");
            }

            var patientAppointments = await _appointmentRepository.GetAllUpcomingForPatientAsync(patientId, cancellationToken);

            var patientHasConflictingAppointment = patientAppointments.Any(existingAppointment =>
                                                                           requestedAppointmentAt < existingAppointment.AppointmentAt.Add(existingAppointment.AppointmentDuration) &&
                                                                           existingAppointment.AppointmentAt < requestedAppointmentAt.Add(requestedAppointmentDuration));

            if (patientHasConflictingAppointment)
            {
                throw new DomainValidationException("The appointment could not be scheduled because the patient has a conflicting appointment.");
            }

            var appointment = new Appointment(appointmentId, doctorId, patientId, requestedAppointmentAt, requestedAppointmentDuration);

            await _appointmentRepository.CreateAsync(appointment, cancellationToken);
        }
예제 #5
0
 public async Task <bool> CreateAppointmentAsync(AppointmentModel appointmentModel) => await _appointmentRepository.CreateAsync(appointmentModel);
예제 #6
0
        public async Task<JsonResult> UpdateData([FromBody] EditParams param)
        {
            if (param==null)
            {
                return Json(NotFound());
            }

            if (param.action == "insert" || (param.action == "batch" && param.added.Count != 0)) 
            {
                var value = (param.action == "insert") ? param.value : param.added[0];

                var client = await _clientRepository.GetClientWithUserAsync(value.ClientUsername);

                var doctor = await _doctorRepository.GetDoctorWithUserAsync(value.DoctorId);

                var animal = await _animalRepository.GetAnimalWithUserAsync(value.AnimalId);

                var specialization = await _specializationRepository.GetByIdAsync(value.SpecializationId);

                Appointment appointment = new Appointment
                {
                    Client = client,
                    Animal = animal,
                    Doctor = doctor,
                    Specialization = specialization,
                    Status = "Waiting",
                    StartTime = value.StartTime,
                    ClientDescription = value.ClientDescription
                };

                await _appointmentRepository.CreateAsync(appointment);

                try
                {
                    _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Requested", $"<h1>You have requested an appointment</h1>" +
                      $"Please wait while we analyze your request!");
                }
                catch (Exception)
                {
                }
          
            }
            if (param.action == "update" || (param.action == "batch" && param.changed.Count != 0))
            {
                var value = param.changed[0];

                var appointment = await _appointmentRepository.GetByIdWithModelsAsync(value.Id);

                if (appointment!=null)
                {
                    appointment.Animal = await _animalRepository.GetAnimalWithUserAsync(value.AnimalId);

                    appointment.Doctor = await _doctorRepository.GetDoctorWithUserAsync(value.DoctorId);

                    appointment.Specialization = await _specializationRepository.GetByIdAsync(value.SpecializationId);

                    appointment.ClientDescription = value.ClientDescription;

                    await _appointmentRepository.UpdateAsync(appointment);

                    try
                    {
                        _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Updated", $"<h1>Your Appointment request has been updated.</h1>" +
                          $"Please wait while we analyze your request!");
                    }
                    catch (Exception)
                    {
                    }
                }             

            }
            if (param.action == "remove" || (param.action == "batch" && param.deleted.Count != 0))
            {
                if (param.action == "remove")
                {

                }
                else
                {
                    foreach (var apps in param.deleted)
                    {
                        var appointment = await _appointmentRepository.GetByIdWithModelsAsync(apps.Id);

                        if (appointment!=null && appointment.Status=="Waiting")
                        {
                           await _appointmentRepository.DeleteAsync(appointment);

                            try
                            {
                                _mailHelper.SendMail(appointment.Client.User.UserName, "Appointment Canceled", $"<h1>Your appointment request has been canceled!</h1>" +
                                 $"Your appointment for { appointment.Animal.Name} with the date { appointment.StartTime} has been canceled.");
                            }
                            catch (Exception)
                            {
                            }
                        }

                    }
                }

            }

            var data = _appointmentRepository.GetAllWithModels().ToList();

            return Json(data, new Newtonsoft.Json.JsonSerializerSettings());
        }