Search in sources :

Example 1 with NamedFunctionInput

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());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) FhirPath(au.csiro.pathling.fhirpath.FhirPath) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) 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 2 with NamedFunctionInput

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());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) 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 3 with NamedFunctionInput

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);
}
Also used : CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) FhirPath(au.csiro.pathling.fhirpath.FhirPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) ElementDefinition(au.csiro.pathling.fhirpath.element.ElementDefinition) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) 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 NamedFunctionInput

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);
}
Also used : FhirPath(au.csiro.pathling.fhirpath.FhirPath) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) BooleanPath(au.csiro.pathling.fhirpath.element.BooleanPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext)

Example 5 with NamedFunctionInput

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());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) NamedFunction(au.csiro.pathling.fhirpath.function.NamedFunction) 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)

Aggregations

NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)18 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)17 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)17 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)16 Test (org.junit.jupiter.api.Test)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)13 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)11 FhirPath (au.csiro.pathling.fhirpath.FhirPath)11 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)7 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)6 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)5 Row (org.apache.spark.sql.Row)5 NamedFunction (au.csiro.pathling.fhirpath.function.NamedFunction)4 CodingPath (au.csiro.pathling.fhirpath.element.CodingPath)3 BooleanPath (au.csiro.pathling.fhirpath.element.BooleanPath)2 SimpleCoding (au.csiro.pathling.fhirpath.encoding.SimpleCoding)2 CodingLiteralPath (au.csiro.pathling.fhirpath.literal.CodingLiteralPath)2 ConceptTranslator (au.csiro.pathling.terminology.ConceptTranslator)2 SparkHelpers.rowFromCodeableConcept (au.csiro.pathling.test.helpers.SparkHelpers.rowFromCodeableConcept)2