Search in sources :

Example 86 with ConceptMap

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

the class BroadcastableMappings 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) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) ArrayDeque(java.util.ArrayDeque) HashSet(java.util.HashSet)

Example 87 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 = BroadcastableMappings.broadcast(spark, ImmutableList.of(conceptMap, delegatingMap));
}
Also used : ConceptMapGroupUnmappedComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupUnmappedComponent) 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 88 with ConceptMap

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

the class ConceptMaps method addToConceptMap.

@Override
protected void addToConceptMap(ConceptMap map, Dataset<Mapping> mappings) {
    // Sort the items so they are grouped together optimally, and so
    // we consistently produce the same ordering, therefore making
    // inspection and comparison of the concept maps easier.
    List<Mapping> sortedMappings = mappings.sort("sourceSystem", "targetSystem", "sourceValue", "targetValue").collectAsList();
    ConceptMapGroupComponent currentGroup = null;
    SourceElementComponent element = null;
    // Workaround for the decoder producing an immutable array by
    // replacing it with a mutable one.
    map.setGroup(new ArrayList<>(map.getGroup()));
    for (Mapping mapping : sortedMappings) {
        // Add a new group if we don't match the previous one.
        if (currentGroup == null || !mapping.getSourceSystem().equals(currentGroup.getSource()) || !mapping.getTargetSystem().equals(currentGroup.getTarget())) {
            currentGroup = null;
            // Find a matching group.
            for (ConceptMapGroupComponent candidate : map.getGroup()) {
                if (mapping.getSourceSystem().equals(candidate.getSource()) && mapping.getTargetSystem().equals(candidate.getTarget())) {
                    currentGroup = candidate;
                    // Workaround for the decoder producing an immutable array by
                    // replacing it with a mutable one.
                    currentGroup.setElement(new ArrayList<>(currentGroup.getElement()));
                    break;
                }
            }
            // No matching group found, so add it.
            if (currentGroup == null) {
                currentGroup = map.addGroup();
                currentGroup.setSource(mapping.getSourceSystem());
                currentGroup.setTarget(mapping.getTargetSystem());
                // Ensure a new element is created for the newly created group.
                element = null;
            }
        }
        // so add one if it does not match the previous.
        if (element == null || !mapping.getSourceValue().equals(element.getCode())) {
            element = currentGroup.addElement();
            element.setCode(mapping.getSourceValue());
        }
        element.addTarget().setCode(mapping.getTargetValue());
    }
}
Also used : Mapping(com.cerner.bunsen.spark.codes.Mapping) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)

Example 89 with ConceptMap

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

the class ConceptMapsTest method conceptMap.

private static final ConceptMap conceptMap(String url, String version) {
    ConceptMap conceptMap = new ConceptMap();
    conceptMap.setUrl(url);
    conceptMap.setVersion(version);
    conceptMap.setExperimental(true);
    conceptMap.setSource(new UriType("urn:source:valueset"));
    conceptMap.setTarget(new UriType("urn:target:valueset"));
    conceptMap.addGroup().setSource("urn:source:system").setTarget("urn:target:system").addElement().setCode("urn:source:code:a").addTarget().setCode("urn:target:code:1");
    return conceptMap;
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 90 with ConceptMap

use of org.hl7.fhir.r4b.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.dstu3.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