Search in sources :

Example 1 with OperatorInput

use of au.csiro.pathling.fhirpath.operator.OperatorInput in project pathling by aehrc.

the class Visitor method visitBinaryOperator.

@Nonnull
private FhirPath visitBinaryOperator(@Nullable final ParseTree leftContext, @Nullable final ParseTree rightContext, @Nullable final String operatorName) {
    checkNotNull(operatorName);
    // Parse the left and right expressions.
    final FhirPath left = new Visitor(context).visit(leftContext);
    final FhirPath right = new Visitor(context).visit(rightContext);
    // Retrieve an Operator instance based upon the operator string.
    final Operator operator = Operator.getInstance(operatorName);
    final OperatorInput operatorInput = new OperatorInput(context, left, right);
    return operator.invoke(operatorInput);
}
Also used : Operator(au.csiro.pathling.fhirpath.operator.Operator) FhirPath(au.csiro.pathling.fhirpath.FhirPath) FhirPathBaseVisitor(au.csiro.pathling.fhirpath.parser.generated.FhirPathBaseVisitor) OperatorInput(au.csiro.pathling.fhirpath.operator.OperatorInput) Nonnull(javax.annotation.Nonnull)

Example 2 with OperatorInput

use of au.csiro.pathling.fhirpath.operator.OperatorInput in project pathling by aehrc.

the class ExtensionFunction method invoke.

@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
    final String expression = NamedFunction.expressionFromInput(input, NAME);
    checkUserInput(input.getArguments().size() == 1, "extension function must have one argument: " + expression);
    final FhirPath urlArgument = input.getArguments().get(0);
    checkUserInput(urlArgument instanceof StringLiteralPath, "extension function must have argument of type String literal: " + expression);
    final NonLiteralPath inputPath = input.getInput();
    final ElementPath extensionPath = new PathTraversalOperator().invoke(new PathTraversalInput(input.getContext(), inputPath, ExtensionSupport.EXTENSION_ELEMENT_NAME()));
    // Now we need to create a correct argument context for the `where` call.
    final ParserContext argumentContext = input.getContext();
    final FhirPath extensionUrlPath = new PathTraversalOperator().invoke(new PathTraversalInput(argumentContext, extensionPath.toThisPath(), "url"));
    final FhirPath extensionUrCondition = new ComparisonOperator(ComparisonOperation.EQUALS).invoke(new OperatorInput(argumentContext, extensionUrlPath, urlArgument));
    // Override the expression in the function input.
    return new WhereFunction().invoke(new NamedFunctionInput(input.getContext(), extensionPath, Collections.singletonList(extensionUrCondition), expression));
}
Also used : PathTraversalInput(au.csiro.pathling.fhirpath.operator.PathTraversalInput) ComparisonOperator(au.csiro.pathling.fhirpath.operator.ComparisonOperator) FhirPath(au.csiro.pathling.fhirpath.FhirPath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) OperatorInput(au.csiro.pathling.fhirpath.operator.OperatorInput) PathTraversalOperator(au.csiro.pathling.fhirpath.operator.PathTraversalOperator) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) Nonnull(javax.annotation.Nonnull)

Aggregations

FhirPath (au.csiro.pathling.fhirpath.FhirPath)2 OperatorInput (au.csiro.pathling.fhirpath.operator.OperatorInput)2 Nonnull (javax.annotation.Nonnull)2 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)1 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)1 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)1 ComparisonOperator (au.csiro.pathling.fhirpath.operator.ComparisonOperator)1 Operator (au.csiro.pathling.fhirpath.operator.Operator)1 PathTraversalInput (au.csiro.pathling.fhirpath.operator.PathTraversalInput)1 PathTraversalOperator (au.csiro.pathling.fhirpath.operator.PathTraversalOperator)1 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)1 FhirPathBaseVisitor (au.csiro.pathling.fhirpath.parser.generated.FhirPathBaseVisitor)1