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