Example #1
0
        public async Task <IActionResult> Create(CreateVisitViewModel vm)
        {
            try
            {
                if (vm.StartDate < DateTime.Now)
                {
                    ModelState.AddModelError("StartDate", "Date must be in future!");
                    vm.Doctors = await _userService.GetDoctorsForSpecialityExcludingDoctor(vm.Speciality);

                    return(View(vm));
                }

                if (ModelState.IsValid)
                {
                    vm.StartDate = vm.StartDate.AddHours(2);
                    var visit = vm.ConvertToDataModel();
                    visit.Patient = await _userService.GetById(vm.PatientId);

                    visit.Doctor = await _userService.GetById(vm.DoctorId);

                    await _visitService
                    .CreateVisit(visit);

                    return(RedirectToAction("Index"));
                }
                vm.Doctors = await _userService.GetDoctorsForSpecialityExcludingDoctor(vm.Speciality);

                return(View(vm));
            }
            catch (Exception ex)
            {
                return(Error(ex));
            }
        }
Example #2
0
        public async Task <CreateVisitStep2ViewModel> CreateVisitStepTwo(CreateVisitViewModel model, CancellationToken cancellationToken)
        {
            var doctor = await _doctorsRepository.GetAsync(model.DoctorName, cancellationToken).ConfigureAwait(false);

            var doctorsAppointments = await _appointmentsRepository.ListAsync(cancellationToken).ConfigureAwait(false);

            var doctorsAppointmentsByDate = doctorsAppointments.Where(a =>
                                                                      a.Doctor.Name == model.DoctorName && a.StartDateTime.Year == model.StartDateTime.Year &&
                                                                      a.StartDateTime.Month == model.StartDateTime.Month && a.StartDateTime.Day == model.StartDateTime.Day);

            var dates = AppointmentManager.GetAvailableTimes(model.StartDateTime);

            foreach (var date in doctorsAppointmentsByDate)
            {
                dates.RemoveAll(dateTime => dateTime.TimeOfDay == date.StartDateTime.TimeOfDay);
            }

            return(new CreateVisitStep2ViewModel
            {
                Date = dates,
                Doctor = doctor,
                DoctorName = model.DoctorName,
                StartDateTime = model.StartDateTime,
                Description = model.Description
            });
        }
Example #3
0
        public ActionResult Create(CreateVisitViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var v = new Visit(vm.Name, Convert.ToDateTime(vm.StartDate), Convert.ToDateTime(vm.Enddate), vm.ReturnToStart, identity.GetUserId(), vm.Duration);

                string[] coords = vm.StartLocation.Split(',');
                double   lat    = Convert.ToDouble(coords[0], CultureInfo.InvariantCulture);
                double   lon    = Convert.ToDouble(coords[1], CultureInfo.InvariantCulture);

                Location location = unitOfWork.LocationRepository.Find(x => x.Coordinates.Latitude == lat && x.Coordinates.Longitude == lon).FirstOrDefault();
                if (location == null)
                {
                    location = CreateLocation(lat, lon);
                }

                v.StartLocation = location;

                unitOfWork.VisitRepository.Insert(v);
                unitOfWork.SaveChanges();

                return(RedirectToAction("AddPoi", new { visitId = v.Id }));
            }

            return(View());
        }
        public async Task <IActionResult> CreateVisit()
        {
            var allDoctors = await _doctorsRepository.GetAllDoctors();

            var selectList = new List <SelectListItem>();

            foreach (var doctor in allDoctors)
            {
                var specname = await _specializationsRepository.GetSpecializationById(doctor.SpecializationId);

                selectList.Add(new SelectListItem
                {
                    Value = doctor.Name,
                    Text  = $"{specname.Name} - {doctor.FirstName} {doctor.LastName}"
                });
            }

            var orderedDoctors = selectList.OrderBy(m => m.Text).ToList();
            var visitModel     = new CreateVisitViewModel
            {
                Doctors       = orderedDoctors,
                StartDateTime = DateTime.Today
            };

            return(View(visitModel));
        }
        public async Task <IActionResult> CreateVisitStep2(CreateVisitViewModel model)
        {
            var isDoctorAvailableOnDate = await _absenceRepository.GetDoctorsAbscenceByDate(model.DoctorName, model.StartDateTime);

            if (isDoctorAvailableOnDate != null)
            {
                ModelState.AddModelError("doctorError", "Niestety, wybrany lekarz jest w tym dniu niedostępny");
            }

            if (!ModelState.IsValid)
            {
                var allDoctors = await _doctorsRepository.GetAllDoctors();

                var selectList = new List <SelectListItem>();

                foreach (var doctorItem in allDoctors)
                {
                    var specname = await _specializationsRepository.GetSpecializationById(doctorItem.SpecializationId);

                    selectList.Add(new SelectListItem
                    {
                        Value = doctorItem.Name,
                        Text  = $"{specname.Name} - {doctorItem.FirstName} {doctorItem.LastName}"
                    });
                }

                model.Doctors = selectList.OrderBy(item => item.Text).ToList();

                return(View("CreateVisit", model));
            }

            var doctor = await _doctorsRepository.GetDoctorByName(model.DoctorName);

            var app = _appointmentsRepository.GetDoctorsAppointmentsByDate(model.StartDateTime, model.DoctorName);

            var dates = AppointmentManager.GetAvailableTimes(model.StartDateTime);

            foreach (var date in app)
            {
                dates.RemoveAll(dateTime => dateTime.TimeOfDay == date.StartDateTime.TimeOfDay);
            }

            var createVisitStep2ViewModel = new CreateVisitStep2ViewModel
            {
                Date          = dates,
                Doctor        = doctor,
                DoctorName    = model.DoctorName,
                StartDateTime = model.StartDateTime,
                Description   = model.Description
            };

            return(View(createVisitStep2ViewModel));
        }
Example #6
0
        public async Task <IActionResult> CreateVisitStep2(CreateVisitViewModel model)
        {
            bool isDoctorAvailableOnDate = await _appService.GetHasDoctorAbsenceOnDate(model.DoctorName, model.StartDateTime, CancellationToken.None);

            if (isDoctorAvailableOnDate)
            {
                ModelState.AddModelError("doctorError", "Niestety, wybrany lekarz jest w tym dniu niedostępny");
            }

            if (!ModelState.IsValid)
            {
                var createVisitViewModel = await _appService.CreateVisit(CancellationToken.None);

                return(View("CreateVisit", createVisitViewModel));
            }

            var createVisitStep2ViewModel = await _appService.CreateVisitStepTwo(model, CancellationToken.None);

            return(View(createVisitStep2ViewModel));
        }
Example #7
0
        public async Task <IActionResult> SubmitVisit(CreateVisitViewModel model)
        {
            var userName = _userManager.GetUserName(User);
            var doctor   = await _doctorsRepository.GetByName(model.Doctor);

            var patient = await _patientsRepository.GetByName(userName);

            var appointment = new Appointment
            {
                StartDateTime = DateTime.Now,
                Doctor        = doctor,
                Patient       = patient,
                Status        = Status.New,
                Description   = model.Description
            };

            await _appointmentsRepository.Add(appointment);

            return(RedirectToAction("Index", "Home"));
        }