Search in sources :

Example 6 with ConceptMap

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

the class ConceptMaps method withConceptMaps.

private ConceptMaps withConceptMaps(Dataset<ConceptMap> newMaps, Dataset<Mapping> newMappings) {
    Dataset<UrlAndVersion> newMembers = getUrlAndVersions(newMaps);
    // Instantiating a new composite ConceptMaps requires a new timestamp
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    Dataset<ConceptMap> newMapsWithTimestamp = newMaps.withColumn("timestamp", lit(timestamp.toString()).cast("timestamp")).as(CONCEPT_MAP_ENCODER);
    return new ConceptMaps(spark, this.members.union(newMembers), this.conceptMaps.union(newMapsWithTimestamp), this.mappings.union(newMappings));
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) Timestamp(java.sql.Timestamp)

Example 7 with ConceptMap

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

the class ConceptMaps method getConceptMap.

/**
 * Returns the concept map with the given uri and version, or null if there is no such map.
 *
 * @param uri the uri of the map to return
 * @param version the version of the map to return
 * @return the specified concept map.
 */
public ConceptMap getConceptMap(String uri, String version) {
    // Load the concept maps, which may contain zero items
    // if the map does not exist.
    // Typecast necessary to placate the Java compiler calling this Scala function.
    ConceptMap[] maps = (ConceptMap[]) this.conceptMaps.filter(functions.col("url").equalTo(lit(uri)).and(functions.col("version").equalTo(lit(version)))).head(1);
    if (maps.length == 0) {
        return null;
    } else {
        ConceptMap map = maps[0];
        Dataset<Mapping> filteredMappings = getMappings(uri, version);
        addToConceptMap(map, filteredMappings);
        return map;
    }
}
Also used : ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap)

Example 8 with ConceptMap

use of org.hl7.fhir.dstu3.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.getSourceReference().getReference();
                    mapping.setSourceValueSet(sourceValue);
                    String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetReference().getReference();
                    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.dstu3.model.ConceptMap.TargetElementComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 9 with ConceptMap

use of org.hl7.fhir.dstu3.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 10 with ConceptMap

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

Aggregations

ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)14 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)3 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)3 UriType (org.hl7.fhir.dstu3.model.UriType)3 ArrayDeque (java.util.ArrayDeque)2 HashSet (java.util.HashSet)2 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)2 ConceptMaps (com.cerner.bunsen.codes.ConceptMaps)1 Mapping (com.cerner.bunsen.codes.Mapping)1 Serializable (java.io.Serializable)1 Timestamp (java.sql.Timestamp)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1