Search in sources :

Example 1 with IntegerLiteralPath

use of au.csiro.pathling.fhirpath.literal.IntegerLiteralPath 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());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) 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 2 with IntegerLiteralPath

use of au.csiro.pathling.fhirpath.literal.IntegerLiteralPath in project pathling by aehrc.

the class IifFunctionTest method returnsCorrectResultsForLiteralAndNonLiteral.

@Test
void returnsCorrectResultsForLiteralAndNonLiteral() {
    final Dataset<Row> inputContextDataset = new ResourceDatasetBuilder(spark).withIdColumn().withRow("observation-1").withRow("observation-2").withRow("observation-3").withRow("observation-4").withRow("observation-5").build();
    when(database.read(ResourceType.OBSERVATION)).thenReturn(inputContextDataset);
    final ResourcePath inputContext = new ResourcePathBuilder(spark).expression("Observation").resourceType(ResourceType.OBSERVATION).database(database).singular(true).build();
    final Dataset<Row> inputDataset = new DatasetBuilder(spark).withIdColumn(ID_ALIAS).withEidColumn().withColumn(DataTypes.BooleanType).withRow("observation-1", makeEid(0), false).withRow("observation-2", makeEid(0), true).withRow("observation-3", makeEid(0), null).withRow("observation-4", makeEid(0), true).withRow("observation-4", makeEid(1), false).withRow("observation-5", makeEid(0), null).withRow("observation-5", makeEid(1), null).build();
    final ElementPath inputPath = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.BOOLEAN).dataset(inputDataset).idAndEidAndValueColumns().expression("valueBoolean").singular(false).build();
    parserContext = new ParserContextBuilder(spark, fhirContext).groupingColumns(Collections.singletonList(inputPath.getIdColumn())).build();
    final NonLiteralPath condition = inputPath.toThisPath();
    final Dataset<Row> ifTrueDataset = new DatasetBuilder(spark).withIdColumn(ID_ALIAS).withEidColumn().withColumn(DataTypes.IntegerType).withRow("observation-1", makeEid(0), 1).withRow("observation-2", makeEid(0), 2).withRow("observation-3", makeEid(0), 3).withRow("observation-4", makeEid(0), 4).withRow("observation-5", makeEid(0), 5).build();
    final ElementPath ifTrue = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.INTEGER).dataset(ifTrueDataset).idAndEidAndValueColumns().expression("someInteger").singular(true).build();
    final IntegerLiteralPath otherwise = IntegerLiteralPath.fromString("99", inputContext);
    final NamedFunctionInput iifInput1 = new NamedFunctionInput(parserContext, inputPath, Arrays.asList(condition, ifTrue, otherwise));
    final FhirPath result1 = NamedFunction.getInstance("iif").invoke(iifInput1);
    final Dataset<Row> expectedDataset1 = new DatasetBuilder(spark).withIdColumn(ID_ALIAS).withEidColumn().withColumn(DataTypes.IntegerType).withRow("observation-1", makeEid(0), 99).withRow("observation-2", makeEid(0), 2).withRow("observation-3", makeEid(0), 99).withRow("observation-4", makeEid(0), 4).withRow("observation-4", makeEid(1), 99).withRow("observation-5", makeEid(0), 99).withRow("observation-5", makeEid(1), 99).build();
    assertThat(result1).hasExpression("valueBoolean.iif($this, someInteger, 99)").isNotSingular().isElementPath(IntegerPath.class).selectOrderedResultWithEid().hasRows(expectedDataset1);
    final NamedFunctionInput iifInput2 = new NamedFunctionInput(parserContext, inputPath, Arrays.asList(condition, otherwise, ifTrue));
    final FhirPath result2 = NamedFunction.getInstance("iif").invoke(iifInput2);
    final Dataset<Row> expectedDataset2 = new DatasetBuilder(spark).withIdColumn(ID_ALIAS).withEidColumn().withColumn(DataTypes.IntegerType).withRow("observation-1", makeEid(0), 1).withRow("observation-2", makeEid(0), 99).withRow("observation-3", makeEid(0), 3).withRow("observation-4", makeEid(0), 99).withRow("observation-4", makeEid(1), 4).withRow("observation-5", makeEid(0), 5).withRow("observation-5", makeEid(1), 5).build();
    assertThat(result2).hasExpression("valueBoolean.iif($this, 99, someInteger)").isNotSingular().isElementPath(IntegerPath.class).selectOrderedResultWithEid().hasRows(expectedDataset2);
}
Also used : FhirPath(au.csiro.pathling.fhirpath.FhirPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) 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 IntegerLiteralPath

use of au.csiro.pathling.fhirpath.literal.IntegerLiteralPath 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 4 with IntegerLiteralPath

use of au.csiro.pathling.fhirpath.literal.IntegerLiteralPath in project pathling by aehrc.

the class CombineOperatorTest method worksWithDifferentCombinableTypes.

@Test
void worksWithDifferentCombinableTypes() {
    final Dataset<Row> leftDataset = new DatasetBuilder(spark).withIdColumn(idColumnName).withEidColumn().withColumn(DataTypes.IntegerType).withRow("observation-1", makeEid(0), 3).withRow("observation-1", makeEid(1), 5).withRow("observation-1", makeEid(2), 7).withRow("observation-2", null, null).withRow("observation-3", makeEid(0), -1).build();
    final ElementPath left = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.INTEGER).dataset(leftDataset).idAndEidAndValueColumns().expression("valueInteger").singular(false).build();
    final IntegerLiteralPath right = IntegerLiteralPath.fromString("99", parserContext.getInputContext());
    final OperatorInput combineInput = new OperatorInput(parserContext, left, right);
    final FhirPath result = Operator.getInstance("combine").invoke(combineInput);
    final Dataset<Row> expectedDataset = new DatasetBuilder(spark).withIdColumn().withColumn(DataTypes.IntegerType).withRow("observation-1", 3).withRow("observation-1", 5).withRow("observation-1", 7).withRow("observation-1", 99).withRow("observation-2", null).withRow("observation-2", 99).withRow("observation-3", -1).withRow("observation-3", 99).build();
    assertThat(result).hasExpression("valueInteger combine 99").isNotSingular().isElementPath(IntegerPath.class).selectResult().hasRowsUnordered(expectedDataset);
}
Also used : ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) FhirPath(au.csiro.pathling.fhirpath.FhirPath) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) 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 5 with IntegerLiteralPath

use of au.csiro.pathling.fhirpath.literal.IntegerLiteralPath in project pathling by aehrc.

the class IifFunctionTest method throwsErrorIfResultArgumentsDifferentTypes.

@Test
void throwsErrorIfResultArgumentsDifferentTypes() {
    final NonLiteralPath condition = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.BOOLEAN).expression("valueBoolean").singular(true).build().toThisPath();
    final StringLiteralPath ifTrue = StringLiteralPath.fromString("foo", condition);
    final IntegerLiteralPath otherwise = IntegerLiteralPath.fromString("99", condition);
    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: 'foo', 99", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) 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)

Aggregations

IntegerLiteralPath (au.csiro.pathling.fhirpath.literal.IntegerLiteralPath)6 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)6 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)4 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)3 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)3 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)3 Row (org.apache.spark.sql.Row)3 FhirPath (au.csiro.pathling.fhirpath.FhirPath)2 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)2 ResourcePath (au.csiro.pathling.fhirpath.ResourcePath)1 UntypedResourcePath (au.csiro.pathling.fhirpath.UntypedResourcePath)1 NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)1 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)1 ResourceDatasetBuilder (au.csiro.pathling.test.builders.ResourceDatasetBuilder)1 ResourcePathBuilder (au.csiro.pathling.test.builders.ResourcePathBuilder)1 UntypedResourcePathBuilder (au.csiro.pathling.test.builders.UntypedResourcePathBuilder)1