Example #1
0
        public ActionResult EditPatient(EditPatientViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            Patient patient = _patientService.GetPatient(UserManager.FindByName(model.Username).PatientId);
            Physician physician = _physicianService.GetPhysician(UserManager.FindByName(User.Identity.Name).PhysicianId);

            if (!PatientBelongsToPhysician(patient, physician))
            {
                ModelState.AddModelError("", "ERROR: You do not have permission to update this patient.");
                return View(model);
            }

            patient.Birthdate = model.Birthdate;
            patient.Ethnicity = (int)Enum.Parse(typeof(PatientEthnicity), model.Ethnicity);
            patient.Gender = (int)Enum.Parse(typeof(PatientGender), model.Gender);
            patient.Height = model.Height;
            patient.Location = (int)Enum.Parse(typeof(Location), model.Location);
            patient.Race = (int)Enum.Parse(typeof(PatientRace), model.Race);
            patient.Weight = model.Weight;
            _patientService.SaveChanges(); // Write changes to DB

            return Redirect("/Account/LoginRedirect");
        }
Example #2
0
        /// <summary>
        /// This function allows the physician to edit a patient's information.
        /// * This function will also allow a physician to change a patient's password.
        /// </summary>
        /// <returns></returns>
        public ActionResult EditPatient(string username)
        {
            EditPatientViewModel model = new EditPatientViewModel();
            if (username == null)
            {
                // Username was not provided.
                model.Username = "******";
                ModelState.AddModelError("", "ERROR: No username provided.");
                return View(model);
            }

            model.Username = username;

            ApplicationUser physicianUser = UserManager.FindByName(User.Identity.Name);
            ApplicationUser patientUser = UserManager.FindByName(username);
            if (patientUser == null)
            {
                // Patient was not in database
                ModelState.AddModelError("", "ERROR: Patient not found in database.");
                return View(model);
            }

            Patient patient = _patientService.GetPatient(patientUser.PatientId);
            Physician physician = _physicianService.GetPhysician(physicianUser.PhysicianId);

            if (!PatientBelongsToPhysician(patient, physician))
            {
                // Patient does not belong to the current physician
                ModelState.AddModelError("", "ERROR: This patient does not belong to you.");
                return View(model);
            }

            // Fill in model with patient information
            model.Birthdate = patient.Birthdate;
            model.Ethnicity = patient.Ethnicity.ToString();
            model.Gender = patient.Gender.ToString();
            model.Height = patient.Height;
            model.Location = patient.Location.ToString();
            model.Race = patient.Race.ToString();
            model.Weight = patient.Weight;

            return View(model);
        }