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;
}
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));
}
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());
}
}
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;
}
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());
}
Aggregations