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