コード例 #1
0
        public override void ParseValue(string Values)
        {
            this.IsValid   = true;
            this.ValueList = new List <SearchQueryDateTimeValue>();
            foreach (string Value in Values.Split(OrDelimiter))
            {
                //var DtoSearchParameterDateTimeValue = new SearchQueryDateTimeValue();
                if (this.Modifier.HasValue && this.Modifier == SearchModifierCode.Missing)
                {
                    bool?IsMissing = SearchQueryDateTimeValue.ParseModifierEqualToMissing(Value);
                    if (IsMissing.HasValue)
                    {
                        ValueList.Add(new SearchQueryDateTimeValue(IsMissing.Value, 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 DateTimeStirng = SearchQueryDateTimeValue.RemovePrefix(Value, Prefix);
                    if (IFhirDateTimeFactory.TryParse(DateTimeStirng.Trim(), out FhirDateTime? FhirDateTime, out string?ErrorMessage))
                    {
                        var SearchQueryDateTimeValue = new SearchQueryDateTimeValue(false, Prefix, FhirDateTime !.Precision, FhirDateTime !.DateTime);
                        ValueList.Add(SearchQueryDateTimeValue);
                    }
                    else
                    {
                        this.InvalidMessage = ErrorMessage !;
                        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;
            }
        }
コード例 #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;
            }
        }