Search in sources :

Example 21 with ResourcePath

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

the class CombineOperatorTest method setUp.

@BeforeEach
void setUp() {
    final Dataset<Row> input = new DatasetBuilder(spark).withIdColumn().withColumn(DataTypes.BooleanType).withIdsAndValue(null, Arrays.asList("observation-1", "observation-2", "observation-3")).build();
    final ResourcePath inputContext = new ResourcePathBuilder(spark).resourceType(ResourceType.OBSERVATION).dataset(input).idAndValueColumns().buildCustom();
    parserContext = new ParserContextBuilder(spark, fhirContext).inputContext(inputContext).build();
    idColumnName = parserContext.getInputContext().getIdColumn().toString();
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ResourcePathBuilder(au.csiro.pathling.test.builders.ResourcePathBuilder) Row(org.apache.spark.sql.Row) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with ResourcePath

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

the class PathTraversalOperatorTest method testExtensionTraversalOnResources.

@Test
void testExtensionTraversalOnResources() {
    final Dataset<Row> patientDataset = new ResourceDatasetBuilder(spark).withIdColumn().withColumn("gender", DataTypes.StringType).withColumn("active", DataTypes.BooleanType).withFidColumn().withExtensionColumn().withRow("patient-1", "female", true, 1, ImmutableMap.builder().put(1, Arrays.asList(MANY_EXT_ROW_1, MANY_EXT_ROW_2)).build()).withRow("patient-2", "female", false, 1, ImmutableMap.builder().put(1, Collections.singletonList(MANY_EXT_ROW_1)).put(2, Collections.singletonList(MANY_EXT_ROW_2)).build()).withRow("patient-3", "male", false, 1, oneEntryMap(2, ONE_MY_EXTENSION)).withRow("patient-4", "male", false, 1, nullEntryMap(1)).withRow("patient-5", "male", true, 1, null).build();
    when(database.read(ResourceType.PATIENT)).thenReturn(patientDataset);
    final ResourcePath left = ResourcePath.build(fhirContext, database, ResourceType.PATIENT, "Patient", false);
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
    final PathTraversalInput input = new PathTraversalInput(parserContext, left, "extension");
    final FhirPath result = new PathTraversalOperator().invoke(input);
    assertThat(result).hasExpression("Patient.extension").isNotSingular().isElementPath(ElementPath.class).hasFhirType(FHIRDefinedType.EXTENSION).selectOrderedResult().hasRows(// Many many extensions for this resource _fix
    RowFactory.create("patient-1", MANY_EXT_ROW_1), RowFactory.create("patient-1", MANY_EXT_ROW_2), // One extension with matching _fid and some with other fids
    RowFactory.create("patient-2", MANY_EXT_ROW_1), // Not extensions with matching _fid
    RowFactory.create("patient-3", null), // Empty list of extension for matching _fix
    RowFactory.create("patient-4", null), // No extensions present all together (empty extension map)
    RowFactory.create("patient-5", null));
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) FhirPath(au.csiro.pathling.fhirpath.FhirPath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) Row(org.apache.spark.sql.Row) ParserContext(au.csiro.pathling.fhirpath.parser.ParserContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with ResourcePath

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

the class PathTraversalOperatorTest method testExtensionTraversalOnElements.

@Test
void testExtensionTraversalOnElements() {
    final Map<Object, Object> manyToFidZeroMap = ImmutableMap.builder().put(0, Arrays.asList(MANY_EXT_ROW_1, MANY_EXT_ROW_2)).build();
    final ImmutableMap<Object, Object> onePerFidZeroAndOneMap = ImmutableMap.builder().put(0, Collections.singletonList(MANY_EXT_ROW_1)).put(1, Collections.singletonList(MANY_EXT_ROW_2)).build();
    // Construct element dataset from the resource dataset so that the resource path can be used as
    // the current resource for this element path.
    // Note: this resource path is not singular as this will be a base for elements.
    final Dataset<Row> resourceLikeDataset = new ResourceDatasetBuilder(spark).withIdColumn().withEidColumn().withStructColumn("name", DataTypes.StringType).withStructColumn("_fid", DataTypes.IntegerType).withStructValueColumn().withExtensionColumn().withRow("observation-1", makeEid(0), RowFactory.create("name1", 0), manyToFidZeroMap).withRow("observation-2", makeEid(0), RowFactory.create("name2-1", 0), onePerFidZeroAndOneMap).withRow("observation-2", makeEid(1), RowFactory.create("name2-2", 1), onePerFidZeroAndOneMap).withRow("observation-3", makeEid(0), RowFactory.create("name3", 0), oneEntryMap(2, ONE_MY_EXTENSION)).withRow("observation-4", makeEid(0), RowFactory.create("name4", 0), nullEntryMap(1)).withRow("observation-5", makeEid(0), RowFactory.create("name5", 0), null).build();
    when(database.read(ResourceType.OBSERVATION)).thenReturn(resourceLikeDataset);
    final ResourcePath baseResourcePath = ResourcePath.build(fhirContext, database, ResourceType.OBSERVATION, "Observation", false);
    final Dataset<Row> elementDataset = toElementDataset(resourceLikeDataset, baseResourcePath);
    final ElementDefinition codeDefinition = checkPresent(FhirHelpers.getChildOfResource(fhirContext, "Observation", "code"));
    final ElementPath left = new ElementPathBuilder(spark).fhirType(FHIRDefinedType.CODEABLECONCEPT).definition(codeDefinition).dataset(elementDataset).idAndEidAndValueColumns().expression("code").singular(false).currentResource(baseResourcePath).buildDefined();
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).build();
    final PathTraversalInput input = new PathTraversalInput(parserContext, left, "extension");
    final FhirPath result = new PathTraversalOperator().invoke(input);
    final Dataset<Row> expectedResult = new DatasetBuilder(spark).withIdColumn().withEidColumn().withStructTypeColumns(DatasetBuilder.SIMPLE_EXTENSION_TYPE).withRow("observation-1", makeEid(0, 0), MANY_EXT_ROW_1).withRow("observation-1", makeEid(0, 1), MANY_EXT_ROW_2).withRow("observation-2", makeEid(0, 0), MANY_EXT_ROW_1).withRow("observation-2", makeEid(1, 0), MANY_EXT_ROW_2).withRow("observation-3", makeEid(0, 0), null).withRow("observation-4", makeEid(0, 0), null).withRow("observation-5", makeEid(0, 0), null).buildWithStructValue();
    assertThat(result).hasExpression("code.extension").isNotSingular().isElementPath(ElementPath.class).hasFhirType(FHIRDefinedType.EXTENSION).selectOrderedResultWithEid().hasRows(expectedResult);
}
Also used : FhirPath(au.csiro.pathling.fhirpath.FhirPath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) ElementPath(au.csiro.pathling.fhirpath.element.ElementPath) ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) Row(org.apache.spark.sql.Row) ElementDefinition(au.csiro.pathling.fhirpath.element.ElementDefinition) DatasetBuilder(au.csiro.pathling.test.builders.DatasetBuilder) ResourceDatasetBuilder(au.csiro.pathling.test.builders.ResourceDatasetBuilder) 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 24 with ResourcePath

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

the class AbstractParserTest method assertThatResultOf.

@SuppressWarnings("SameParameterValue")
@Nonnull
protected FhirPathAssertion assertThatResultOf(@Nonnull final ResourceType resourceType, @Nonnull final String expression) {
    final ResourcePath subjectResource = ResourcePath.build(fhirContext, database, resourceType, resourceType.toCode(), true);
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).terminologyClientFactory(terminologyServiceFactory).database(database).inputContext(subjectResource).build();
    final Parser resourceParser = new Parser(parserContext);
    return assertThat(resourceParser.parse(expression));
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) Nonnull(javax.annotation.Nonnull)

Example 25 with ResourcePath

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

the class AbstractParserTest method setUp.

@BeforeEach
void setUp() {
    SharedMocks.resetAll();
    mockResource(ResourceType.PATIENT, ResourceType.CONDITION, ResourceType.ENCOUNTER, ResourceType.PROCEDURE, ResourceType.MEDICATIONREQUEST, ResourceType.OBSERVATION, ResourceType.DIAGNOSTICREPORT, ResourceType.ORGANIZATION, ResourceType.QUESTIONNAIRE, ResourceType.CAREPLAN);
    final ResourcePath subjectResource = ResourcePath.build(fhirContext, database, ResourceType.PATIENT, ResourceType.PATIENT.toCode(), true);
    final ParserContext parserContext = new ParserContextBuilder(spark, fhirContext).terminologyClientFactory(terminologyServiceFactory).database(database).inputContext(subjectResource).groupingColumns(Collections.singletonList(subjectResource.getIdColumn())).build();
    parser = new Parser(parserContext);
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) ParserContextBuilder(au.csiro.pathling.test.builders.ParserContextBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

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