public static IEnumerable <IFluentPathValue> IsEquivalentTo(this IEnumerable <IFluentPathValue> left, IEnumerable <IFluentPathValue> right) { if (!left.Any() && !right.Any()) { return(FhirValueList.Create(true)); } if (left.Count() != right.Count()) { return(FhirValueList.Create(false)); } return(FhirValueList.Create(left.All((IFluentPathValue l) => right.Any(r => l.IsEquivalentTo(r))))); }
public static IEnumerable <IFluentPathValue> IsEqualTo(this IEnumerable <IFluentPathValue> left, IEnumerable <IFluentPathValue> right) { if (!left.Any() && !right.Any()) { return(FhirValueList.Create(true)); } if (left.Count() != right.Count()) { return(FhirValueList.Create(false)); } return(FhirValueList.Create(left.Zip(right, (l, r) => l.IsEqualTo(r)).All(x => x))); }
public static Evaluator Any(Evaluator condition) { return((f, c) => { if (condition != null) { return f.Any(elements => condition(elements, c)); } else { return FhirValueList.Create(f.Any()); } }); }
public static Evaluator Axis(Axis axis) { return((focus, ctx) => { switch (axis) { case FluentPath.Axis.Descendants: return focus.JustElements().Descendants(); case FluentPath.Axis.Parent: return focus.JustElements().Parents(); case FluentPath.Axis.Focus: return focus; case FluentPath.Axis.Children: return focus.JustElements().Children(); case FluentPath.Axis.Context: if (ctx.OriginalContext == null) { throw new InvalidOperationException("Cannot resolve the $context, the Evaluator did not provide it at runtime"); } else { return ctx.OriginalContext; } case FluentPath.Axis.Resource: if (ctx.OriginalResource == null) { throw new InvalidOperationException("Cannot resolve the $resource, the evaluation context has no information about it."); } else { return FhirValueList.Create(ctx.OriginalResource); } default: throw new InvalidOperationException("Internal error: unknown axis '{0}'".FormatWith(axis)); } }); }
public static IEnumerable <IFluentPathValue> Substring(this IEnumerable <IFluentPathValue> focus, long start, long?length) { if (focus.Count() == 1) { if (focus.First().Value != null) { var str = focus.First().AsStringRepresentation(); if (length.HasValue) { return(FhirValueList.Create(str.Substring((int)start, (int)length.Value))); } else { return(FhirValueList.Create(str.Substring((int)start))); } } } return(FhirValueList.Empty()); }
public static IEnumerable <IFluentPathValue> Or(this IEnumerable <IFluentPathValue> left, IEnumerable <IFluentPathValue> right) { return(FhirValueList.Create(left.booleanEval() || right.booleanEval())); }
public static IEnumerable <IFluentPathValue> Not(this IEnumerable <IFluentPathValue> focus) { return(FhirValueList.Create(!focus.booleanEval())); }
public static IEnumerable <IFluentPathValue> IsEmpty(this IEnumerable <IFluentPathValue> focus) { return(FhirValueList.Create(!focus.Any())); }
public static IEnumerable <IFluentPathValue> IsEqualTo(this IEnumerable <IFluentPathValue> left, object value) { var result = left.SingleOrDefault(v => Object.Equals(v.Value, value)) != null; return(FhirValueList.Create(result)); }
//public static IEnumerable<IFluentPathElement> Resolve(this IEnumerable<IFluentPathValue> focus, FhirClient client) //{ // return focus.Resolve(new BaseEvaluationContext(client)); //} //public static IEnumerable<IFluentPathElement> Resolve(this IEnumerable<IFluentPathValue> focus, IEvaluationContext context) //{ // foreach (var item in focus) // { // string url = null; // // Something that looks like a Reference // if (item is IFluentPathElement) // { // var maybeReference = ((IFluentPathElement)item).Children("reference").SingleOrDefault(); // if (maybeReference != null && maybeReference.Value != null && maybeReference.Value is string) // url = maybeReference.AsString(); // } // // A string as a direct url // if (item.Value != null && item.Value is string) // url = item.AsString(); // if(url != null) // yield return context.ResolveResource(url); // } //} public static IEnumerable <IFluentPathValue> MaxLength(this IEnumerable <IFluentPathValue> focus) { return(FhirValueList.Create(focus.JustValues() .Aggregate(0, (val, item) => Math.Max(item.AsStringRepresentation().Length, val)))); }
public static IEnumerable <IFluentPathValue> CountItems(this IEnumerable <IFluentPathValue> focus) { return(FhirValueList.Create(focus.Count())); }
public static IEnumerable <IFluentPathValue> Select(this IEnumerable <IFluentPathValue> focus, Func <IEnumerable <IFluentPathValue>, IEnumerable <IFluentPathValue> > mapper) { return(focus.SelectMany(v => mapper(FhirValueList.Create(v)))); }
public static IEnumerable <IFluentPathValue> All(this IEnumerable <IFluentPathValue> focus, Func <IEnumerable <IFluentPathValue>, IEnumerable <IFluentPathValue> > condition) { return(FhirValueList.Create(focus.All(v => condition(FhirValueList.Create(v)).booleanEval()))); }
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(string expression, IFluentPathValue instance) { var evaluator = Compile(expression); return(evaluator(FhirValueList.Create(instance), new BaseEvaluationContext())); }