use of com.cerner.bunsen.spark.codes.broadcast.BroadcastableConceptMap in project bunsen by cerner.
the class BroadcastableMappingsTest method testBroadcastLatest.
@Test
public void testBroadcastLatest() {
BroadcastableConceptMap broadcastableConceptMap = broadcastLatest.getValue().getBroadcastConceptMap("uri:test:concept:map");
BroadcastableConceptMap.CodeValue value = broadcastableConceptMap.getTarget("uri:test:source:system", "abc").get(0);
Assert.assertEquals("uri:test:target:system", value.getSystem());
Assert.assertEquals("123", value.getValue());
value = broadcastableConceptMap.getTarget("uri:test:source:system", "def").get(0);
Assert.assertEquals("uri:test:target:system", value.getSystem());
Assert.assertEquals("xyz", value.getValue());
}
use of com.cerner.bunsen.spark.codes.broadcast.BroadcastableConceptMap in project bunsen by cerner.
the class BroadcastableMappingsTest method testDelegateMapping.
@Test
public void testDelegateMapping() {
BroadcastableConceptMap broadcastableConceptMap = broadcast.getValue().getBroadcastConceptMap("uri:test:concept:delegating");
BroadcastableConceptMap.CodeValue value = broadcastableConceptMap.getTarget("uri:test:source:system", "abc").get(0);
Assert.assertEquals("uri:test:target:system", value.getSystem());
Assert.assertEquals("123", value.getValue());
}
use of com.cerner.bunsen.spark.codes.broadcast.BroadcastableConceptMap in project bunsen by cerner.
the class ConceptMaps method broadcast.
@Override
public Broadcast<BroadcastableMappings> broadcast(Map<String, String> conceptMapUriToVersion) {
List<ConceptMap> mapsList = getMaps().collectAsList().stream().map(row -> (ConceptMap) conceptMapRowConverter.rowToResource(row)).collect(Collectors.toList());
Map<String, ConceptMap> mapsToLoad = mapsList.stream().filter(conceptMap -> conceptMap.getVersion().equals(conceptMapUriToVersion.get(conceptMap.getUrl()))).collect(Collectors.toMap(ConceptMap::getUrl, java.util.function.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 = 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(getMaps().sparkSession().sparkContext());
return ctx.broadcast(new BroadcastableMappings(broadcastableMaps));
}
use of com.cerner.bunsen.spark.codes.broadcast.BroadcastableConceptMap in project bunsen by cerner.
the class BroadcastableMappingsTest method testFoundMapping.
@Test
public void testFoundMapping() {
BroadcastableConceptMap broadcastableConceptMap = broadcast.getValue().getBroadcastConceptMap("uri:test:concept:map");
BroadcastableConceptMap.CodeValue value = broadcastableConceptMap.getTarget("uri:test:source:system", "abc").get(0);
Assert.assertEquals("uri:test:target:system", value.getSystem());
Assert.assertEquals("123", value.getValue());
}
Aggregations