Search in sources :

Example 91 with ConceptMap

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));
}
Also used : Mapping(com.cerner.bunsen.spark.codes.Mapping) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Example 92 with ConceptMap

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());
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Example 93 with ConceptMap

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());
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Test(org.junit.Test)

Example 94 with ConceptMap

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));
}
Also used : ConceptMapGroupUnmappedComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupUnmappedComponent) ConceptMaps(com.cerner.bunsen.stu3.codes.ConceptMaps) BroadcastableConceptMap(com.cerner.bunsen.spark.codes.broadcast.BroadcastableConceptMap) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) UriType(org.hl7.fhir.dstu3.model.UriType) BeforeClass(org.junit.BeforeClass)

Example 95 with ConceptMap

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));
}
Also used : SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent) UrlAndVersion(com.cerner.bunsen.codes.UrlAndVersion) Dataset(org.apache.spark.sql.Dataset) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) HashMap(java.util.HashMap) ConceptMapGroupUnmappedMode(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupUnmappedMode) Deque(java.util.Deque) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FhirVersionEnum(ca.uhn.fhir.context.FhirVersionEnum) Map(java.util.Map) org.apache.spark.sql.functions.lit(org.apache.spark.sql.functions.lit) MapFunction(org.apache.spark.api.java.function.MapFunction) SparkSession(org.apache.spark.sql.SparkSession) BroadcastableConceptMap(com.cerner.bunsen.codes.broadcast.BroadcastableConceptMap) Broadcast(org.apache.spark.broadcast.Broadcast) Iterator(java.util.Iterator) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) FhirEncoders(com.cerner.bunsen.FhirEncoders) List(java.util.List) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) Encoder(org.apache.spark.sql.Encoder) BroadcastableMappings(com.cerner.bunsen.codes.broadcast.BroadcastableMappings) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r4.model.UriType) ArrayDeque(java.util.ArrayDeque) AbstractConceptMaps(com.cerner.bunsen.codes.base.AbstractConceptMaps) Collections(java.util.Collections) Mapping(com.cerner.bunsen.codes.Mapping) BroadcastableConceptMap(com.cerner.bunsen.codes.broadcast.BroadcastableConceptMap) HashMap(java.util.HashMap) Mapping(com.cerner.bunsen.codes.Mapping) BroadcastableMappings(com.cerner.bunsen.codes.broadcast.BroadcastableMappings) ArrayList(java.util.ArrayList) List(java.util.List) JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) BroadcastableConceptMap(com.cerner.bunsen.codes.broadcast.BroadcastableConceptMap) ConceptMap(org.hl7.fhir.r4.model.ConceptMap)

Aggregations

ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)34 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)27 FHIRException (org.hl7.fhir.exceptions.FHIRException)26 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)23 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)22 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)17 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)15 HashSet (java.util.HashSet)13 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FileOutputStream (java.io.FileOutputStream)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)10 Test (org.junit.jupiter.api.Test)10 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)9 Coding (org.hl7.fhir.r4.model.Coding)9 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)9