use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece in project kindling by HL7.
the class PageProcessor method generateToc.
private String generateToc() throws Exception {
// return breadCrumbManager.makeToc();
List<String> entries = new ArrayList<String>();
entries.addAll(toc.keySet());
Collections.sort(entries, new SectionSorter());
Set<String> pages = new HashSet<String>();
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(folders.dstDir, false, true);
TableModel model = gen.new TableModel("toc", true);
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Table of Contents", "Table of Contents", null, 0));
Deque<TocItem> stack = new ArrayDeque<TocItem>();
for (String s : entries) {
TocEntry t = toc.get(s);
if (!t.isIg() && !s.startsWith("?")) {
String nd = s;
while (nd.endsWith(".0")) nd = nd.substring(0, nd.length() - 2);
int d = Utilities.charCount(nd, '.');
if (d < 4 && !pages.contains(t.getLink())) {
String np = getNormativePackageForPage(t.getLink());
pages.add(t.getLink());
while (!stack.isEmpty() && stack.getFirst().depth >= d) stack.pop();
Row row = gen.new Row();
row.setIcon("icon_page.gif", null);
String td = t.getText();
if (!stack.isEmpty()) {
if (td.startsWith(stack.getFirst().entry.getText() + " - "))
td = td.substring(stack.getFirst().entry.getText().length() + 3);
else if (td.startsWith(stack.getFirst().entry.getText()))
td = td.substring(stack.getFirst().entry.getText().length());
}
Cell cell = gen.new Cell(null, t.getLink(), nd + " " + td, t.getText() + " ", null);
row.getCells().add(cell);
if (np != null) {
cell.addPiece(gen.new Piece(null, " ", null));
cell.addPiece(gen.new Piece("versions.html#std-process", "basic".equals(np) ? "(Normative)" : "(Normative / " + Utilities.capitalize(np) + ")", null).addStyle("color: #008000"));
if (np.equals("infrastructure"))
row.setIcon("icon_page_n_i.gif", null);
else if (np.equals("conformance"))
row.setIcon("icon_page_n_c.gif", null);
else if (np.equals("patient"))
row.setIcon("icon_page_n_p.gif", null);
else if (np.equals("observation"))
row.setIcon("icon_page_n_o.gif", null);
else
row.setIcon("icon_page_n.gif", null);
} else {
cell.addPiece(gen.new Piece(null, " ", null));
cell.addPiece(gen.new Piece("versions.html#std-process", "(Trial Use)", null).addStyle("color: #b3b3b3"));
}
if (stack.isEmpty())
model.getRows().add(row);
else
stack.getFirst().row.getSubRows().add(row);
stack.push(new TocItem(t, row, d));
}
}
}
return new XhtmlComposer(XhtmlComposer.HTML).compose(gen.generate(model, "", 0, null));
}
use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genElement.
private void genElement(String defPath, HierarchicalTableGenerator gen, List<Row> rows, ElementDefinition element, List<ElementDefinition> all, List<StructureDefinition> profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, boolean snapshot, String corePath, String imagePath, boolean root, boolean logicalModel, boolean isConstraintMode, boolean allInvariants) throws IOException {
StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
String s = tail(element.getPath());
List<ElementDefinition> children = getChildren(all, element);
boolean isExtension = (s.equals("extension") || s.equals("modifierExtension"));
if (!snapshot && isExtension && extensions != null && extensions != isExtension)
return;
if (!onlyInformationIsMapping(all, element)) {
Row row = gen.new Row();
row.setAnchor(element.getPath());
row.setColor(getRowColor(element, isConstraintMode));
boolean hasDef = element != null;
boolean ext = false;
if (s.equals("extension")) {
if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile()))
row.setIcon("icon_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
else
row.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
ext = true;
} else if (s.equals("modifierExtension")) {
if (element.hasType() && element.getType().get(0).hasProfile() && extensionIsComplex(element.getType().get(0).getProfile()))
row.setIcon("icon_modifier_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
else
row.setIcon("icon_modifier_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
} else if (!hasDef || element.getType().size() == 0)
row.setIcon("icon_element.gif", HierarchicalTableGenerator.TEXT_ICON_ELEMENT);
else if (hasDef && element.getType().size() > 1) {
if (allTypesAre(element.getType(), "Reference"))
row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
else
row.setIcon("icon_choice.gif", HierarchicalTableGenerator.TEXT_ICON_CHOICE);
} else if (hasDef && element.getType().get(0).getCode() != null && element.getType().get(0).getCode().startsWith("@"))
row.setIcon("icon_reuse.png", HierarchicalTableGenerator.TEXT_ICON_REUSE);
else if (hasDef && isPrimitive(element.getType().get(0).getCode()))
row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
else if (hasDef && isReference(element.getType().get(0).getCode()))
row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
else if (hasDef && isDataType(element.getType().get(0).getCode()))
row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
else
row.setIcon("icon_resource.png", HierarchicalTableGenerator.TEXT_ICON_RESOURCE);
String ref = defPath == null ? null : defPath + element.getId();
UnusedTracker used = new UnusedTracker();
used.used = true;
Cell left = gen.new Cell(null, ref, s, (element.hasSliceName() ? translate("sd.table", "Slice") + " " + element.getSliceName() : "") + (hasDef && element.hasSliceName() ? ": " : "") + (!hasDef ? null : gt(element.getDefinitionElement())), null);
row.getCells().add(left);
Cell gc = gen.new Cell();
row.getCells().add(gc);
if (element != null && element.getIsModifier())
checkForNoChange(element.getIsModifierElement(), gc.addStyledText(translate("sd.table", "This element is a modifier element"), "?!", null, null, null, false));
if (element != null && element.getMustSupport())
checkForNoChange(element.getMustSupportElement(), gc.addStyledText(translate("sd.table", "This element must be supported"), "S", "white", "red", null, false));
if (element != null && element.getIsSummary())
checkForNoChange(element.getIsSummaryElement(), gc.addStyledText(translate("sd.table", "This element is included in summaries"), "\u03A3", null, null, null, false));
if (element != null && (!element.getConstraint().isEmpty() || !element.getCondition().isEmpty()))
gc.addStyledText(translate("sd.table", "This element has or is affected by some invariants"), "I", null, null, null, false);
ExtensionContext extDefn = null;
if (ext) {
if (element != null && element.getType().size() == 1 && element.getType().get(0).hasProfile()) {
extDefn = locateExtension(StructureDefinition.class, element.getType().get(0).getProfile());
if (extDefn == null) {
genCardinality(gen, element, row, hasDef, used, null);
row.getCells().add(gen.new Cell(null, null, "?? " + element.getType().get(0).getProfile(), null, null));
generateDescription(gen, row, element, null, used.used, profile.getUrl(), element.getType().get(0).getProfile(), profile, corePath, imagePath, root, logicalModel, allInvariants);
} else {
String name = urltail(element.getType().get(0).getProfile());
left.getPieces().get(0).setText(name);
// left.getPieces().get(0).setReference((String) extDefn.getExtensionStructure().getTag("filename"));
left.getPieces().get(0).setHint(translate("sd.table", "Extension URL") + " = " + extDefn.getUrl());
genCardinality(gen, element, row, hasDef, used, extDefn.getElement());
ElementDefinition valueDefn = extDefn.getExtensionValueDefinition();
if (valueDefn != null && !"0".equals(valueDefn.getMax()))
genTypes(gen, row, valueDefn, profileBaseFileName, profile, corePath, imagePath);
else
// if it's complex, we just call it nothing
// genTypes(gen, row, extDefn.getSnapshot().getElement().get(0), profileBaseFileName, profile);
row.getCells().add(gen.new Cell(null, null, "(" + translate("sd.table", "Complex") + ")", null, null));
generateDescription(gen, row, element, extDefn.getElement(), used.used, null, extDefn.getUrl(), profile, corePath, imagePath, root, logicalModel, allInvariants, valueDefn);
}
} else {
genCardinality(gen, element, row, hasDef, used, null);
if ("0".equals(element.getMax()))
row.getCells().add(gen.new Cell());
else
genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath);
generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants);
}
} else {
genCardinality(gen, element, row, hasDef, used, null);
if (hasDef && !"0".equals(element.getMax()))
genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath);
else
row.getCells().add(gen.new Cell());
generateDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, logicalModel, allInvariants);
}
if (element.hasSlicing()) {
if (standardExtensionSlicing(element)) {
used.used = element.hasType() && element.getType().get(0).hasProfile();
showMissing = false;
} else {
row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
row.getCells().get(2).getPieces().clear();
for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
p.addStyle("font-style: italic");
}
}
}
if (used.used || showMissing)
rows.add(row);
if (!used.used && !element.hasSlicing()) {
for (Cell cell : row.getCells()) for (Piece p : cell.getPieces()) {
p.setStyle("text-decoration:line-through");
p.setReference(null);
}
} else {
for (ElementDefinition child : children) if (logicalModel || !child.getPath().endsWith(".id") || (child.getPath().endsWith(".id") && (profile != null) && (profile.getDerivation() == TypeDerivationRule.CONSTRAINT)))
genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, snapshot, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants);
if (!snapshot && (extensions == null || !extensions))
for (ElementDefinition child : children) if (child.getPath().endsWith(".extension") || child.getPath().endsWith(".modifierExtension"))
genElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, true, false, corePath, imagePath, false, logicalModel, isConstraintMode, allInvariants);
}
}
}
use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method generateExtensionTable.
public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
gen.setTranslator(getTranslator());
TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false);
boolean deep = false;
String m = "";
boolean vdeep = false;
if (ed.getSnapshot().getElementFirstRep().getIsModifier())
m = "modifier_";
for (ElementDefinition eld : ed.getSnapshot().getElement()) {
deep = deep || eld.getPath().contains("Extension.extension.");
vdeep = vdeep || eld.getPath().contains("Extension.extension.extension.");
}
Row r = gen.new Row();
model.getRows().add(r);
r.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ed.getSnapshot().getElement().get(0).getIsModifier() ? "modifierExtension" : "extension", null, null));
r.getCells().add(gen.new Cell());
r.getCells().add(gen.new Cell(null, null, describeCardinality(ed.getSnapshot().getElement().get(0), null, new UnusedTracker()), null, null));
ElementDefinition ved = null;
if (full || vdeep) {
r.getCells().add(gen.new Cell("", "", "Extension", null, null));
r.setIcon(deep ? "icon_" + m + "extension_complex.png" : "icon_extension_simple.png", deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
List<ElementDefinition> children = getChildren(ed.getSnapshot().getElement(), ed.getSnapshot().getElement().get(0));
for (ElementDefinition child : children) if (!child.getPath().endsWith(".id"))
genElement(defFile == null ? "" : defFile + "-definitions.html#extension.", gen, r.getSubRows(), child, ed.getSnapshot().getElement(), null, true, defFile, true, full, corePath, imagePath, true, false, false, false);
} else if (deep) {
List<ElementDefinition> children = new ArrayList<ElementDefinition>();
for (ElementDefinition ted : ed.getSnapshot().getElement()) {
if (ted.getPath().equals("Extension.extension"))
children.add(ted);
}
r.getCells().add(gen.new Cell("", "", "Extension", null, null));
r.setIcon("icon_" + m + "extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX);
for (ElementDefinition c : children) {
ved = getValueFor(ed, c);
ElementDefinition ued = getUrlFor(ed, c);
if (ved != null && ued != null) {
Row r1 = gen.new Row();
r.getSubRows().add(r1);
r1.getCells().add(gen.new Cell(null, defFile == null ? "" : defFile + "-definitions.html#extension." + ed.getName(), ((UriType) ued.getFixed()).getValue(), null, null));
r1.getCells().add(gen.new Cell());
r1.getCells().add(gen.new Cell(null, null, describeCardinality(c, null, new UnusedTracker()), null, null));
genTypes(gen, r1, ved, defFile, ed, corePath, imagePath);
r1.getCells().add(gen.new Cell(null, null, c.getDefinition(), null, null));
r1.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
}
}
} else {
for (ElementDefinition ted : ed.getSnapshot().getElement()) {
if (ted.getPath().startsWith("Extension.value"))
ved = ted;
}
genTypes(gen, r, ved, defFile, ed, corePath, imagePath);
r.setIcon("icon_" + m + "extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE);
}
Cell c = gen.new Cell("", "", "URL = " + ed.getUrl(), null, null);
c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, ed.getName() + ": " + ed.getDescription(), null));
if (!full && !(deep || vdeep) && ved != null && ved.hasBinding()) {
c.addPiece(gen.new Piece("br"));
BindingResolution br = pkp.resolveBinding(ed, ved.getBinding(), ved.getPath());
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, translate("sd.table", "Binding") + ": ", null).addStyle("font-weight:bold")));
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(br.url == null ? null : Utilities.isAbsoluteUrl(br.url) || !pkp.prependLinks() ? br.url : corePath + br.url, br.display, null)));
if (ved.getBinding().hasStrength()) {
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(null, " (", null)));
c.getPieces().add(checkForNoChange(ved.getBinding(), gen.new Piece(corePath + "terminologies.html#" + ved.getBinding().getStrength().toCode(), egt(ved.getBinding().getStrengthElement()), ved.getBinding().getStrength().getDefinition())));
c.getPieces().add(gen.new Piece(null, ")", null));
}
}
c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, describeExtensionContext(ed), null));
r.getCells().add(c);
try {
return gen.generate(model, corePath, 0, outputTracker);
} catch (org.hl7.fhir.exceptions.FHIRException e) {
throw new FHIRException(e.getMessage(), e);
}
}
use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genCardinality.
private void genCardinality(HierarchicalTableGenerator gen, ElementDefinition definition, Row row, boolean hasDef, UnusedTracker tracker, ElementDefinition fallback) {
IntegerType min = !hasDef ? new IntegerType() : definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
StringType max = !hasDef ? new StringType() : definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
if (min.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
if (base.hasMinElement()) {
min = base.getMinElement().copy();
min.setUserData(DERIVATION_EQUALS, true);
}
}
if (max.isEmpty() && definition.getUserData(DERIVATION_POINTER) != null) {
ElementDefinition base = (ElementDefinition) definition.getUserData(DERIVATION_POINTER);
if (base.hasMaxElement()) {
max = base.getMaxElement().copy();
max.setUserData(DERIVATION_EQUALS, true);
}
}
if (min.isEmpty() && fallback != null)
min = fallback.getMinElement();
if (max.isEmpty() && fallback != null)
max = fallback.getMaxElement();
if (!max.isEmpty())
tracker.used = !max.getValue().equals("0");
Cell cell = gen.new Cell(null, null, null, null, null);
row.getCells().add(cell);
if (!min.isEmpty() || !max.isEmpty()) {
cell.addPiece(checkForNoChange(min, gen.new Piece(null, !min.hasValue() ? "" : Integer.toString(min.getValue()), null)));
cell.addPiece(checkForNoChange(min, max, gen.new Piece(null, "..", null)));
cell.addPiece(checkForNoChange(min, gen.new Piece(null, !max.hasValue() ? "" : max.getValue(), null)));
}
}
use of org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genGridElement.
private void genGridElement(String defPath, HierarchicalTableGenerator gen, List<Row> rows, ElementDefinition element, List<ElementDefinition> all, List<StructureDefinition> profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, String corePath, String imagePath, boolean root, boolean isConstraintMode) throws IOException {
StructureDefinition profile = profiles == null ? null : profiles.get(profiles.size() - 1);
String s = tail(element.getPath());
List<ElementDefinition> children = getChildren(all, element);
boolean isExtension = (s.equals("extension") || s.equals("modifierExtension"));
if (!onlyInformationIsMapping(all, element)) {
Row row = gen.new Row();
row.setAnchor(element.getPath());
row.setColor(getRowColor(element, isConstraintMode));
boolean hasDef = element != null;
String ref = defPath == null ? null : defPath + element.getId();
UnusedTracker used = new UnusedTracker();
used.used = true;
Cell left = gen.new Cell();
if (element.getType().size() == 1 && element.getType().get(0).isPrimitive())
left.getPieces().add(gen.new Piece(ref, "\u00A0\u00A0" + s, !hasDef ? null : gt(element.getDefinitionElement())).addStyle("font-weight:bold"));
else
left.getPieces().add(gen.new Piece(ref, "\u00A0\u00A0" + s, !hasDef ? null : gt(element.getDefinitionElement())));
if (element.hasSliceName()) {
left.getPieces().add(gen.new Piece("br"));
String indent = StringUtils.repeat('\u00A0', 1 + 2 * (element.getPath().split("\\.").length));
left.getPieces().add(gen.new Piece(null, indent + "(" + element.getSliceName() + ")", null));
}
row.getCells().add(left);
ExtensionContext extDefn = null;
genCardinality(gen, element, row, hasDef, used, null);
if (hasDef && !"0".equals(element.getMax()))
genTypes(gen, row, element, profileBaseFileName, profile, corePath, imagePath);
else
row.getCells().add(gen.new Cell());
generateGridDescription(gen, row, element, null, used.used, null, null, profile, corePath, imagePath, root, null);
/* if (element.hasSlicing()) {
if (standardExtensionSlicing(element)) {
used.used = element.hasType() && element.getType().get(0).hasProfile();
showMissing = false;
} else {
row.setIcon("icon_slice.png", HierarchicalTableGenerator.TEXT_ICON_SLICE);
row.getCells().get(2).getPieces().clear();
for (Cell cell : row.getCells())
for (Piece p : cell.getPieces()) {
p.addStyle("font-style: italic");
}
}
}*/
rows.add(row);
for (ElementDefinition child : children) if (child.getMustSupport())
genGridElement(defPath, gen, row.getSubRows(), child, all, profiles, showMissing, profileBaseFileName, isExtension, corePath, imagePath, false, isConstraintMode);
}
}
Aggregations