public IActionResult Create(CreatePatientViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Image != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); } Patient patient = new Patient { Name = model.Name, Age = model.Age, Alchol = model.Alchol, Gender = (gender)model.Gender, History = model.History, Mobile = model.Mobile, TobaccoUsage = model.TobaccoUsage, Image = uniqueFileName }; patientservice.insert(patient); return(RedirectToAction(nameof(Index))); } return(View()); }
//if (ModelState.IsValid) //{ // patientservice.insert(patient); // return RedirectToAction(nameof(Index)); //} //return View(patient); // GET: Patients/Edit/5 public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var patient = patientservice.GetOne(id); CreatePatientViewModel model = new CreatePatientViewModel { ID = patient.ID, Name = patient.Name, Age = patient.Age, Alchol = patient.Alchol, History = patient.History, Mobile = patient.Mobile, TobaccoUsage = patient.TobaccoUsage, }; ViewBag.gender = patient.Gender; ViewBag.image = patient.Image; if (patient == null) { return(NotFound()); } ViewBag.records = recordeService.GetPatientRecords(patient.ID); ViewBag.appointments = appointmentsServices.GetPatientAppointments(patient.ID); return(View(model)); }
private ValidationResult ValidationResult(CreatePatientViewModel model) { var validator = new CreatePatientViewModelValidator(_futureDateValidator, _clinicalIdValidator, _nhsValidator, _clinicalSystemIdDescriptionProvider); var result = validator.Validate(model); return(result); }
public ActionResult DeleteConfirmed(int id) { CreatePatientViewModel createPatientViewModel = db.CreatePatientViewModels.Find(id); db.CreatePatientViewModels.Remove(createPatientViewModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult CreatePatient([FromBody] CreatePatientViewModel createPatientViewModel) { var patientDTO = PatientMapper.CreatePatientVMToDTO(createPatientViewModel); _service.Create(patientDTO); return(Ok(ModelState)); }
public void CreatePOST_GivenValidModel_PatientCommandShouldBeBuilt() { var model = new CreatePatientViewModel(); _personController.Create(model); A.CallTo(() => _patientBuilder.BuildAddPatientCommand(model)).MustHaveHappened(Repeated.Exactly.Once); }
public ActionResult Create() { var patient = new CreatePatientViewModel { Doctors = GetDoctorListForPatientsViewModel(_doctorService.GetDoctors()) }; return(View(patient)); }
// GET: Patients/Create public ActionResult Create() { CreatePatientViewModel createPatientViewModel = new CreatePatientViewModel { _genders = db.Genders.ToList(), _bloodTypes = db.BloodTypes.ToList() }; return(View(createPatientViewModel)); }
public void CreatePOST_GivenInvalidModel_ShouldReturnDefaultModel() { var viewModel = new CreatePatientViewModel(); _personController.ModelState.AddModelError("invalid", "Last Name is required"); var result = _personController.Create(viewModel) as ViewResult; result.Model.Should().Be(viewModel); }
public ActionResult CreatePatient(int reservationId, string email) { var model = new CreatePatientViewModel { ReservationId = reservationId, Email = email }; return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,Name,Gender,BloodGroup,Contact,Password")] CreatePatientViewModel createPatientViewModel) { if (ModelState.IsValid) { db.Entry(createPatientViewModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(createPatientViewModel)); }
public static PatientDTO CreatePatientVMToDTO(CreatePatientViewModel createPatientViewModel) { return(new PatientDTO { FirstName = createPatientViewModel.FirstName, LastName = createPatientViewModel.LastName, DateOfBirth = createPatientViewModel.DateOfBirth, Email = createPatientViewModel.Email, PhoneNumber = createPatientViewModel.PhoneNumber, }); }
public ActionResult Create([Bind(Include = "Id,Name,Gender,BloodGroup,Contact,Password")] CreatePatientViewModel createPatientViewModel) { if (ModelState.IsValid) { PatientBusinessLayer createPatient = new PatientBusinessLayer(); createPatient.CreatePatient(createPatientViewModel); return(RedirectToAction("Index")); } return(View(createPatientViewModel)); }
public PatientDto MapCreatePatientViewModelToPatientDto(CreatePatientViewModel createPatientViewModel) { if (createPatientViewModel == null) { return(null); } PatientDto patientDto = new PatientDto(); patientDto.FirstName = createPatientViewModel.FirstName; patientDto.LastName = createPatientViewModel.LastName; return(patientDto); }
public void CreatePatientViewModelValidator_GivenLastNameIsNotProvided_ValidationShouldFail() { var model = new CreatePatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", GenderId = 1 }; var result = ValidationResult(model); result.IsValid.Should().BeFalse(); }
// GET: CreatePatient/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CreatePatientViewModel createPatientViewModel = db.CreatePatientViewModels.Find(id); if (createPatientViewModel == null) { return(HttpNotFound()); } return(View(createPatientViewModel)); }
public virtual ActionResult Create(CreatePatientViewModel model) { if (ModelState.IsValid) { var command = _patientViewModelBuilder.BuildAddPatientCommand(model); _commandDispatcher.Dispatch(command); _unitOfWork.SaveChanges(); return(RedirectToAction(MVC.Assessment.Create(command.PatientId))); } return(View(model)); }
public CreatePatientViewModel BuildPatientViewModel(Genders gender) { if (gender == null) { throw new ArgumentNullException("gender"); } var model = new CreatePatientViewModel { Genders = GenderItems(gender), DateOfBirthViewModel = _dateOfBirthBuilder.BuildDateOfBirthViewModel(null) }; return(model); }
public ActionResult CreatePatient(CreatePatientViewModel model) { try { string returnUrl = Url.Action("Patient", "Patient", new { area = "PatientManagement" }); PatientViewModel response = _IPatientHandler.CreatePatient(model); PatientId = response.PatientId; return(Json(new { ok = true, url = returnUrl })); } catch (ModelException ex) { return(Json(new { errors = ex.ModelErrors })); } }
public ActionResult CreatePatient(CreatePatientViewModel model) { try { string returnUrl = Url.Action("Patient", "Patient", new { area = "PatientManagement" }); PatientViewModel response = _IPatientHandler.CreatePatient(model); PatientId = response.PatientId; return(JavaScript("window.location='" + returnUrl + "'")); } catch (ModelException ex) { return(Json(new { errors = ex.ModelErrors })); } }
public void CreatePatientViewModelValidator_GivenNhsNumberIsNotProvided_ValidationShouldFail() { var model = new CreatePatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 9434765870 }; var result = ValidationResult(model); result.IsValid.Should().BeTrue(); }
public PatientViewModel CreatePatient(CreatePatientViewModel createPatientViewModel) { PatientDetailResponse response = _PhekoServiceClient.SavePatient(_PatientViewModelMapper.MapCreatePatientViewModelToPatientDto(createPatientViewModel)); if (response.HasErrors) { ModelException modelException = new ModelException(); response.FieldErrors.ToList <FieldError>().ForEach(item => modelException.ModelErrors.Add(new ModelError() { FieldName = item.FieldName, Message = item.ErrorMessage })); throw modelException; } return(_PatientViewModelMapper.MapToPatientViewModel(response.Patient)); }
public void CreatePatientViewModelValidator_GivenNonDuplicateClinicalId_ValidationShouldPass() { const string clinicalSystemId = "PatientId"; A.CallTo(() => _clinicalIdValidator.Unique(clinicalSystemId)).Returns(true); var model = new CreatePatientViewModel() { ClinicalSystemId = clinicalSystemId, DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 4567899881 }; var result = ValidationResult(model); result.IsValid.Should().BeTrue(); }
public void CreatePatientViewModelValidator_GivenInvalidNHSNumberIsProvided_ValidationShouldFail() { const long nhsNumber = 4567899898; A.CallTo(() => _nhsValidator.Valid(nhsNumber)).Returns(false); var model = new CreatePatientViewModel() { ClinicalSystemId = "PatientId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = nhsNumber }; var result = ValidationResult(model); result.IsValid.Should().BeFalse(); }
public async Task <ActionResult> Create(CreatePatientViewModel patientViewModel) { if (!ModelState.IsValid) { patientViewModel.Doctors = GetDoctorListForPatientsViewModel(_doctorService.GetDoctors()); return(View(patientViewModel)); } var patient = _mapper.Map <CreatePatientViewModel, Patient>(patientViewModel); if (!_patientService.CheckUniqueness(patient)) { ModelState.AddModelError("", "User with same UserName or Email exist!"); patientViewModel.Doctors = GetDoctorListForPatientsViewModel(_doctorService.GetDoctors()); return(View(patientViewModel)); } await _patientService.Create(patient); _loggerService.Info($"{User.Identity.Name} added {patient.FirstName} {patient.LastName}"); return(RedirectToAction("Index")); }
public ActionResult Create(CreatePatientViewModel patientViewModel) { try { Patient newPatient = new Patient(); Mapper.Map <CreatePatientViewModel, Patient>(patientViewModel, newPatient); newPatient.Gender = db.Genders.Where(x => x.Id == patientViewModel.SelectedGenderId).FirstOrDefault(); newPatient.BloodType = db.BloodTypes.Where(x => x.Id == patientViewModel.SelectedBloodTypeId).FirstOrDefault(); db.Patient.Add(newPatient); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { CreatePatientViewModel createPatientViewModel = new CreatePatientViewModel { _genders = db.Genders.ToList(), _bloodTypes = db.BloodTypes.ToList() }; return(View(createPatientViewModel)); } }
public void Should_successfully_create_a_patient() { IBus bus = ObjectFactory.GetInstance <IBus>(); var viewModel = new CreatePatientViewModel(bus); viewModel.Command.Name = "Jeff Carley"; viewModel.Command.Status = "Active"; viewModel.Command.Street = "123 Main St"; viewModel.Command.City = "Madison"; viewModel.Command.State = "WI"; viewModel.Command.Zip = "53598"; viewModel.CreateCustomer.Execute(null); IReportingRepository <PatientDto> repository = ObjectFactory.GetInstance <IReportingRepository <PatientDto> >(); var patient = repository.GetAll(x => x.Name == "Jeff Carley").FirstOrDefault(); patient.ShouldNotBeNull(); patient.Name.ShouldEqual("Jeff Carley"); }
public void CreatePatientViewModelValidator_GivenDateIsInTheFuture_ValidationShouldFail() { A.CallTo(() => _futureDateValidator.Valid(A <DateTime?> ._)).Returns(false); var model = new CreatePatientViewModel() { ClinicalSystemId = "PatientId", FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 4567899881, DateOfBirthViewModel = new DateOfBirthViewModel() { Year = 2050, Month = 1, Day = 1 } }; var result = ValidationResult(model); result.IsValid.Should().BeFalse(); }
public ActionResult Create(CreatePatientViewModel model) { if (ModelState.IsValid) { string urlImage = ""; var files = HttpContext.Request.Form.Files; foreach (var image in files) { if (image != null && image.Length > 0) { var file = image; var uploadFile = Path.Combine(_hostingEnviroment.WebRootPath, "images"); if (file.Length > 0) { var fileName = Guid.NewGuid().ToString().Replace("_", "") + file.FileName; using (var fileStream = new FileStream(Path.Combine(uploadFile, fileName), FileMode.Create)) { file.CopyTo(fileStream); urlImage = fileName; } } } } var data = new Patient() { PatientName = model.PatientName, Age = model.Age, DoctorId = model.DoctorId, UrlImage = urlImage }; _productRepository.AddPatient(data); return(RedirectToAction("Index")); } CategoryDDL(); return(View()); }
public void CreatePatientViewModelValidator_GivenDuplicateClinicalSystemId_ErrorMessageShouldContainClinicalSystemIdDescription() { const string clinicalsystemid = "clinicalSystemId"; A.CallTo(() => _clinicalSystemIdDescriptionProvider.GetDescription()).Returns(clinicalsystemid); A.CallTo(() => _clinicalIdValidator.Unique(A <string> ._)).Returns(false); var model = new CreatePatientViewModel() { ClinicalSystemId = "clinicalSystemId", DateOfBirthViewModel = DateOfBirthViewModel(), FirstName = "David", LastName = "Miller", GenderId = 1, NhsNumber = 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)); }