use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent 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.getSourceUriType().getValue();
mapping.setSourceValueSet(sourceValue);
String targetValue = map.getTarget() instanceof UriType ? map.getTargetUriType().getValue() : map.getTargetUriType().getValue();
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.TargetElementComponent 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.TargetElementComponent 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.r5.model.ConceptMap.TargetElementComponent 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);
}
}
use of org.hl7.fhir.r5.model.ConceptMap.TargetElementComponent in project kindling by HL7.
the class Publisher method buildConceptMap.
private ConceptMap buildConceptMap(String path, ValueSet vs, ResourceDefn rd) throws EOperationOutcome, FHIRException, IOException {
ConceptMap cm = new ConceptMap();
cm.setUserData("path", "sc-" + vs.getUserString("path"));
cm.setUserData("resource-definition", rd);
cm.setId("sc-" + vs.getId());
cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
cm.setVersion(page.getVersion().toCode());
cm.setName(vs.getName() + "CanonicalMap");
cm.setTitle("Canonical Mapping for \"" + vs.present() + "\"");
cm.setStatus(PublicationStatus.DRAFT);
cm.setDate(vs.getDate());
cm.setPublisher(vs.getPublisher());
cm.addContact(vs.getContactFirstRep());
cm.setDescription("Canonical Mapping for \"" + vs.getDescription() + "\"");
cm.setSource(new CanonicalType(vs.getUrl()));
cm.setTarget(new CanonicalType("http://hl7.org/fhir/ValueSet/resource-status"));
List<String> canonical = page.getDefinitions().getStatusCodes().get("@code");
List<String> self = page.getDefinitions().getStatusCodes().get(path);
ConceptMapGroupComponent grp = cm.addGroup();
grp.setTarget("http://hl7.org/fhir/resource-status");
grp.setSource(vs.getCompose().getIncludeFirstRep().getSystem());
for (int i = 0; i < self.size(); i++) {
if (!Utilities.noString(self.get(i))) {
String cc = canonical.get(i);
String sc = self.get(i);
SourceElementComponent e = grp.addElement();
e.setCode(sc);
TargetElementComponent t = e.addTarget();
t.setCode(cc);
t.setRelationship(ConceptMapRelationship.EQUIVALENT);
}
}
if (!grp.hasElement())
return null;
page.getConceptMaps().see(cm, page.packageInfo());
statusCodeConceptMaps.add(cm);
return cm;
}
Aggregations