Skip to content

Commit

Permalink
Adding impure results to Extract view filtrs.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrszul committed Oct 24, 2023
1 parent 7d311a4 commit 0be06dc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -41,11 +38,11 @@ public class DefaultProjectionContext implements ProjectionContext {

@Nonnull
@Override
public Column evalExpression(@Nonnull final FhirPath<Collection> path,
public One<Column> evalExpression(@Nonnull final FhirPath<Collection> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,8 +61,8 @@ public PrimitiveSelection(@Nonnull final FhirPath<Collection> path,

@Override
public DatasetResult<Column> evaluate(@Nonnull final ProjectionContext context) {
final Column resultColumn = context.evalExpression(path, !asCollection);
return DatasetResult.pureOne(alias.map(resultColumn::alias).orElse(resultColumn));
final One<Column> resultColumn = context.evalExpression(path, !asCollection);
return alias.map(a -> resultColumn.map(c -> c.as(a))).orElse(resultColumn);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ default One<ProjectionContext> subContext(
* @return the result as a column
*/
@Nonnull
Column evalExpression(@Nonnull final FhirPath<Collection> path, final boolean singularise);
One<Column> evalExpression(@Nonnull final FhirPath<Collection> path, final boolean singularise);


/**
Expand All @@ -81,7 +81,7 @@ default One<ProjectionContext> subContext(
* @return the result as a column
*/
@Nonnull
default Column evalExpression(@Nonnull final FhirPath<Collection> path) {
default One<Column> evalExpression(@Nonnull final FhirPath<Collection> path) {
return evalExpression(path, true);
}

Expand All @@ -95,9 +95,10 @@ default Column evalExpression(@Nonnull final FhirPath<Collection> path) {
* @return the result as a column
*/
@Nonnull
default Column evalExpression(@Nonnull final FhirPath<Collection> path, final boolean singularise,
default One<Column> evalExpression(@Nonnull final FhirPath<Collection> path,
final boolean singularise,
@Nonnull final String alias) {
return evalExpression(path, singularise).as(alias);
return evalExpression(path, singularise).map(c -> c.as(alias));
}

/**
Expand All @@ -109,7 +110,8 @@ default Column evalExpression(@Nonnull final FhirPath<Collection> path, final bo
* @return the result as a column
*/
@Nonnull
default Column evalExpression(@Nonnull final FhirPath<Collection> path, final boolean singularise,
default One<Column> evalExpression(@Nonnull final FhirPath<Collection> path,
final boolean singularise,
@Nonnull final
Optional<String> maybeAlias) {
return maybeAlias.map(alias -> evalExpression(path, singularise, alias))
Expand Down

0 comments on commit 0be06dc

Please sign in to comment.