use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateGridDescription.
private Cell generateGridDescription(HierarchicalTableGenerator gen, Row row, ElementDefinition definition, ElementDefinition fallback, boolean used, String baseURL, String url, StructureDefinition profile, String corePath, String imagePath, boolean root, ElementDefinition valueDefn) throws IOException {
Cell c = gen.new Cell();
row.getCells().add(c);
if (used) {
if (definition.hasContentReference()) {
ElementDefinition ed = getElementByName(profile.getSnapshot().getElement(), definition.getContentReference());
if (ed == null)
c.getPieces().add(gen.new Piece(null, "Unknown reference to " + definition.getContentReference(), null));
else
c.getPieces().add(gen.new Piece("#" + ed.getPath(), "See " + 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 (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;
if (ed != null) {
String p = ed.getUserString("path");
if (p != null) {
ref = p.startsWith("http:") || igmode ? p : Utilities.pathURL(corePath, p);
}
}
c.getPieces().add(gen.new Piece(null, "URL: ", 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, "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, "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(), binding.getStrength().toCode(), binding.getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
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, inv.getHuman(), null)));
}
if (definition.hasFixed()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getFixed(), gen.new Piece(null, buildJson(definition.getFixed()), null).addStyle("color: darkgreen")));
} else if (definition.hasPattern()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, "Required Pattern: ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(definition.getPattern(), gen.new Piece(null, buildJson(definition.getPattern()), null).addStyle("color: darkgreen")));
} 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, "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));
}
}
}
}
}
if (definition.getComment() != null) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Comments: ", null).addStyle("font-weight:bold"));
c.addPiece(gen.new Piece("br"));
c.addMarkdown(definition.getComment());
// c.getPieces().add(checkForNoChange(definition.getCommentElement(), gen.new Piece(null, definition.getComment(), null)));
}
}
}
}
return c;
}
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, boolean mustSupportOnly, boolean allowSubRows, RenderingContext rc) 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 (root) {
if (profile != null && profile.getAbstract()) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.addPiece(gen.new Piece(null, "This is an abstract profile", 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(gen.new Piece(null, gt(fallback.getShortElement()), null).addStyle("opacity: 0.5"));
}
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.getPath().contains(".") && ToolingExtensions.hasExtension(profile, ToolingExtensions.EXT_BINDING_STYLE)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, "This type can be bound to a value set using the ", null));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, ToolingExtensions.EXT_BINDING_STYLE), null));
c.getPieces().add(gen.new Piece(null, " binding style", null));
}
if (definition.hasExtension(ToolingExtensions.EXT_XML_NAME)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
c.getPieces().add(gen.new Piece(null, " (", null));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
c.getPieces().add(gen.new Piece(null, ")", null));
} else {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Element Name") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
}
} else if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
}
if (definition != null) {
ElementDefinitionBindingComponent binding = null;
if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
binding = makeUnifiedBinding(valueDefn.getBinding(), valueDefn);
else if (definition.hasBinding())
binding = makeUnifiedBinding(definition.getBinding(), definition);
if (binding != null && !binding.isEmpty()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp == null ? makeNullBr(binding) : 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.getValueSetElement(), 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.getStrengthElement(), gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, ")", null)));
}
if (binding.hasDescription() && MarkDownProcessor.isSimpleMarkdown(binding.getDescription())) {
c.getPieces().add(gen.new Piece(null, ": ", null));
c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement()).asStringValue(), checkForNoChange(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement())));
}
AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(pkp, corePath, profile, definition.getPath(), rc, null);
if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
abr.seeMaxBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MAX_VALUESET));
}
if (binding.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
abr.seeMinBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MIN_VALUESET));
}
if (binding.hasExtension(ToolingExtensions.EXT_BINDING_ADDITIONAL)) {
abr.seeAdditionalBindings(binding.getExtensionsByUrl(ToolingExtensions.EXT_BINDING_ADDITIONAL));
}
abr.render(gen, c);
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
if (!inv.hasSource() || profile == null || inv.getSource().equals(profile.getUrl()) || 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() && "*".equals(definition.getBase().getMax())) || (definition.hasMax() && "*".equals(definition.getMax()))) {
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 || !allowSubRows || 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, false);
}
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 || !allowSubRows || 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, mustSupportOnly);
}
} 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;
}
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 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, boolean mustSupportOnly, boolean allowSubRows, RenderingContext rc) 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 (root) {
if (profile != null && profile.getAbstract()) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.addPiece(gen.new Piece(null, "This is an abstract profile", 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(gen.new Piece(null, gt(fallback.getShortElement()), null).addStyle("opacity: 0.5"));
}
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.getPath().contains(".") && ToolingExtensions.hasExtension(profile, ToolingExtensions.EXT_BINDING_STYLE)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.getPieces().add(gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, "This type can be bound to a value set using the ", null));
c.getPieces().add(gen.new Piece(null, ToolingExtensions.readStringExtension(profile, ToolingExtensions.EXT_BINDING_STYLE), null));
c.getPieces().add(gen.new Piece(null, " binding style", null));
}
if (definition.hasExtension(ToolingExtensions.EXT_XML_NAME)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
c.getPieces().add(gen.new Piece(null, " (", null));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
c.getPieces().add(gen.new Piece(null, ")", null));
} else {
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Element Name") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAME), null));
}
} else if (definition.hasExtension(ToolingExtensions.EXT_XML_NAMESPACE)) {
if (!c.getPieces().isEmpty()) {
c.addPiece(gen.new Piece("br"));
}
c.getPieces().add(gen.new Piece(null, translate("sd.table", "XML Namespace") + ": ", null).addStyle("font-weight:bold"));
c.getPieces().add(gen.new Piece(null, definition.getExtensionString(ToolingExtensions.EXT_XML_NAMESPACE), null));
}
if (definition != null) {
ElementDefinitionBindingComponent binding = null;
if (valueDefn != null && valueDefn.hasBinding() && !valueDefn.getBinding().isEmpty())
binding = makeUnifiedBinding(valueDefn.getBinding(), valueDefn);
else if (definition.hasBinding())
binding = makeUnifiedBinding(definition.getBinding(), definition);
if (binding != null && !binding.isEmpty()) {
if (!c.getPieces().isEmpty())
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp == null ? makeNullBr(binding) : 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.getValueSetElement(), 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.getStrengthElement(), gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(corePath + "terminologies.html#" + binding.getStrength().toCode(), egt(binding.getStrengthElement()), binding.getStrength().getDefinition())));
c.getPieces().add(checkForNoChange(binding.getStrengthElement(), gen.new Piece(null, ")", null)));
}
if (binding.hasDescription() && MarkDownProcessor.isSimpleMarkdown(binding.getDescription())) {
c.getPieces().add(gen.new Piece(null, ": ", null));
c.addMarkdownNoPara(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement()).asStringValue(), checkForNoChange(PublicationHacker.fixBindingDescriptions(context, binding.getDescriptionElement())));
}
AdditionalBindingsRenderer abr = new AdditionalBindingsRenderer(pkp, corePath, profile, definition.getPath(), rc, null);
if (binding.hasExtension(ToolingExtensions.EXT_MAX_VALUESET)) {
abr.seeMaxBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MAX_VALUESET));
}
if (binding.hasExtension(ToolingExtensions.EXT_MIN_VALUESET)) {
abr.seeMinBinding(ToolingExtensions.getExtension(binding, ToolingExtensions.EXT_MIN_VALUESET));
}
if (binding.hasExtension(ToolingExtensions.EXT_BINDING_ADDITIONAL)) {
abr.seeAdditionalBindings(binding.getExtensionsByUrl(ToolingExtensions.EXT_BINDING_ADDITIONAL));
}
abr.render(gen, c);
}
for (ElementDefinitionConstraintComponent inv : definition.getConstraint()) {
if (!inv.hasSource() || profile == null || inv.getSource().equals(profile.getUrl()) || 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() && "*".equals(definition.getBase().getMax())) || (definition.hasMax() && "*".equals(definition.getMax()))) {
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 || !allowSubRows || 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, false);
}
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 || !allowSubRows || 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, mustSupportOnly);
}
} 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;
}
use of org.hl7.fhir.r4b.model.StructureDefinition.StructureDefinitionMappingComponent in project org.hl7.fhir.core by hapifhir.
the class StructureDefinitionSpreadsheetGenerator method processElement.
public void processElement(Sheet sheet, StructureDefinition sd, ElementDefinition ed) throws Exception {
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
int i = 0;
addCell(row, i++, ed.getPath(), styles.get("body"));
addCell(row, i++, ed.getSliceName());
addCell(row, i++, itemList(ed.getAlias()));
addCell(row, i++, ed.getLabel());
addCell(row, i++, ed.getMin());
addCell(row, i++, ed.getMax());
addCell(row, i++, ed.getMustSupport() ? "Y" : "");
addCell(row, i++, ed.getIsModifier() ? "Y" : "");
addCell(row, i++, ed.getIsSummary() ? "Y" : "");
addCell(row, i++, itemList(ed.getType()));
addCell(row, i++, ed.getShort());
addCell(row, i++, ed.getDefinition());
addCell(row, i++, ed.getComment());
addCell(row, i++, ed.getRequirements());
addCell(row, i++, ed.getDefaultValue() != null ? renderType(ed.getDefaultValue()) : "");
addCell(row, i++, ed.getMeaningWhenMissing());
addCell(row, i++, ed.hasFixed() ? renderType(ed.getFixed()) : "");
addCell(row, i++, ed.hasPattern() ? renderType(ed.getPattern()) : "");
// todo...?
addCell(row, i++, ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : "");
addCell(row, i++, ed.hasMinValue() ? renderType(ed.getMinValue()) : "");
addCell(row, i++, ed.hasMaxValue() ? renderType(ed.getMaxValue()) : "");
addCell(row, i++, (ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : ""));
if (ed.hasBinding()) {
addCell(row, i++, ed.getBinding().getStrength() != null ? ed.getBinding().getStrength().toCode() : "");
addCell(row, i++, ed.getBinding().getDescription());
if (ed.getBinding().getValueSet() == null)
addCell(row, i++, "");
else
addCell(row, i++, ed.getBinding().getValueSet());
} else {
addCell(row, i++, "");
addCell(row, i++, "");
addCell(row, i++, "");
}
addCell(row, i++, itemList(ed.getCode()));
if (ed.hasSlicing()) {
addCell(row, i++, itemList(ed.getSlicing().getDiscriminator()));
addCell(row, i++, ed.getSlicing().getDescription());
addCell(row, i++, ed.getSlicing().getOrdered());
addCell(row, i++, ed.getSlicing().getRules() != null ? ed.getSlicing().getRules().toCode() : "");
} else {
addCell(row, i++, "");
addCell(row, i++, "");
addCell(row, i++, "");
addCell(row, i++, "");
}
if (ed.getBase() != null) {
addCell(row, i++, ed.getBase().getPath());
addCell(row, i++, ed.getBase().getMin());
addCell(row, i++, ed.getBase().getMax());
} else {
addCell(row, i++, "");
addCell(row, i++, "");
addCell(row, i++, "");
}
addCell(row, i++, itemList(ed.getCondition()));
addCell(row, i++, itemList(ed.getConstraint()));
for (StructureDefinitionMappingComponent mapKey : sd.getMapping()) {
String mapString = "";
for (ElementDefinitionMappingComponent map : ed.getMapping()) {
if (map.getIdentity().equals(mapKey.getIdentity()))
mapString = map.getMap();
}
addCell(row, i++, mapString);
}
}
Aggregations