Exemplo n.º 1
0
        public void AddPatientRequestToQueue(PatientOrganRequestViewModel model)
        {
            var isOrganInfoExist = _organInfoService.IfOrganInfoExists(model.OrganInfoId);

            if (!isOrganInfoExist)
            {
                throw new ArgumentException(nameof(model.OrganInfoId));
            }

            if (!Enum.IsDefined(typeof(PatientRequestPriority), model.QueryPriority))
            {
                model.QueryPriority = PatientRequestPriority.Normal;
            }

            var user            = _userManager.FindByEmailAsync(model.Email).Result;
            var patientUserInfo = user == null
                ? _userInfoService.RegisterPatient(model)
                : _userInfoService.GetUserInfoByUserId(user.Id);

            var patientRequest = new PatientRequest()
            {
                OrganInfoId   = model.OrganInfoId,
                PatientInfoId = patientUserInfo.UserInfoId,
                Priority      = model.QueryPriority,
                Message       = model.AdditionalInfo,
                Status        = PatientRequestStatuses.AwaitingForDonor
            };

            _patientRequestsRepository.Add(patientRequest);

            //TODO: send email to patient email with credentials
            //TODO: send email to clinic that query has been added
        }
        public IActionResult CreatePatientRequest(PatientOrganRequestViewModel model)
        {
            var result = Execute(() =>
            {
                bool isMedEmployee = _userManager.IsUserInMedEmployeeRole(User.Identity.Name);
                if (!isMedEmployee)
                {
                    throw new UnauthorizedAccessException("You have not appropriate rights to access this action");
                }

                _patientRequestService.AddPatientRequestToQueue(model);
            });

            return(Json(result));
        }
        public UserInfo RegisterPatient(PatientOrganRequestViewModel model)
        {
            var patientInfo = new UserInfo()
            {
                FirstName    = model.FirstName,
                SecondName   = model.SecondName,
                Country      = model.Country,
                City         = model.City,
                AddressLine1 = model.AddressLine1,
                AddressLine2 = model.AddressLine2,
                Email        = model.Email,
                PhoneNumber  = model.PhoneNumber,
                ZipCode      = model.ZipCode
            };

            AppUser user = new AppUser()
            {
                Email                = model.Email,
                UserName             = model.Email,
                Created              = DateTime.UtcNow,
                CreatedBy            = "CurrentUser",
                EmailConfirmed       = true,
                PhoneNumber          = model.PhoneNumber,
                PhoneNumberConfirmed = true,
                UserInfo             = patientInfo
            };

            var password = PasswordHasher.GetStaticPassword();
            var result   = _userManager.CreateAsync(user, password).Result;

            if (result.Succeeded)
            {
                result = _userManager.AddToRoleAsync(user, RolesConstants.Patient).Result;
            }
            else
            {
                throw new InvalidOperationException(UserCreationFailedErrorMessage);
            }

            if (!result.Succeeded)
            {
                _userManager.DeleteAsync(user).Wait();
                throw new InvalidOperationException(UserCreationFailedErrorMessage);
            }

            return(patientInfo);
        }