示例#1
0
文件: Person.cs 项目: mikran/Swarmops
        protected int ResolveGeography()
        {
            if (base.CountryId == 0)
            {
                base.GeographyId = 1;
                SwarmDb.GetDatabaseForWriting().SetPersonGeography(Identity, 1);
                return(1); // root geography, if no country set
            }

            Cities cities = Cities.FromPostalCode(PostalCode, base.CountryId);
            City   city   = null;

            if (cities.Count == 0 && PostalCode.Length > 3)
            {
                // try shortening the postal code - like NL dataset - and see if we find anything

                for (int shortening = 1; shortening <= 3; shortening++)
                {
                    cities = Cities.FromPostalCode(PostalCode.Substring(0, PostalCode.Length - shortening),
                                                   base.CountryId);
                    if (cities.Count > 0)
                    {
                        break;
                    }
                }
            }

            if (cities.Count == 0) // still no hit? Move on to getting city by name
            {
                try
                {
                    city = City.FromName(CityName, CountryId);
                }
                catch (ArgumentException)
                {
                    // ignore
                }
            }
            else
            {
                city = cities[0]; // This may be adjusted manually, but will work in 99.9% of cases
            }

            if (city == null)
            {
                base.GeographyId = Country.FromIdentity(base.CountryId).GeographyId;
                return(base.GeographyId);
            }

            base.GeographyId = city.GeographyId;
            SwarmDb.GetDatabaseForWriting().SetPersonGeography(Identity, base.GeographyId);
            return(city.GeographyId);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            PatientsContext _context = new PatientsContext();

            if (string.IsNullOrEmpty(FirstName) || FirstName == " ")
            {
                yield return(new ValidationResult("First name is a required field and cannot be blank spaces", new[] { "FirstName" }));
            }
            else
            {
                FirstName = FirstName.Trim();
                FirstName = MBValidations.MBCapitalize(FirstName);
            }
            if (string.IsNullOrEmpty(LastName) || LastName == " ")
            {
                yield return(new ValidationResult("Last name is a required field and should not be blank space", new[] { "LastName" }));
            }
            else
            {
                LastName = LastName.Trim();
                LastName = MBValidations.MBCapitalize(LastName);
            }
            if (string.IsNullOrEmpty(Gender) || Gender == " ")
            {
                yield return(new ValidationResult("Gender is a required field and should not start with a blank space", new[] { "Gender" }));
            }
            else
            {
                Gender = Gender.Trim();
                Gender = MBValidations.MBCapitalize(Gender);
            }
            if (!string.IsNullOrEmpty(Address))
            {
                Address = Address.Trim();
                Address = MBValidations.MBCapitalize(Address);
            }
            if (!string.IsNullOrEmpty(City))
            {
                City = City.Trim();
                City = MBValidations.MBCapitalize(City);
            }
            if (!string.IsNullOrEmpty(ProvinceCode))
            {
                ProvinceCode = ProvinceCode.Trim();
                Province Pro   = new Province();
                string   error = "";
                ProvinceCode = ProvinceCode.ToUpper();
                try
                {
                    Pro = _context.Province.Where(m => m.ProvinceCode == ProvinceCode).FirstOrDefault();
                    //var country = Pro.CountryCode;
                }
                catch (Exception e)
                {
                    error = e.GetBaseException().Message;
                }
                if (Pro == null)
                {
                    yield return(new ValidationResult(error, new[] { nameof(ProvinceCode) }));
                }
                else
                {
                    if (PostalCode != null)
                    {
                        PostalCode = PostalCode.Trim();
                        bool   val       = false;
                        string USZipCode = PostalCode;
                        if (Pro.CountryCode == "CA")
                        {
                            var    x       = Pro.FirstPostalLetter;
                            char[] charArr = x.ToCharArray();
                            foreach (char ch in charArr)
                            {
                                if (Convert.ToChar(PostalCode.Substring(0, 1).ToUpper()) == ch)
                                {
                                    //if(PostalCode.StartsWith(ch))
                                    val = true;
                                }
                            }
                            if (!val)
                            {
                                yield return(new ValidationResult("Postal code entered is not a valid code for the selected province", new[] { "PostalCode" }));
                            }
                            if (!MBValidations.MBPostalCodeValidation(PostalCode))
                            {
                                yield return(new ValidationResult("Postal code entered is not in valid format", new[] { "PostalCode" }));
                            }
                            else
                            {
                                PostalCode = MBValidations.MBPostalCodeFormat(PostalCode);
                            }
                        }
                        if (Pro.CountryCode == "US")
                        {
                            if (!MBValidations.MBZipCodeValidation(ref USZipCode))
                            {
                                yield return(new ValidationResult("Zip code entered is not in valid format", new[] { "PostalCode" }));
                            }
                            else
                            {
                                PostalCode = USZipCode;
                            }
                        }
                    }
                }
            }

            if (Ohip != null)
            {
                Ohip = Ohip.ToUpper();
                Regex pattern = new Regex(@"^\d\d\d\d-\d\d\d-\d\d\d-[a-z][a-z]$", RegexOptions.IgnoreCase);
                if (!pattern.IsMatch(Ohip))
                {
                    yield return(new ValidationResult("The value for OHIP entered is not in valid format", new[] { "Ohip" }));
                }
            }
            if (HomePhone != null)
            {
                HomePhone = HomePhone.Trim();
                if (HomePhone.Length != 10)
                {
                    yield return(new ValidationResult("The Home Phone Number entered should be exactly 10 digits", new[] { "HomePhone" }));
                }
                HomePhone = HomePhone.Insert(3, "-");
                HomePhone = HomePhone.Insert(7, "-");
            }
            if (DateOfBirth != null)
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("The date of Birth cannot be greater than current date", new[] { "DateOfBirth" }));
                }
            }
            if (Deceased)
            {
                if (DateOfDeath == null)
                {
                    yield return(new ValidationResult("The date of death is required if the deceased checkbox is chec", new[] { "DateOfDeath" }));
                }
            }
            else
            {
                DateOfDeath = null;
            }
            if (DateOfDeath != null)
            {
                if (DateOfDeath > DateTime.Now || DateOfDeath < DateOfBirth)
                {
                    yield return(new ValidationResult("The date of death cannot be greater than current date and before the Date of birth", new[] { "DateOfBirth" }));
                }
            }

            if (Gender != "M" && Gender != "F" && Gender != "X")
            {
                yield return(new ValidationResult("The value for gender entered must be M, F or X", new[] { "Gender" }));
            }

            yield return(ValidationResult.Success);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var patientProvince = new Province();

            if (FirstName == null || FirstName.Trim() == "")
            {
                yield return(new ValidationResult("First Name cannot be empty or just blanks", new[] { nameof(FirstName) }));
            }
            else
            {
                FirstName = SBValidations.SBCapitaize(FirstName);
            }
            if (LastName == null || LastName.Trim() == "")
            {
                yield return(new ValidationResult("Last Name cannot be empty or just blanks", new[] { nameof(LastName) }));
            }
            else
            {
                LastName = SBValidations.SBCapitaize(LastName);
            }
            if (ProvinceCode != null)
            {
                if (ProvinceCode.Trim() != "")
                {
                    ProvinceCode = ProvinceCode.Trim().ToUpper();
                    _context     = (PatientsContext)validationContext.GetService(typeof(PatientsContext));
                    if (!_context.Province.Any(a => a.ProvinceCode == ProvinceCode))
                    {
                        yield return(new ValidationResult("Please enter valid Province Code", new[] { nameof(ProvinceCode) }));
                    }
                    else
                    {
                        patientProvince = _context.Province.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault();
                    }
                }
            }
            if (PostalCode != null)
            {
                if (patientProvince.CountryCode == "CA")
                {
                    string firstCharInPostalCode = PostalCode.Substring(0, 1).ToUpper();
                    if (!patientProvince.FirstPostalLetter.Contains(firstCharInPostalCode))
                    {
                        yield return(new ValidationResult("Please enter suitable Canadian Postal Code for your Province Code", new[] { nameof(PostalCode) }));

                        yield return(new ValidationResult("Please enter suitable Province Code for your Canadian Postal Code", new[] { nameof(ProvinceCode) }));
                    }
                    else if (SBValidations.SBPostalCodeValidation(PostalCode))
                    {
                        PostalCode = SBValidations.SBPostalCodeFormat(PostalCode);
                    }
                    else
                    {
                        yield return(new ValidationResult("Please enter valid Canadian Postal Code", new[] { nameof(PostalCode) }));
                    }
                }
                else
                {
                    string postalCode = PostalCode;
                    if (SBValidations.SBZipCodeValidation(ref postalCode))
                    {
                        PostalCode = postalCode;
                    }
                    else
                    {
                        yield return(new ValidationResult("Please enter valid US Postal Code", new[] { nameof(PostalCode) }));
                    }
                }
            }
            if (Ohip != null)
            {
                Ohip = Ohip.ToUpper();
                var _ohipRegEx = @"^\d{4}-\d{3}-\d{3}-[A-Z]{2}$";
                if (!Regex.Match(Ohip, _ohipRegEx).Success)
                {
                    yield return(new ValidationResult("OHIP, if provided must match pattern; 1234-123-123-XX", new[] { nameof(Ohip) }));
                }
            }
            if (HomePhone != null)
            {
                HomePhone = SBValidations.SBExtractDigits(HomePhone);
                if (HomePhone.Length != 10)
                {
                    yield return(new ValidationResult("Enter valid phone number", new[] { nameof(HomePhone) }));
                }
                HomePhone = string.Format("{0:###-###-####}", long.Parse(HomePhone));
            }
            if (DateOfBirth != null || DateOfBirth.ToString().Trim() != "")
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of birth can't be in the future", new[] { nameof(DateOfBirth) }));
                }
            }
            if (Deceased)
            {
                if (DateOfDeath == null || DateOfDeath.ToString().Trim() == "")
                {
                    yield return(new ValidationResult("Date of death is required if the person is deceased", new[] { nameof(DateOfDeath) }));
                }
                else if (DateOfDeath.Value > DateTime.Now || DateOfDeath.Value < DateOfBirth)
                {
                    yield return(new ValidationResult("Date of death can't be before date of birth or in the future", new[] { nameof(DateOfDeath) }));
                }
            }
            else
            {
                if (!(DateOfDeath == null) || !(DateOfDeath.ToString().Trim() == ""))
                {
                    yield return(new ValidationResult("Date of death is not required", new[] { nameof(DateOfDeath) }));
                }
            }
            if (Gender == null || Gender.Trim() == "")
            {
                yield return(new ValidationResult("Gender cannot be empty or just blanks", new[] { nameof(Gender) }));
            }
            else
            {
                Gender = SBValidations.SBCapitaize(Gender).Substring(0, 1);
                if (!Gender.Equals("M") && !Gender.Equals("F") && !Gender.Equals("X"))
                {
                    yield return(new ValidationResult("Please enter valid gender among (M, F, X)", new[] { nameof(Gender) }));
                }
            }
            if (Address != null)
            {
                if (Address.Trim() != "")
                {
                    Address = SBValidations.SBCapitaize(Address);
                }
            }
            if (City != null)
            {
                if (City.Trim() != "")
                {
                    City = SBValidations.SBCapitaize(City);
                }
            }

            yield return(ValidationResult.Success);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (FirstName == null)
            {
                FirstName = string.Empty;
            }
            else
            {
                FirstName = FirstName.Trim();
                FirstName = ASValidations.ASCapitalize(FirstName).ToString();
            }

            if (LastName == null)
            {
                LastName = string.Empty;
            }
            else
            {
                LastName = LastName.Trim();
                LastName = ASValidations.ASCapitalize(LastName).ToString();
            }

            if (Gender == null)
            {
                Gender = string.Empty;
            }
            else
            {
                Gender = Gender.Trim();
                Gender = ASValidations.ASCapitalize(Gender).ToString();
            }

            if (Address == null)
            {
                Address = string.Empty;
            }
            else
            {
                Address = Address.Trim();
                Address = ASValidations.ASCapitalize(Address).ToString();
            }

            if (City == null)
            {
                City = string.Empty;
            }
            else
            {
                City = City.Trim();
                City = ASValidations.ASCapitalize(City).ToString();
            }

            if (ProvinceCode != null)
            {
                var provSearch = _context.Province.Where(p => p.ProvinceCode == ProvinceCode).FirstOrDefault();

                if (provSearch == null)
                {
                    yield return(new ValidationResult("Province code is not on file", new[] { nameof(ProvinceCode) }));

                    yield return(new ValidationResult("Province code is required to validate Postal Code", new[] { nameof(PostalCode) }));
                }
                else
                {
                    var countrySearch = _context.Country.Where(a => a.CountryCode == provSearch.CountryCode).FirstOrDefault();

                    if (provSearch.CountryCode == "CA")
                    {
                        ProvinceCode = ProvinceCode.Trim();
                        ProvinceCode = ProvinceCode.ToUpper();

                        if (PostalCode != null || PostalCode == "")
                        {
                            PostalCode = PostalCode.Trim().ToUpper();
                            if (provSearch.FirstPostalLetter.Contains(PostalCode.Substring(0, 1)) == false)
                            {
                                yield return(new ValidationResult("First letter of postal code not valid for given province", new[] { nameof(PostalCode) }));
                            }
                            else
                            {
                                if (ASValidations.ASPostalCodeValidation(PostalCode) == false)
                                {
                                    yield return(new ValidationResult("Postal code not in cdn format: A3A 3A3", new[] { nameof(PostalCode) }));
                                }
                                else
                                {
                                    PostalCode = string.Format("{0} {1}", PostalCode.Substring(0, 3), PostalCode.Substring(3));
                                }
                            }
                        }
                    }
                    else if (provSearch.CountryCode == "US")
                    {
                        ProvinceCode = ProvinceCode.Trim();
                        if (!String.IsNullOrEmpty(PostalCode))
                        {
                            PostalCode = PostalCode.Trim();
                            if (!ASValidations.ASZipCodeValidation(PostalCode))
                            {
                                yield return(new ValidationResult("US Zip code format incorrect: 12345 / 12345-6789", new[] { nameof(PostalCode) }));
                            }
                        }
                    }
                }
            }



            if ((Deceased == true) && (DateOfDeath == null))
            {
                yield return(new ValidationResult("If deceased is true, a date of death is required", new[] { nameof(DateOfDeath) }));
            }
            else if ((Deceased == false) && (DateOfDeath != null))
            {
                yield return(new ValidationResult("Deceased must be true, if Date of Death is provided", new[] { nameof(Deceased) }));
            }

            if (Ohip != null)
            {
                Ohip = Ohip.ToUpper();
            }

            if (HomePhone != null)
            {
                HomePhone = HomePhone.Trim();
                var HomePhoneNumber = ASValidations.ASExtractDigits(HomePhone).ToString();
                if (HomePhoneNumber.Length != 10)
                {
                    yield return(new ValidationResult("Home Phone if provided, should be 10 digits: 123-123-1234", new[] { nameof(HomePhone) }));
                }
                else
                {
                    HomePhone = string.Format("{0}-{1}-{2}", HomePhoneNumber.Substring(0, 3), HomePhoneNumber.Substring(3, 3), HomePhoneNumber.Substring(6));
                }
            }



            yield return(ValidationResult.Success);
        }
示例#5
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            // variables
            HKPatientsContext _context    = (HKPatientsContext)validationContext.GetService(typeof(HKPatientsContext));
            string            countryCode = "";

            // Capitalize
            FirstName    = HKValidations.HKCapitalize((FirstName + "").Trim());
            LastName     = HKValidations.HKCapitalize((LastName + "").Trim());
            Gender       = HKValidations.HKCapitalize((Gender + "").Trim());
            Address      = HKValidations.HKCapitalize((Address + "").Trim());
            City         = HKValidations.HKCapitalize((City + "").Trim());
            Ohip         = (Ohip + "").Trim().ToUpper();
            PostalCode   = (PostalCode + "").Trim();
            ProvinceCode = (ProvinceCode + "").Trim().ToUpper();
            HomePhone    = (HomePhone + "").Trim();


            if (FirstName == "")
            {
                yield return(new ValidationResult("First name cannot be empty or just blanks",
                                                  new[] { nameof(FirstName) }));
            }

            if (LastName == "")
            {
                yield return(new ValidationResult("Last Name cannot be empty or just blanks",
                                                  new[] { nameof(LastName) }));
            }

            if (Gender == "")
            {
                yield return(new ValidationResult("Gender cannot be empty or just blanks",
                                                  new[] { nameof(Gender) }));
            }
            else if (Gender.Trim() != "M" && Gender.Trim() != "F" && Gender.Trim() != "X")
            {
                yield return(new ValidationResult("Gender must be either 'M', 'F', or 'X'",
                                                  new[] { nameof(Gender) }));
            }


            // 2.e validate ProvinceCode
            if (ProvinceCode == "")
            {
                yield return(new ValidationResult("Province Code cannot be empty or just blanks",
                                                  new[] { nameof(ProvinceCode) }));
            }
            else
            {
                // 2.e.i, Validate ProvinceCode from the database
                var _provinceContext = _context.Province.Where(e => e.ProvinceCode == ProvinceCode).SingleOrDefault();

                // e.ii if feetching province code throws an exception, show message
                if (_provinceContext != null)
                {
                    countryCode = _provinceContext.CountryCode;
                }
                else
                {
                    yield return(new ValidationResult("Province code is not on file", new[] { nameof(ProvinceCode) }));
                }
            }

            // 2.f validate PostalCode
            if (PostalCode != "")
            {
                // 2.f.i
                if (ProvinceCode == "" || countryCode == "")
                {
                    yield return(new ValidationResult("Province code is required to validate Postal Code", new[] { nameof(PostalCode) }));
                }
                else
                {
                    // 2.f.ii
                    if (countryCode == "CA")
                    {
                        string theFirstLetter = _context.Province.FirstOrDefault(p => p.ProvinceCode == ProvinceCode).FirstPostalLetter;
                        if (!theFirstLetter.Contains(PostalCode.Substring(0, 1).ToUpper()))
                        {
                            yield return(new ValidationResult("First letter of Postal Code not valid for given province",
                                                              new[] { nameof(PostalCode), nameof(ProvinceCode) }));
                        }
                        // 2.f.iii
                        if (!HKValidations.HKPostalCodeValidation(PostalCode))
                        {
                            yield return(new ValidationResult("Postal code is not CDN pattern: A3A 3A3",
                                                              new[] { nameof(PostalCode) }));
                        }

                        PostalCode = HKValidations.HKPostalCodeFormat(PostalCode);
                    }
                    else
                    {
                        // 2.f.iii
                        string zipCode = PostalCode;
                        if (!HKValidations.HKZipCodeValidation(ref zipCode))
                        {
                            yield return(new ValidationResult("Postal code is not valid(3)",
                                                              new[] { nameof(PostalCode) }));
                        }
                        PostalCode = zipCode;
                    }
                }
            }

            // 2.g validate Ohip
            if (Ohip != "")
            {
                Regex pattern = new Regex(@"^[0-9]{4}[-][0-9]{3}[-][0-9]{3}[-][A-Za-z]{2}$", RegexOptions.IgnoreCase);
                if (!pattern.IsMatch(Ohip))
                {
                    yield return(new ValidationResult("OHIP, if provided, must match patter: 1234-123-123-XX",
                                                      new[] { nameof(Ohip) }));
                }
            }

            // 2.h validate HomePhone
            if (HomePhone != "")
            {
                string extractedHomePhone = HKValidations.HKExtractDigits(HomePhone);
                if (extractedHomePhone.Length != 10)
                {
                    yield return(new ValidationResult("Home phone, if provided, must be 10 digits: 123-123-1234",
                                                      new[] { nameof(HomePhone) }));
                }
                else
                {
                    Regex pattern = new Regex(@"^[0-9]{3}[-]?[0-9]{3}[-]?[0-9]{4}$", RegexOptions.IgnoreCase);
                    if (!pattern.IsMatch(HomePhone))
                    {
                        yield return(new ValidationResult("Home phone, if provided, must be 10 digits: 123-123-1234",
                                                          new[] { nameof(HomePhone) }));
                    }
                }
                HomePhone = (extractedHomePhone.Insert(3, "-")).Insert(7, "-");
            }

            // 2.i validate DateOfBirth
            if (DateOfBirth != null)
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of Birth can not be in the future",
                                                      new[] { nameof(DateOfBirth) }));
                }
            }

            if (DateOfDeath > DateTime.Now)
            {
                yield return(new ValidationResult("Date of Death can not be in the future",
                                                  new[] { nameof(DateOfDeath) }));
            }


            if (Deceased)
            {
                // 2.i.i If deceased is true, dateOfDeath is required
                if (DateOfDeath == null)
                {
                    yield return(new ValidationResult("if Deceased is true, a Date of Death is required",
                                                      new[] { nameof(DateOfDeath) }));
                }
                // 2.i.iii before dateOfBirth (if it is provided)
                else // DateOfDeath != null
                {
                    if (DateOfDeath < DateOfBirth)
                    {
                        yield return(new ValidationResult("The Date of Death cannot be earlier than the Date of Birth",
                                                          new[] { nameof(DateOfDeath) }));
                    }
                }
            }
            // 2.i.ii.	If deceased is false, dateOfDeath must be null.
            else
            {
                if (DateOfDeath != null)
                {
                    yield return(new ValidationResult("Deceased must be true if Date if Death is provided",
                                                      new[] { nameof(Deceased) }));
                }
            }
        }
示例#6
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            //trim all strings
            //DateOfDeath, DateOfBirth are not trimmed because they are not string


            //first name process
            if (string.IsNullOrEmpty(FirstName))
            {
                yield return(new ValidationResult("First Name is required", new[] { "FirstName" }));
            }
            else
            {
                FirstName = FirstName.Trim();
                FirstName = AYValidation.AYCapitalize(FirstName);
            }

            if (string.IsNullOrEmpty(LastName))
            {
                yield return(new ValidationResult("last Name is required", new[] { "LastName" }));
            }
            else
            {
                LastName = LastName.Trim();
                LastName = AYValidation.AYCapitalize(LastName);
            }

            Regex genderPattern = new Regex(@"^[MFXmfx]$");

            if (string.IsNullOrEmpty(Gender))
            {
                yield return(new ValidationResult("Gender is required", new[] { "Gender" }));
            }
            else if (genderPattern.IsMatch(Gender))
            {
                Gender = AYValidation.AYCapitalize(Gender);
            }
            else
            {
                yield return(new ValidationResult("Gender is among: M, F, X", new[] { "Gender" }));
            }


            Address = AYValidation.AYCapitalize(Address).Trim();
            City    = AYValidation.AYCapitalize(City).Trim();


            Province correspondingProvince = null;

            if (!string.IsNullOrEmpty(ProvinceCode))
            {
                ProvinceCode = ProvinceCode.Trim().ToUpper();
                string err = string.Empty;
                try
                {
                    correspondingProvince = _context.Province.Where(a => a.ProvinceCode == ProvinceCode).FirstOrDefault();
                }
                catch (Exception ex)
                {
                    err = ex.GetBaseException().Message;
                }

                if (correspondingProvince == null)
                {
                    yield return(new ValidationResult("Province Code not on the list", new[] { "ProvinceCode" }));
                }
                if (!string.IsNullOrEmpty(err))
                {
                    yield return(new ValidationResult(err, new[] { "ProvinceCode" }));
                }
            }

            if (!string.IsNullOrEmpty(PostalCode))
            {
                if (string.IsNullOrEmpty(ProvinceCode))
                {
                    yield return(new ValidationResult("Province Code is needed first", new[] { "PostalCode" }));
                }
                if (correspondingProvince != null) //countrycode could be US or CA
                {
                    if (correspondingProvince.CountryCode == "CA")
                    {
                        Regex firstLetterPattern = new Regex("^[" + correspondingProvince.FirstPostalLetter + "]$");
                        if (!firstLetterPattern.IsMatch(PostalCode.Substring(0, 1)))
                        {
                            yield return(new ValidationResult("Postal Code is not correct for that Province", new[] { "ProvinceCode", "PostalCode" }));
                        }
                        else
                        {
                            if (AYValidation.AYPostalCodeValidation(PostalCode))
                            {
                                PostalCode = AYValidation.AYPostalCodeFormat(PostalCode);
                            }
                            else
                            {
                                yield return(new ValidationResult("Postal Code is not correct.", new[] { "PostalCode" }));
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(Ohip))
            {
                Ohip = Ohip.Trim().ToUpper();
                Regex ohipPattern = new Regex(@"^\d\d\d\d[-]\d\d\d[-]\d\d\d[-][A-Z][A-Z]$", RegexOptions.IgnoreCase);
                if (!ohipPattern.IsMatch(Ohip))
                {
                    yield return(new ValidationResult("Ohip should match pattern: 1234-123-123-XX", new[] { "Ohip" }));
                }
            }

            if (!string.IsNullOrEmpty(HomePhone))
            {
                HomePhone = AYValidation.AYExtractDigits(HomePhone);
                if (HomePhone.Length != 10)
                {
                    yield return(new ValidationResult("Home phone should be 10 digits", new[] { "HomePhone" }));
                }
                else
                {
                    HomePhone = HomePhone.Insert(3, "-").Insert(7, "-");
                }
            }

            if (DateOfBirth != null) //dateofbirth is not string
            {
                if (DateOfBirth > DateTime.Now)
                {
                    yield return(new ValidationResult("Date of birth is not correct", new[] { "DateOfBirth" }));
                }
            }

            if (Deceased)
            {
                if (DateOfDeath == null)
                {
                    yield return(new ValidationResult("Please enter date of death", new[] { "DateOfBirth" }));
                }
                if (DateOfDeath > DateTime.Now || DateOfDeath > DateTime.Now)
                {
                    yield return(new ValidationResult("Please enter correct date of death", new[] { "DateOfBirth" }));
                }
            }
            else
            {
                if (DateOfDeath != null)
                {
                    yield return(new ValidationResult("Don' enter date of death if not deceased", new[] { "DateOfDeath" }));
                }
            }

            yield return(ValidationResult.Success);
        }