use of au.csiro.pathling.test.builders.UntypedResourcePathBuilder in project pathling by aehrc.
the class OfTypeFunctionTest method resolvesPolymorphicReference.
@Test
void resolvesPolymorphicReference() {
final Dataset<Row> inputDataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withTypeColumn().withStructTypeColumns(referenceStructType()).withRow("encounter-1", makeEid(1), "Patient", RowFactory.create(null, "Patient/patient-1", null)).withRow("encounter-1", makeEid(0), "Patient", RowFactory.create(null, "Patient/patient-2", null)).withRow("encounter-2", makeEid(0), "Patient", RowFactory.create(null, "Patient/patient-3", null)).withRow("encounter-2", makeEid(1), "Group", RowFactory.create(null, "Group/group-1", null)).withRow("encounter-3", makeEid(0), "Patient", RowFactory.create(null, "Patient/patient-2", null)).withRow("encounter-4", makeEid(0), "Patient", RowFactory.create(null, "Patient/patient-2", null)).withRow("encounter-5", makeEid(0), "Group", RowFactory.create(null, "Group/group-1", null)).withRow("encounter-6", null, null, null).buildWithStructValue();
final UntypedResourcePath inputPath = new UntypedResourcePathBuilder(spark).expression("subject.resolve()").dataset(inputDataset).idEidTypeAndValueColumns().singular(false).build();
final Dataset<Row> argumentDataset = new ResourceDatasetBuilder(spark).withIdColumn().withColumn(DataTypes.StringType).withColumn(DataTypes.BooleanType).withRow("patient-1", "female", true).withRow("patient-2", "female", false).withRow("patient-3", "male", true).build();
when(database.read(ResourceType.PATIENT)).thenReturn(argumentDataset);
final ResourcePath argumentPath = new ResourcePathBuilder(spark).database(database).resourceType(ResourceType.PATIENT).expression("Patient").build();
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).idColumn(inputPath.getIdColumn()).build();
final NamedFunctionInput ofTypeInput = new NamedFunctionInput(parserContext, inputPath, Collections.singletonList(argumentPath));
final NamedFunction ofType = NamedFunction.getInstance("ofType");
final FhirPath result = ofType.invoke(ofTypeInput);
assertTrue(result instanceof ResourcePath);
assertThat((ResourcePath) result).hasExpression("subject.resolve().ofType(Patient)").isNotSingular().hasResourceType(ResourceType.PATIENT);
final Dataset<Row> expectedDataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withIdColumn().withRow("encounter-1", makeEid(0), "patient-2").withRow("encounter-1", makeEid(1), "patient-1").withRow("encounter-2", makeEid(0), "patient-3").withRow("encounter-2", makeEid(1), null).withRow("encounter-3", makeEid(0), "patient-2").withRow("encounter-4", makeEid(0), "patient-2").withRow("encounter-5", makeEid(0), null).withRow("encounter-6", null, null).build();
assertThat(result).selectOrderedResultWithEid().hasRows(expectedDataset);
}
use of au.csiro.pathling.test.builders.UntypedResourcePathBuilder in project pathling by aehrc.
the class OfTypeFunctionTest method throwsErrorIfMoreThanOneArgument.
@Test
void throwsErrorIfMoreThanOneArgument() {
final UntypedResourcePath input = new UntypedResourcePathBuilder(spark).expression("subject").build();
final ResourcePath argument1 = new ResourcePathBuilder(spark).expression("Patient").build();
final ResourcePath argument2 = new ResourcePathBuilder(spark).expression("Condition").build();
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
final NamedFunctionInput ofTypeInput = new NamedFunctionInput(parserContext, input, Arrays.asList(argument1, argument2));
final NamedFunction ofTypeFunction = NamedFunction.getInstance("ofType");
final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> ofTypeFunction.invoke(ofTypeInput));
assertEquals("ofType function must have one argument: subject.ofType(Patient, Condition)", error.getMessage());
}
use of au.csiro.pathling.test.builders.UntypedResourcePathBuilder in project pathling by aehrc.
the class IifFunctionTest method throwsErrorWithUntypedResourceAndLiteralResults.
@Test
void throwsErrorWithUntypedResourceAndLiteralResults() {
final NonLiteralPath condition = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.BOOLEAN).expression("valueBoolean").singular(true).build().toThisPath();
final UntypedResourcePath ifTrue = new UntypedResourcePathBuilder(spark).expression("someUntypedResource").build();
final StringLiteralPath otherwise = StringLiteralPath.fromString("foo", 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: someUntypedResource, 'foo'", error.getMessage());
}
use of au.csiro.pathling.test.builders.UntypedResourcePathBuilder in project pathling by aehrc.
the class OfTypeFunctionTest method throwsErrorIfArgumentNotResource.
@Test
void throwsErrorIfArgumentNotResource() {
final UntypedResourcePath input = new UntypedResourcePathBuilder(spark).expression("subject").build();
final StringLiteralPath argument = StringLiteralPath.fromString("'some string'", input);
final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
final NamedFunctionInput ofTypeInput = new NamedFunctionInput(parserContext, input, Collections.singletonList(argument));
final NamedFunction ofTypeFunction = NamedFunction.getInstance("ofType");
final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> ofTypeFunction.invoke(ofTypeInput));
assertEquals("Argument to ofType function must be a resource type: 'some string'", error.getMessage());
}
Aggregations