use of org.hl7.fhir.dstu3.model.ConceptMap in project bunsen by cerner.
the class ConceptMaps method addToConceptMap.
/**
* Adds the given mappings to the concept map.
*
* @param map the concept map
* @param mappings the mappings to add
*/
private static 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.dstu3.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());
}
use of org.hl7.fhir.dstu3.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());
}
use of org.hl7.fhir.dstu3.model.ConceptMap in project bunsen by cerner.
the class ConceptMapsTest method testLoadExpandedMappings.
@Test
public void testLoadExpandedMappings() throws FHIRException {
ConceptMap map = conceptMap("urn:cerner:map:testmap", "1");
// Explicitly create a mapping dataset to simulate an ETL load from an external source.
Mapping mapping = new Mapping();
mapping.setConceptMapUri(map.getUrl());
mapping.setConceptMapVersion(map.getVersion());
mapping.setSourceValueSet("urn:source:valueset");
mapping.setTargetValue("urn:target:valueset");
mapping.setSourceSystem("urn:source:system");
mapping.setSourceValue("urn:source:code:a");
mapping.setTargetSystem("urn:target:system");
mapping.setTargetValue("urn:target:code:1");
Dataset<Mapping> mappings = spark.createDataset(Arrays.asList(mapping), ConceptMaps.getMappingEncoder());
ConceptMaps maps = ConceptMaps.getEmpty(spark).withExpandedMap(map, mappings);
Dataset<Mapping> loadedMappings = maps.getMappings();
Assert.assertEquals(1, loadedMappings.count());
Mapping loadedMapping = loadedMappings.head();
Assert.assertEquals(mapping, loadedMapping);
}
use of org.hl7.fhir.dstu3.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;
}
Aggregations