Search in sources :

Example 96 with ConceptMap

use of org.hl7.fhir.r4.model.ConceptMap in project bunsen by cerner.

the class ConceptMaps method sortMapsToLoad.

/**
 * Returns a list of concept maps in the order they need to be loaded.
 */
private static List<String> sortMapsToLoad(Set<String> mapsToLoad, Map<String, ConceptMap> allMaps) {
    Deque<String> pendingMaps = new ArrayDeque<>(mapsToLoad);
    List<String> loadOrder = new ArrayList<>();
    Set<String> loadedMaps = new HashSet<>();
    while (!pendingMaps.isEmpty()) {
        String nextMap = pendingMaps.peek();
        // remove it and continue.
        if (loadedMaps.contains(nextMap)) {
            pendingMaps.pop();
            continue;
        }
        ConceptMap mapToLoad = allMaps.get(nextMap);
        if (mapToLoad == null) {
            throw new IllegalStateException("Concept map " + nextMap + " " + " is referenced but not in the collection of concept maps.");
        }
        // Get the set of children we need to load before the pending map.
        Set<String> childrenToLoad = getMapChildren(mapToLoad);
        childrenToLoad.removeAll(loadedMaps);
        // add it to our load order.
        if (childrenToLoad.isEmpty()) {
            loadedMaps.add(nextMap);
            loadOrder.add(nextMap);
            pendingMaps.pop();
        } else {
            // The pending map has children, so we need to load them first.
            for (String child : childrenToLoad) {
                pendingMaps.push(child);
            }
        }
    }
    return loadOrder;
}
Also used : ArrayList(java.util.ArrayList) BroadcastableConceptMap(com.cerner.bunsen.codes.broadcast.BroadcastableConceptMap) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 97 with ConceptMap

use of org.hl7.fhir.r4.model.ConceptMap in project bunsen by cerner.

the class ConceptMaps method expandMappingsIterator.

private static Iterator<Mapping> expandMappingsIterator(ConceptMap map) {
    List<Mapping> mappings = new ArrayList<>();
    for (ConceptMapGroupComponent group : map.getGroup()) {
        for (SourceElementComponent element : group.getElement()) {
            for (TargetElementComponent target : element.getTarget()) {
                Mapping mapping = new Mapping();
                mapping.setConceptMapUri(map.getUrl());
                mapping.setConceptMapVersion(map.getVersion());
                try {
                    String sourceValue = map.getSource() instanceof UriType ? map.getSourceUriType().getValue() : map.getSourceUriType().getValue();
                    mapping.setSourceValueSet(sourceValue);
                    String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetUriType().getValue();
                    mapping.setTargetValueSet(targetValue);
                } catch (FHIRException fhirException) {
                    // an exception.
                    throw new RuntimeException(fhirException);
                }
                mapping.setSourceSystem(group.getSource());
                mapping.setSourceValue(element.getCode());
                mapping.setTargetSystem(group.getTarget());
                mapping.setTargetValue(target.getCode());
                if (target.getEquivalence() != null) {
                    mapping.setEquivalence(target.getEquivalence().toCode());
                }
                mappings.add(mapping);
            }
        }
    }
    return mappings.iterator();
}
Also used : ArrayList(java.util.ArrayList) TargetElementComponent(org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent) Mapping(com.cerner.bunsen.codes.Mapping) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent) UriType(org.hl7.fhir.r4.model.UriType)

Example 98 with ConceptMap

use of org.hl7.fhir.r4.model.ConceptMap in project bunsen by cerner.

the class ConceptMapsTest method testWithDisjointMapsFromDirectory.

@Test
public void testWithDisjointMapsFromDirectory() {
    String database = "test_conceptmaps_disjoint";
    spark.sql("CREATE DATABASE " + database);
    ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/xml/conceptmaps").writeToDatabase(database);
    ConceptMaps maps = ConceptMaps.getFromDatabase(spark, database).withDisjointMapsFromDirectory("src/test/resources/xml/conceptmaps", database);
    ConceptMap genderMap = maps.getConceptMap("urn:cerner:poprec:fhir:conceptmap:demographics:gender", "0.0.1");
    Assert.assertEquals(1, maps.getMaps().count());
    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.r4.model.ConceptMap) Test(org.junit.Test)

Example 99 with ConceptMap

use of org.hl7.fhir.r4.model.ConceptMap in project bunsen by cerner.

the class ConceptMapsTest method testCreateSimpleMappings.

@Test
public void testCreateSimpleMappings() throws FHIRException {
    ConceptMaps maps = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap("urn:cerner:map:testmap", "1"), conceptMap("urn:cerner:map:othermap", "1"));
    Dataset<Mapping> mappings = maps.getMappings();
    Assert.assertEquals(2, mappings.count());
    ConceptMap firstMap = maps.getConceptMap("urn:cerner:map:testmap", "1");
    checkMap(firstMap, "urn:cerner:map:testmap", "1");
    ConceptMap secondMap = maps.getConceptMap("urn:cerner:map:othermap", "1");
    checkMap(secondMap, "urn:cerner:map:othermap", "1");
}
Also used : Mapping(com.cerner.bunsen.codes.Mapping) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) Test(org.junit.Test)

Example 100 with ConceptMap

use of org.hl7.fhir.r4.model.ConceptMap in project bunsen by cerner.

the class ConceptMapsTest method testWithMapsFromDirectoryJson.

@Test
public void testWithMapsFromDirectoryJson() {
    ConceptMaps maps = ConceptMaps.getEmpty(spark).withMapsFromDirectory("src/test/resources/json/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.r4.model.ConceptMap) Test(org.junit.Test)

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