Beispiel #1
0
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(int careSettingCode, FromBodyText providedEmails)
        {
            if (string.IsNullOrWhiteSpace(providedEmails))
            {
                this.ModelState.AddModelError("Email(s)", "No emails were provided.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            string[] emails = ((string)providedEmails).Split(",");

            // Emails are either "Other" provisioners, or office manager(s)
            if (emails.Any() && !EmailService.AreValidEmails(emails))
            {
                this.ModelState.AddModelError("Email(s)", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee.Id);

            await _emailService.SendProvisionerLinkAsync(emails, createdToken, careSettingCode);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, "Provisioner link sent to email(s): " + string.Join(",", emails));

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }
        public async Task <ActionResult> GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            if (User.HasAdminView())
            {
                return(Ok(ApiResponse.Result(await _enrolleeService.GetEnrolleesAsync(searchOptions))));
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                return(Ok(ApiResponse.Result(enrollee == null ? Enumerable.Empty <Enrollee>() : new[] { enrollee })));
            }
        }
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(int careSettingCode, FromBodyText providedEmails)
        {
            var emails = Email.ParseCommaSeparatedEmails(providedEmails);

            if (!emails.Any())
            {
                ModelState.AddModelError("Emails", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee.Id);

            await _emailService.SendProvisionerLinkAsync(emails, createdToken, careSettingCode);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, $"Provisioner link sent to email(s): {providedEmails}");

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }
        public async Task <ActionResult <IEnumerable <Enrollee> > > GetEnrollees(
            [FromQuery] EnrolleeSearchOptions searchOptions)
        {
            IEnumerable <Enrollee> enrollees = null;

            // User must have the ADMIN role to see all enrollees
            if (User.IsInRole(PrimeConstants.PRIME_ADMIN_ROLE))
            {
                enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                enrollees = new List <Enrollee>();

                if (enrollee != null)
                {
                    enrollees = enrollees.Append(enrollee);
                }
            }

            return(Ok(new ApiOkResponse <IEnumerable <Enrollee> >(enrollees)));
        }
Beispiel #5
0
        public async Task <ActionResult <IEnumerable <Enrollee> > > GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            IEnumerable <Enrollee> enrollees = null;

            // User must have the RO_ADMIN or ADMIN role to see all enrollees
            if (User.IsAdmin() || User.HasAdminView())
            {
                enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                enrollees = (enrollee != null) ? new[] { enrollee } : new Enrollee[0];
            }

            return(Ok(ApiResponse.Result(enrollees)));
        }
Beispiel #6
0
        public async Task <ActionResult> GetEnrollees([FromQuery] EnrolleeSearchOptions searchOptions)
        {
            if (User.HasAdminView())
            {
                var notifiedIds = await _enrolleeService.GetNotifiedEnrolleeIdsForAdminAsync(User);

                var enrollees = await _enrolleeService.GetEnrolleesAsync(searchOptions);

                var result = enrollees.Select(e => e.SetNotification(notifiedIds.Contains(e.Id)));
                return(Ok(ApiResponse.Result(result)));
            }
            else
            {
                var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

                return(Ok(ApiResponse.Result(enrollee == null ? Enumerable.Empty <Enrollee>() : new[] { enrollee })));
            }
        }
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > CreateEnrolmentCertificateAccessToken()
        {
            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(new ApiBadRequestResponse(this.ModelState)));
            }
            if (enrollee.CurrentStatus?.Status.Code != Status.ACCEPTED_TOS_CODE)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(new ApiBadRequestResponse(this.ModelState)));
            }

            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee);

            return(CreatedAtAction(nameof(GetEnrolmentCertificate), new { accessTokenId = createdToken.Id }, new ApiCreatedResponse <EnrolmentCertificateAccessToken>(createdToken)));
        }
Beispiel #8
0
        public async Task <ActionResult <EnrolmentCertificateAccessToken> > SendProvisionerLink(string provisionerName, FromBodyText providedEmails)
        {
            // TODO temporary removed and may be removed permanently
            // var provisionerNames = _certificateService.GetPharmaNetProvisionerNames();
            // if (!provisionerNames.Contains(provisionerName) && provisionerName != "Other")
            if (provisionerName != "Administrator" || string.IsNullOrWhiteSpace(providedEmails))
            {
                this.ModelState.AddModelError("Provisioner", "The provisioner provided is not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            string[] emails = string.IsNullOrWhiteSpace(providedEmails)
                ? new string[0]
                : ((string)providedEmails).Split(",");

            // Emails are either "Other" provisioners, or office manager(s)
            if (emails.Any() && !EmailService.AreValidEmails(emails))
            {
                this.ModelState.AddModelError("Email(s)", "The email(s) provided are not valid.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (provisionerName == "Other" && emails.Count() > 1)
            {
                this.ModelState.AddModelError("Email", "Other provisioners can only provide a single email address.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var enrollee = await _enrolleeService.GetEnrolleeForUserIdAsync(User.GetPrimeUserId());

            if (enrollee == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "No enrollee exists for this User Id.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (enrollee.ExpiryDate == null)
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in a finished state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            if (!enrollee.CurrentStatus.IsType(StatusType.Editable))
            {
                this.ModelState.AddModelError("Enrollee.UserId", "The enrollee for this User Id is not in an editable state.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }
            var createdToken = await _certificateService.CreateCertificateAccessTokenAsync(enrollee);

            // Only a few provisioners want emails sent directly, otherwise sent only to managers
            if (provisionerName == "iClinic" || provisionerName == "MediNet" || provisionerName == "Other")
            {
                var provisionerEmail = (provisionerName != "Other")
                    ? await _emailService.GetPharmaNetProvisionerEmailAsync(provisionerName)
                    : emails[0];

                emails = new[] { provisionerEmail };
            }
            else
            {
                provisionerName = null;
            }

            // TODO temporary removed and may be removed permanently
            // await _emailService.SendProvisionerLinkAsync(emails, createdToken, provisionerName);
            await _emailService.SendProvisionerLinkAsync(emails, createdToken);

            await _businessEventService.CreateEmailEventAsync(enrollee.Id, "Provisioner link sent to email(s): " + string.Join(",", emails));

            return(CreatedAtAction(
                       nameof(GetEnrolmentCertificate),
                       new { accessTokenId = createdToken.Id },
                       ApiResponse.Result(createdToken)
                       ));
        }