Search in sources :

Example 1 with FilterFunction

use of org.apache.spark.api.java.function.FilterFunction in project bunsen by cerner.

the class ConceptMaps method getMappings.

/**
 * Returns a dataset with the mappings for each uri and version.
 *
 * @param uriToVersion a map of concept map URI to the version to load
 * @return a dataset of mappings for the given URIs and versions.
 */
public Dataset<Mapping> getMappings(Map<String, String> uriToVersion) {
    JavaSparkContext context = new JavaSparkContext(this.spark.sparkContext());
    Broadcast<Map<String, String>> broadcastMaps = context.broadcast(uriToVersion);
    return this.mappings.filter((FilterFunction<Mapping>) mapping -> {
        String latestVersion = broadcastMaps.getValue().get(mapping.getConceptMapUri());
        return latestVersion != null && latestVersion.equals(mapping.getConceptMapVersion());
    });
}
Also used : Arrays(java.util.Arrays) Dataset(org.apache.spark.sql.Dataset) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) ArrayList(java.util.ArrayList) FhirContext(ca.uhn.fhir.context.FhirContext) NoSuchTableException(org.apache.spark.sql.catalyst.analysis.NoSuchTableException) Map(java.util.Map) org.apache.spark.sql.functions.lit(org.apache.spark.sql.functions.lit) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) IParser(ca.uhn.fhir.parser.IParser) JavaRDD(org.apache.spark.api.java.JavaRDD) MapFunction(org.apache.spark.api.java.function.MapFunction) SparkSession(org.apache.spark.sql.SparkSession) Broadcast(org.apache.spark.broadcast.Broadcast) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent) SaveMode(org.apache.spark.sql.SaveMode) Iterator(java.util.Iterator) Timestamp(java.sql.Timestamp) UriType(org.hl7.fhir.dstu3.model.UriType) Set(java.util.Set) Row(org.apache.spark.sql.Row) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) Encoders(org.apache.spark.sql.Encoders) FhirEncoders(com.cerner.bunsen.FhirEncoders) List(java.util.List) Encoder(org.apache.spark.sql.Encoder) org.apache.spark.sql.functions.col(org.apache.spark.sql.functions.col) FHIRException(org.hl7.fhir.exceptions.FHIRException) Pattern(java.util.regex.Pattern) Function(org.apache.spark.api.java.function.Function) org.apache.spark.sql.functions(org.apache.spark.sql.functions) FilterFunction(org.apache.spark.api.java.function.FilterFunction) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Map(java.util.Map) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap)

Example 2 with FilterFunction

use of org.apache.spark.api.java.function.FilterFunction in project bunsen by cerner.

the class ValueSets method getValues.

/**
 * Returns a dataset with the values for each element in the map of uri to version.
 *
 * @param uriToVersion a map of value set URI to the version to load
 * @return a dataset of values for the given URIs and versions.
 */
public Dataset<Value> getValues(Map<String, String> uriToVersion) {
    JavaSparkContext context = new JavaSparkContext(this.spark.sparkContext());
    Broadcast<Map<String, String>> broadcastUrisToVersion = context.broadcast(uriToVersion);
    return this.values.filter((FilterFunction<Value>) value -> {
        String latestVersion = broadcastUrisToVersion.getValue().get(value.getValueSetUri());
        return latestVersion != null && latestVersion.equals(value.getValueSetVersion());
    });
}
Also used : Arrays(java.util.Arrays) Dataset(org.apache.spark.sql.Dataset) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) ArrayList(java.util.ArrayList) FhirContext(ca.uhn.fhir.context.FhirContext) NoSuchTableException(org.apache.spark.sql.catalyst.analysis.NoSuchTableException) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) Map(java.util.Map) org.apache.spark.sql.functions.lit(org.apache.spark.sql.functions.lit) IParser(ca.uhn.fhir.parser.IParser) JavaRDD(org.apache.spark.api.java.JavaRDD) MapFunction(org.apache.spark.api.java.function.MapFunction) SparkSession(org.apache.spark.sql.SparkSession) Broadcast(org.apache.spark.broadcast.Broadcast) SaveMode(org.apache.spark.sql.SaveMode) Iterator(java.util.Iterator) Timestamp(java.sql.Timestamp) Set(java.util.Set) Row(org.apache.spark.sql.Row) Tuple2(scala.Tuple2) Collectors(java.util.stream.Collectors) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent) Encoders(org.apache.spark.sql.Encoders) FhirEncoders(com.cerner.bunsen.FhirEncoders) List(java.util.List) Encoder(org.apache.spark.sql.Encoder) org.apache.spark.sql.functions.col(org.apache.spark.sql.functions.col) Pattern(java.util.regex.Pattern) Function(org.apache.spark.api.java.function.Function) FilterFunction(org.apache.spark.api.java.function.FilterFunction) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) Map(java.util.Map)

Aggregations

FhirContext (ca.uhn.fhir.context.FhirContext)2 IParser (ca.uhn.fhir.parser.IParser)2 FhirEncoders (com.cerner.bunsen.FhirEncoders)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 JavaRDD (org.apache.spark.api.java.JavaRDD)2 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)2 FilterFunction (org.apache.spark.api.java.function.FilterFunction)2 Function (org.apache.spark.api.java.function.Function)2 MapFunction (org.apache.spark.api.java.function.MapFunction)2 Broadcast (org.apache.spark.broadcast.Broadcast)2 Dataset (org.apache.spark.sql.Dataset)2 Encoder (org.apache.spark.sql.Encoder)2