Search in sources :

Example 96 with ElementPath

use of au.csiro.pathling.fhirpath.element.ElementPath in project pathling by aehrc.

the class BooleansTestFunctionTest method inputMustNotContainArguments.

@ParameterizedTest
@MethodSource("parameters")
void inputMustNotContainArguments(@Nonnull final TestParameters parameters) {
    final ElementPath input = new ElementPathBuilder(spark).build();
    final StringLiteralPath argument = StringLiteralPath.fromString("'some argument'", input);
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
    final NamedFunctionInput functionInput = new NamedFunctionInput(parserContext, input, Collections.singletonList(argument));
    final NamedFunction function = NamedFunction.getInstance(parameters.getFunctionName());
    final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> function.invoke(functionInput));
    assertEquals("Arguments can not be passed to " + parameters.getFunctionName() + " function", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 97 with ElementPath

use of au.csiro.pathling.fhirpath.element.ElementPath in project pathling by aehrc.

the class MemberOfFunction method invoke.

@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
    validateInput(input);
    final ElementPath inputPath = (ElementPath) input.getInput();
    final StringLiteralPath argument = (StringLiteralPath) input.getArguments().get(0);
    final ParserContext inputContext = input.getContext();
    final Column idColumn = inputPath.getIdColumn();
    final Column conceptColumn = inputPath.getValueColumn();
    final Column codingArrayCol = (isCodeableConcept(inputPath)) ? conceptColumn.getField("coding") : when(conceptColumn.isNotNull(), array(conceptColumn)).otherwise(lit(null));
    // Prepare the data which will be used within the map operation. All of these things must be
    // Serializable.
    @SuppressWarnings("OptionalGetWithoutIsPresent") final TerminologyServiceFactory terminologyServiceFactory = inputContext.getTerminologyServiceFactory().get();
    final String valueSetUri = argument.getJavaValue();
    final Dataset<Row> dataset = inputPath.getDataset();
    // Perform a validate code operation on each Coding or CodeableConcept in the input dataset,
    // then create a new dataset with the boolean results.
    final MapperWithPreview<List<SimpleCoding>, Boolean, Set<SimpleCoding>> mapper = new MemberOfMapperWithPreview(MDC.get("requestId"), terminologyServiceFactory, valueSetUri);
    // This de-duplicates the Codings to be validated, then performs the validation on a
    // per-partition basis.
    final Dataset<Row> resultDataset = SqlExtensions.mapWithPartitionPreview(dataset, codingArrayCol, SimpleCodingsDecoders::decodeList, mapper, StructField.apply("result", DataTypes.BooleanType, true, Metadata.empty()));
    final Column resultColumn = col("result");
    // Construct a new result expression.
    final String expression = expressionFromInput(input, NAME);
    return ElementPath.build(expression, resultDataset, idColumn, inputPath.getEidColumn(), resultColumn, inputPath.isSingular(), inputPath.getCurrentResource(), inputPath.getThisColumn(), FHIRDefinedType.BOOLEAN);
}
Also used : StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) Set(java.util.Set) TerminologyServiceFactory(au.csiro.pathling.fhir.TerminologyServiceFactory) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Column(org.apache.spark.sql.Column) SimpleCodingsDecoders(au.csiro.pathling.fhirpath.encoding.SimpleCodingsDecoders) List(java.util.List) Row(org.apache.spark.sql.Row) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) Nonnull(javax.annotation.Nonnull)

Aggregations

ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)97 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)93 Test (org.junit.jupiter.api.Test)72 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)72 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)57 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)51 Row (org.apache.spark.sql.Row)49 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)47 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)43 FhirPath (au.csiro.pathling.fhirpath.FhirPath)39 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)24 NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)15 ResourcePath (au.csiro.pathling.fhirpath.ResourcePath)13 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)13 ResourceDatasetBuilder (au.csiro.pathling.test.builders.ResourceDatasetBuilder)13 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)11 ResourcePathBuilder (au.csiro.pathling.test.builders.ResourcePathBuilder)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 UntypedResourcePath (au.csiro.pathling.fhirpath.UntypedResourcePath)6