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