From 0be06dc9a1a883f0c5e7b8e74bc76a704ffdb441 Mon Sep 17 00:00:00 2001 From: Piotr Szul Date: Wed, 25 Oct 2023 09:13:59 +1000 Subject: [PATCH] Adding impure results to Extract view filtrs. --- .../extract/ExtractAggregatePOCViewTest.java | 4 ++-- .../pathling/view/DefaultProjectionContext.java | 9 +++------ .../au/csiro/pathling/view/PrimitiveSelection.java | 5 +++-- .../au/csiro/pathling/view/ProjectionContext.java | 12 +++++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/fhir-server/src/test/java/au/csiro/pathling/extract/ExtractAggregatePOCViewTest.java b/fhir-server/src/test/java/au/csiro/pathling/extract/ExtractAggregatePOCViewTest.java index 1c0896eb7a..0a490bbded 100644 --- a/fhir-server/src/test/java/au/csiro/pathling/extract/ExtractAggregatePOCViewTest.java +++ b/fhir-server/src/test/java/au/csiro/pathling/extract/ExtractAggregatePOCViewTest.java @@ -172,7 +172,8 @@ static Selection optimise(@Nonnull final Selection selection) { @BeforeEach void setUp() { SharedMocks.resetAll(); - mockResource(ResourceType.PATIENT, ResourceType.CONDITION, ResourceType.OBSERVATION); + mockResource(ResourceType.PATIENT, ResourceType.CONDITION, ResourceType.OBSERVATION, + ResourceType.MEDICATIONREQUEST); } @@ -247,7 +248,6 @@ void testExtractFGPDView() { System.out.println("### Filters: ###"); filters.forEach(System.out::println); - final ExtractRequest extractRequest = ExtractRequest.fromUserInput( ResourceType.PATIENT, Optional.of(expressions), diff --git a/fhirpath/src/main/java/au/csiro/pathling/view/DefaultProjectionContext.java b/fhirpath/src/main/java/au/csiro/pathling/view/DefaultProjectionContext.java index ab3ed4d4ea..9af228a6d1 100644 --- a/fhirpath/src/main/java/au/csiro/pathling/view/DefaultProjectionContext.java +++ b/fhirpath/src/main/java/au/csiro/pathling/view/DefaultProjectionContext.java @@ -17,8 +17,6 @@ package au.csiro.pathling.view; -import static au.csiro.pathling.utilities.Strings.randomAlias; - import au.csiro.pathling.fhirpath.EvaluationContext; import au.csiro.pathling.fhirpath.FhirPath; import au.csiro.pathling.fhirpath.collection.Collection; @@ -31,7 +29,6 @@ import org.apache.spark.sql.Column; import org.apache.spark.sql.Dataset; import org.apache.spark.sql.Row; -import org.apache.spark.sql.functions; import org.hl7.fhir.r4.model.Enumerations.ResourceType; @Value @@ -41,11 +38,11 @@ public class DefaultProjectionContext implements ProjectionContext { @Nonnull @Override - public Column evalExpression(@Nonnull final FhirPath path, + public One evalExpression(@Nonnull final FhirPath path, final boolean singularise) { return singularise - ? evaluateInternal(path).getPureValue().getSingleton() - : evaluateInternal(path).getPureValue().getColumn(); + ? evaluateInternal(path).map(Collection::getSingleton) + : evaluateInternal(path).map(Collection::getColumn); } @Nonnull diff --git a/fhirpath/src/main/java/au/csiro/pathling/view/PrimitiveSelection.java b/fhirpath/src/main/java/au/csiro/pathling/view/PrimitiveSelection.java index df53fe5949..26bf4ab726 100644 --- a/fhirpath/src/main/java/au/csiro/pathling/view/PrimitiveSelection.java +++ b/fhirpath/src/main/java/au/csiro/pathling/view/PrimitiveSelection.java @@ -23,6 +23,7 @@ import java.util.function.Function; import java.util.stream.Stream; import javax.annotation.Nonnull; +import au.csiro.pathling.view.DatasetResult.One; import lombok.AllArgsConstructor; import lombok.Value; import org.apache.spark.sql.Column; @@ -60,8 +61,8 @@ public PrimitiveSelection(@Nonnull final FhirPath path, @Override public DatasetResult evaluate(@Nonnull final ProjectionContext context) { - final Column resultColumn = context.evalExpression(path, !asCollection); - return DatasetResult.pureOne(alias.map(resultColumn::alias).orElse(resultColumn)); + final One resultColumn = context.evalExpression(path, !asCollection); + return alias.map(a -> resultColumn.map(c -> c.as(a))).orElse(resultColumn); } @Override diff --git a/fhirpath/src/main/java/au/csiro/pathling/view/ProjectionContext.java b/fhirpath/src/main/java/au/csiro/pathling/view/ProjectionContext.java index fc4457b2c9..710a649748 100644 --- a/fhirpath/src/main/java/au/csiro/pathling/view/ProjectionContext.java +++ b/fhirpath/src/main/java/au/csiro/pathling/view/ProjectionContext.java @@ -71,7 +71,7 @@ default One subContext( * @return the result as a column */ @Nonnull - Column evalExpression(@Nonnull final FhirPath path, final boolean singularise); + One evalExpression(@Nonnull final FhirPath path, final boolean singularise); /** @@ -81,7 +81,7 @@ default One subContext( * @return the result as a column */ @Nonnull - default Column evalExpression(@Nonnull final FhirPath path) { + default One evalExpression(@Nonnull final FhirPath path) { return evalExpression(path, true); } @@ -95,9 +95,10 @@ default Column evalExpression(@Nonnull final FhirPath path) { * @return the result as a column */ @Nonnull - default Column evalExpression(@Nonnull final FhirPath path, final boolean singularise, + default One evalExpression(@Nonnull final FhirPath path, + final boolean singularise, @Nonnull final String alias) { - return evalExpression(path, singularise).as(alias); + return evalExpression(path, singularise).map(c -> c.as(alias)); } /** @@ -109,7 +110,8 @@ default Column evalExpression(@Nonnull final FhirPath path, final bo * @return the result as a column */ @Nonnull - default Column evalExpression(@Nonnull final FhirPath path, final boolean singularise, + default One evalExpression(@Nonnull final FhirPath path, + final boolean singularise, @Nonnull final Optional maybeAlias) { return maybeAlias.map(alias -> evalExpression(path, singularise, alias))