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);
}
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations