Ejemplo n.º 1
0
 /// <summary>
 /// Delete a patient from the database.
 /// </summary>
 /// <param name="patient">Patient to delete from the database</param>
 public void DeletePatient(Patient patient)
 {
     if (patient != null)
     {
         _repository.Delete(patient);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Get the patient data records for the given patient or all records for all patients.
 /// </summary>
 /// <param name="patient">Patient object used to retrieve the patient's data records</param>
 /// <param name="skip">Skip a number of records in the data collection</param>
 /// <param name="take">Number of records to return.</param>
 /// <returns></returns>
 public IEnumerable<PatientData> GetPatientData(Patient patient, int skip = 0, int take = 0)
 {
     if (patient == null)
         return _repository.GetAll();
     else
         return _repository.GetMany(r => r.Patient.Id == patient.Id, r => r.Id, skip, take);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add a new patient to the database
 /// </summary>
 /// <param name="patient">Patient object to add to the database</param>
 public void CreatePatient(Patient patient)
 {
     if(patient != null) {
         _repository.Add(patient);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Checks if the patient belongs to the physician
 /// </summary>
 /// <param name="patient">Patient input</param>
 /// <param name="physician">Physician input</param>
 /// <returns>True if the patient's physician is the physician user</returns>
 private bool PatientBelongsToPhysician(Patient patient, Physician physician)
 {
     if (patient.Physician != physician)
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
        public ActionResult CreatePatient(CreatePatientViewModel model)
        {
            ApplicationUser user = UserManager.FindById(User.Identity.GetUserId());
            Physician physician = _physicianService.GetPhysician(user.PhysicianId);

            // Conversions from the model
            int race = (int)Enum.Parse(typeof(PatientRace), model.Race);//convert.GenderRaceStringToInt(model.Race);
            int gender = (int)Enum.Parse(typeof(PatientGender), model.Gender);//convert.PatientGenderStringToInt(model.Gender);
            int ethnicity = (int)Enum.Parse(typeof(PatientEthnicity), model.Ethnicity);// convert.PatientEthnicityStringToInt(model.Ethnicity);

            // Check if the user is already in the database.
            if (UserIsInDatabase(model.Username))
            {
                // User is already in the database
                // Display an error and request the physician to enter in a different username.
                ModelState.Clear();
                ModelState.AddModelError("UsernameExistsError", "Username already exists.");
            }
            else
            {
                // User is not in the database.
                // Proceed to add the user to the database.
                Patient patient = new Patient();

                patient.Birthdate = DateTime.Parse(model.Birthdate); //model.Birthdate; // Need to fix this, temporarily putting in 0.
                patient.Height = (int)model.Height;
                patient.Weight = (int)model.Weight;
                patient.Location = (int)Enum.Parse(typeof(Location), model.Location);//model.Location; // Need to fix this. temporarily putting in 12.
                patient.Ethnicity = ethnicity;
                patient.Gender = gender;
                patient.Race = race;
                patient.Physician = physician;

                var newUser = new ApplicationUser { UserName = model.Username, Status = (int)Account_Status.Active };
                if ((newUser != null) && (model.Password != null))
                {
                    //Create a new context to change the user creation validation rules for the patient only.
                    using (ApplicationDbContext context = new ApplicationDbContext()) {
                        var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context));
                        // This user validator is being created only to remove email as a required field for creating a user.
                        // The email field in the AspNetUsers table is nullable and our requirments state that a patient does not
                        // have an email address so in order to satisfy that requiremnt we need to remove the required email
                        // parameter on user creation validation.
                        manager.UserValidator = new UserValidator<ApplicationUser>(manager) {
                            AllowOnlyAlphanumericUserNames = false,
                            RequireUniqueEmail = false
                        };
                        var result = manager.Create(newUser, model.Password);

                        if (result.Succeeded) {
                            // User added to database successfully.
                            _patientService.CreatePatient(patient);
                            _patientService.SaveChanges();
                            newUser.PatientId = patient.Id;

                            result = manager.Update(newUser);

                            //Role must match what is found in the database AspNetRoles table.
                            result = manager.AddToRole(newUser.Id, "Patient");

                            physician.Patients.Add(patient);
                            _physicianService.UpdatePhysician(physician);
                            _physicianService.SaveChanges();
                        }
                        else {
                            // User failed to add.
                            ModelState.Clear();
                            foreach (string error in result.Errors) {
                                ModelState.AddModelError("ResultError", error);
                            }
                            return View(model);
                        }
                    }
                }
                else
                {
                    // Username or password was null if we got here.
                }

            }
            return View(model);
        }
Ejemplo n.º 6
0
        //
        // GET: /Manage/Index
        public async Task<ActionResult> Index(ManageMessageId? message)
        {
            ApplicationUser user = UserManager.FindById(User.Identity.GetUserId());
           
            string accountRole = "";
            //user = UserManager.FindById(userId);
            UserRole userRole = UserRole.Patient;
            
            if (User.IsInRole(UserRole.Patient.ToString())) {
                userRole = UserRole.Patient;
                accountRole = UserRole.Patient.ToString();
            }
            else if (User.IsInRole(UserRole.Physician.ToString())) {
                userRole = UserRole.Physician;
                accountRole = UserRole.Physician.ToString();
            }
            else if (User.IsInRole(UserRole.Experiment_Administrator.ToString().Replace("_", " "))) {
                userRole = UserRole.Experiment_Administrator;
                accountRole = UserRole.Experiment_Administrator.ToString().Replace("_", " ");
            } else
            {
                userRole = UserRole.System_Administrator;
                accountRole = UserRole.System_Administrator.ToString().Replace("_", " ");                
            }

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            IndexViewModel model = new IndexViewModel {
                HasPassword = (user.PasswordHash != null) ? true : false,
                PhoneNumber = user.PhoneNumber,
                TwoFactor = user.TwoFactorEnabled,
                //Logins = user.Logins,
                //BrowserRemembered = user.brows
                        AccountRole = accountRole
                    };

            switch (userRole)
            {
                case UserRole.Patient:
                    // Patient
                    Patient patient = new Patient();
                    patient = _patientService.GetPatient(user.PatientId);

                    model.Username = user.UserName;
                    model.Weight = patient.Weight;
                    model.Height = patient.Height;
                    model.Race = patient.Race.ToString();
                    model.Ethnicity = patient.Ethnicity.ToString();
                    model.Location = patient.Location.ToString();
                    model.Birthdate = patient.Birthdate;     
                    model.Gender = patient.Gender.ToString();

                    break;


                case UserRole.Physician:
                    // Physician
                    Physician physician = new Physician();
                    physician = _physicianService.GetPhysician(user.PhysicianId);

                    model.Email = physician.Email;
                    model.Username = user.UserName;
                    model.Address = physician.Address;
                    model.PhoneNumber = physician.PhoneNumber;
                    model.FirstName = physician.FirstName;
                    model.LastName = physician.LastName;

                    break;


                case UserRole.Experiment_Administrator:
                    // Experiment Administrator
                    ExperimentAdministrator experimentAdministrator = new ExperimentAdministrator();
                    experimentAdministrator = _experimentAdminService.GetExperimentAdministrator(user.ExperimentAdministratorId);

                    model.Email = experimentAdministrator.Email;
                    model.Username = user.UserName;
                    model.Address = experimentAdministrator.Address;
                    model.PhoneNumber = experimentAdministrator.PhoneNumber;
                    model.FirstName = experimentAdministrator.FirstName;
                    model.LastName = experimentAdministrator.LastName;

                    break;


                case UserRole.System_Administrator:
                    // System Admin
                    model.Username = user.UserName;
                    model.Email = user.Email;
                    break;


                default:
                    // Display error
                    break;
            }
            return View(model);
        }
Ejemplo n.º 7
0
        public ActionResult ConfirmUpdateUser (UpdateUserViewModel model)
        {
            var user = new ApplicationUser();
            user = UserManager.FindById(User.Identity.GetUserId());
            
            if (User.IsInRole("Patient"))
            {
                Patient patient = new Patient();
                patient = _patientService.GetPatient(user.PatientId);
                patient.Birthdate = model.Birthdate;
                patient.Height = model.Height;
                patient.Weight = model.Weight;
                patient.Ethnicity = (int)Enum.Parse(typeof(PatientEthnicity), model.Ethnicity);
                patient.Gender = (int)Enum.Parse(typeof(PatientGender), model.Gender);
                patient.Location = (int)Enum.Parse(typeof(Location), model.Location);
                patient.Race = (int)Enum.Parse(typeof(PatientRace), model.Race);
                _patientService.SaveChanges();
            }
            else if (User.IsInRole("Physician"))
            {
                Physician physician = new Physician();
                physician = _physicianService.GetPhysician(user.PhysicianId);
                physician.Email = model.Email;
                user.Email = model.Email;
                physician.Address = model.Address;
                physician.FirstName = model.FirstName;
                physician.LastName = model.LastName;
                physician.PhoneNumber = model.PhoneNumber;
                _physicianService.SaveChanges();
            }
            else if (User.IsInRole("Experiment Administrator"))
            {
                ExperimentAdministrator experimentAdministrator = new ExperimentAdministrator();
                experimentAdministrator = _experimentAdminService.GetExperimentAdministrator(user.ExperimentAdministratorId);
                experimentAdministrator.Email = model.Email;
                user.Email = model.Email;
                experimentAdministrator.Address = model.Address;
                experimentAdministrator.FirstName = model.FirstName;
                experimentAdministrator.LastName = model.LastName;
                experimentAdministrator.PhoneNumber = model.PhoneNumber;
                _experimentAdminService.SaveChanges();
            }
            else if (User.IsInRole("System Administrator"))
            {
                // Not yet implemented.
                user.Email = model.Email;
            }
            else
            {
                // Error path.
                ModelState.AddModelError("", "ERROR: User role not specified.");
                return View();
            }

            return (Redirect ("/Account/LoginRedirect"));
        }