use of au.csiro.pathling.fhirpath.encoding.SimpleCodingsDecoders in project pathling by aehrc.
the class SubsumesFunction method invoke.
@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
validateInput(input);
final NonLiteralPath inputFhirPath = input.getInput();
final Dataset<Row> idAndCodingSet = createJoinedDataset(input.getInput(), input.getArguments().get(0));
// Process the subsumption operation per partition, adding a result column to the dataset.
final Column codingPairCol = struct(idAndCodingSet.col(COL_INPUT_CODINGS), idAndCodingSet.col(COL_ARG_CODINGS));
@SuppressWarnings({ "OptionalGetWithoutIsPresent", "TypeMayBeWeakened" }) final SubsumptionMapperWithPreview mapper = new SubsumptionMapperWithPreview(MDC.get("requestId"), input.getContext().getTerminologyServiceFactory().get(), inverted);
final Dataset<Row> resultDataset = SqlExtensions.mapWithPartitionPreview(idAndCodingSet, codingPairCol, SimpleCodingsDecoders::decodeListPair, mapper, StructField.apply("result", DataTypes.BooleanType, true, Metadata.empty()));
final Column resultColumn = col("result");
// Construct a new result expression.
final String expression = expressionFromInput(input, functionName);
return ElementPath.build(expression, resultDataset, inputFhirPath.getIdColumn(), inputFhirPath.getEidColumn(), resultColumn, inputFhirPath.isSingular(), inputFhirPath.getCurrentResource(), inputFhirPath.getThisColumn(), FHIRDefinedType.BOOLEAN);
}
use of au.csiro.pathling.fhirpath.encoding.SimpleCodingsDecoders in project pathling by aehrc.
the class TranslateFunction method invoke.
@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
validateInput(input);
final ElementPath inputPath = (ElementPath) input.getInput();
final ParserContext inputContext = input.getContext();
final Column idColumn = inputPath.getIdColumn();
final Column conceptColumn = inputPath.getValueColumn();
final boolean isCodeableConcept = isCodeableConcept(inputPath);
final Column codingArrayCol = isCodeableConcept ? conceptColumn.getField("coding") : when(conceptColumn.isNotNull(), array(conceptColumn)).otherwise(lit(null));
// The definition of the result is always the Coding element.
@SuppressWarnings("OptionalGetWithoutIsPresent") final ElementDefinition resultDefinition = isCodeableConcept ? inputPath.getChildElement("coding").get() : inputPath.getDefinition().get();
// Prepare the data which will be used within the map operation. All of these things must be
// Serializable.
@SuppressWarnings("OptionalGetWithoutIsPresent") final TerminologyServiceFactory terminologyServiceFactory = inputContext.getTerminologyServiceFactory().get();
final Arguments arguments = Arguments.of(input);
final String conceptMapUrl = arguments.getValue(0, String.class);
final boolean reverse = arguments.getValueOr(1, DEFAULT_REVERSE);
final String equivalence = arguments.getValueOr(2, DEFAULT_EQUIVALENCE);
final Dataset<Row> dataset = inputPath.getDataset();
final MapperWithPreview<List<SimpleCoding>, Row[], ConceptTranslator> mapper = new TranslateMapperWithPreview(MDC.get("requestId"), terminologyServiceFactory, conceptMapUrl, reverse, Strings.parseCsvList(equivalence, wrapInUserInputError(ConceptMapEquivalence::fromCode)));
final Dataset<Row> translatedDataset = SqlExtensions.mapWithPartitionPreview(dataset, codingArrayCol, SimpleCodingsDecoders::decodeList, mapper, StructField.apply("result", DataTypes.createArrayType(CodingEncoding.DATA_TYPE), true, Metadata.empty()));
// The result is an array of translations per each input element, which we now
// need to explode in the same way as for path traversal, creating unique element ids.
final MutablePair<Column, Column> valueAndEidColumns = new MutablePair<>();
final Dataset<Row> resultDataset = inputPath.explodeArray(translatedDataset, translatedDataset.col("result"), valueAndEidColumns);
// Construct a new result expression.
final String expression = expressionFromInput(input, NAME);
return ElementPath.build(expression, resultDataset, idColumn, Optional.of(valueAndEidColumns.getRight()), valueAndEidColumns.getLeft(), false, inputPath.getCurrentResource(), inputPath.getThisColumn(), resultDefinition);
}
use of au.csiro.pathling.fhirpath.encoding.SimpleCodingsDecoders in project pathling by aehrc.
the class MemberOfFunction method invoke.
@Nonnull
@Override
public FhirPath invoke(@Nonnull final NamedFunctionInput input) {
validateInput(input);
final ElementPath inputPath = (ElementPath) input.getInput();
final StringLiteralPath argument = (StringLiteralPath) input.getArguments().get(0);
final ParserContext inputContext = input.getContext();
final Column idColumn = inputPath.getIdColumn();
final Column conceptColumn = inputPath.getValueColumn();
final Column codingArrayCol = (isCodeableConcept(inputPath)) ? conceptColumn.getField("coding") : when(conceptColumn.isNotNull(), array(conceptColumn)).otherwise(lit(null));
// Prepare the data which will be used within the map operation. All of these things must be
// Serializable.
@SuppressWarnings("OptionalGetWithoutIsPresent") final TerminologyServiceFactory terminologyServiceFactory = inputContext.getTerminologyServiceFactory().get();
final String valueSetUri = argument.getJavaValue();
final Dataset<Row> dataset = inputPath.getDataset();
// Perform a validate code operation on each Coding or CodeableConcept in the input dataset,
// then create a new dataset with the boolean results.
final MapperWithPreview<List<SimpleCoding>, Boolean, Set<SimpleCoding>> mapper = new MemberOfMapperWithPreview(MDC.get("requestId"), terminologyServiceFactory, valueSetUri);
// This de-duplicates the Codings to be validated, then performs the validation on a
// per-partition basis.
final Dataset<Row> resultDataset = SqlExtensions.mapWithPartitionPreview(dataset, codingArrayCol, SimpleCodingsDecoders::decodeList, mapper, StructField.apply("result", DataTypes.BooleanType, true, Metadata.empty()));
final Column resultColumn = col("result");
// Construct a new result expression.
final String expression = expressionFromInput(input, NAME);
return ElementPath.build(expression, resultDataset, idColumn, inputPath.getEidColumn(), resultColumn, inputPath.isSingular(), inputPath.getCurrentResource(), inputPath.getThisColumn(), FHIRDefinedType.BOOLEAN);
}
Aggregations