use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class ValueSetRenderer method findReleventMaps.
private List<UsedConceptMap> findReleventMaps(ValueSet vs) throws FHIRException {
List<UsedConceptMap> res = new ArrayList<UsedConceptMap>();
for (CanonicalResource md : getContext().getWorker().allConformanceResources()) {
if (md instanceof ConceptMap) {
ConceptMap cm = (ConceptMap) md;
if (isSource(vs, cm.getSource())) {
ConceptMapRenderInstructions re = findByTarget(cm.getTarget());
if (re != null) {
ValueSet vst = cm.hasTarget() ? getContext().getWorker().fetchResource(ValueSet.class, cm.hasTargetCanonicalType() ? cm.getTargetCanonicalType().getValue() : cm.getTargetUriType().asStringValue()) : null;
res.add(new UsedConceptMap(re, vst == null ? cm.getUserString("path") : vst.getUserString("path"), cm));
}
}
}
}
return res;
// Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
// for (ConceptMap a : context.getWorker().findMapsForSource(vs.getUrl())) {
// String url = "";
// ValueSet vsr = context.getWorker().fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(a, url);
// }
// Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
// for (ConceptMap a : context.getWorker().findMapsForSource(cs.getValueSet())) {
// String url = "";
// ValueSet vsr = context.getWorker().fetchResource(ValueSet.class, ((Reference) a.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(a, url);
// }
// also, look in the contained resources for a concept map
// for (Resource r : cs.getContained()) {
// if (r instanceof ConceptMap) {
// ConceptMap cm = (ConceptMap) r;
// if (((Reference) cm.getSource()).getReference().equals(cs.getValueSet())) {
// String url = "";
// ValueSet vsr = context.getWorker().fetchResource(ValueSet.class, ((Reference) cm.getTarget()).getReference());
// if (vsr != null)
// url = (String) vsr.getUserData("filename");
// mymaps.put(cm, url);
// }
// }
// }
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class ConceptMapRenderer method render.
public boolean render(XhtmlNode x, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
XhtmlNode p = x.para();
p.tx("Mapping from ");
if (cm.hasSource())
AddVsRef(cm.getSource().primitiveValue(), p);
else
p.tx("(not specified)");
p.tx(" to ");
if (cm.hasTarget())
AddVsRef(cm.getTarget().primitiveValue(), p);
else
p.tx("(not specified)");
p = x.para();
if (cm.getExperimental())
p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
else
p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
p.tx("Published on " + (cm.hasDate() ? display(cm.getDateElement()) : "?ngen-10?") + " by " + cm.getPublisher());
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
for (ContactDetail ci : cm.getContact()) {
if (firsti)
firsti = false;
else
p.tx(", ");
if (ci.hasName())
p.addText(ci.getName() + ": ");
boolean first = true;
for (ContactPoint c : ci.getTelecom()) {
if (first)
first = false;
else
p.tx(", ");
addTelecom(p, c);
}
}
p.tx(")");
}
p.tx(". ");
p.addText(cm.getCopyright());
if (!Utilities.noString(cm.getDescription()))
addMarkdown(x, cm.getDescription());
x.br();
CodeSystem cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-relationship");
if (cs == null)
cs = getContext().getWorker().fetchCodeSystem("http://hl7.org/fhir/concept-map-equivalence");
String eqpath = cs == null ? null : cs.getUserString("path");
for (ConceptMapGroupComponent grp : cm.getGroup()) {
String src = grp.getSource();
boolean comment = false;
boolean ok = true;
Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
sources.put("code", new HashSet<String>());
targets.put("code", new HashSet<String>());
SourceElementComponent cc = grp.getElement().get(0);
String dst = grp.getTarget();
sources.get("code").add(grp.getSource());
targets.get("code").add(grp.getTarget());
for (SourceElementComponent ccl : grp.getElement()) {
ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
for (TargetElementComponent ccm : ccl.getTarget()) {
comment = comment || !Utilities.noString(ccm.getComment());
for (OtherElementComponent d : ccm.getDependsOn()) {
if (!sources.containsKey(d.getProperty()))
sources.put(d.getProperty(), new HashSet<String>());
sources.get(d.getProperty()).add(d.getSystem());
}
for (OtherElementComponent d : ccm.getProduct()) {
if (!targets.containsKey(d.getProperty()))
targets.put(d.getProperty(), new HashSet<String>());
targets.get(d.getProperty()).add(d.getSystem());
}
}
}
String display;
if (ok) {
// simple
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Source Code");
tr.td().b().tx("Relationship");
tr.td().b().tx("Destination Code");
if (comment)
tr.td().b().tx("Comment");
tr = tbl.tr();
XhtmlNode td = tr.td().colspan(comment ? "4" : "3");
td.tx("Mapping from ");
if (grp.hasSource()) {
renderCanonical(cm, td, grp.getSource());
} else {
td.code("unspecified code system");
}
td.tx(" to ");
if (grp.hasTarget()) {
renderCanonical(cm, td, grp.getTarget());
} else {
td.code("unspecified code system");
}
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
td = tr.td();
td.addText(ccl.getCode());
display = ccl.hasDisplay() ? ccl.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
if (display != null && !isSameCodeAndDisplay(ccl.getCode(), display))
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
if (!ccm.hasRelationship())
tr.td().tx(":" + "(" + ConceptMapRelationship.EQUIVALENT.toCode() + ")");
else {
if (ccm.getRelationshipElement().hasExtension(ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE)) {
String code = ToolingExtensions.readStringExtension(ccm.getRelationshipElement(), ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE);
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
} else {
tr.td().ah(eqpath + "#" + ccm.getRelationship().toCode()).tx(presentRelationshipCode(ccm.getRelationship().toCode()));
}
}
td = tr.td();
td.addText(ccm.getCode());
display = ccm.hasDisplay() ? ccm.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
if (display != null && !isSameCodeAndDisplay(ccm.getCode(), display))
td.tx(" (" + display + ")");
if (comment)
tr.td().addText(ccm.getComment());
addUnmapped(tbl, grp);
}
} else {
boolean hasRelationships = false;
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
if (ccm.hasRelationship()) {
hasRelationships = true;
}
}
}
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode td;
tr.td().colspan(Integer.toString(1 + sources.size())).b().tx("Source Concept Details");
if (hasRelationships) {
tr.td().b().tx("Relationship");
}
tr.td().colspan(Integer.toString(1 + targets.size())).b().tx("Destination Concept Details");
if (comment) {
tr.td().b().tx("Comment");
}
tr = tbl.tr();
if (sources.get("code").size() == 1) {
String url = sources.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : sources.keySet()) {
if (!s.equals("code")) {
if (sources.get(s).size() == 1) {
String url = sources.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (hasRelationships) {
tr.td();
}
if (targets.get("code").size() == 1) {
String url = targets.get("code").iterator().next();
renderCSDetailsLink(tr, url, true);
} else
tr.td().b().tx("Code");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
if (targets.get(s).size() == 1) {
String url = targets.get(s).iterator().next();
renderCSDetailsLink(tr, url, false);
} else
tr.td().b().addText(getDescForConcept(s));
}
}
if (comment)
tr.td();
for (int si = 0; si < grp.getElement().size(); si++) {
SourceElementComponent ccl = grp.getElement().get(si);
boolean slast = si == grp.getElement().size() - 1;
boolean first = true;
if (ccl.hasNoMap() && ccl.getNoMap()) {
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first)
td.style("border-top-style: none");
else
td.style("border-bottom-style: none");
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
tr.td().colspan("4").style("background-color: #efefef").tx("(not mapped)");
} else {
for (int ti = 0; ti < ccl.getTarget().size(); ti++) {
TargetElementComponent ccm = ccl.getTarget().get(ti);
boolean last = ti == ccl.getTarget().size() - 1;
tr = tbl.tr();
td = tr.td().style("border-right-width: 0px");
if (!first && !last)
td.style("border-top-style: none; border-bottom-style: none");
else if (!first)
td.style("border-top-style: none");
else if (!last)
td.style("border-bottom-style: none");
if (first) {
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = ccl.hasDisplay() ? ccl.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getSource()), versionFromCanonical(grp.getSource()), ccl.getCode());
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-bottom-style: none");
else
td.style("border-left-width: 0px");
td.tx(display == null ? "" : display);
} else {
// for display
td = tr.td();
if (!last)
td.style("border-left-width: 0px; border-top-style: none; border-bottom-style: none");
else
td.style("border-top-style: none; border-left-width: 0px");
}
for (String s : sources.keySet()) {
if (!s.equals("code")) {
td = tr.td();
if (first) {
td.addText(getValue(ccm.getDependsOn(), s, sources.get(s).size() != 1));
display = getDisplay(ccm.getDependsOn(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
}
first = false;
if (hasRelationships) {
if (!ccm.hasRelationship())
tr.td();
else {
if (ccm.getRelationshipElement().hasExtension(ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE)) {
String code = ToolingExtensions.readStringExtension(ccm.getRelationshipElement(), ToolingExtensions.EXT_OLD_CONCEPTMAP_EQUIVALENCE);
tr.td().ah(eqpath + "#" + code).tx(presentEquivalenceCode(code));
} else {
tr.td().ah(eqpath + "#" + ccm.getRelationship().toCode()).tx(presentRelationshipCode(ccm.getRelationship().toCode()));
}
}
}
td = tr.td().style("border-right-width: 0px");
if (targets.get("code").size() == 1)
td.addText(ccm.getCode());
else
td.addText(grp.getTarget() + " / " + ccm.getCode());
display = ccm.hasDisplay() ? ccm.getDisplay() : getDisplayForConcept(systemFromCanonical(grp.getTarget()), versionFromCanonical(grp.getTarget()), ccm.getCode());
tr.td().style("border-left-width: 0px").tx(display == null ? "" : display);
for (String s : targets.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getValue(ccm.getProduct(), s, targets.get(s).size() != 1));
display = getDisplay(ccm.getProduct(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (comment)
tr.td().addText(ccm.getComment());
}
}
addUnmapped(tbl, grp);
}
}
}
return true;
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method produceConceptMap.
private static void produceConceptMap(StringBuilder b, ConceptMap cm) {
b.append("conceptmap \"");
b.append(cm.getId());
b.append("\" {\r\n");
Map<String, String> prefixesSrc = new HashMap<String, String>();
Map<String, String> prefixesTgt = new HashMap<String, String>();
char prefix = 's';
for (ConceptMapGroupComponent cg : cm.getGroup()) {
if (!prefixesSrc.containsKey(cg.getSource())) {
prefixesSrc.put(cg.getSource(), String.valueOf(prefix));
b.append(" prefix ");
b.append(prefix);
b.append(" = \"");
b.append(cg.getSource());
b.append("\"\r\n");
prefix++;
}
if (!prefixesTgt.containsKey(cg.getTarget())) {
prefixesTgt.put(cg.getTarget(), String.valueOf(prefix));
b.append(" prefix ");
b.append(prefix);
b.append(" = \"");
b.append(cg.getTarget());
b.append("\"\r\n");
prefix++;
}
}
b.append("\r\n");
for (ConceptMapGroupComponent cg : cm.getGroup()) {
if (cg.hasUnmapped()) {
b.append(" unmapped for ");
b.append(prefixesSrc.get(cg.getSource()));
b.append(" = ");
b.append(cg.getUnmapped().getMode().toCode());
b.append("\r\n");
}
}
for (ConceptMapGroupComponent cg : cm.getGroup()) {
for (SourceElementComponent ce : cg.getElement()) {
b.append(" ");
b.append(prefixesSrc.get(cg.getSource()));
b.append(":");
if (Utilities.isToken(ce.getCode())) {
b.append(ce.getCode());
} else {
b.append("\"");
b.append(ce.getCode());
b.append("\"");
}
b.append(" ");
b.append(getChar(ce.getTargetFirstRep().getRelationship()));
b.append(" ");
b.append(prefixesTgt.get(cg.getTarget()));
b.append(":");
if (Utilities.isToken(ce.getTargetFirstRep().getCode())) {
b.append(ce.getTargetFirstRep().getCode());
} else {
b.append("\"");
b.append(ce.getTargetFirstRep().getCode());
b.append("\"");
}
b.append("\r\n");
}
}
b.append("}\r\n\r\n");
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateCodeSystemContent.
private boolean generateCodeSystemContent(XhtmlNode x, CodeSystem cs, boolean hasExtensions, Map<ConceptMap, String> mymaps, List<String> langs) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode p = x.para();
if (cs.getContent() == CodeSystemContentMode.COMPLETE)
p.tx("This code system " + cs.getUrl() + " defines the following codes:");
else if (cs.getContent() == CodeSystemContentMode.EXAMPLE)
p.tx("This code system " + cs.getUrl() + " defines many codes, of which the following are some examples:");
else if (cs.getContent() == CodeSystemContentMode.FRAGMENT)
p.tx("This code system " + cs.getUrl() + " defines many codes, of which the following are a subset:");
else if (cs.getContent() == CodeSystemContentMode.NOTPRESENT) {
p.tx("This code system " + cs.getUrl() + " defines many codes, but they are not represented here");
return false;
}
XhtmlNode t = x.table("codes");
boolean commentS = false;
boolean deprecated = false;
boolean display = false;
boolean hierarchy = false;
for (ConceptDefinitionComponent c : cs.getConcept()) {
commentS = commentS || conceptsHaveComments(c);
deprecated = deprecated || conceptsHaveDeprecated(cs, c);
display = display || conceptsHaveDisplay(c);
hierarchy = hierarchy || c.hasConcept();
scanLangs(c, langs);
}
addMapHeaders(addTableHeaderRowStandard(t, hierarchy, display, true, commentS, deprecated), mymaps);
for (ConceptDefinitionComponent c : cs.getConcept()) {
hasExtensions = addDefineRowToTable(t, c, 0, hierarchy, display, commentS, deprecated, mymaps, cs.getUrl(), cs) || hasExtensions;
}
if (langs.size() > 0) {
Collections.sort(langs);
x.para().b().tx("Additional Language Displays");
t = x.table("codes");
XhtmlNode tr = t.tr();
tr.td().b().tx("Code");
for (String lang : langs) tr.td().b().addText(describeLang(lang));
for (ConceptDefinitionComponent c : cs.getConcept()) {
addLanguageRow(c, t, langs);
}
}
return hasExtensions;
}
use of org.hl7.fhir.r4b.model.ConceptMap in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateDefinition.
private boolean generateDefinition(XhtmlNode x, CodeSystem cs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
boolean hasExtensions = false;
Map<ConceptMap, String> mymaps = new HashMap<ConceptMap, String>();
// also, look in the contained resources for a concept map
for (Resource r : cs.getContained()) {
if (r instanceof ConceptMap) {
ConceptMap cm = (ConceptMap) r;
if (((Reference) cm.getSource()).getReference().equals(cs.getValueSet())) {
String url = "";
ValueSet vsr = context.fetchResource(ValueSet.class, ((Reference) cm.getTarget()).getReference());
if (vsr != null)
url = (String) vsr.getUserData("filename");
mymaps.put(cm, url);
}
}
}
List<String> langs = new ArrayList<String>();
if (header) {
XhtmlNode h = x.h2();
h.addText(cs.hasTitle() ? cs.getTitle() : cs.getName());
addMarkdown(x, cs.getDescription());
if (cs.hasCopyright())
generateCopyright(x, cs);
}
generateProperties(x, cs);
generateFilters(x, cs);
hasExtensions = generateCodeSystemContent(x, cs, hasExtensions, mymaps, langs);
return hasExtensions;
}
Aggregations