use of au.csiro.pathling.fhirpath.function.NamedFunctionInput in project pathling by aehrc.
the class MemberOfFunctionTest method throwsErrorIfTerminologyServiceNotConfigured.
@Test
void throwsErrorIfTerminologyServiceNotConfigured() {
final ElementPath input = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODEABLECONCEPT).build();
final FhirPath argument = StringLiteralPath.fromString("some string", input);
final ParserContext context = new ParserContextBuilder(spark, fhirContext).build();
final NamedFunctionInput memberOfInput = new NamedFunctionInput(context, input, Collections.singletonList(argument));
final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> new MemberOfFunction().invoke(memberOfInput));
assertEquals("Attempt to call terminology function memberOf when terminology service has not been configured", error.getMessage());
}
use of au.csiro.pathling.fhirpath.function.NamedFunctionInput in project pathling by aehrc.
the class MemberOfFunctionTest method throwsErrorIfArgumentIsNotString.
@Test
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).terminologyClientFactory(mock(TerminologyServiceFactory.class)).build();
final NamedFunctionInput memberOfInput = new NamedFunctionInput(context, input, Collections.singletonList(argument));
final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> new MemberOfFunction().invoke(memberOfInput));
assertEquals("memberOf function accepts one argument of type String literal", error.getMessage());
}
use of au.csiro.pathling.fhirpath.function.NamedFunctionInput in project pathling by aehrc.
the class MemberOfFunctionTest method memberOfEmptyCodingDatasetDoesNotCallTerminology.
@Test
void memberOfEmptyCodingDatasetDoesNotCallTerminology() {
final Optional<ElementDefinition> optionalDefinition = FhirHelpers.getChildOfResource(fhirContext, "Encounter", "class");
assertTrue(optionalDefinition.isPresent());
final ElementDefinition definition = optionalDefinition.get();
final Dataset<Row> inputDataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withStructTypeColumns(codingStructType()).buildWithStructValue();
final CodingPath inputExpression = (CodingPath) new ElementPathBuilder(spark).dataset(inputDataset).idAndEidAndValueColumns().expression("Encounter.class").singular(false).definition(definition).buildDefined();
final StringLiteralPath argumentExpression = StringLiteralPath.fromString("'" + MY_VALUE_SET_URL + "'", inputExpression);
// Prepare the inputs to the function.
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).idColumn(inputExpression.getIdColumn()).terminologyClientFactory(terminologyServiceFactory).build();
final NamedFunctionInput memberOfInput = new NamedFunctionInput(parserContext, inputExpression, Collections.singletonList(argumentExpression));
// Invoke the function.
final FhirPath result = new MemberOfFunction().invoke(memberOfInput);
// The outcome is somehow random with regard to the sequence passed to MemberOfMapperAnswerer.
final Dataset<Row> expectedResult = new DatasetBuilder(spark).withIdColumn().withEidColumn().withColumn(DataTypes.BooleanType).build();
// Check the result.
assertThat(result).hasExpression("Encounter.class.memberOf('" + MY_VALUE_SET_URL + "')").isElementPath(BooleanPath.class).hasFhirType(FHIRDefinedType.BOOLEAN).isNotSingular().selectOrderedResultWithEid().hasRows(expectedResult);
verifyNoMoreInteractions(terminologyService);
}
use of au.csiro.pathling.fhirpath.function.NamedFunctionInput in project pathling by aehrc.
the class SubsumesFunctionTest method assertCallSuccess.
ElementPathAssertion assertCallSuccess(final NamedFunction function, final NonLiteralPath inputExpression, final FhirPath argumentExpression) {
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).terminologyClientFactory(terminologyServiceFactory).build();
final NamedFunctionInput functionInput = new NamedFunctionInput(parserContext, inputExpression, Collections.singletonList(argumentExpression));
final FhirPath result = function.invoke(functionInput);
return assertThat(result).isElementPath(BooleanPath.class).preservesCardinalityOf(inputExpression);
}
use of au.csiro.pathling.fhirpath.function.NamedFunctionInput in project pathling by aehrc.
the class SubsumesFunctionTest method throwsErrorIfArgumentTypeIsUnsupported.
@Test
void throwsErrorIfArgumentTypeIsUnsupported() {
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).terminologyClientFactory(mock(TerminologyServiceFactory.class)).build();
final ElementPath input = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODEABLECONCEPT).build();
final StringLiteralPath argument = StringLiteralPath.fromString("'str'", input);
final NamedFunctionInput functionInput = new NamedFunctionInput(parserContext, input, Collections.singletonList(argument));
final NamedFunction subsumesFunction = NamedFunction.getInstance("subsumes");
final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> subsumesFunction.invoke(functionInput));
assertEquals("subsumes function accepts argument of type Coding or CodeableConcept", error.getMessage());
}
Aggregations