コード例 #1
0
        private Expression <Func <IndexQuantity, bool> > NumberNotEqualTo(decimal midValue, int scale)
        {
            var PredicateMain = LinqKit.PredicateBuilder.New <IndexQuantity>(true);
            var lowValue      = DecimalSupport.CalculateLowNumber(midValue, scale);
            var highValue     = DecimalSupport.CalculateHighNumber(midValue, scale);

            //PredicateOne: x => (x.Number < lowValue || x.Number > highValue) && x.Comparator == null
            var PredicateOne = LinqKit.PredicateBuilder.New <IndexQuantity>(true);
            var SubOr        = LinqKit.PredicateBuilder.New <IndexQuantity>(true);

            SubOr        = SubOr.Or(IndexDecimal_IsLowerThan(lowValue));
            SubOr        = SubOr.Or(IndexDecimal_IsHigherThan(highValue));
            PredicateOne = PredicateOne.And(SubOr);
            PredicateOne = PredicateOne.And(ComparatorIsNull());

            //PredicateTwo: x => x.Number <= midValue && x.Comparator == GreaterOrEqual
            var PredicateTwo = LinqKit.PredicateBuilder.New <IndexQuantity>(true);

            PredicateTwo = PredicateTwo.And(IndexDecimal_IsHigherThan(midValue));
            PredicateTwo = PredicateTwo.And(ComparatorIsEqualTo(QuantityComparator.GreaterOrEqual));

            //PredicateThree: x => x.Number >= midValue && x.Comparator == LessOrEqual
            var PredicateThree = LinqKit.PredicateBuilder.New <IndexQuantity>(true);

            PredicateThree = PredicateThree.And(IndexDecimal_IsHigherThanOrEqualTo(midValue));
            PredicateThree = PredicateThree.And(ComparatorIsEqualTo(QuantityComparator.GreaterThan));

            //PredicateThree: x => x.Number > midValue && x.Comparator == LessOrEqual
            var PredicateFour = LinqKit.PredicateBuilder.New <IndexQuantity>(true);

            PredicateFour = PredicateFour.And(IndexDecimal_IsLowerThan(midValue));
            PredicateFour = PredicateFour.And(ComparatorIsEqualTo(QuantityComparator.LessOrEqual));

            //PredicateThree: x => x.Number < midValue && x.Comparator == GreaterThan
            var PredicateFive = LinqKit.PredicateBuilder.New <IndexQuantity>(true);

            PredicateFive = PredicateFive.And(IndexDecimal_IsLowerThanOrEqualTo(midValue));
            PredicateFive = PredicateFive.And(ComparatorIsEqualTo(QuantityComparator.LessThan));

            PredicateMain = PredicateMain.Or(PredicateOne);
            PredicateMain = PredicateMain.Or(PredicateTwo);
            PredicateMain = PredicateMain.Or(PredicateThree);
            PredicateMain = PredicateMain.Or(PredicateFour);
            PredicateMain = PredicateMain.Or(PredicateFive);

            return(PredicateMain);
        }
コード例 #2
0
        public override void ParseValue(string Values)
        {
            this.IsValid = true;
            this.ValueList.Clear();
            foreach (var Value in Values.Split(OrDelimiter))
            {
                //        var DtoSearchParameterNumber = new SearchQueryQuantityValue();
                if (this.Modifier.HasValue && this.Modifier == SearchModifierCode.Missing)
                {
                    bool?IsMissing = SearchQueryQuantityValue.ParseModifierEqualToMissing(Value);
                    if (IsMissing.HasValue)
                    {
                        this.ValueList.Add(new SearchQueryQuantityValue(IsMissing.Value, null, null, null, null, null, null));
                    }
                    else
                    {
                        this.InvalidMessage = $"Found the {SearchModifierCode.Missing.GetCode()} Modifier yet is value was expected to be true or false yet found '{Value}'. ";
                        this.IsValid        = false;
                        break;
                    }
                }
                else
                {
                    //Examples:
                    //Syntax: [parameter]=[prefix][number]|[system]|[code] matches a quantity with the given unit
                    //Observation?value=5.4|http://unitsofmeasure.org|mg
                    //Observation?value=5.4||mg
                    //Observation?value=le5.4|http://unitsofmeasure.org|mg
                    //Observation?value=ap5.4|http://unitsofmeasure.org|mg

                    //Observation?value=ap5.4
                    //Observation?value=ap5.4|
                    //Observation?value=ap5.4|http://unitsofmeasure.org
                    //Observation?value=ap5.4|http://unitsofmeasure.org|

                    string[]         Split  = Value.Trim().Split(VerticalBarDelimiter);
                    SearchComparator?Prefix = SearchQueryDateTimeValue.GetPrefix(Split[0]);
                    if (!SearchQueryQuantityValue.ValidatePreFix(this.SearchParamTypeId, Prefix) && Prefix.HasValue)
                    {
                        this.InvalidMessage = $"The search parameter had an unsupported prefix of '{Prefix.Value.GetCode()}'. ";
                        this.IsValid        = false;
                        break;
                    }
                    string NumberAsString = SearchQueryDateTimeValue.RemovePrefix(Split[0], Prefix).Trim();
                    if (Split.Count() == 1)
                    {
                        if (Decimal.TryParse(NumberAsString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out decimal TempDecimal))
                        {
                            DecimalInfo DecimalInfo = DecimalSupport.GetDecimalInfo(TempDecimal);
                            var         DtoSearchParameterNumber = new SearchQueryQuantityValue(false,
                                                                                                Prefix,
                                                                                                null,
                                                                                                null,
                                                                                                DecimalInfo.Precision,
                                                                                                DecimalInfo.Scale,
                                                                                                TempDecimal);
                            this.ValueList.Add(DtoSearchParameterNumber);
                        }
                        else
                        {
                            this.InvalidMessage = $"Expected a Quantity value yet was unable to parse the provided value '{NumberAsString}' as a Decimal. ";
                            this.IsValid        = false;
                            break;
                        }
                    }
                    else if (Split.Count() == 2)
                    {
                        if (Decimal.TryParse(NumberAsString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out decimal TempDecimal))
                        {
                            string?System;
                            if (!string.IsNullOrWhiteSpace(Split[1].Trim()))
                            {
                                System = Split[1].Trim();
                            }
                            else
                            {
                                System = null;
                            }
                            DecimalInfo DecimalInfo = DecimalSupport.GetDecimalInfo(TempDecimal);
                            var         DtoSearchParameterNumber = new SearchQueryQuantityValue(false,
                                                                                                Prefix,
                                                                                                System,
                                                                                                null,
                                                                                                DecimalInfo.Precision,
                                                                                                DecimalInfo.Scale,
                                                                                                TempDecimal);

                            this.ValueList.Add(DtoSearchParameterNumber);
                        }
                        else
                        {
                            this.InvalidMessage = $"Expected a Quantity value yet was unable to parse the provided value '{NumberAsString}' as a Decimal. ";
                            this.IsValid        = false;
                            break;
                        }
                    }
                    else if (Split.Count() == 3)
                    {
                        if (Decimal.TryParse(NumberAsString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out decimal TempDecimal))
                        {
                            string?System = null;
                            if (!string.IsNullOrWhiteSpace(Split[1].Trim()))
                            {
                                System = Split[1].Trim();
                            }

                            string?Code = null;
                            if (!string.IsNullOrWhiteSpace(Split[2].Trim()))
                            {
                                Code = Split[2].Trim();
                            }
                            DecimalInfo DecimalInfo = DecimalSupport.GetDecimalInfo(TempDecimal);
                            var         DtoSearchParameterNumber = new SearchQueryQuantityValue(false,
                                                                                                Prefix,
                                                                                                System,
                                                                                                Code,
                                                                                                DecimalInfo.Precision,
                                                                                                DecimalInfo.Scale,
                                                                                                TempDecimal);

                            this.ValueList.Add(DtoSearchParameterNumber);
                        }
                        else
                        {
                            this.InvalidMessage = $"Expected a Quantity value yet was unable to parse the provided value '{NumberAsString}' as a Decimal. ";
                            this.IsValid        = false;
                            break;
                        }
                    }
                    else
                    {
                        this.InvalidMessage = $"Expected a Quantity value type yet found to many {VerticalBarDelimiter} Delimiters. ";
                        this.IsValid        = false;
                        break;
                    }
                }
            }
            if (ValueList.Count > 1)
            {
                this.HasLogicalOrProperties = true;
            }

            if (this.ValueList.Count == 0)
            {
                this.InvalidMessage = $"Unable to parse any values into a {this.GetType().Name} from the string: {Values}.";
                this.IsValid        = false;
            }
        }
コード例 #3
0
        public override void ParseValue(string Values)
        {
            this.IsValid   = true;
            this.ValueList = new List <SearchQueryNumberValue>();
            foreach (var Value in Values.Split(OrDelimiter))
            {
                //var DtoSearchParameterNumber = new SearchQueryNumberValue();
                if (this.Modifier.HasValue && this.Modifier == SearchModifierCode.Missing)
                {
                    bool?IsMissing = SearchQueryNumberValue.ParseModifierEqualToMissing(Value);
                    if (IsMissing.HasValue)
                    {
                        this.ValueList.Add(new SearchQueryNumberValue(IsMissing.Value, null, null, null, null));
                    }
                    else
                    {
                        this.InvalidMessage = $"Found the {SearchModifierCode.Missing.GetCode()} Modifier yet is value was expected to be true or false yet found '{Value}'. ";
                        this.IsValid        = false;
                        break;
                    }
                }
                else
                {
                    SearchComparator?Prefix = SearchQueryDateTimeValue.GetPrefix(Value);
                    if (!SearchQueryQuantityValue.ValidatePreFix(this.SearchParamTypeId, Prefix) && Prefix.HasValue)
                    {
                        this.InvalidMessage = $"The search parameter had an unsupported prefix of '{Prefix.Value.GetCode()}'. ";
                        this.IsValid        = false;
                        break;
                    }

                    string NumberAsString = SearchQueryDateTimeValue.RemovePrefix(Value, Prefix);
                    if (Decimal.TryParse(NumberAsString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out decimal TempDecimal))
                    {
                        var DecimalInfo            = DecimalSupport.GetDecimalInfo(TempDecimal);
                        var SearchQueryNumberValue = new SearchQueryNumberValue(false,
                                                                                Prefix,
                                                                                DecimalInfo.Precision,
                                                                                DecimalInfo.Scale,
                                                                                TempDecimal);
                        this.ValueList.Add(SearchQueryNumberValue);
                    }
                    else
                    {
                        this.InvalidMessage = $"Unable to parse the value of : {NumberAsString} to a DateTime.";
                        this.IsValid        = false;
                        break;
                    }
                }
            }
            if (ValueList.Count > 1)
            {
                this.HasLogicalOrProperties = true;
            }

            if (this.ValueList.Count == 0)
            {
                this.InvalidMessage = $"Unable to parse any values into a {this.GetType().Name} from the string: {Values}.";
                this.IsValid        = false;
            }
        }