diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java index 4ae719b8d..5701beccc 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java @@ -1279,6 +1279,83 @@ public class ProfileUtilities { return false; } + public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, + boolean inlineGraphics, boolean full, String corePath, Set outputTracker) + throws IOException, FHIRException { + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false, TableGenerationMode.XML); + + boolean deep = false; + boolean vdeep = false; + 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)); + + if (full || vdeep) { + r.getCells().add(gen.new Cell("", "", "Extension", null, null)); + + r.setIcon(deep ? "icon_extension_complex.png" : "icon_extension_simple.png", + deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX + : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE); + List 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); + } else if (deep) { + List children = new ArrayList(); + 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_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX); + + for (ElementDefinition c : children) { + ElementDefinition 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); + r1.getCells().add(gen.new Cell(null, null, c.getDefinition(), null, null)); + r1.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE); + } + } + } else { + ElementDefinition ved = null; + for (ElementDefinition ted : ed.getSnapshot().getElement()) { + if (ted.getPath().startsWith("Extension.value")) + ved = ted; + } + + genTypes(gen, r, ved, defFile, ed, corePath); + + r.setIcon("icon_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)); + c.addPiece(gen.new Piece("br")).addPiece(gen.new Piece(null, describeExtensionContext(ed), null)); + r.getCells().add(c); + + return gen.generate(model, corePath, 0, outputTracker); + } + private ElementDefinition getUrlFor(StructureDefinition ed, ElementDefinition c) { int i = ed.getSnapshot().getElement().indexOf(c) + 1; while (i < ed.getSnapshot().getElement().size() @@ -1486,6 +1563,21 @@ public class ProfileUtilities { return piece; } + public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, + boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, Set outputTracker) + throws IOException, FHIRException { + assert (diff != snapshot);// check it's ok to get rid of one of these + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, profile.getId() + (diff ? "d" : "s"), false, + TableGenerationMode.XML); + List list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement(); + List profiles = new ArrayList(); + profiles.add(profile); + genElement(defFile == null ? null : defFile + "#" + profile.getId() + ".", gen, model.getRows(), list.get(0), list, + profiles, diff, profileBaseFileName, null, snapshot, corePath); + return gen.generate(model, corePath, 0, outputTracker); + } + private void genElement(String defPath, HierarchicalTableGenerator gen, List rows, ElementDefinition element, List all, List profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, boolean snapshot, String corePath) throws IOException { diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java index 32608c705..35530de7b 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java @@ -1281,6 +1281,87 @@ public class ProfileUtilities { return false; } + public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, + boolean inlineGraphics, boolean full, String corePath, Set outputTracker) + throws IOException, FHIRException { + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false, TableGenerationMode.XML); + + boolean deep = false; + boolean vdeep = false; + 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)); + + if (full || vdeep) { + r.getCells().add(gen.new Cell("", "", "Extension", null, null)); + + r.setIcon(deep ? "icon_extension_complex.png" : "icon_extension_simple.png", + deep ? HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX + : HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE); + List 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, true, false); + } else if (deep) { + List children = new ArrayList(); + 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_extension_complex.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_COMPLEX); + + for (ElementDefinition c : children) { + ElementDefinition 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); + r1.getCells().add(gen.new Cell(null, null, c.getDefinition(), null, null)); + r1.setIcon("icon_extension_simple.png", HierarchicalTableGenerator.TEXT_ICON_EXTENSION_SIMPLE); + } + } + } else { + ElementDefinition ved = null; + for (ElementDefinition ted : ed.getSnapshot().getElement()) { + if (ted.getPath().startsWith("Extension.value")) + ved = ted; + } + + genTypes(gen, r, ved, defFile, ed, corePath); + + r.setIcon("icon_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)); + 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); + } + } + private ElementDefinition getUrlFor(StructureDefinition ed, ElementDefinition c) { int i = ed.getSnapshot().getElement().indexOf(c) + 1; while (i < ed.getSnapshot().getElement().size() @@ -1481,6 +1562,25 @@ public class ProfileUtilities { return piece; } + public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, + boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, boolean logicalModel, + Set outputTracker) throws IOException, FHIRException { + assert (diff != snapshot);// check it's ok to get rid of one of these + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, profile.getId() + (diff ? "d" : "s"), false, + TableGenerationMode.XML); + List list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement(); + List profiles = new ArrayList(); + profiles.add(profile); + genElement(defFile == null ? null : defFile + "#" + profile.getId() + ".", gen, model.getRows(), list.get(0), list, + profiles, diff, profileBaseFileName, null, snapshot, corePath, true, logicalModel); + try { + return gen.generate(model, corePath, 0, outputTracker); + } catch (org.hl7.fhir.exceptions.FHIRException e) { + throw new FHIRException(e.getMessage(), e); + } + } + private void genElement(String defPath, HierarchicalTableGenerator gen, List rows, ElementDefinition element, List all, List profiles, boolean showMissing, String profileBaseFileName, Boolean extensions, boolean snapshot, String corePath, boolean root, boolean logicalModel) throws IOException { diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java index 348f70076..4e1299b53 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java @@ -1620,6 +1620,91 @@ public class ProfileUtilities extends TranslatingUtilities { return !p.contains("."); } + public XhtmlNode generateExtensionTable(String defFile, StructureDefinition ed, String imageFolder, boolean inlineGraphics, boolean full, String corePath, String imagePath, Set outputTracker) throws IOException, FHIRException { + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, ed.getId(), false, TableGenerationMode.XML); + + 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 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 children = new ArrayList(); + 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); + } + } + private ElementDefinition getUrlFor(StructureDefinition ed, ElementDefinition c) { int i = ed.getSnapshot().getElement().indexOf(c) + 1; while (i < ed.getSnapshot().getElement().size() && ed.getSnapshot().getElement().get(i).getPath().startsWith(c.getPath()+".")) { @@ -1902,6 +1987,37 @@ public class ProfileUtilities extends TranslatingUtilities { return piece; } + public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, String imagePath, boolean logicalModel, boolean allInvariants, Set outputTracker) throws IOException, FHIRException { + assert(diff != snapshot);// check it's ok to get rid of one of these + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"), false, TableGenerationMode.XML); + List list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement(); + List profiles = new ArrayList(); + profiles.add(profile); + genElement(defFile == null ? null : defFile+"#", gen, model.getRows(), list.get(0), list, profiles, diff, profileBaseFileName, null, snapshot, corePath, imagePath, true, logicalModel, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list), allInvariants); + try { + return gen.generate(model, imagePath, 0, outputTracker); + } catch (org.hl7.fhir.exceptions.FHIRException e) { + throw new FHIRException(e.getMessage(), e); + } + } + + + public XhtmlNode generateGrid(String defFile, StructureDefinition profile, String imageFolder, boolean inlineGraphics, String profileBaseFileName, String corePath, String imagePath, Set outputTracker) throws IOException, FHIRException { + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, inlineGraphics); + TableModel model = gen.initGridTable(corePath, profile.getId()); + List list = profile.getSnapshot().getElement(); + List profiles = new ArrayList(); + profiles.add(profile); + genGridElement(defFile == null ? null : defFile+"#", gen, model.getRows(), list.get(0), list, profiles, true, profileBaseFileName, null, corePath, imagePath, true, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list)); + try { + return gen.generate(model, imagePath, 1, outputTracker); + } catch (org.hl7.fhir.exceptions.FHIRException e) { + throw new FHIRException(e.getMessage(), e); + } + } + + private boolean usesMustSupport(List list) { for (ElementDefinition ed : list) if (ed.hasMustSupport() && ed.getMustSupport()) @@ -3363,6 +3479,16 @@ public class ProfileUtilities extends TranslatingUtilities { } + public XhtmlNode generateSpanningTable(StructureDefinition profile, String imageFolder, boolean onlyConstraints, String constraintPrefix, Set outputTracker) throws IOException, FHIRException { + HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), imageFolder, false); + TableModel model = initSpanningTable(gen, "", false, profile.getId()); + Set processed = new HashSet(); + SpanEntry span = buildSpanningTable("(focus)", "", profile, processed, onlyConstraints, constraintPrefix); + + genSpanEntry(gen, model.getRows(), span); + return gen.generate(model, "", 0, outputTracker); + } + private SpanEntry buildSpanningTable(String name, String cardinality, StructureDefinition profile, Set processed, boolean onlyConstraints, String constraintPrefix) throws IOException { SpanEntry res = buildSpanEntryFromProfile(name, cardinality, profile); boolean wantProcess = !processed.contains(profile.getUrl());