Search in sources :

Example 1 with CodingPath

use of au.csiro.pathling.fhirpath.element.CodingPath 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 2 with CodingPath

use of au.csiro.pathling.fhirpath.element.CodingPath in project pathling by aehrc.

the class SubsumesFunctionTest method createNullCodingInput.

CodingPath createNullCodingInput() {
    final Dataset<Row> dataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withIdEidValueRows(ALL_RES_IDS, id -> null, id -> null).withStructTypeColumns(codingStructType()).buildWithStructValue();
    final ElementPath argument = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODING).dataset(dataset).idAndEidAndValueColumns().build();
    return (CodingPath) argument;
}
Also used : CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder)

Example 3 with CodingPath

use of au.csiro.pathling.fhirpath.element.CodingPath in project pathling by aehrc.

the class SubsumesFunctionTest method createEmptyCodingInput.

CodingPath createEmptyCodingInput() {
    final Dataset<Row> dataset = new DatasetBuilder(spark).withIdColumn().withEidColumn().withStructTypeColumns(codingStructType()).buildWithStructValue();
    final ElementPath argument = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODING).dataset(dataset).idAndEidAndValueColumns().build();
    return (CodingPath) argument;
}
Also used : CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder)

Example 4 with CodingPath

use of au.csiro.pathling.fhirpath.element.CodingPath in project pathling by aehrc.

the class SubsumesFunctionTest method createSingularCodingInput.

CodingPath createSingularCodingInput() {
    final Dataset<Row> dataset = new DatasetBuilder(spark).withIdColumn().withStructTypeColumns(codingStructType()).withRow(RES_ID1, rowFromCoding(CODING_SMALL)).withRow(RES_ID2, rowFromCoding(CODING_MEDIUM)).withRow(RES_ID3, rowFromCoding(CODING_LARGE)).withRow(RES_ID4, rowFromCoding(CODING_OTHER1)).withRow(RES_ID5, null).buildWithStructValue();
    final ElementPath inputExpression = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODING).dataset(dataset).idAndValueColumns().singular(true).build();
    return (CodingPath) inputExpression;
}
Also used : CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder)

Example 5 with CodingPath

use of au.csiro.pathling.fhirpath.element.CodingPath in project pathling by aehrc.

the class SubsumesFunctionTest method createNullCodingArg.

CodingPath createNullCodingArg() {
    final Dataset<Row> dataset = new DatasetBuilder(spark).withIdColumn().withStructTypeColumns(codingStructType()).withIdValueRows(ALL_RES_IDS, id -> null).buildWithStructValue();
    final ElementPath argument = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODING).dataset(dataset).idAndValueColumns().build();
    return (CodingPath) argument;
}
Also used : DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanPath(au.csiro.pathling.fhirpath.element.BooleanPath) FhirContext(ca.uhn.fhir.context.FhirContext) Tag(org.junit.jupiter.api.Tag) Assertions.assertThat(au.csiro.pathling.test.assertions.Assertions.assertThat) DataTypes(org.apache.spark.sql.types.DataTypes) SparkHelpers.codingStructType(au.csiro.pathling.test.helpers.SparkHelpers.codingStructType) ElementPathAssertion(au.csiro.pathling.test.assertions.ElementPathAssertion) FHIRDefinedType(org.hl7.fhir.r4.model.Enumerations.FHIRDefinedType) SparkHelpers.codeableConceptStructType(au.csiro.pathling.test.helpers.SparkHelpers.codeableConceptStructType) CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Test(org.junit.jupiter.api.Test) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CodingLiteralPath(au.csiro.pathling.fhirpath.literal.CodingLiteralPath) StringLiteralPath(au.csiro.pathling.fhirpath.literal.StringLiteralPath) RelationBuilder(au.csiro.pathling.test.fixtures.RelationBuilder) Coding(org.hl7.fhir.r4.model.Coding) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Dataset(org.apache.spark.sql.Dataset) NonLiteralPath(au.csiro.pathling.fhirpath.NonLiteralPath) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) SparkHelpers.rowFromCoding(au.csiro.pathling.test.helpers.SparkHelpers.rowFromCoding) NamedFunctionInput(au.csiro.pathling.fhirpath.function.NamedFunctionInput) DatasetAssert(au.csiro.pathling.test.assertions.DatasetAssert) NamedFunction(au.csiro.pathling.fhirpath.function.NamedFunction) Relation(au.csiro.pathling.terminology.Relation) TerminologyServiceFactory(au.csiro.pathling.fhir.TerminologyServiceFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InvalidUserInputError(au.csiro.pathling.errors.InvalidUserInputError) Nonnull(javax.annotation.Nonnull) TerminologyService(au.csiro.pathling.terminology.TerminologyService) SparkSession(org.apache.spark.sql.SparkSession) Mockito.when(org.mockito.Mockito.when) Row(org.apache.spark.sql.Row) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) SparkHelpers.rowFromCodeableConcept(au.csiro.pathling.test.helpers.SparkHelpers.rowFromCodeableConcept) FhirPath(au.csiro.pathling.fhirpath.FhirPath) SharedMocks(au.csiro.pathling.test.SharedMocks) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) DatasetBuilder.makeEid(au.csiro.pathling.test.builders.DatasetBuilder.makeEid) Collections(java.util.Collections) CodingPath(au.csiro.pathling.fhirpath.element.CodingPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ElementPathBuilder(au.csiro.pathling.test.builders.ElementPathBuilder)

Aggregations

CodingPath (au.csiro.pathling.fhirpath.element.CodingPath)9 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)9 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)9 Row (org.apache.spark.sql.Row)9 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)6 FhirPath (au.csiro.pathling.fhirpath.FhirPath)5 NamedFunctionInput (au.csiro.pathling.fhirpath.function.NamedFunctionInput)5 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)5 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SparkHelpers.rowFromCoding (au.csiro.pathling.test.helpers.SparkHelpers.rowFromCoding)3 Coding (org.hl7.fhir.r4.model.Coding)3 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)2 TerminologyServiceFactory (au.csiro.pathling.fhir.TerminologyServiceFactory)2 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)2 BooleanPath (au.csiro.pathling.fhirpath.element.BooleanPath)2 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)2 NamedFunction (au.csiro.pathling.fhirpath.function.NamedFunction)2