use of org.hl7.fhir.r4b.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 = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap, delegatingMap).broadcast(ImmutableMap.of("uri:test:concept:map", "0", "uri:test:concept:delegating", "0"));
ConceptMap conceptMapLatest = new ConceptMap();
conceptMapLatest.setUrl("uri:test:concept:map").setVersion("1").setSource(new UriType("uri:test:source:valueset")).setTarget(new UriType("uri:test:target:valueset"));
ConceptMapGroupComponent groupLatest = conceptMapLatest.addGroup().setSource("uri:test:source:system").setTarget("uri:test:target:system");
groupLatest.addElement().setCode("abc").addTarget().setCode("123");
groupLatest.addElement().setCode("def").addTarget().setCode("xyz");
ConceptMaps maps = ConceptMaps.getEmpty(spark).withConceptMaps(conceptMap, conceptMapLatest);
broadcastLatest = maps.broadcast(maps.getLatestVersions(true));
}
use of org.hl7.fhir.r4b.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());
}
}
use of org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.
the class ResourceNameConceptMapGenerator method genMap.
private static void genMap(String src, String srcV, String dst, String dstV, Sheet xls, String dstFolder, String name, Date date) throws FileNotFoundException, IOException {
ConceptMap cm = new ConceptMap();
cm.setId(name);
cm.setUrl("http://hl7.org/fhir/" + name);
cm.setName("ResourceNames" + src.toUpperCase() + "to" + dst.toUpperCase());
cm.setTitle("Resource Names " + src.toUpperCase() + " to " + dst.toUpperCase());
cm.setDescription("This map contains a mapping between resources from " + src + " to " + dst);
cm.setStatus(PublicationStatus.ACTIVE);
cm.setDate(date);
ConceptMapGroupComponent grp = cm.addGroup();
grp.setSource("http://hl7.org/fhir/" + srcV + "/resource-types");
grp.setTarget("http://hl7.org/fhir/" + dstV + "/resource-types");
for (int row = 0; row < xls.rows.size(); row++) {
String s = xls.getColumn(row, src);
String t = xls.getColumn(row, dst);
if (!Utilities.noString(s) && (Character.isAlphabetic(s.charAt(0)) || s.startsWith("->") || s.startsWith("("))) {
String c = s.startsWith("->") ? s.substring(2).trim() : s.startsWith("(") ? s.substring(1, s.length() - 1) : s;
SourceElementComponent map = elementForCode(grp, c);
if (Utilities.noString(t))
map.addTarget().setRelationship(ConceptMapRelationship.NOTRELATEDTO);
else if (t.startsWith("("))
map.addTarget().setCode(t.substring(1, t.length() - 1)).setRelationship(ConceptMapRelationship.RELATEDTO);
else if (t.startsWith("->"))
map.addTarget().setCode(t.substring(2).trim()).setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
else if (t.startsWith(":"))
map.addTarget().setComment(t.substring(1).trim()).setRelationship(ConceptMapRelationship.NOTRELATEDTO);
else if (s.startsWith("-<"))
map.addTarget().setCode(t).setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
else if (s.startsWith("("))
map.addTarget().setCode(t).setRelationship(ConceptMapRelationship.RELATEDTO);
else
map.addTarget().setCode(t).setRelationship(ConceptMapRelationship.EQUIVALENT);
}
}
//
new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dstFolder, "ConceptMap-" + name + ".json")), cm);
}
use of org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.
the class CodeListToValueSetParser method processV3Map.
private void processV3Map(ConceptMap cm, String url, String code, String v3map) throws Exception {
if (Utilities.noString(v3map))
return;
for (String m : v3map.split(",")) {
// analyse m
String[] n = m.split("\\(");
String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
n = n[0].split("\\.");
if (n.length != 2)
throw new Exception("Error processing v3 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
String rel = null;
String tbl = n[0];
if (Utilities.existsInList(n[0].substring(0, 1), "=", "~", ">", "<")) {
rel = n[0].substring(0, 1);
tbl = n[0].substring(1);
}
String cd = n[1];
ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v3-" + tbl);
SourceElementComponent src = getSource(grp, code);
TargetElementComponent tgt = src.addTarget();
tgt.setCode(cd.trim());
tgt.setComment(comm);
if (rel == null || rel.equals("="))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals("~"))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals("<"))
tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
else if (rel.equals(">")) {
tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
if (!tgt.hasComment())
throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
} else
throw new Exception("Unable to understand relationship character " + rel);
}
}
use of org.hl7.fhir.r4b.model.ConceptMap.ConceptMapGroupComponent in project kindling by HL7.
the class CodeListToValueSetParser method processV2Map.
private void processV2Map(ConceptMap cm, String url, String code, String v2map) throws Exception {
if (Utilities.noString(v2map))
return;
for (String m : v2map.split(",")) {
// analyse m
String[] n = m.split("\\(");
String comm = (n.length > 1) ? n[1].substring(0, n[1].length() - 1) : null;
n = n[0].split("\\.");
if (n.length != 2)
throw new Exception("Error processing v2 map value for " + cm.getName() + "." + code + " '" + m + "' - format should be CodeSystem.code (comment) - the comment bit is optional");
String rel = n[0].substring(0, 1);
String tbl = n[0].substring(1);
String cd = n[1];
ConceptMapGroupComponent grp = getGroup(cm, url, "http://terminology.hl7.org/CodeSystem/v2-" + tbl);
SourceElementComponent src = getSource(grp, code);
TargetElementComponent tgt = src.addTarget();
tgt.setCode(cd.trim());
tgt.setComment(comm);
if (rel.equals("="))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals("~"))
tgt.setRelationship(ConceptMapRelationship.EQUIVALENT);
else if (rel.equals(">"))
tgt.setRelationship(ConceptMapRelationship.SOURCEISBROADERTHANTARGET);
else if (rel.equals("<")) {
tgt.setRelationship(ConceptMapRelationship.SOURCEISNARROWERTHANTARGET);
if (!tgt.hasComment())
throw new Exception("Missing comment for narrower match on " + cm.getName() + "/" + code);
} else
throw new Exception("Unable to understand relationship character " + rel);
}
}
Aggregations