protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted)
        {
            ComorbidityDetails       = Notification.ComorbidityDetails;
            ImmunosuppressionDetails = Notification.ImmunosuppressionDetails;

            ImmunosuppressionStatus = ImmunosuppressionDetails.Status;
            HasBioTherapy           = ImmunosuppressionDetails.HasBioTherapy == true;
            HasTransplantation      = ImmunosuppressionDetails.HasTransplantation == true;
            HasOther         = ImmunosuppressionDetails.HasOther == true;
            OtherDescription = ImmunosuppressionDetails.OtherDescription;

            await SetNotificationProperties(isBeingSubmitted, ComorbidityDetails);
            await SetNotificationProperties(isBeingSubmitted, ImmunosuppressionDetails);

            if (ComorbidityDetails.ShouldValidateFull)
            {
                TryValidateModel(ComorbidityDetails, nameof(ComorbidityDetails));
            }

            if (ImmunosuppressionDetails.ShouldValidateFull)
            {
                TryValidateModel(ImmunosuppressionDetails, nameof(ImmunosuppressionDetails));
            }

            return(Page());
        }
Ejemplo n.º 2
0
        public async Task UpdateImmunosuppressionDetails_StripsOtherDescriptionWhenHasOtherIsFalse()
        {
            // Arrange
            var reference = new ImmunosuppressionDetails
            {
                Status           = Status.Yes,
                HasOther         = false,
                OtherDescription = "Test description"
            };
            var input = new ImmunosuppressionDetails
            {
                Status           = reference.Status,
                HasOther         = reference.HasOther,
                OtherDescription = reference.OtherDescription
            };
            var notification = new Notification();

            // Act
            await _notificationService.UpdateImmunosuppresionDetailsAsync(notification, input);

            // Assert
            Assert.Equal(reference.Status, input.Status);
            Assert.Equal(reference.HasOther, input.HasOther);
            Assert.NotEqual(reference.OtherDescription, input.OtherDescription);
            Assert.Null(input.OtherDescription);

            _mockContext.Verify(context => context.SetValues(notification.ImmunosuppressionDetails, input));
            VerifyUpdateDatabaseCalled();
        }
Ejemplo n.º 3
0
        public async Task UpdateImmunosuppressionDetails_LeavesValuesUnchangedWhenStatusIsYes()
        {
            // Arrange
            var reference = new ImmunosuppressionDetails
            {
                Status             = Status.Yes,
                HasBioTherapy      = true,
                HasTransplantation = true,
                HasOther           = true,
                OtherDescription   = "Test description"
            };
            var input = new ImmunosuppressionDetails
            {
                Status             = reference.Status,
                HasBioTherapy      = reference.HasBioTherapy,
                HasTransplantation = reference.HasTransplantation,
                HasOther           = reference.HasOther,
                OtherDescription   = reference.OtherDescription
            };
            var notification = new Notification();

            // Act
            await _notificationService.UpdateImmunosuppresionDetailsAsync(notification, input);

            // Assert
            Assert.Equal(reference.Status, input.Status);
            Assert.Equal(reference.HasBioTherapy, input.HasBioTherapy);
            Assert.Equal(reference.HasTransplantation, input.HasTransplantation);
            Assert.Equal(reference.HasOther, input.HasOther);
            Assert.Equal(reference.OtherDescription, input.OtherDescription);
            VerifyUpdateDatabaseCalled();
        }
        public IActionResult OnPostValidateImmunosuppression([FromBody] ImmunosuppressionValidationModel validationData)
        {
            var parsedStatus = string.IsNullOrEmpty(validationData.ImmunosuppressionStatus) ? null : (Status?)Enum.Parse(typeof(Status), validationData.ImmunosuppressionStatus);
            var model        = new ImmunosuppressionDetails
            {
                Status             = parsedStatus,
                HasBioTherapy      = validationData.HasBioTherapy,
                HasTransplantation = validationData.HasTransplantation,
                HasOther           = validationData.HasOther,
                OtherDescription   = string.IsNullOrEmpty(validationData.OtherDescription) ? null : validationData.OtherDescription
            };

            return(ValidationService.GetFullModelValidationResult(model));
        }
        public IActionResult OnGetValidateImmunosuppression(
            string immunosuppressionStatus,
            bool hasBioTherapy,
            bool hasTransplantation,
            bool hasOther,
            string otherDescription)
        {
            var parsedStatus = string.IsNullOrEmpty(immunosuppressionStatus) ? null : (Status?)Enum.Parse(typeof(Status), immunosuppressionStatus);
            var model        = new ImmunosuppressionDetails
            {
                Status             = parsedStatus,
                HasBioTherapy      = hasBioTherapy,
                HasTransplantation = hasTransplantation,
                HasOther           = hasOther,
                OtherDescription   = string.IsNullOrEmpty(otherDescription) ? null : otherDescription
            };

            return(ValidationService.GetFullModelValidationResult(model));
        }
Ejemplo n.º 6
0
        private static ImmunosuppressionDetails ExtractImmunosuppressionDetails(MigrationDbNotification notification)
        {
            var details = new ImmunosuppressionDetails();

            details.Status = Converter.GetStatusFromString(notification.ImmunosuppressionStatus);
            if (details.Status != Status.Yes)
            {
                return(details);
            }

            details.HasBioTherapy      = Converter.GetNullableBoolValue(notification.HasBioTherapy);
            details.HasTransplantation = Converter.GetNullableBoolValue(notification.HasTransplantation);
            details.HasOther           = Converter.GetNullableBoolValue(notification.HasOther);

            if (details.HasBioTherapy != true && details.HasTransplantation != true && details.HasOther != true)
            {
                details.HasOther         = true;
                details.OtherDescription = "No immunosuppression type was provided in the legacy record";
            }
            else if (details.HasOther == true)
            {
                if (!string.IsNullOrWhiteSpace(notification.OtherDescription))
                {
                    var otherDescription = RemoveCharactersNotIn(
                        ValidationRegexes.CharacterValidationWithNumbersForwardSlashExtended,
                        notification.OtherDescription);
                    details.OtherDescription = otherDescription;
                }
                else
                {
                    details.OtherDescription = "No description provided in the legacy system";
                }
            }

            // Ensure that if a description exists, HasOther is ticked
            if (details.HasOther != true && !string.IsNullOrWhiteSpace(details.OtherDescription))
            {
                details.HasOther = true;
            }

            return(details);
        }
        protected override async Task ValidateAndSave()
        {
            ComorbidityDetails.SetValidationContext(Notification);

            ImmunosuppressionDetails = new ImmunosuppressionDetails {
                Status             = ImmunosuppressionStatus,
                HasBioTherapy      = HasBioTherapy,
                HasTransplantation = HasTransplantation,
                HasOther           = HasOther,
                OtherDescription   = OtherDescription,
            };

            ImmunosuppressionDetails.SetValidationContext(Notification);

            if (TryValidateModel(ComorbidityDetails, nameof(ComorbidityDetails)) &&
                TryValidateModel(ImmunosuppressionDetails, nameof(ImmunosuppressionDetails)))
            {
                await Service.UpdateComorbidityAsync(Notification, ComorbidityDetails);

                await Service.UpdateImmunosuppresionDetailsAsync(Notification, ImmunosuppressionDetails);
            }
        }
Ejemplo n.º 8
0
        public async Task UpdateImmunosuppressionDetails_StripsAllButStatusWhenStatusIsNotYes(int status)
        {
            // Arrange
            var parsedStatus = (Status)status;
            var reference    = new ImmunosuppressionDetails
            {
                Status             = parsedStatus,
                HasBioTherapy      = true,
                HasTransplantation = true,
                HasOther           = true,
                OtherDescription   = "Test description"
            };
            var input = new ImmunosuppressionDetails
            {
                Status             = reference.Status,
                HasBioTherapy      = reference.HasBioTherapy,
                HasTransplantation = reference.HasTransplantation,
                HasOther           = reference.HasOther,
                OtherDescription   = reference.OtherDescription
            };
            var notification = new Notification();

            // Act
            await _notificationService.UpdateImmunosuppresionDetailsAsync(notification, input);

            // Assert
            Assert.Equal(reference.Status, input.Status);
            Assert.NotEqual(reference.HasBioTherapy, input.HasBioTherapy);
            Assert.Null(input.HasBioTherapy);
            Assert.NotEqual(reference.HasTransplantation, input.HasTransplantation);
            Assert.Null(input.HasTransplantation);
            Assert.NotEqual(reference.HasOther, input.HasOther);
            Assert.Null(input.HasOther);
            Assert.NotEqual(reference.OtherDescription, input.OtherDescription);
            Assert.Null(input.OtherDescription);

            _mockContext.Verify(context => context.SetValues(notification.ImmunosuppressionDetails, input));
            VerifyUpdateDatabaseCalled();
        }
Ejemplo n.º 9
0
        public async Task UpdateImmunosuppresionDetailsAsync(Notification notification, ImmunosuppressionDetails immunosuppressionDetails)
        {
            if (immunosuppressionDetails.Status != Status.Yes)
            {
                immunosuppressionDetails.HasBioTherapy      = null;
                immunosuppressionDetails.HasTransplantation = null;
                immunosuppressionDetails.HasOther           = null;
                immunosuppressionDetails.OtherDescription   = null;
            }

            if (immunosuppressionDetails.HasOther == false)
            {
                immunosuppressionDetails.OtherDescription = null;
            }

            _context.SetValues(notification.ImmunosuppressionDetails, immunosuppressionDetails);
            await _notificationRepository.SaveChangesAsync();
        }