Esempio n. 1
0
        public async Task <IActionResult> UpdatePecCode(int siteId, FromBodyText pecCode)
        {
            if (string.IsNullOrWhiteSpace(pecCode))
            {
                this.ModelState.AddModelError("Site.PEC", "PEC Code was not provided");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var site = await _siteService.GetSiteNoTrackingAsync(siteId);

            if (site == null)
            {
                return(NotFound(ApiResponse.Message($"Site not found with id {siteId}")));
            }

            var party = await _partyService.GetPartyForUserIdAsync(User.GetPrimeUserId());

            if (!User.CanEdit(party))
            {
                return(Forbid());
            }

            var updatedSite = await _siteService.UpdatePecCode(siteId, pecCode);

            return(Ok(ApiResponse.Result(updatedSite)));
        }
        public async Task <IActionResult> UpdatePecCode(int siteId, FromBodyText pecCode)
        {
            if (string.IsNullOrWhiteSpace(pecCode))
            {
                this.ModelState.AddModelError("Site.PEC", "PEC Code was not provided");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var site = await _siteService.GetSiteNoTrackingAsync(siteId);

            if (site == null)
            {
                return(NotFound(ApiResponse.Message($"Site not found with id {siteId}")));
            }

            if (!site.Provisioner.PermissionsRecord().EditableBy(User))
            {
                return(Forbid());
            }

            var updatedSite = await _siteService.UpdatePecCode(siteId, pecCode);

            return(Ok(ApiResponse.Result(updatedSite)));
        }
Esempio n. 3
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)
                       ));
        }
        public async Task <ActionResult <SiteRegistrationNote> > CreateSiteRegistrationNote(int siteId, FromBodyText note)
        {
            var site = await _siteService.GetSiteAsync(siteId);

            if (site == null)
            {
                return(NotFound(ApiResponse.Message($"Site not found with id {siteId}")));
            }
            if (string.IsNullOrWhiteSpace(note))
            {
                this.ModelState.AddModelError("note", "site registration notes can't be null or empty.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var admin = await _adminService.GetAdminAsync(User.GetPrimeUserId());

            var createdSiteRegistrationNote = await _siteService.CreateSiteRegistrationNoteAsync(siteId, note, admin.Id);

            return(Ok(ApiResponse.Result(createdSiteRegistrationNote)));
        }
Esempio n. 5
0
        public async Task <ActionResult <AdjudicatorNote> > CreateAdjudicatorNote(int enrolleeId, FromBodyText note, [FromQuery] bool link)
        {
            if (!await _enrolleeService.EnrolleeExistsAsync(enrolleeId))
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}")));
            }

            if (string.IsNullOrWhiteSpace(note))
            {
                this.ModelState.AddModelError("note", "Adjudicator notes can't be null or empty.");
                return(BadRequest(ApiResponse.BadRequest(this.ModelState)));
            }

            var admin = await _adminService.GetAdminForUserIdAsync(User.GetPrimeUserId());

            var createdAdjudicatorNote = await _enrolleeService.CreateEnrolleeAdjudicatorNoteAsync(enrolleeId, note, admin.Id);

            if (link)
            {
                // Link Adjudicator note to most recent status change on an enrollee if request
                var enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId);

                await _enrolleeService.AddAdjudicatorNoteToReferenceIdAsync(enrollee.CurrentStatus.Id, createdAdjudicatorNote.Id);
            }

            return(CreatedAtAction(
                       nameof(CreateAdjudicatorNote),
                       new { enrolleeId = enrolleeId },
                       ApiResponse.Result(createdAdjudicatorNote)
                       ));
        }
Esempio n. 6
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 <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)
                       ));
        }