public async Task CorrectTimeShouldReturnTrue()
        {
            var user = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user.Id,
                User     = user,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                StartTime = DateTime.UtcNow.TimeOfDay,
                EndTime   = DateTime.UtcNow.AddDays(5).TimeOfDay,
                Date      = DateTime.UtcNow.AddDays(2),
            };

            var isTimeCorrect = this.ConsultationsService.CheckIfTimeIsCorrect(model);

            Assert.True(isTimeCorrect);
        }
        public IActionResult SuccessfullyBooked(AddConsultationInputModel model)
        {
            var doctorName = this.doctorsService.GetDoctorNameById(model.DoctorId);
            var viewModel  = new SuccessfullyBookedViewModel()
            {
                Date = model.Date, DoctorName = doctorName
            };

            return(this.View(viewModel));
        }
        public IActionResult AddConsultation(AddConsultationInputModel model)
        {
            var patient = this.patientsService.GetPatientByUserId(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (this.consultationsService.AddConsultation(model, patient.Id).Result)
            {
                return(this.RedirectToAction(nameof(this.SuccessfullyBooked), model));
            }

            return(this.View("InvalidTimeInput"));
        }
        public async Task UpdateConsultationsWhenCompletedShouldUpdateIsActiveToFalse()
        {
            var user1 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user1.Id,
                User     = user1,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var doctor = new Doctor()
            {
                Name   = "Test",
                User   = user2,
                UserId = user2.Id,
            };

            await this.DoctorsRepository.AddAsync(doctor);

            await this.DoctorsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                DoctorId  = doctor.Id,
                StartTime = DateTime.UtcNow.TimeOfDay,
                EndTime   = DateTime.UtcNow.AddMinutes(40).TimeOfDay,
                Date      = DateTime.UtcNow.AddDays(5),
            };

            await this.ConsultationsService.AddConsultation(model, patient.Id);

            var consultation = await this.ConsultationsRepository.All().FirstAsync();

            consultation.Date = DateTime.Today.AddDays(-1);
            await this.ConsultationsRepository.SaveChangesAsync();

            await this.ConsultationsService.UpdateConsultationsWhenCompleted();

            Assert.False(consultation.IsActive);
        }
        public IActionResult AddConsultation(string id)
        {
            var doctorName = this.doctorsService.GetDoctorNameById(id);
            var temp       = this.patientsService.GetPatientByUserId(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var viewModel  = new AddConsultationInputModel()
            {
                DoctorId   = id,
                DoctorName = doctorName,
                PatientId  = temp.Id,
            };

            return(this.View(viewModel));
        }
        public void IncorrectTimeShouldReturnFalseWhenEndTimeIsBeforeStartTime()
        {
            var model = new AddConsultationInputModel()
            {
                StartTime = DateTime.Now.AddHours(3).TimeOfDay,
                EndTime   = DateTime.Now.TimeOfDay,
                Date      = DateTime.Now.AddDays(2),
            };

            var isAdded = this.ConsultationsService.CheckIfTimeIsCorrect(model);

            Assert.False(isAdded);
        }
        public void Test3()
        {
            var model = new AddConsultationInputModel()
            {
                StartTime = TimeSpan.Parse("15:15:15"),
                EndTime   = TimeSpan.Parse("15:15:15"),
                Date      = DateTime.Now.AddDays(2),
            };

            var isTimeCorrect = this.ConsultationsService.CheckIfTimeIsCorrect(model);

            Assert.False(isTimeCorrect);
        }
        public void Test2()
        {
            var model = new AddConsultationInputModel()
            {
                StartTime = DateTime.Now.AddMinutes(-50).TimeOfDay,
                EndTime   = DateTime.Now.AddMinutes(50).TimeOfDay,
                Date      = DateTime.Now.AddDays(2),
            };

            var isTimeCorrect = this.ConsultationsService.CheckIfTimeIsCorrect(model);

            Assert.True(isTimeCorrect);
        }
        public async Task GettingPatientsConsultationsShouldReturnTheCorrectAmountOfThem()
        {
            var user1 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user1.Id,
                User     = user1,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var doctor = new Doctor()
            {
                Name   = "Test",
                User   = user2,
                UserId = user2.Id,
            };

            await this.DoctorsRepository.AddAsync(doctor);

            await this.DoctorsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                DoctorId  = doctor.Id,
                StartTime = DateTime.UtcNow.TimeOfDay,
                EndTime   = DateTime.UtcNow.AddMinutes(40).TimeOfDay,
                Date      = DateTime.UtcNow.AddDays(5),
            };

            await this.ConsultationsService.AddConsultation(model, patient.Id);

            await this.ConsultationsService.AddConsultation(model, patient.Id);

            var consultationsCount =
                this.ConsultationsService.GetPatientsConsultations <ConsultationViewModel>(patient.Id).Count();

            Assert.Equal(2, consultationsCount);
        }
        public async Task SuccessfullyApprovingConsultationShouldConfirmTheConsultation()
        {
            var user1 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user1.Id,
                User     = user1,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var doctor = new Doctor()
            {
                Name   = "Test",
                User   = user2,
                UserId = user2.Id,
            };

            await this.DoctorsRepository.AddAsync(doctor);

            await this.DoctorsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                DoctorId  = doctor.Id,
                StartTime = DateTime.UtcNow.TimeOfDay,
                EndTime   = DateTime.UtcNow.AddMinutes(40).TimeOfDay,
                Date      = DateTime.UtcNow.AddDays(5),
            };

            await this.ConsultationsService.AddConsultation(model, patient.Id);

            var consultation = await this.ConsultationsRepository.All().FirstAsync();

            await this.ConsultationsService.ApproveConsultationAsync(consultation.Id);

            Assert.True(consultation.IsConfirmed);
        }
Esempio n. 11
0
        public bool CheckIfTimeIsCorrect(AddConsultationInputModel model)
        {
            if (model.StartTime > model.EndTime)
            {
                return(false);
            }
            else if (model.StartTime == model.EndTime)
            {
                return(false);
            }
            else if (model.Date <= DateTime.Now)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
        public async Task <bool> AddConsultation(AddConsultationInputModel model, string patientId)
        {
            if (!this.CheckIfTimeIsCorrect(model))
            {
                return(false);
            }

            var patient = this.patientsRepository.All().FirstOrDefault(x => x.Id == patientId);
            var doctor  = this.doctorRepository.All().FirstOrDefault(x => x.Id == model.DoctorId);

            var consultation = new Consultation()
            {
                Date        = model.Date,
                Description = model.Description,
                StartTime   = (TimeSpan)model.StartTime,
                EndTime     = (TimeSpan)model.EndTime,
                PatientId   = patientId,
                DoctorId    = doctor.Id,
                IsActive    = true,
                IsCancelled = false,
                IsConfirmed = null,
            };

            var calendarEvent = new CalendarEvent()
            {
                Color    = "yellow",
                Start    = consultation.Date + consultation.StartTime,
                End      = consultation.Date + consultation.EndTime,
                Text     = $"{consultation.StartTime}",
                IsActive = true,
            };

            consultation.CalendarEvent = calendarEvent;
            doctor.Consultations.Add(consultation);

            await this.consultationsRepository.AddAsync(consultation);

            await this.consultationsRepository.SaveChangesAsync();

            var doctorEmail = await this.doctorsService.GetDoctorEmailById(model.DoctorId);

            await this.emailsService.AddConsultationEmailAsync(patient.FirstName, patient.LastName, doctorEmail, model.Date, model.StartTime);

            return(true);
        }
        public async Task IncorrectTimeShouldReturnFalseWhenStartAndFinishTimeIsTheSame()
        {
            var user1 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user1.Id,
                User     = user1,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var doctor = new Doctor()
            {
                Name   = "Test",
                User   = user2,
                UserId = user2.Id,
            };

            await this.DoctorsRepository.AddAsync(doctor);

            await this.DoctorsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                DoctorId  = doctor.Id,
                StartTime = TimeSpan.Parse("15:15:15"),
                EndTime   = TimeSpan.Parse("15:15:15"),
                Date      = DateTime.Now.AddDays(1),
            };

            var isAdded = await this.ConsultationsService.AddConsultation(model, patient.Id);

            Assert.False(isAdded);
        }
        public async Task IncorrectTimeShouldReturnFalseWhenTheDateIsBeforeToday()
        {
            var user1 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };
            var user2 = new ApplicationUser()
            {
                UserName = "******", Email = "*****@*****.**"
            };

            var patient = new Patient()
            {
                LastName = "Test",
                UserId   = user1.Id,
                User     = user1,
            };

            await this.PatientsRepository.AddAsync(patient);

            await this.PatientsRepository.SaveChangesAsync();

            var doctor = new Doctor()
            {
                Name   = "Test",
                User   = user2,
                UserId = user2.Id,
            };

            await this.DoctorsRepository.AddAsync(doctor);

            await this.DoctorsRepository.SaveChangesAsync();

            var model = new AddConsultationInputModel()
            {
                DoctorId  = doctor.Id,
                StartTime = DateTime.Now.AddHours(5).TimeOfDay,
                EndTime   = DateTime.Now.AddMinutes(40).TimeOfDay,
                Date      = DateTime.Now.AddDays(-1),
            };

            var isAdded = await this.ConsultationsService.AddConsultation(model, patient.Id);

            Assert.False(isAdded);
        }