use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class ConceptMapsTest method testExpandMappings.
@Test
public void testExpandMappings() {
ConceptMap conceptMap = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap("urn:cerner:conceptmap:map", "1")).getConceptMap("urn:cerner:conceptmap:map", "1");
List<Mapping> mappings = ConceptMaps.expandMappings(conceptMap);
Mapping expectedValue = new Mapping("urn:cerner:conceptmap:map", "1", "urn:source:valueset", "urn:target:valueset", "urn:source:system", "urn:source:code:a", "urn:target:system", "urn:target:code:1", Mapping.EQUIVALENT);
Assert.assertEquals(1, mappings.size());
Assert.assertEquals(expectedValue, mappings.get(0));
}
use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class ConceptMapsTest method testWithMapsFromDirectoryXml.
@Test
public void testWithMapsFromDirectoryXml() {
ConceptMaps maps = ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/xml/conceptmaps");
ConceptMap genderMap = maps.getConceptMap("urn:cerner:poprec:fhir:conceptmap:demographics:gender", "0.0.1");
Assert.assertNotNull(genderMap);
Assert.assertEquals("urn:cerner:poprec:fhir:conceptmap:demographics:gender", genderMap.getUrl());
Assert.assertEquals("0.0.1", genderMap.getVersion());
}
use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class ConceptMapsTest method testWriteToNewTables.
@Test
public void testWriteToNewTables() {
spark.sql("create database test_mapping_write");
ConceptMaps maps = ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/xml/conceptmaps");
maps.writeToDatabase("test_mapping_write");
ConceptMaps reloadedMaps = ConceptMaps.getFromDatabase(spark, "test_mapping_write");
ConceptMap genderMap = reloadedMaps.getConceptMap("urn:cerner:poprec:fhir:conceptmap:demographics:gender", "0.0.1");
Assert.assertNotNull(genderMap);
Assert.assertEquals("urn:cerner:poprec:fhir:conceptmap:demographics:gender", genderMap.getUrl());
Assert.assertEquals("0.0.1", genderMap.getVersion());
Assert.assertEquals(3, genderMap.getGroup().size());
}
use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class BroadcastableMappingsTest method setUp.
/**
* Sets up Spark and concept maps for testing.
*/
@BeforeClass
public static void setUp() {
spark = SparkSession.builder().master("local[2]").appName("BroadcastableMappingsTest").getOrCreate();
ConceptMap conceptMap = new ConceptMap();
conceptMap.setUrl("uri:test:concept:map").setVersion("0").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
ConceptMapGroupComponent group = conceptMap.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system");
group.addElement().setCode("abc").addTarget().setCode("123");
group.addElement().setCode("def").addTarget().setCode("456");
ConceptMap delegatingMap = new ConceptMap();
delegatingMap.setUrl("uri:test:concept:delegating").setVersion("0").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
delegatingMap.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system").setUnmapped(new ConceptMapGroupUnmappedComponent().setMode(ConceptMapGroupUnmappedMode.OTHERMAP).setUrl("uri:test:concept:map"));
broadcast = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap, delegatingMap).broadcast(ImmutableMap.of("uri:test:concept:map", "0", "uri:test:concept:delegating", "0"));
ConceptMap conceptMapLatest = new ConceptMap();
conceptMapLatest.setUrl("uri:test:concept:map").setVersion("1").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
ConceptMapGroupComponent groupLatest = conceptMapLatest.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system");
groupLatest.addElement().setCode("abc").addTarget().setCode("123");
groupLatest.addElement().setCode("def").addTarget().setCode("xyz");
ConceptMaps maps = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap, conceptMapLatest);
broadcastLatest = maps.broadcast(maps.getLatestVersions(true));
}
use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class ConceptMaps method broadcast.
@Override
public Broadcast<BroadcastableMappings> broadcast(Map<String, String> conceptMapUriToVersion) {
List<ConceptMap> mapsList = getMaps().collectAsList();
Map<String, ConceptMap> mapsToLoad = mapsList.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 = 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));
}
Aggregations