public void IsEmpty_ReturnsCorrectValue(FormattedDate formattedDate, bool expectedResult)
        {
            // Act
            var result = formattedDate.IsEmpty();

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void IfDateUnparsable_CanConvertReturnsFalse(FormattedDate formattedDate)
        {
            // Act
            var canConvert = formattedDate.TryConvertToDateTime(out _);

            // Assert
            Assert.False(canConvert);
        }
        private void UpdateFlags()
        {
            if (ClinicalDetails.IsSymptomatic == false)
            {
                ClinicalDetails.SymptomStartDate = null;
                FormattedSymptomDate             = ClinicalDetails.SymptomStartDate.ConvertToFormattedDate();
                ModelState.Remove("ClinicalDetails.SymptomStartDate");
            }

            if (ClinicalDetails.StartedTreatment == false)
            {
                ClinicalDetails.TreatmentStartDate = null;
                FormattedTreatmentDate             = ClinicalDetails.TreatmentStartDate.ConvertToFormattedDate();
                ModelState.Remove("ClinicalDetails.TreatmentStartDate");
            }

            if (ClinicalDetails.BCGVaccinationState != Status.Yes)
            {
                ClinicalDetails.BCGVaccinationYear = null;
                ModelState.Remove("ClinicalDetails.BCGVaccinationYear");
            }

            if (ClinicalDetails.TreatmentRegimen != TreatmentRegimen.Other)
            {
                ClinicalDetails.TreatmentRegimenOtherDescription = null;
                ModelState.Remove("ClinicalDetails.TreatmentRegimenOtherDescription");
            }

            if (!NotificationSiteMap.ContainsKey(SiteId.OTHER) || !NotificationSiteMap[SiteId.OTHER])
            {
                OtherSite = null;
                ModelState.Remove("OtherSite.SiteDescription");
            }

            if (ClinicalDetails.HomeVisitCarriedOut != Status.Yes)
            {
                ClinicalDetails.FirstHomeVisitDate = null;
                FormattedHomeVisitDate             = ClinicalDetails.FirstHomeVisitDate.ConvertToFormattedDate();
                ModelState.Remove("ClinicalDetails.FirstHomeVisitDate");
            }

            if (ClinicalDetails.HealthcareSetting != HealthcareSetting.Other)
            {
                ClinicalDetails.HealthcareDescription = null;
            }

            if (ClinicalDetails.IsDotOffered != Status.Yes)
            {
                ClinicalDetails.DotStatus = null;
            }

            if (ClinicalDetails.EnhancedCaseManagementStatus != Status.Yes)
            {
                ClinicalDetails.EnhancedCaseManagementLevel = 0;
            }
        }
 private void DatesCmb_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         FormattedDate         = new FormattedDate((string)DatesCmb.SelectedItem);
         GetImageBtn.IsEnabled = true;
     }
     catch (Exception exception)
     {
         MessageBox.Show($"The date {DatesCmb.SelectedItem} is invalid, please choose a valid date");
         GetImageBtn.IsEnabled = false;
         SaveLocation.Text     = "";
     }
 }
        public void IfDateParsable_CanConvertReturnsTrueAndDateTime()
        {
            // Arrange
            var formattedDate = new FormattedDate()
            {
                Day = "28", Month = "2", Year = "2000"
            };
            var expectedResult = new DateTime(2000, 2, 28);

            // Act
            var canConvert = formattedDate.TryConvertToDateTime(out var result);

            // Assert
            Assert.True(canConvert);
            Assert.Equal(expectedResult, result);
        }
        protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted)
        {
            if (RowId != null)
            {
                TestResultForEdit = Notification.TestData.ManualTestResults
                                    .SingleOrDefault(r => r.ManualTestResultId == RowId.Value);
                if (TestResultForEdit == null)
                {
                    return(NotFound());
                }
                FormattedTestDate = TestResultForEdit.TestDate.ConvertToFormattedDate();
            }

            await SetDropdownsAsync();

            return(Page());
        }
        public void TestDateInputs()
        {
            SetupConfiguration();
            var dates = DateReader.ReadDates(Path);

            var date1 = new FormattedDate(dates[0]);

            Assert.True(date1.FormattedDateString == "2017-02-27");
            var date2 = new FormattedDate(dates[1]);

            Assert.True(date2.FormattedDateString == "2018-06-02");
            var date3 = new FormattedDate(dates[2]);

            Assert.True(date3.FormattedDateString == "2016-07-13");
            Func <FormattedDate> date4 = () => new FormattedDate(dates[3]);

            Assert.Throws <System.FormatException>(date4);
        }
        protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted)
        {
            PatientDetails = Notification.PatientDetails;
            await SetNotificationProperties(isBeingSubmitted, PatientDetails);

            await GenerateReferenceDataAsync();

            FormattedDob = PatientDetails.Dob.ConvertToFormattedDate();

            if (PatientDetails.ShouldValidateFull)
            {
                TryValidateModel(PatientDetails, "PatientDetails");
            }

            DuplicateNhsNumberNotifications = await GenerateDuplicateNhsNumberNotificationUrlsAsync(PatientDetails.NhsNumber, Notification.Group);

            return(Page());
        }
        public DenotifyModel(
            INotificationService service,
            IAuthorizationService authorizationService,
            INotificationRepository notificationRepository) : base(service, authorizationService, notificationRepository)
        {
            ValidationService = new ValidationService(this);

            if (FormattedDenotificationDate == null)
            {
                var now = DateTime.Now;
                FormattedDenotificationDate = new FormattedDate()
                {
                    Day   = now.Day.ToString(),
                    Month = now.Month.ToString(),
                    Year  = now.Year.ToString()
                };
            }
        }
        public async Task <IActionResult> OnGetAsync()
        {
            TransferRequest = new TransferRequestActionViewModel();
            await GetNotificationAndAlert();

            // Check edit permission of user and redirect if not allowed
            if (TransferRequest.TransferAlert is null || !await _authorizationService.IsUserAuthorizedToManageAlert(User, TransferRequest.TransferAlert))
            {
                return(RedirectToPage("/Notifications/Overview", new { NotificationId }));
            }

            await SetDropdownsAsync();

            TransferRequest.TargetCaseManagerId = TransferRequest.TransferAlert.CaseManagerId;
            TransferRequest.TransferDate        = TransferRequest.TransferAlert.TransferDate ?? DateTime.Now.Date;
            FormattedTransferDate = TransferRequest.TransferDate.ConvertToFormattedDate();
            return(Page());
        }
        protected override async Task <IActionResult> PrepareAndDisplayPageAsync(bool isBeingSubmitted)
        {
            ClinicalDetails = Notification.ClinicalDetails;
            await SetNotificationProperties(isBeingSubmitted, ClinicalDetails);

            var notificationSites = Notification.NotificationSites;

            notificationSites.ForEach(x => x.ShouldValidateFull = Notification.ShouldValidateFull);

            SetupNotificationSiteMap(notificationSites);
            OtherSite = new NotificationSite
            {
                SiteId             = (int)SiteId.OTHER,
                SiteDescription    = notificationSites.FirstOrDefault(ns => ns.SiteId == (int)SiteId.OTHER)?.SiteDescription,
                ShouldValidateFull = Notification.ShouldValidateFull
            };
            Sites = (await _referenceDataRepository.GetAllSitesAsync()).ToList();

            PatientBirthYear = Notification.PatientDetails.Dob?.Year;

            FormattedSymptomDate               = ClinicalDetails.SymptomStartDate.ConvertToFormattedDate();
            FormattedFirstPresentationDate     = ClinicalDetails.FirstPresentationDate.ConvertToFormattedDate();
            FormattedTbServicePresentationDate = ClinicalDetails.TBServicePresentationDate.ConvertToFormattedDate();
            FormattedDiagnosisDate             = ClinicalDetails.DiagnosisDate.ConvertToFormattedDate();
            FormattedTreatmentDate             = ClinicalDetails.TreatmentStartDate.ConvertToFormattedDate();
            FormattedMdrTreatmentDate          = ClinicalDetails.MDRTreatmentStartDate.ConvertToFormattedDate();
            FormattedHomeVisitDate             = ClinicalDetails.FirstHomeVisitDate.ConvertToFormattedDate();

            if (ClinicalDetails.ShouldValidateFull)
            {
                TryValidateModel(this);

                // EditPageErrorDictionary is null only if coming from a GET call, we want to guard here
                // only in a GET call
                if (EditPageErrorDictionary == null &&
                    (!NotificationSiteMap.ContainsKey(SiteId.OTHER) || !NotificationSiteMap[SiteId.OTHER]))
                {
                    ModelState.Remove("OtherSite.SiteDescription");
                }
            }

            return(Page());
        }
Beispiel #12
0
        public ContentResult OnGetValidateSocialContextDates(IEnumerable <Dictionary <string, string> > keyValuePairs)
        {
            List <(string, object)> propertyValueTuples = new List <(string key, object property)>();

            foreach (var keyValuePair in keyValuePairs)
            {
                var formattedDate = new FormattedDate()
                {
                    Day = keyValuePair["day"], Month = keyValuePair["month"], Year = keyValuePair["year"]
                };
                if (formattedDate.TryConvertToDateTime(out DateTime? convertedDob))
                {
                    propertyValueTuples.Add((keyValuePair["key"], convertedDob));
                }
                else
                {
                    // should not ever get here as we validate individual dates first before comparing
                    return(null);
                }
            }
            return(ValidationService.GetMultiplePropertiesValidationResult <T>(propertyValueTuples));
        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string date = context.GetValue(this.Date);
                Console.WriteLine("Date is: " + date);
                string culture = context.GetValue(this.CulturalInfo);
                Console.WriteLine("Culture is: " + culture);
                string format = context.GetValue(this.OutputFormat);
                Console.WriteLine("Output format is: " + format);

                CultureInfo ci = new CultureInfo(culture);
                DateTime    d  = Convert.ToDateTime(date, ci);

                FormattedDate.Set(context, d.ToString(format));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Exception.Set(context, ex);
                throw ex;
            }
        }
        public IActionResult OnPostValidateSocialContextDates([FromBody] DatesValidationModel validationData)
        {
            List <(string, object)> propertyValueTuples = new List <(string key, object property)>();

            foreach (var keyValuePair in validationData.KeyValuePairs)
            {
                var formattedDate = new FormattedDate()
                {
                    Day = keyValuePair["day"], Month = keyValuePair["month"], Year = keyValuePair["year"]
                };
                if (formattedDate.TryConvertToDateTime(out var convertedDob))
                {
                    propertyValueTuples.Add((keyValuePair["key"], convertedDob));
                }
                else
                {
                    // As we know that the validation will have already run for each date separately, we don't need to
                    // return any errors as they will already have been displayed.
                    // It would be better if we didn't get to this point if we knew there was an invalid date.
                    return(BadRequest("One or more of the provided dates does not have a valid format."));
                }
            }
            return(ValidationService.GetMultiplePropertiesValidationResult <T>(propertyValueTuples));
        }
Beispiel #15
0
        protected override void Execute(CodeActivityContext context)
        {
            var workflowContext = context.GetExtension <IWorkflowContext>();
            var service         = this.RetrieveOrganizationService(context);

            List <OptionSetValue> values = new List <OptionSetValue>()
            {
                this.Part1.Get <OptionSetValue>(context),
                this.Part2.Get <OptionSetValue>(context),
                this.Part3.Get <OptionSetValue>(context),
                this.Part4.Get <OptionSetValue>(context),
                this.Part5.Get <OptionSetValue>(context),
                this.Part6.Get <OptionSetValue>(context),
                this.Part7.Get <OptionSetValue>(context),
                this.Part8.Get <OptionSetValue>(context),
                this.Part9.Get <OptionSetValue>(context),
                this.Part10.Get <OptionSetValue>(context),
                this.Part11.Get <OptionSetValue>(context),
                this.Part12.Get <OptionSetValue>(context),
                this.Part13.Get <OptionSetValue>(context),
                this.Part14.Get <OptionSetValue>(context),
                this.Part15.Get <OptionSetValue>(context),
                this.Part16.Get <OptionSetValue>(context),
                this.Part17.Get <OptionSetValue>(context),
                this.Part18.Get <OptionSetValue>(context),
                this.Part19.Get <OptionSetValue>(context),
                this.Part20.Get <OptionSetValue>(context)
            };

            values.RemoveAll(osv => osv == null || osv.Value == 222540025);

            TimeZoneSummary timeZone     = StaticMethods.CalculateTimeZoneToUse(this.TimeZoneOption.Get(context), workflowContext, service);
            DateTime        dateToModify = this.DateToModify.Get(context);

            if (dateToModify.Kind != DateTimeKind.Utc)
            {
                dateToModify = dateToModify.ToUniversalTime();
            }


            LocalTimeFromUtcTimeRequest timeZoneChangeRequest = new LocalTimeFromUtcTimeRequest()
            {
                UtcTime = dateToModify, TimeZoneCode = timeZone.MicrosoftIndex
            };
            LocalTimeFromUtcTimeResponse timeZoneResponse = service.Execute(timeZoneChangeRequest) as LocalTimeFromUtcTimeResponse;
            DateTime timeZoneSpecificDateTime             = timeZoneResponse.LocalTime;

            StringBuilder sb = new StringBuilder();

            foreach (OptionSetValue osv in values)
            {
                try
                {
                    switch (osv.Value)
                    {
                    case 222540000:
                        sb.Append(timeZoneSpecificDateTime.ToString("%h"));
                        break;

                    case 222540001:
                        sb.Append(timeZoneSpecificDateTime.ToString("hh"));
                        break;

                    case 222540002:
                        sb.Append(timeZoneSpecificDateTime.ToString("%H"));
                        break;

                    case 222540003:
                        sb.Append(timeZoneSpecificDateTime.ToString("HH"));
                        break;

                    case 222540004:
                        sb.Append(timeZoneSpecificDateTime.ToString("%m"));
                        break;

                    case 222540005:
                        sb.Append(timeZoneSpecificDateTime.ToString("mm"));
                        break;

                    case 222540006:
                        sb.Append(timeZoneSpecificDateTime.ToString("%d"));
                        break;

                    case 222540007:
                        sb.Append(timeZoneSpecificDateTime.ToString("dd"));
                        break;

                    case 222540008:
                        sb.Append(timeZoneSpecificDateTime.ToString("ddd"));
                        break;

                    case 222540009:
                        sb.Append(timeZoneSpecificDateTime.ToString("dddd"));
                        break;

                    case 222540010:
                        sb.Append(timeZoneSpecificDateTime.ToString("%M"));
                        break;

                    case 222540011:
                        sb.Append(timeZoneSpecificDateTime.ToString("MM"));
                        break;

                    case 222540012:
                        sb.Append(timeZoneSpecificDateTime.ToString("MMM"));
                        break;

                    case 222540013:
                        sb.Append(timeZoneSpecificDateTime.ToString("MMMM"));
                        break;

                    case 222540014:
                        sb.Append(timeZoneSpecificDateTime.ToString("%y"));
                        break;

                    case 222540015:
                        sb.Append(timeZoneSpecificDateTime.ToString("yy"));
                        break;

                    case 222540016:
                        sb.Append(timeZoneSpecificDateTime.ToString("yyyy"));
                        break;

                    case 222540017:
                        sb.Append(timeZoneSpecificDateTime.ToString("%t"));
                        break;

                    case 222540018:
                        sb.Append(timeZoneSpecificDateTime.ToString("tt"));
                        break;

                    case 222540019:
                        sb.Append(" ");
                        break;

                    case 222540020:
                        sb.Append(",");
                        break;

                    case 222540021:
                        sb.Append(".");
                        break;

                    case 222540022:
                        sb.Append(":");
                        break;

                    case 222540023:
                        sb.Append("/");
                        break;

                    case 222540024:
                        sb.Append(@"\");
                        break;

                    case 222540026:
                        sb.Append("-");
                        break;

                    case 222540027:
                        sb.Append(timeZone.Id);
                        break;

                    case 222540028:
                        sb.Append(timeZone.FullName);
                        break;

                    default:
                        break;
                    }
                }
                catch
                {
                    throw new Exception(osv.Value.ToString());
                }
            }

            FormattedDate.Set(context, sb.ToString());
        }
Beispiel #16
0
 protected void FormatDatesForGet(T model)
 {
     FormattedDateFrom = model.DateFrom.ConvertToFormattedDate();
     FormattedDateTo   = model.DateTo.ConvertToFormattedDate();
 }