use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project org.hl7.fhir.core by hapifhir.
the class CSVWriter method processElement.
/* private void findMapKeys(StructureDefinition def, List<StructureDefinitionMappingComponent> maps, IWorkerContext context) {
maps.addAll(def.getMapping());
if (def.getBaseDefinition()!=null) {
StructureDefinition base = context.fetchResource(StructureDefinition.class, def.getBaseDefinition());
findMapKeys(base, maps, context);
}
}*/
public void processElement(ElementDefinition ed) throws Exception {
CSVLine line = new CSVLine();
lines.add(line);
line.addString(ed.getPath());
line.addString(ed.getSliceName());
line.addString(itemList(ed.getAlias()));
line.addString(ed.getLabel());
line.addValue(ed.getMin());
line.addValue(ed.getMax());
line.addString(ed.getMustSupport() ? "Y" : "");
line.addString(ed.getIsModifier() ? "Y" : "");
line.addString(ed.getIsSummary() ? "Y" : "");
line.addString(itemList(ed.getType()));
line.addString(ed.getShort());
line.addString(ed.getDefinition());
line.addString(ed.getComment());
line.addString(ed.getRequirements());
line.addString(ed.getDefaultValue() != null ? renderType(ed.getDefaultValue()) : "");
line.addString(ed.getMeaningWhenMissing());
line.addString(ed.hasFixed() ? renderType(ed.getFixed()) : "");
line.addString(ed.hasPattern() ? renderType(ed.getPattern()) : "");
// todo...?
line.addString(ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : "");
line.addString(ed.hasMinValue() ? renderType(ed.getMinValue()) : "");
line.addString(ed.hasMaxValue() ? renderType(ed.getMaxValue()) : "");
line.addValue((ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : ""));
if (ed.hasBinding()) {
line.addString(ed.getBinding().getStrength() != null ? ed.getBinding().getStrength().toCode() : "");
line.addString(ed.getBinding().getDescription());
if (ed.getBinding().getValueSet() == null)
line.addString("");
else
line.addString(ed.getBinding().getValueSet());
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
line.addString(itemList(ed.getCode()));
if (ed.hasSlicing()) {
line.addString(itemList(ed.getSlicing().getDiscriminator()));
line.addString(ed.getSlicing().getDescription());
line.addBoolean(ed.getSlicing().getOrdered());
line.addString(ed.getSlicing().getRules() != null ? ed.getSlicing().getRules().toCode() : "");
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
if (ed.getBase() != null) {
line.addString(ed.getBase().getPath());
line.addValue(ed.getBase().getMin());
line.addValue(ed.getBase().getMax());
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
line.addString(itemList(ed.getCondition()));
line.addString(itemList(ed.getConstraint()));
for (StructureDefinitionMappingComponent mapKey : def.getMapping()) {
for (ElementDefinitionMappingComponent map : ed.getMapping()) {
if (map.getIdentity().equals(mapKey.getIdentity()))
line.addString(map.getMap());
}
}
}
use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project kindling by HL7.
the class ProfileGenerator method addMapping.
private void addMapping(StructureDefinition p, ElementDefinition definition, String target, String map, Profile pack) {
if (!Utilities.noString(map)) {
String id;
if (pack != null && pack.getMappingSpaces().containsKey(target))
id = pack.getMappingSpaces().get(target).getId();
else
id = definitions.getMapTypes().get(target).getId();
if (!mappingExists(p, id)) {
StructureDefinitionMappingComponent pm = new StructureDefinitionMappingComponent();
p.getMapping().add(pm);
pm.setIdentity(id);
pm.setUri(target);
if (pack != null && pack.getMappingSpaces().containsKey(target))
pm.setName(pack.getMappingSpaces().get(target).getTitle());
else
pm.setName(definitions.getMapTypes().get(target).getTitle());
}
boolean found = false;
for (ElementDefinitionMappingComponent m : definition.getMapping()) {
found = found || (m.getIdentity().equals(id) && m.getMap().equals(map));
}
if (!found) {
ElementDefinitionMappingComponent m = new ElementDefinitionMappingComponent();
m.setIdentity(id);
m.setMap(map);
definition.getMapping().add(m);
}
}
}
use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project kindling by HL7.
the class PageProcessor method genLogicalMappings.
private String genLogicalMappings(ResourceDefn logical, String genlevel) throws FHIRException {
String url = logical.getMappingUrl();
StringBuilder b = new StringBuilder();
b.append("<table class=\"lmap\">");
b.append(" <tr>");
b.append(" <th></th>\r\n");
List<ElementDefn> elements = new ArrayList<ElementDefn>();
listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
for (ElementDefn e : elements) {
if (logical.getRoot().getElements().contains(e)) {
b.append("<td><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getName() + "</a></td>\r\n");
} else {
b.append("<td><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getName() + "</a></td>\r\n");
}
}
b.append(" </tr>\r\n");
boolean any = false;
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn rd = definitions.getResourceByName(s);
StructureDefinition sd = rd.getProfile();
String code = null;
for (StructureDefinitionMappingComponent m : sd.getMapping()) {
if (m.getUri().equals(url))
code = m.getIdentity();
}
if (code != null) {
if (hasLogicalMapping(sd, logical, code)) {
any = true;
b.append(" <tr>\r\n");
b.append(" <td><a href=\"" + rd.getName().toLowerCase() + ".html\">" + rd.getName() + "</a></td>\r\n");
for (ElementDefn e : elements) {
populateLogicalMappingColumn(b, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, null, null, null);
}
b.append(" </tr>\r\n");
}
}
}
b.append("</table>\r\n");
if (any)
return "<a name=\"mappings\"></a><h3>Mappings</h3>\r\n\r\n" + b.toString();
else
return "";
}
use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project kindling by HL7.
the class PageProcessor method genLogicalAnalysis.
private String genLogicalAnalysis(ResourceDefn logical, String genlevel) throws FHIRException, IOException {
IniFile ini = new IniFile(Utilities.path(getFolders().srcDir, logical.getName(), logical.getName() + "-tasks.ini"));
String url = logical.getMappingUrl();
Map<ElementDefn, StringBuilder> bm = new HashMap<>();
List<ElementDefn> elements = new ArrayList<ElementDefn>();
listAllElements(elements, logical.getRoot().getName(), logical.getRoot());
for (ElementDefn e : elements) {
StringBuilder b2 = new StringBuilder();
bm.put(e, b2);
}
boolean any = false;
for (String s : sorted(definitions.getResources().keySet())) {
ResourceDefn rd = definitions.getResourceByName(s);
StructureDefinition sd = rd.getProfile();
String code = null;
for (StructureDefinitionMappingComponent m : sd.getMapping()) {
if (m.getUri().equals(url))
code = m.getIdentity();
}
if (code != null) {
if (hasLogicalMapping(sd, logical, code)) {
any = true;
for (ElementDefn e : elements) {
StringBuilder b2 = bm.get(e);
populateLogicalMappingColumn(null, logical.getRoot().getName(), rd.getName().toLowerCase() + "-definitions.html#", e, sd, rd.getName(), code, url, b2, ini, e.getPath());
}
}
}
}
if (any) {
StringBuilder bx = new StringBuilder();
bx.append("<a name=\"mappings\"></a><h3>Mappings</h3>\r\n");
bx.append("<table class=\"grid\">\r\n");
for (ElementDefn e : elements) {
if (logical.getRoot().getElements().contains(e)) {
bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">" + e.getPath() + "</a></b></td></tr>\r\n");
} else {
bx.append("<tr><td colspan=\"6\"><b><a href=\"" + logical.getName().toLowerCase() + "-definitions.html#" + e.getPath() + "\">." + e.getPath() + "</a></b></td></tr>\r\n");
}
bx.append("<tr><td colspan=\"6\">" + e.getPath() + " : " + e.typeCode() + " [" + e.describeCardinality() + "]</td></tr>\r\n");
bx.append("<tr><td>Resource</td><td>Matches</td><td>Issues</td><td>Tasks</td><td>Status</td><td>Notes</td></tr>\r\n");
bx.append(bm.get(e).toString());
}
bx.append("</table>\r\n");
return bx.toString();
} else
return "";
}
use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateDescription.
private Cell generateDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, boolean logicalModel, boolean allInvariants, ElementDefinition valueDefn, boolean snapshot) throws IOException, FHIRException {
Cell c = gen.new Cell();
row.getCells().add(c);
if (used) {
if (logicalModel && ToolingExtensions.hasExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) {
if (root) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
} else if (!root && ToolingExtensions.hasExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace") && !ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").equals(ToolingExtensions.readStringExtension(profile, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"))) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(definition, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"), null));
}
}
if (definition.hasContentReference()) {
ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
if (ed == null)
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Unknown reference to %s", definition.getContentReference()), null));
else
c.getPieces().add(gen.new Piece("#" + ed.getPath(), translate("sd.table", "See %s", ed.getPath()), null));
}
if (definition.getPath().endsWith("url") && definition.hasFixed()) {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "\"" + buildJson(definition.getFixed()) + "\"", null).addStyle("color: darkgreen")));
} else {
if (definition != null && definition.hasShort()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(definition.getShortElement(), gen.new Piece(null, gt(definition.getShortElement()), null)));
} else if (fallback != null && fallback.hasShort()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.addPiece(checkForNoChange(fallback.getShortElement(), gen.new Piece(null, gt(fallback.getShortElement()), null)));
}
if (url != null) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
String fullUrl = url.startsWith("#") ? baseURL + url : url;
StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
String ref = null;
String ref2 = null;
String fixedUrl = null;
if (ed != null) {
String p = ed.getUserString("path");
if (p != null) {
ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
}
fixedUrl = getFixedUrl(ed);
if (fixedUrl != null) {
// if its null, we guess that it's not a profiled extension?
if (fixedUrl.equals(url))
fixedUrl = null;
else {
StructureDefinition ed2 = context.fetchResource(StructureDefinition.class, fixedUrl);
if (ed2 != null) {
String p2 = ed2.getUserString("path");
if (p2 != null) {
ref2 = p2.startsWith("http:") || igmode ? p2 : Utilities.pathURL(corePath, p2);
}
}
}
}
}
if (fixedUrl == null) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref, fullUrl, null));
} else {
// reference to a profile take on the extension show the base URL
c.getPieces().add(gen.new Piece(null, translate("sd.table", "URL") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref2, fixedUrl, null));
c.getPieces().add(gen.new Piece(null, translate("sd.table", " profiled by ") + " ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(ref, fullUrl, null));
}
}
if (definition.hasSlicing()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Slice") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, describeSlice(definition.getSlicing()), null));
}
if (definition != null) {
ElementDefinitionBindingComponent binding = null;
if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
binding = valueDefn.getBinding();
else if (definition.hasBinding())
binding = definition.getBinding();
if (binding != null && !binding.isEmpty()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp.resolveBinding(profile, binding, definition.getPath());
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
if (binding.hasStrength()) {
c.getPieces().add(checkForNoChange(binding, gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MAX_VALUESET), definition.getPath());
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-maxvalueset.html", translate("sd.table", "Max Binding") + ": ", "Max Value Set Extension").addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
}
if (binding.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
br = pkp.resolveBinding(profile, ToolingExtensions.readStringExtension(binding, ToolingExtensions.EXT_MIN_VALUESET), definition.getPath());
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(corePath + "extension-elementdefinition-minvalueset.html", translate("sd.table", "Min Binding") + ": ", "Min Value Set Extension").addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(binding, gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
}
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
if (!inv.hasSource() || allInvariants) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, inv.getKey() + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(inv, gen.new Piece(null, gt(inv.getHumanElement()), null)));
}
}
if ((definition.hasBase() && definition.getBase().getMax().equals("*")) || (definition.hasMax() && definition.getMax().equals("*"))) {
if (c.getPieces().size() > 0)
c.addPiece(gen.new Piece("br"));
if (definition.hasOrderMeaning()) {
c.getPieces().add(gen.new Piece(null, "This repeating element order: " + definition.getOrderMeaning(), null));
} else {
// don't show this, this it's important: c.getPieces().add(gen.new Piece(null, "This repeating element has no defined order", null));
}
}
if (definition.hasFixed()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, translate("sd.table", "Fixed Value") + ": ", null).addStyle("font-weight:bold")));
if (!useTableForFixedValues || definition.getFixed().isPrimitive()) {
String s = buildJson(definition.getFixed());
String link = null;
if (Utilities.isAbsoluteUrl(s))
link = pkp.getLinkForUrl(corePath, s);
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(link, s, null).addStyle("color: darkgreen")));
} else {
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "As shown", null).addStyle("color: darkgreen")));
genFixedValue(gen, row, definition.getFixed(), snapshot, false, corePath);
}
if (isCoded(definition.getFixed()) && !hasDescription(definition.getFixed())) {
Piece p = describeCoded(gen, definition.getFixed());
if (p != null)
c.getPieces().add(p);
}
} else if (definition.hasPattern()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, translate("sd.table", "Required Pattern") + ": ", null).addStyle("font-weight:bold")));
if (!useTableForFixedValues || definition.getPattern().isPrimitive())
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
else {
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "At least the following", null).addStyle("color: darkgreen")));
genFixedValue(gen, row, definition.getPattern(), snapshot, true, corePath);
}
} else if (definition.hasExample()) {
for (ElementDefinitionExampleComponent ex : definition.getExample()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, translate("sd.table", "Example") + ("".equals("General") ? "" : " " + ex.getLabel() + "'") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(ex, gen.new Piece(null, buildJson(ex.getValue()), null).addStyle("color: darkgreen")));
}
}
if (definition.hasMaxLength() && definition.getMaxLength() != 0) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, "Max Length: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getMaxLengthElement(), gen.new Piece(null, Integer.toString(definition.getMaxLength()), null).addStyle("color: darkgreen")));
}
if (profile != null) {
for (StructureDefinitionMappingComponent md : profile.getMapping()) {
if (md.hasExtension(ToolingExtensions.EXT_TABLE_NAME)) {
ElementDefinitionMappingComponent map = null;
for (ElementDefinitionMappingComponent m : definition.getMapping()) if (m.getIdentity().equals(md.getIdentity()))
map = m;
if (map != null) {
for (int i = 0; i < definition.getMapping().size(); i++) {
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(md, ToolingExtensions.EXT_TABLE_NAME) + ": " + map.getMap(), null));
}
}
}
}
}
}
}
}
return c;
}
Aggregations