Search in sources :

Example 1 with InvalidUserInputError

use of au.csiro.pathling.errors.InvalidUserInputError in project pathling by aehrc.

the class LiteralTermVisitor method visitCodingLiteral.

@Override
@Nonnull
public FhirPath visitCodingLiteral(@Nullable final CodingLiteralContext ctx) {
    @Nullable final String fhirPath = checkNotNull(ctx).getText();
    checkNotNull(fhirPath);
    try {
        return CodingLiteralPath.fromString(fhirPath, context.getThisContext().orElse(context.getInputContext()));
    } catch (final IllegalArgumentException e) {
        throw new InvalidUserInputError(e.getMessage(), e);
    }
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Example 2 with InvalidUserInputError

use of au.csiro.pathling.errors.InvalidUserInputError in project pathling by aehrc.

the class LiteralTermVisitor method visitDateTimeLiteral.

@Override
@Nonnull
public FhirPath visitDateTimeLiteral(@Nullable final DateTimeLiteralContext ctx) {
    @Nullable final String fhirPath = checkNotNull(ctx).getText();
    checkNotNull(fhirPath);
    try {
        return DateTimeLiteralPath.fromString(fhirPath, context.getThisContext().orElse(context.getInputContext()));
    } catch (final ParseException ex) {
        throw new InvalidUserInputError("Unable to parse date/time format: " + fhirPath);
    }
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ParseException(java.text.ParseException) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Example 3 with InvalidUserInputError

use of au.csiro.pathling.errors.InvalidUserInputError in project pathling by aehrc.

the class CountFunctionTest method inputMustNotContainArguments.

@Test
void inputMustNotContainArguments() {
    final ElementPath inputPath = new ElementPathBuilder(spark).build();
    final ElementPath argumentPath = new ElementPathBuilder(spark).build();
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
    final NamedFunctionInput countInput = new NamedFunctionInput(parserContext, inputPath, Collections.singletonList(argumentPath));
    final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> NamedFunction.getInstance("count").invoke(countInput));
    assertEquals("Arguments can not be passed to count function", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with InvalidUserInputError

use of au.csiro.pathling.errors.InvalidUserInputError in project pathling by aehrc.

the class ExtensionFunctionTest method throwsErrorIfArgumentIsNotString.

@Test
public void throwsErrorIfArgumentIsNotString() {
    final ElementPath input = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODEABLECONCEPT).build();
    final IntegerLiteralPath argument = IntegerLiteralPath.fromString("4", input);
    final ParserContext context = new ParserContextBuilder(spark, fhirContext).build();
    final NamedFunctionInput extensionInput = new NamedFunctionInput(context, input, Collections.singletonList(argument));
    final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> new ExtensionFunction().invoke(extensionInput));
    assertEquals("extension function must have argument of type String literal: .extension(4)", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) IntegerLiteralPath(au.csiro.pathling.fhirpath.literal.IntegerLiteralPath) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with InvalidUserInputError

use of au.csiro.pathling.errors.InvalidUserInputError in project pathling by aehrc.

the class IifFunctionTest method throwsErrorWithElementAndResourceResults.

@Test
void throwsErrorWithElementAndResourceResults() {
    final NonLiteralPath condition = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.BOOLEAN).expression("valueBoolean").singular(true).build().toThisPath();
    final ElementPath ifTrue = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.STRING).expression("someString").build();
    final ResourcePath otherwise = new ResourcePathBuilder(spark).expression("someResource").resourceType(ResourceType.CONDITION).build();
    final NamedFunctionInput iifInput = new NamedFunctionInput(parserContext, condition, Arrays.asList(condition, ifTrue, otherwise));
    final NamedFunction notFunction = NamedFunction.getInstance("iif");
    final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> notFunction.invoke(iifInput));
    assertEquals("Paths cannot be merged into a collection together: someString, someResource", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)73 Test (org.junit.jupiter.api.Test)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)55 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)45 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)41 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)31 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)31 ResourcePath (au.csiro.pathling.fhirpath.ResourcePath)13 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)13 ResourcePathBuilder (au.csiro.pathling.test.builders.ResourcePathBuilder)13 NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)11 UntypedResourcePath (au.csiro.pathling.fhirpath.UntypedResourcePath)7 UntypedResourcePathBuilder (au.csiro.pathling.test.builders.UntypedResourcePathBuilder)7 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)6 Nonnull (javax.annotation.Nonnull)5 Nullable (javax.annotation.Nullable)5 FhirPath (au.csiro.pathling.fhirpath.FhirPath)4 NamedFunction (au.csiro.pathling.fhirpath.function.NamedFunction)3 IntegerLiteralPath (au.csiro.pathling.fhirpath.literal.IntegerLiteralPath)3 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)3