Search in sources :

Example 11 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath in project pathling by aehrc.

the class IifFunctionTest method throwsErrorWithResourceAndLiteralResults.

@Test
void throwsErrorWithResourceAndLiteralResults() {
    final NonLiteralPath condition = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.BOOLEAN).expression("valueBoolean").singular(true).build().toThisPath();
    final ResourcePath ifTrue = new ResourcePathBuilder(spark).expression("someResource").resourceType(ResourceType.PATIENT).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: someResource, 'foo'", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath 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);
}
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) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) 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) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath in project pathling by aehrc.

the class OfTypeFunctionTest method throwsErrorIfInputNotPolymorphic.

@Test
void throwsErrorIfInputNotPolymorphic() {
    final ResourcePath input = new ResourcePathBuilder(spark).expression("Patient").build();
    final ResourcePath argument = new ResourcePathBuilder(spark).build();
    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("Input to ofType function must be a polymorphic resource type: Patient", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath 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());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) UntypedResourcePathBuilder(au.csiro.pathling.test.builders.UntypedResourcePathBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) UntypedResourcePath(au.csiro.pathling.fhirpath.UntypedResourcePath) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath in project pathling by aehrc.

the class ReverseResolveFunctionTest method throwsErrorIfArgumentTypeDoesNotMatchInput.

@Test
void throwsErrorIfArgumentTypeDoesNotMatchInput() {
    final ResourcePath input = new ResourcePathBuilder(spark).resourceType(ResourceType.PATIENT).expression("Patient").build();
    final BaseRuntimeChildDefinition childDefinition = fhirContext.getResourceDefinition("Encounter").getChildByName("episodeOfCare");
    final ElementDefinition definition = ElementDefinition.build(childDefinition, "episodeOfCare");
    final ElementPath argument = new ElementPathBuilder(spark).expression("Encounter.episodeOfCare").fhirType(FHIRDefinedType.REFERENCE).definition(definition).buildDefined();
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).inputExpression("Patient").build();
    final NamedFunctionInput reverseResolveInput = new NamedFunctionInput(parserContext, input, Collections.singletonList(argument));
    final NamedFunction reverseResolveFunction = NamedFunction.getInstance("reverseResolve");
    final InvalidUserInputError error = assertThrows(InvalidUserInputError.class, () -> reverseResolveFunction.invoke(reverseResolveInput));
    assertEquals("Reference in argument to reverseResolve does not support input resource type: reverseResolve(Encounter.episodeOfCare)", error.getMessage());
}
Also used : InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition) ElementDefinition(au.csiro.pathling.fhirpath.element.ElementDefinition) 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

ResourcePath (au.csiro.pathling.fhirpath.ResourcePath)46 Test (org.junit.jupiter.api.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)28 Row (org.apache.spark.sql.Row)26 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)25 FhirPath (au.csiro.pathling.fhirpath.FhirPath)23 ResourcePathBuilder (au.csiro.pathling.test.builders.ResourcePathBuilder)23 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)16 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)16 ResourceDatasetBuilder (au.csiro.pathling.test.builders.ResourceDatasetBuilder)16 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)15 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)14 Column (org.apache.spark.sql.Column)14 UntypedResourcePath (au.csiro.pathling.fhirpath.UntypedResourcePath)11 Nonnull (javax.annotation.Nonnull)11 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)8 UntypedResourcePathBuilder (au.csiro.pathling.test.builders.UntypedResourcePathBuilder)8 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)5 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)4