public static ValueType GetFhirType(this IFluentPathValue value)
        {
            if (value == null || value.Value == null)
            {
                throw Error.ArgumentNull("value");
            }

            var val = value.Value;

            if (val is Boolean)
            {
                return(ValueType.Boolean);
            }
            if (val is String)
            {
                return(ValueType.String);
            }
            if (val is Int64)
            {
                return(ValueType.Integer);
            }
            if (val is Decimal)
            {
                return(ValueType.Decimal);
            }
            if (val is PartialDateTime)
            {
                return(ValueType.DateTime);
            }

            throw new InvalidOperationException("IFhirPathValue.Value returned an unsupported type {0}".FormatWith(val.GetType().Name));
        }
 public static bool AsBoolean(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((bool)me.Value);
 }
 public static decimal AsDecimal(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((decimal)me.Value);
 }
 public static Int64 AsInteger(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((Int64)me.Value);
 }
        //public static IEnumerable<IFhirPathElement> Child(this IEnumerable<IFhirPathValue> focus, string name)
        //{
        //    return focus.JustFhirPathElements().Child(name);
        //}

        //public static IEnumerable<IFhirPathElement> Child(this IEnumerable<IFhirPathElement> focus, string name)
        //{
        //    return focus.SelectMany(node => node.Children().Where(child => child.IsMatch(name)));
        //}


        public static IEnumerable <IFluentPathElement> Children(this IFluentPathValue focus)
        {
            if (focus is IFluentPathElement)
            {
                return(((IFluentPathElement)focus).Children().Select(c => c.Child));
            }

            return(Enumerable.Empty <IFluentPathElement>());
        }
        public static bool IsEqualTo(this IFluentPathValue left, IFluentPathValue right)
        {
            if (!Object.Equals(left.Value, right.Value))
            {
                return(false);
            }

            return(left.Children().IsEqualTo(right.Children()).AsBoolean());
        }
        private static IFluentPathValue math(this IFluentPathValue left, Func <dynamic, dynamic, object> f, IFluentPathValue right)
        {
            if (left.Value == null || right.Value == null)
            {
                throw Error.InvalidOperation("Operands must both be values");
            }
            if (left.Value.GetType() != right.Value.GetType())
            {
                throw Error.InvalidOperation("Operands must be of the same type");
            }

            return(new TypedValue(f(left.Value, right.Value)));
        }
        public static bool IsEquivalentTo(this IFluentPathValue left, IFluentPathValue right)
        {
            // Exception: In equality comparisons, the "id" elements do not need to be equal
            if (left is IFluentPathElement && right is IFluentPathElement)
            {
                var lElem = (IFluentPathElement)left;
                var rElem = (IFluentPathElement)right;

                //  if (lElem.Name == "id" && rElem.Name == "id")
                return(true);
            }

            throw new NotImplementedException();
        }
        /// <summary>
        /// A String representation of the entity that will convert whatever type it is into a string
        /// (unlike the AsString, which just cases to a string)
        /// </summary>
        /// <param name="me"></param>
        /// <returns></returns>
        public static string AsStringRepresentation(this IFluentPathValue me)
        {
            if (me.Value == null)
            {
                return(null);
            }

            if (me.Value is PartialDateTime)
            {
                return(me.Value.ToString());
            }
            else
            {
                return(PrimitiveTypeConverter.ConvertTo <string>(me.Value));
            }
        }
        private static bool compare(this IFluentPathValue left, InfixOperator comp, IFluentPathValue right)
        {
            if (left.Value == null || right.Value == null)
            {
                throw Error.InvalidOperation("'{0)' requires both operands to be values".FormatWith(comp));
            }
            if (left.Value.GetType() != right.Value.GetType())
            {
                throw Error.InvalidOperation("Operands to '{0}' must be of the same type".FormatWith(comp));
            }

            if (left.Value is string)
            {
                var result = String.Compare(left.AsString(), right.AsString());
                if (comp == InfixOperator.LessThan)
                {
                    return(result == -1);
                }
                if (comp == InfixOperator.GreaterThan)
                {
                    return(result == 1);
                }
            }
            else
            {
                if (comp == InfixOperator.LessThan)
                {
                    return((dynamic)left.Value < (dynamic)right.Value);
                }
                if (comp == InfixOperator.GreaterThan)
                {
                    return((dynamic)left.Value > (dynamic)right.Value);
                }
            }

            throw Error.InvalidOperation("Comparison failed on operator '{0}'".FormatWith(comp));
        }
 public static bool Predicate(this Evaluator evaluator, IFluentPathValue instance, IEvaluationContext context)
 {
     return(evaluator.Evaluate(instance, context).BooleanEval().AsBoolean());
 }
 public static object Scalar(this Evaluator evaluator, IFluentPathValue instance)
 {
     return(evaluator.Evaluate(instance, new BaseEvaluationContext()).SingleValue());
 }
        public static IEnumerable <IFluentPathValue> Evaluate(this Evaluator evaluator, IFluentPathValue instance)
        {
            var original = FhirValueList.Create(instance);

            return(evaluator.Evaluate(instance, new BaseEvaluationContext()));
        }
        public static IEnumerable <IFluentPathValue> Evaluate(this Evaluator evaluator, IFluentPathValue instance, IEvaluationContext context)
        {
            var original = FhirValueList.Create(instance);

            context.OriginalContext = original;
            return(evaluator(original, context));
        }
Beispiel #15
0
        public static bool Predicate(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator.Predicate(instance, new BaseEvaluationContext()));
        }
Beispiel #16
0
        public static object Scalar(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator.Scalar(instance, new BaseEvaluationContext()));
        }
 public static IFluentPathValue GreaterThan(this IFluentPathValue left, IFluentPathValue right)
 {
     return(new TypedValue(left.compare(InfixOperator.GreaterThan, right)));
 }
 public static IFluentPathValue LessOrEqual(this IFluentPathValue left, IFluentPathValue right)
 {
     return(new TypedValue(left.IsEqualTo(right) || left.compare(InfixOperator.LessThan, right)));
 }
 public static PartialDateTime AsDateTime(this IFluentPathValue me)
 {
     return((PartialDateTime)me.Value);
 }
 /// <summary>
 /// Cast this value to a string (not ToString, consider AsStringRepresentation if you want that)
 /// </summary>
 /// <param name="me"></param>
 /// <returns></returns>
 public static string AsString(this IFluentPathValue me)
 {
     return((string)me.Value);
 }
 public static bool IsTrue(this Evaluator evaluator, IFluentPathValue instance)
 {
     return(evaluator.Evaluate(instance, new BaseEvaluationContext()).BooleanEval().AsBoolean());
 }
 public static IFluentPathValue Div(this IFluentPathValue left, IFluentPathValue right)
 {
     return(left.math((a, b) => a / b, right));
 }
Beispiel #23
0
        public static IEnumerable <IFluentPathValue> Evaluate(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator(FhirValueList.Create(instance), new BaseEvaluationContext()));
        }