use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent 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();
}
use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent 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.r5.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.
the class PageProcessor method parseConceptMapMapping.
private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
if (!src.startsWith("{map:"))
return null;
ConceptMap map = new ConceptMap();
map.setId(logical.getPath() + "2" + resource.getPath());
map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
map.setVersion(version.toCode());
ConceptMapGroupComponent grp = map.addGroup();
String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
if (statements.length == 0)
throw new FHIRException("Unable to parse map details '" + src + "'");
for (String s : statements) {
String[] p = s.split("\\=");
if (p.length < 2)
throw new FHIRException("Unable to parse map details '" + src + "'");
if (":default".equals(p[0].trim())) {
grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
grp.getUnmapped().setCode(p[1].trim());
} else {
grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
}
}
return map;
}
use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.
the class ResourceNameConceptMapGenerator method elementForCode.
private static SourceElementComponent elementForCode(ConceptMapGroupComponent grp, String s) {
for (SourceElementComponent t : grp.getElement()) if (t.getCode().equals(s))
return t;
SourceElementComponent t = grp.addElement();
t.setCode(s);
return t;
}
use of org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent 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());
}
}
Aggregations