use of org.hl7.fhir.r4b.model.ConceptMap in project bunsen by cerner.
the class ConceptMapsTest method testAppendMappings.
@Test
public void testAppendMappings() throws FHIRException {
ConceptMaps original = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap("urn:cerner:map:testmap", "1"), conceptMap("urn:cerner:map:othermap", "1"));
ConceptMaps maps = original.withConceptMaps(conceptMap("urn:cerner:map:newmap", "1"));
// The original should be unchanged.
Assert.assertEquals(2, original.getMappings().count());
Assert.assertEquals(3, maps.getMappings().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");
ConceptMap newMap = maps.getConceptMap("urn:cerner:map:newmap", "1");
checkMap(newMap, "urn:cerner:map:newmap", "1");
}
use of org.hl7.fhir.r4b.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");
}
use of org.hl7.fhir.r4b.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));
}
use of org.hl7.fhir.r4b.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;
}
}
use of org.hl7.fhir.r4b.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();
}
Aggregations