public async Task <EditPatientViewModel> GetPatient(string email) { var user = new EClinicUser(); if (String.IsNullOrEmpty(email)) { throw new ArgumentException("email is Null"); } try { user = this.db.Users.FirstOrDefault(x => x.Email == email && x.IsDeleted == false); } catch (Exception e) { throw new ArgumentException("email is Null"); } var exams = await this.examService.GetAllExamForPatient(email); var userToReturnn = new EditPatientViewModel() { Address = user.Address, Age = user.Age, CreatedOn = user.CreatedOn, FirstName = user.FirstName, MiddleName = user.MiddleName, LastName = user.LastName, ImageUrl = user.ImageUrl, Email = user.Email, Exams = exams }; return(userToReturnn); }
public void BuildUpdatePatientCommand_GivenValidEditPatientViewModel_CommandPropertiesShouldBeMapped() { var patientId = Guid.NewGuid(); var viewModel = new EditPatientViewModel() { PatientId = patientId, ClinicalSystemId = "clinicalsystemid", NhsNumber = 123456789, FirstName = "firstname", LastName = "lastname", DateOfBirthViewModel = new DateOfBirthViewModel() { Year = 2015, Month = 1, Day = 1 }, GenderId = 1 }; var result = _builder.BuildUpdatePatientCommand(viewModel); result.PatientId.Should().Be(patientId); result.ClinicalSystemId.Should().Be("clinicalsystemid"); result.NhsNumber.Should().Be(123456789); result.FirstName.Should().Be("firstname"); result.LastName.Should().Be("lastname"); result.DateOfBirth.Should().Be(new DateTime(2015, 1, 1)); result.GenderId.Should().Be(1); }
public void EditPatientViewModelValidator_GivenDuplicateClinicalSystemId_ErrorMessageShouldContainClinicalSystemIdDescription() { const string clinicalsystemid = "clinicalSystemId"; A.CallTo(() => _clinicalSystemIdDescriptionProvider.GetDescription()).Returns(clinicalsystemid); A.CallTo(() => _clinicalIdValidator.Unique(A <string> ._)).Returns(false); var model = new EditPatientViewModel() { ClinicalSystemId = "clinicalsystemid1", CurrentClinicalSystemId = "clinicalsystemid", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 4567899881, CurrentNhsNumber = 4567899881 }; var result = ValidationResult(model); result.Errors.Should() .Contain(x => x.PropertyName == "ClinicalSystemId" && x.ErrorMessage == string.Format("A person with this {0} already exists", clinicalsystemid)); }
public ActionResult EditPatient(int id) { var patient = this._repository.GetPatient(id); var countryList = _languagesRepository.GetCountriesList(); var model = new EditPatientViewModel { Nationalities = countryList, Countries = countryList, BuildingNumber = patient.Address.BuildingNumber, City = patient.Address.City, CityOfBirth = patient.CityOfBirth, DateOfBirth = patient.DateOfBirth, FirstName = patient.FirstName, FlatNumber = patient.Address.FlatNumber, Pesel = patient.Pesel, PhoneNumber = patient.PhoneNumber, SecondName = patient.SecondName, Street = patient.Address.Street, Surname = patient.Surname, ZipCode = patient.Address.ZipCode, Id = patient.Id, CountryName = patient.Address.Country.Name, NationalityName = patient.Nationality.Name, CountryId = patient.Address.CountryId, NationalityId = patient.NationalityId, PatientNotes = _repository.GetPatientNotes(patient.Id), PatientDocuments = _patientManager.GetPatientDocuments(patient.PatientDocuments) }; return(View(model)); }
private ValidationResult ValidationResult(EditPatientViewModel model) { var validator = new EditPatientViewModelValidator(_futureDateValidator, _clinicalIdValidator, _nhsValidator, _clinicalSystemIdDescriptionProvider); var result = validator.Validate(model); return(result); }
public async Task <IActionResult> ChangeUserPatient(int id) { var patient = await this.GetPatientAsync(id); var model = new EditPatientViewModel(); if (patient != null) { model.Document = patient.User.Document; model.FirstName = patient.User.FirstName; model.LastName = patient.User.LastName; model.Id = patient.Id; model.PhoneNumber = patient.User.PhoneNumber; model.FathersEmail = patient.User.FathersEmail; model.DateBirth = patient.User.DateBirth; model.CanEdit = patient.User.CanEdit; if (patient.Doctor == null) { model.Doctors = GetComboDoctors(); } else { model.Doctors = GetComboDoctors(); model.DoctorId = patient.Doctor.Id; } } return(View(model)); }
public async Task <IActionResult> ChangeUserPatient(EditPatientViewModel model) { if (ModelState.IsValid) { var patient = await _dataContext.Patients .Include(o => o.User) .FirstOrDefaultAsync(o => o.Id == model.Id); patient.User.Document = model.Document; patient.User.FirstName = model.FirstName; patient.User.LastName = model.LastName; patient.User.PhoneNumber = model.PhoneNumber; patient.User.FathersEmail = model.FathersEmail; patient.User.DateBirth = model.DateBirth; patient.Doctor = await _dataContext.Doctors.FindAsync(model.DoctorId); patient.User.CanEdit = model.CanEdit; var id = patient.Id; await _userHelper.UpdateUserAsync(patient.User); return(RedirectToAction("Details/" + id)); } return(View(model)); }
public async Task <IActionResult> EditPatient() { //if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName)) //{ // return this.Redirect("GetAllUsers"); //} EditPatientViewModel user = new EditPatientViewModel(); try { user = await this.usersService.GetPatient(this.User.Identity.Name); } catch (Exception e) { return(this.Redirect("GetAllUsers")); } var newModel = new EditPatientInputModel() { Address = user.Address, Age = user.Age, FirstName = user.FirstName, LastName = user.LastName, MiddleName = user.MiddleName, Email = user.Email }; return(View(newModel)); }
public ActionResult Edit(EditPatientViewModel editPatientViewModel) { try { Patient modifiedPatient = db.Patient.Include(x => x.Gender) .Include(x => x.CareGivers) .Include(x => x.BloodType) .Where(x => x.Id == editPatientViewModel.Id) .FirstOrDefault(); Mapper.Map <EditPatientViewModel, Patient>(editPatientViewModel, modifiedPatient); modifiedPatient.Gender = db.Genders.Where(x => x.Id == editPatientViewModel.SelectedGenderId).FirstOrDefault(); modifiedPatient.BloodType = db.BloodTypes.Where(x => x.Id == editPatientViewModel.SelectedBloodTypeId).FirstOrDefault(); db.Entry(modifiedPatient).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { EditPatientViewModel createPatientViewModel = new EditPatientViewModel { _genders = db.Genders.ToList(), _bloodTypes = db.BloodTypes.ToList() }; return(View(createPatientViewModel)); } }
public async Task <ActionResult> EditPatient(int id) { ApplicationUser user = await UserManager.FindByIdAsync(id); Patient patient = unitOfWork.Patients.FindById(id); if (user != null && patient != null) { EditPatientViewModel editPatientViewModel = new EditPatientViewModel() { Id = user.Id, Name = patient.Name, Patronymic = patient.Patronymic, Surname = patient.Surname, PatientHeight = patient.PatientHeight, PatientWeight = patient.PatientWeight, BloodTypeId = patient.BloodTypeId, GenderId = patient.GenderId, Email = user.Email, PatientBirthdate = patient.PatientBirthdate, ImageMimeType = patient.ImageMimeType, ImageData = patient.ImageData }; ViewBag.BloodTypes = unitOfWork.BloodTypes.Get().ToList(); ViewBag.Genders = unitOfWork.Genders.Get().ToList(); return(View(editPatientViewModel)); } else { return(RedirectToAction("Index")); } }
public void EditPOST_GivenValidModel_PatientBuilderShouldBeCalled() { var model = new EditPatientViewModel(); _personController.Edit(model); A.CallTo(() => _patientBuilder.BuildUpdatePatientCommand(model)).MustHaveHappened(Repeated.Exactly.Once); }
private void EditPatientsDoctors(EditPatientViewModel editPatientViewModel, Patient currentPatient) { if (editPatientViewModel.DoctorsIds != null) { currentPatient.Doctors.Clear(); currentPatient.Doctors.AddRange(db.Doctors.ToList().Where (doctor => editPatientViewModel.DoctorsIds.Contains(doctor.Id))); } }
public IActionResult DeletePatient([FromBody] EditPatientViewModel model) { if (ModelState.IsValid) { var patient = Mapper.Map <EditPatientViewModel, Patient>(model); _patientService.DeletePatient(patient); } return(new HttpStatusCodeResult(200)); }
public AddUpdatePatientCommand BuildUpdatePatientCommand(EditPatientViewModel viewModel) { if (viewModel == null) { throw new ArgumentNullException(); } return(Mapper.Map <EditPatientViewModel, AddUpdatePatientCommand>(viewModel)); }
private void ChangeImage(EditPatientViewModel editPatientViewModel, Patient currentPatient) { if (editPatientViewModel.ChangedImage != null) { ImageWorker imagePathGetter = new ImageWorker(); currentPatient.ImageUrl = imagePathGetter.GetImageStringPath(editPatientViewModel.ChangedImage); editPatientViewModel.ChangedImage.SaveAs(Path.Combine( Server.MapPath("~/AppFile/PatientPictures"), currentPatient.ImageUrl)); } }
public void EditPOST_GivenModelIsNotValid_ModelShouldBeReturned() { var model = new EditPatientViewModel(); _personController.ModelState.AddModelError("error", "error"); var result = _personController.Edit(model) as ViewResult; result.Model.Should().Be(model); }
public void EditGET_GivenPatient_EditPatientViewModelShouldBeReturned() { var viewModel = new EditPatientViewModel(); A.CallTo(() => _patientBuilder.BuildEditPatientViewModel(A <Patient> ._, A <Genders> ._)).Returns(viewModel); var result = _personController.Edit(A <Guid> ._) as ViewResult; result.Model.Should().BeOfType <EditPatientViewModel>(); result.Model.Should().NotBeNull(); }
public IActionResult EditPatient([FromBody] EditPatientViewModel model) { if (ModelState.IsValid) { var patient = Mapper.Map <EditPatientViewModel, Patient>(model); patient.LastModifiedDateUtc = System.DateTime.UtcNow; patient.LastModifiedBy = 1; _patientService.EditPatient(patient); } return(new HttpStatusCodeResult(200)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Patient patient = db.Patients.Find(id); EditPatientViewModel patientViewModel = EditPatientViewModel.ToViewModel(patient); patientViewModel.Doctors = db.Doctors.ToList(); return(View(patientViewModel)); }
public void EditPatientViewModelValidator_GivenLastNameIsNotProvided_ValidationShouldFail() { var model = new EditPatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = new DateOfBirthViewModel(), FirstName = "David", GenderId = 1 }; var result = ValidationResult(model); result.IsValid.Should().BeFalse(); }
public ActionResult EditPatient(EditPatientViewModel editPatient) { if (ModelState.IsValid) { var patient = _mapper.Map <EditPatientViewModel, Patient>(editPatient); var updated = _patientRepository.Update(patient); if (updated) { return(RedirectToAction("Index")); } } return(View(editPatient)); }
public void EditPatientViewModelValidator_GivenNhsNumberIsNotProvided_ValidationShouldPass() { var model = new EditPatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1 }; var result = ValidationResult(model); result.IsValid.Should().BeTrue(); }
public virtual ActionResult Edit(EditPatientViewModel model) { if (ModelState.IsValid) { var command = _patientViewModelBuilder.BuildUpdatePatientCommand(model); _commandDispatcher.Dispatch(command); _unitOfWork.SaveChanges(); return(RedirectToAction(MVC.Person.Index())); } return(View(model)); }
public void Save() { EditPatientViewModel patient = View.GetPatient(); try { using (var proxy = _patientService.CreateChannel()) { proxy.UpdatePatient(patient); } } catch (Exception ex) { throw; } }
public ActionResult Edit(EditPatientViewModel editPatientViewModel) { if (ModelState.IsValid) { Patient currentPatient = db.Patients.First(p => p.Id == editPatientViewModel.Id); editPatientViewModel.EditPatient(editPatientViewModel, currentPatient); EditPatientsDoctors(editPatientViewModel, currentPatient); ChangeImage(editPatientViewModel, currentPatient); db.Entry(currentPatient).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(editPatientViewModel)); }
public async Task <IActionResult> EditPatient(EditPatientInputModel viewModel) { //if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName)) //{ // return this.Redirect("GetAllUsers"); //} if (!this.ModelState.IsValid) { return(this.Redirect("Index")); } string fileName = null; string fullPath = null; if (viewModel.Image != null) { fileName = Guid.NewGuid().ToString() + "_" + viewModel.Image.FileName; fullPath = Path.Combine("/img/", fileName); viewModel.Image.CopyTo(new FileStream(hostingEnvironment.WebRootPath + fullPath, FileMode.Create)); } var newModel = new EditPatientViewModel() { Address = viewModel.Address, Age = viewModel.Age, FirstName = viewModel.FirstName, LastName = viewModel.LastName, MiddleName = viewModel.MiddleName, ImageUrl = fullPath == null? await this.usersService.GetUserProfilePicture(this.User.Identity.Name):fullPath, Email = viewModel.Email }; try { await this.usersService.EditPatient(newModel); } catch (Exception e) { return(this.Redirect("GetAllUsers")); } return(this.Redirect("Index")); }
// GET: Patients/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Patient patient = db.Patient.Include(x => x.Gender) .Include(x => x.CareGivers) .Include(x => x.BloodType) .Where(x => x.Id == id) .FirstOrDefault(); if (patient == null) { return(HttpNotFound()); } int foundSelectedBloodTypeId = 0; if (patient.BloodType != null) { foundSelectedBloodTypeId = patient.BloodType.Id; } int foundSelectedGenderId = 0; if (patient.Gender != null) { foundSelectedGenderId = patient.Gender.Id; } EditPatientViewModel editPatientViewModel = new EditPatientViewModel { SelectedBloodTypeId = foundSelectedBloodTypeId, SelectedGenderId = foundSelectedGenderId, _genders = db.Genders.ToList(), _bloodTypes = db.BloodTypes.ToList(), }; Mapper.Map <Patient, EditPatientViewModel>(patient, editPatientViewModel); return(View(editPatientViewModel)); }
public async Task <IActionResult> ChangeUserPatient() { var user = await _userHelper.GetUserByEmailAsync(User.Identity.Name); var patient = await this.GetPatientAsync(user.Id); var model = new EditPatientViewModel(); if (user != null) { model.Document = user.Document; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Id = patient.Id; model.PhoneNumber = user.PhoneNumber; model.FathersEmail = user.FathersEmail; model.DateBirth = user.DateBirth; model.Objective = user.Objective; if (patient.Doctor == null) { model.Doctors = GetComboDoctors(); } else { model.Doctors = GetComboDoctors(); model.DoctorId = patient.Doctor.Id; } } /*var model = new EditPatientViewModel * { * Document = patient.User.Document, * FirstName = patient.User.FirstName, * LastName = patient.User.LastName, * Id = patient.Id, * PhoneNumber = patient.User.PhoneNumber, * Doctors = GetComboDoctors(), * };*/ return(View(model)); }
public void EditPatientViewModelValidator_GivenNhsNumberIsProvided_ValidationShouldPass() { A.CallTo(() => _nhsValidator.Valid(A <decimal?> ._)).Returns(true); A.CallTo(() => _nhsValidator.Unique(A <decimal?> ._)).Returns(true); var model = new EditPatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 9434765870 }; var result = ValidationResult(model); result.IsValid.Should().BeTrue(); }
public void EditPatientViewModelValidator_GivenInvalidNhsNumberIsProvided_ValidationShouldFail() { const long nhsNumber = 4567899898; A.CallTo(() => _nhsValidator.Valid(nhsNumber)).Returns(false); var model = new EditPatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = nhsNumber }; var result = ValidationResult(model); result.IsValid.Should().BeFalse(); }