use of com.cerner.bunsen.codes.ConceptMaps in project bunsen by cerner.
the class BroadcastableMappings method broadcast.
/**
* Broadcasts the given set of concept maps.
*
* @param spark the spark session.
* @param conceptMaps the FHIR ConceptMaps to broadcast
* @return a broadcast variable containing a mappings object usable in UDFs.
*/
public static Broadcast<BroadcastableMappings> broadcast(SparkSession spark, List<ConceptMap> conceptMaps) {
ConceptMaps mapData = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMaps);
Map<String, String> conceptMapUris = conceptMaps.stream().collect(Collectors.toMap(ConceptMap::getUrl, ConceptMap::getVersion));
return broadcast(mapData, conceptMapUris);
}
use of com.cerner.bunsen.codes.ConceptMaps in project bunsen by cerner.
the class BroadcastableMappings method broadcast.
/**
* Broadcast mappings stored in the given conceptMaps instance that match the given
* conceptMapUris.
*
* @param conceptMaps the {@link ConceptMaps} instance with the content to broadcast
* @param conceptMapUriToVersion map of the concept map URIs to broadcast to their versions.
* @return a broadcast variable containing a mappings object usable in UDFs.
*/
public static Broadcast<BroadcastableMappings> broadcast(ConceptMaps conceptMaps, Map<String, String> conceptMapUriToVersion) {
Map<String, ConceptMap> mapsToLoad = conceptMaps.getMaps().collectAsList().stream().filter(conceptMap -> conceptMap.getVersion().equals(conceptMapUriToVersion.get(conceptMap.getUrl()))).collect(Collectors.toMap(ConceptMap::getUrl, Function.identity()));
// Expand the concept maps to load and sort them so dependencies are before
// their dependents in the list.
List<String> sortedMapsToLoad = sortMapsToLoad(conceptMapUriToVersion.keySet(), mapsToLoad);
// Since this is used to map from one system to another, we use only targets
// that don't introduce inaccurate meanings. (For instance, we can't map
// general condition code to a more specific type, since that is not
// representative of the source data.)
Dataset<Mapping> mappings = conceptMaps.getMappings(conceptMapUriToVersion).filter("equivalence in ('equivalent', 'equals', 'wider', 'subsumes')");
// Group mappings by their concept map URI
Map<String, List<Mapping>> groupedMappings = mappings.collectAsList().stream().collect(Collectors.groupingBy(Mapping::getConceptMapUri));
Map<String, BroadcastableConceptMap> broadcastableMaps = new HashMap<>();
for (String conceptMapUri : sortedMapsToLoad) {
ConceptMap map = mapsToLoad.get(conceptMapUri);
Set<String> children = getMapChildren(map);
List<BroadcastableConceptMap> childMaps = children.stream().map(child -> broadcastableMaps.get(child)).collect(Collectors.toList());
BroadcastableConceptMap broadcastableConceptMap = new BroadcastableConceptMap(conceptMapUri, groupedMappings.getOrDefault(conceptMapUri, Collections.emptyList()), childMaps);
broadcastableMaps.put(conceptMapUri, broadcastableConceptMap);
}
JavaSparkContext ctx = new JavaSparkContext(conceptMaps.getMaps().sparkSession().sparkContext());
return ctx.broadcast(new BroadcastableMappings(broadcastableMaps));
}
Aggregations