use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent in project org.hl7.fhir.core by hapifhir.
the class ConceptMapEngine method translateByJustCode.
private Coding translateByJustCode(ConceptMap cm, String code) throws FHIRException {
SourceElementComponent ct = null;
ConceptMapGroupComponent cg = null;
for (ConceptMapGroupComponent g : cm.getGroup()) {
for (SourceElementComponent e : g.getElement()) {
if (code.equals(e.getCode())) {
if (e != null)
throw new FHIRException("Unable to process translate " + code + " because multiple candidate matches were found in concept map " + cm.getUrl());
ct = e;
cg = g;
}
}
}
if (ct == null)
return null;
TargetElementComponent tt = null;
for (TargetElementComponent t : ct.getTarget()) {
if (!t.hasDependsOn() && !t.hasProduct() && isOkRelationship(t.getRelationship())) {
if (tt != null)
throw new FHIRException("Unable to process translate " + code + " because multiple targets were found in concept map " + cm.getUrl());
tt = t;
}
}
if (tt == null)
return null;
CanonicalPair cp = new CanonicalPair(cg.getTarget());
return new Coding().setSystem(cp.getUrl()).setVersion(cp.getVersion()).setCode(tt.getCode()).setDisplay(tt.getDisplay());
}
use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent in project org.hl7.fhir.core by hapifhir.
the class MappingSheetParser method getConceptMap.
public ConceptMap getConceptMap() throws FHIRException {
ConceptMap map = new ConceptMap();
loadMetadata(map);
if (metadata.containsKey("copyright"))
map.setCopyright(metadata.get("copyright"));
for (MappingRow row : rows) {
SourceElementComponent element = map.getGroupFirstRep().addElement();
element.setCode(row.getIdentifier());
element.setId(row.getSequence());
element.setDisplay(row.getName() + " : " + row.getDataType() + " [" + row.getCardinality() + "]");
element.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
element.addExtension(ToolingExtensions.EXT_MAPPING_TYPE, new StringType(row.getDataType()));
element.addExtension(ToolingExtensions.EXT_MAPPING_CARD, new StringType(row.getCardinality()));
if ("N/A".equals(row.getAttribute()))
element.addTarget().setEquivalence(ConceptMapEquivalence.UNMATCHED);
else {
element.getTargetFirstRep().setEquivalence(ConceptMapEquivalence.RELATEDTO);
if (row.getCondition() != null)
element.getTargetFirstRep().addDependsOn().setProperty("http://hl7.org/fhirpath").setValue(processCondition(row.getCondition()));
element.getTargetFirstRep().setCode(row.getAttribute());
element.getTargetFirstRep().setDisplay(row.getType() + " : [" + row.getMinMax() + "]");
element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
if (row.getDerived() != null)
element.getTargetFirstRep().getProductFirstRep().setProperty(row.getDerived()).setValue(row.getDerivedMapping());
if (row.getComments() != null)
element.getTargetFirstRep().setComment(row.getComments());
if (row.getDtMapping() != null)
element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping", new UrlType("todo#" + row.getDtMapping()));
if (row.getVocabMapping() != null)
element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping", new UrlType("todo#" + row.getVocabMapping()));
}
}
return map;
}
use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseConceptMap.
private void parseConceptMap(StructureMap result, FHIRLexer lexer) throws FHIRLexerException {
lexer.token("conceptmap");
ConceptMap map = new ConceptMap();
String id = lexer.readConstant("map id");
if (id.startsWith("#"))
throw lexer.error("Concept Map identifier must start with #");
map.setId(id);
// todo: how to add this to the text format
map.setStatus(PublicationStatus.DRAFT);
result.getContained().add(map);
lexer.token("{");
// lexer.token("source");
// map.setSource(new UriType(lexer.readConstant("source")));
// lexer.token("target");
// map.setSource(new UriType(lexer.readConstant("target")));
Map<String, String> prefixes = new HashMap<String, String>();
while (lexer.hasToken("prefix")) {
lexer.token("prefix");
String n = lexer.take();
lexer.token("=");
String v = lexer.readConstant("prefix url");
prefixes.put(n, v);
}
while (lexer.hasToken("unmapped")) {
lexer.token("unmapped");
lexer.token("for");
String n = readPrefix(prefixes, lexer);
ConceptMapGroupComponent g = getGroup(map, n, null);
lexer.token("=");
String v = lexer.take();
if (v.equals("provided")) {
g.getUnmapped().setMode(ConceptMapGroupUnmappedMode.PROVIDED);
} else
throw lexer.error("Only unmapped mode PROVIDED is supported at this time");
}
while (!lexer.hasToken("}")) {
String srcs = readPrefix(prefixes, lexer);
lexer.token(":");
String sc = lexer.getCurrent().startsWith("\"") ? lexer.readConstant("code") : lexer.take();
ConceptMapRelationship rel = readRelationship(lexer);
String tgts = readPrefix(prefixes, lexer);
ConceptMapGroupComponent g = getGroup(map, srcs, tgts);
SourceElementComponent e = g.addElement();
e.setCode(sc);
if (e.getCode().startsWith("\""))
e.setCode(lexer.processConstant(e.getCode()));
TargetElementComponent tgt = e.addTarget();
tgt.setRelationship(rel);
lexer.token(":");
tgt.setCode(lexer.take());
if (tgt.getCode().startsWith("\""))
tgt.setCode(lexer.processConstant(tgt.getCode()));
tgt.setComment(lexer.getFirstComment());
}
lexer.token("}");
}
use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent in project org.hl7.fhir.core by hapifhir.
the class MappingSheetParser method getConceptMap.
public ConceptMap getConceptMap() throws FHIRException {
ConceptMap map = new ConceptMap();
loadMetadata(map);
if (metadata.containsKey("copyright"))
map.setCopyright(metadata.get("copyright"));
for (MappingRow row : rows) {
SourceElementComponent element = map.getGroupFirstRep().addElement();
element.setCode(row.getIdentifier());
element.setId(row.getSequence());
element.setDisplay(row.getName() + " : " + row.getDataType() + " [" + row.getCardinality() + "]");
element.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
element.addExtension(ToolingExtensions.EXT_MAPPING_TYPE, new StringType(row.getDataType()));
element.addExtension(ToolingExtensions.EXT_MAPPING_CARD, new StringType(row.getCardinality()));
if ("N/A".equals(row.getAttribute()))
element.setNoMap(true);
else {
element.getTargetFirstRep().setRelationship(ConceptMapRelationship.RELATEDTO);
if (row.getCondition() != null)
element.getTargetFirstRep().addDependsOn().setProperty("http://hl7.org/fhirpath").setValue(processCondition(row.getCondition()));
element.getTargetFirstRep().setCode(row.getAttribute());
element.getTargetFirstRep().setDisplay(row.getType() + " : [" + row.getMinMax() + "]");
element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
element.getTargetFirstRep().addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
if (row.getDerived() != null)
element.getTargetFirstRep().getProductFirstRep().setProperty(row.getDerived()).setValue(row.getDerivedMapping());
if (row.getComments() != null)
element.getTargetFirstRep().setComment(row.getComments());
if (row.getDtMapping() != null)
element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping", new UrlType("todo#" + row.getDtMapping()));
if (row.getVocabMapping() != null)
element.getTargetFirstRep().addExtension("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping", new UrlType("todo#" + row.getVocabMapping()));
}
}
return map;
}
use of org.hl7.fhir.r5.model.ConceptMap.SourceElementComponent in project org.hl7.fhir.core by hapifhir.
the class MappingSheetParser method readConceptMap.
private void readConceptMap(ConceptMap cm) throws FHIRException {
for (ConceptMapGroupComponent g : cm.getGroup()) {
for (SourceElementComponent e : g.getElement()) {
if (e.hasId() && e.getTarget().size() == 1 && e.hasExtension(ToolingExtensions.EXT_MAPPING_TYPE)) {
TargetElementComponent t = e.getTargetFirstRep();
MappingRow row = new MappingRow();
row.sequence = e.getId();
row.identifier = e.getCode();
row.name = e.getExtensionString(ToolingExtensions.EXT_MAPPING_NAME);
row.dataType = e.getExtensionString(ToolingExtensions.EXT_MAPPING_TYPE);
row.cardinality = e.getExtensionString(ToolingExtensions.EXT_MAPPING_CARD);
if (e.getNoMap() == true) {
row.attribute = "N/A";
} else {
OtherElementComponent dep = getDependency(t, "http://hl7.org/fhirpath");
if (dep != null)
row.condition = dep.getValue();
row.attribute = t.getCode();
row.type = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTTYPE);
row.minMax = t.getExtensionString(ToolingExtensions.EXT_MAPPING_TGTCARD);
row.dtMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-type-mapping");
row.vocabMapping = t.getExtensionString("http://hl7.org/fhir/StructureDefinition/ConceptMap-vocab-mapping");
if (t.getProduct().size() > 0) {
row.derived = t.getProductFirstRep().getProperty();
row.derivedMapping = t.getProductFirstRep().getValue();
}
}
row.comments = t.getComment();
rows.add(row);
}
}
}
}
Aggregations