fix problem with rendering confusion between paths around local and base specifications

This commit is contained in:
Grahame Grieve 2020-05-28 14:08:30 +10:00
parent c7258dc7eb
commit f64d5c7fd5
25 changed files with 194 additions and 60 deletions

View File

@ -1403,7 +1403,7 @@ public class OldProfileComparer implements ProfileKnowledgeProvider {
} }
private void genValueSetFile(String filename, ValueSet vs) throws IOException, FHIRException, EOperationOutcome { private void genValueSetFile(String filename, ValueSet vs) throws IOException, FHIRException, EOperationOutcome {
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setNoSlowLookup(true); rc.setNoSlowLookup(true);
RendererFactory.factory(vs, rc).render(vs); RendererFactory.factory(vs, rc).render(vs);
String s = new XhtmlComposer(XhtmlComposer.HTML).compose(vs.getText().getDiv()); String s = new XhtmlComposer(XhtmlComposer.HTML).compose(vs.getText().getDiv());

View File

@ -1391,7 +1391,7 @@ public class ProfileComparer implements ProfileKnowledgeProvider {
} }
private void genValueSetFile(String filename, ValueSet vs) throws IOException, FHIRException, EOperationOutcome { private void genValueSetFile(String filename, ValueSet vs) throws IOException, FHIRException, EOperationOutcome {
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setNoSlowLookup(true); rc.setNoSlowLookup(true);
RendererFactory.factory(vs, rc).render(vs); RendererFactory.factory(vs, rc).render(vs);
String s = new XhtmlComposer(XhtmlComposer.HTML).compose(vs.getText().getDiv()); String s = new XhtmlComposer(XhtmlComposer.HTML).compose(vs.getText().getDiv());

View File

@ -15,7 +15,10 @@ import org.hl7.fhir.r5.model.Bundle.BundleEntrySearchComponent;
import org.hl7.fhir.r5.model.Bundle.BundleType; import org.hl7.fhir.r5.model.Bundle.BundleType;
import org.hl7.fhir.r5.model.Composition; import org.hl7.fhir.r5.model.Composition;
import org.hl7.fhir.r5.model.DomainResource; import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Provenance;
import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper;
import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
import org.hl7.fhir.r5.renderers.utils.RenderingContext; import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext; import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome; import org.hl7.fhir.r5.utils.EOperationOutcome;
@ -42,13 +45,54 @@ public class BundleRenderer extends ResourceRenderer {
return null; return null;
} }
@Override
public boolean render(XhtmlNode x, ResourceWrapper b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
List<BaseWrapper> entries = b.children("entry");
if ("document".equals(b.get("type").primitiveValue())) {
if (entries.isEmpty() || (entries.get(0).has("resource") && "Composition".equals(entries.get(0).get("resource").fhirType())))
throw new FHIRException("Invalid document - first entry is not a Composition");
ResourceWrapper r = (ResourceWrapper) entries.get(0).getChildByName("resource").getValues().get(0);
x.addChildren(r.getNarrative());
} else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) {
// nothing
} else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
root.para().addText("Bundle "+b.getId()+" of type "+b.get("type").primitiveValue());
int i = 0;
for (BaseWrapper be : entries) {
i++;
if (be.has("fullUrl")) {
root.an(makeInternalLink(be.get("fullUrl").primitiveValue()));
}
if (be.has("resource") && be.getChildByName("resource").getValues().get(0).has("id")) {
root.an(be.get("resource").fhirType().toLowerCase() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
}
root.hr();
root.para().addText("Entry "+Integer.toString(i)+(be.has("fullUrl") ? " - Full URL = " + be.get("fullUrl").primitiveValue() : ""));
// if (be.hasRequest())
// renderRequest(root, be.getRequest());
// if (be.hasSearch())
// renderSearch(root, be.getSearch());
// if (be.hasResponse())
// renderResponse(root, be.getResponse());
if (be.has("resource")) {
root.para().addText("Resource "+be.get("resource").fhirType()+":");
ResourceWrapper rw = be.getChildByName("resource").getAsResource();
root.blockquote().addChildren(rw.getNarrative());
}
}
}
return false;
}
public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome { public XhtmlNode render(Bundle b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
if (b.getType() == BundleType.DOCUMENT) { if (b.getType() == BundleType.DOCUMENT) {
if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition)) if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition))
throw new FHIRException("Invalid document - first entry is not a Composition"); throw new FHIRException("Invalid document - first entry is not a Composition");
Composition dr = (Composition) b.getEntryFirstRep().getResource(); Composition dr = (Composition) b.getEntryFirstRep().getResource();
return dr.getText().getDiv(); return dr.getText().getDiv();
} else if ((b.getType() == BundleType.DOCUMENT && allEntresAreHistoryProvenance(b))) { } else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
return null; return null;
} else { } else {
XhtmlNode root = new XhtmlNode(NodeType.Element, "div"); XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
@ -81,9 +125,22 @@ public class BundleRenderer extends ResourceRenderer {
} }
} }
private boolean allEntriesAreHistoryProvenance(List<BaseWrapper> entries) throws UnsupportedEncodingException, FHIRException, IOException {
for (BaseWrapper be : entries) {
if (!"Provenance".equals(be.get("resource").fhirType())) {
return false;
}
}
return !entries.isEmpty();
}
private boolean allEntresAreHistoryProvenance(Bundle b) { private boolean allEntresAreHistoryProvenance(Bundle b) {
return false; for (BundleEntryComponent be : b.getEntry()) {
if (!(be.getResource() instanceof Provenance)) {
return false;
}
}
return !b.getEntry().isEmpty();
} }
private List<XhtmlNode> checkInternalLinks(Bundle b, List<XhtmlNode> childNodes) { private List<XhtmlNode> checkInternalLinks(Bundle b, List<XhtmlNode> childNodes) {

View File

@ -82,7 +82,7 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
tr = t.tr(); tr = t.tr();
tr.td().addText(r.getType()); tr.td().addText(r.getType());
if (r.hasProfile()) { if (r.hasProfile()) {
tr.td().ah(context.getSpecLink()+r.getProfile()).addText(r.getProfile()); tr.td().ah(r.getProfile()).addText(r.getProfile());
} }
tr.td().addText(showOp(r, TypeRestfulInteraction.READ)); tr.td().addText(showOp(r, TypeRestfulInteraction.READ));
if (hasVRead) if (hasVRead)

View File

@ -414,7 +414,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
first = false; first = false;
XhtmlNode span = td.span(null, mapping.comp.hasRelationship() ? mapping.comp.getRelationship().toCode() : ""); XhtmlNode span = td.span(null, mapping.comp.hasRelationship() ? mapping.comp.getRelationship().toCode() : "");
span.addText(getCharForRelationship(mapping.comp)); span.addText(getCharForRelationship(mapping.comp));
a = td.ah(getContext().getSpecLink()+m.getLink()+"#"+makeAnchor(mapping.group.getTarget(), mapping.comp.getCode())); a = td.ah(getContext().getSpecificationLink()+m.getLink()+"#"+makeAnchor(mapping.group.getTarget(), mapping.comp.getCode()));
a.addText(mapping.comp.getCode()); a.addText(mapping.comp.getCode());
if (!Utilities.noString(mapping.comp.getComment())) if (!Utilities.noString(mapping.comp.getComment()))
td.i().tx("("+mapping.comp.getComment()+")"); td.i().tx("("+mapping.comp.getComment()+")");

View File

@ -375,7 +375,7 @@ public class ConceptMapRenderer extends TerminologyRenderer {
if (cs == null) if (cs == null)
td.tx(url); td.tx(url);
else else
td.ah(cs.getUserString("path")).attribute("title", url).tx(cs.present()); td.ah(context.fixReference(cs.getUserString("path"))).attribute("title", url).tx(cs.present());
} }
private void addUnmapped(XhtmlNode tbl, ConceptMapGroupComponent grp) { private void addUnmapped(XhtmlNode tbl, ConceptMapGroupComponent grp) {

View File

@ -61,7 +61,7 @@ public class DataRenderer {
public DataRenderer(IWorkerContext worker) { public DataRenderer(IWorkerContext worker) {
super(); super();
this.context = new RenderingContext(worker, new MarkDownProcessor(Dialect.COMMON_MARK), ValidationOptions.defaults(), "", null, ResourceRendererMode.RESOURCE); this.context = new RenderingContext(worker, new MarkDownProcessor(Dialect.COMMON_MARK), ValidationOptions.defaults(), "http://hl7.org/fhir/R4", "", null, ResourceRendererMode.RESOURCE);
} }
// -- 2. Markdown support ------------------------------------------------------- // -- 2. Markdown support -------------------------------------------------------
@ -218,7 +218,7 @@ public class DataRenderer {
// -- 5. Data type Rendering ---------------------------------------------- // -- 5. Data type Rendering ----------------------------------------------
public static String display(IWorkerContext context, DataType type) { public static String display(IWorkerContext context, DataType type) {
return new DataRenderer(new RenderingContext(context, null, null, "", null, ResourceRendererMode.RESOURCE)).display(type); return new DataRenderer(new RenderingContext(context, null, null, "http://hl7.org/fhir/R4", "", null, ResourceRendererMode.RESOURCE)).display(type);
} }
public String displayBase(Base b) { public String displayBase(Base b) {

View File

@ -105,7 +105,7 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
if (p.hasSearchType()) { if (p.hasSearchType()) {
td.br(); td.br();
td.tx("("); td.tx("(");
td.ah( context.getSpecLink() == null ? "search.html#"+p.getSearchType().toCode() : Utilities.pathURL(context.getSpecLink(), "search.html#"+p.getSearchType().toCode())).tx(p.getSearchType().toCode()); td.ah( context.getSpecificationLink() == null ? "search.html#"+p.getSearchType().toCode() : Utilities.pathURL(context.getSpecificationLink(), "search.html#"+p.getSearchType().toCode())).tx(p.getSearchType().toCode());
td.tx(")"); td.tx(")");
} }
td = tr.td(); td = tr.td();

View File

@ -59,8 +59,8 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true); HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
TableModel model = gen.new TableModel("qtree="+q.getId(), true); TableModel model = gen.new TableModel("qtree="+q.getId(), true);
model.setAlternating(true); model.setAlternating(true);
model.setDocoImg(context.getSpecLink() +"help16.png"); model.setDocoImg(context.getSpecificationLink() +"help16.png");
model.setDocoRef(context.getSpecLink()+"formats.html#table"); model.setDocoRef(context.getSpecificationLink()+"formats.html#table");
model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "LinkId"), translate("sd.hint", "The linkId for the item"), null, 0)); model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "LinkId"), translate("sd.hint", "The linkId for the item"), null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Text"), translate("sd.hint", "Text for the item"), null, 0)); model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Text"), translate("sd.hint", "Text for the item"), null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Cardinality"), translate("sd.hint", "Minimum and Maximum # of times the the itemcan appear in the instance"), null, 0)); model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Cardinality"), translate("sd.hint", "Minimum and Maximum # of times the the itemcan appear in the instance"), null, 0));
@ -87,19 +87,19 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
String txt = (i.hasPrefix() ? i.getPrefix() + ". " : "") + i.getText(); String txt = (i.hasPrefix() ? i.getPrefix() + ". " : "") + i.getText();
r.getCells().add(gen.new Cell(null, null, txt, null, null)); r.getCells().add(gen.new Cell(null, null, txt, null, null));
r.getCells().add(gen.new Cell(null, null, (i.getRequired() ? "1" : "0")+".."+(i.getRepeats() ? "*" : "1"), null, null)); r.getCells().add(gen.new Cell(null, null, (i.getRequired() ? "1" : "0")+".."+(i.getRepeats() ? "*" : "1"), null, null));
r.getCells().add(gen.new Cell(null, context.getSpecLink()+"codesystem-item-type.html#"+i.getType().toCode(), i.getType().toCode(), null, null)); r.getCells().add(gen.new Cell(null, context.getSpecificationLink()+"codesystem-item-type.html#"+i.getType().toCode(), i.getType().toCode(), null, null));
// flags: // flags:
Cell flags = gen.new Cell(); Cell flags = gen.new Cell();
r.getCells().add(flags); r.getCells().add(flags);
if (i.getReadOnly()) { if (i.getReadOnly()) {
flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecLink(), "questionnaire-definitions.html#Questionnaire.item.readOnly"), null, "Is Readonly").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-readonly.png")))); flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecificationLink(), "questionnaire-definitions.html#Questionnaire.item.readOnly"), null, "Is Readonly").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-readonly.png"))));
} }
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) { if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject")) {
flags.addPiece(gen.new Piece("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject", null, "Can change the subject of the questionnaire").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-subject.png")))); flags.addPiece(gen.new Piece("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-isSubject", null, "Can change the subject of the questionnaire").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-subject.png"))));
} }
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) { if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecLink(), "extension-questionnaire-hidden.html"), null, "Is a hidden item").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-hidden.png")))); flags.addPiece(gen.new Piece(Utilities.pathURL(context.getSpecificationLink(), "extension-questionnaire-hidden.html"), null, "Is a hidden item").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-hidden.png"))));
} }
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) { if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {
flags.addPiece(gen.new Piece("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay", null, "Is optional to display").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-optional.png")))); flags.addPiece(gen.new Piece("http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay", null, "Is optional to display").addHtml(new XhtmlNode(NodeType.Element, "img").attribute("src", Utilities.path(context.getDestDir(), "icon-qi-optional.png"))));
@ -225,8 +225,8 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true); HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
TableModel model = gen.new TableModel("qtree="+q.getId(), true); TableModel model = gen.new TableModel("qtree="+q.getId(), true);
model.setAlternating(true); model.setAlternating(true);
model.setDocoImg(context.getSpecLink() +"help16.png"); model.setDocoImg(context.getSpecificationLink() +"help16.png");
model.setDocoRef(context.getSpecLink()+"formats.html#table"); model.setDocoRef(context.getSpecificationLink()+"formats.html#table");
model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "LinkId"), translate("sd.hint", "The linkId for the item"), null, 0)); model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "LinkId"), translate("sd.hint", "The linkId for the item"), null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Description & Constraints"), translate("sd.hint", "Additional information about the item"), null, 0)); model.getTitles().add(gen.new Title(null, model.getDocoRef(), translate("sd.head", "Description & Constraints"), translate("sd.hint", "Additional information about the item"), null, 0));
@ -474,7 +474,7 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
} }
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) { if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/StructureDefinition/questionnaire-hidden")) {
hasFlag = true; hasFlag = true;
flags.ah(Utilities.pathURL(context.getSpecLink(), "extension-questionnaire-hidden.html"), "Is a hidden item").img(Utilities.path(context.getDestDir(), "icon-qi-hidden.png")); flags.ah(Utilities.pathURL(context.getSpecificationLink(), "extension-questionnaire-hidden.html"), "Is a hidden item").img(Utilities.path(context.getDestDir(), "icon-qi-hidden.png"));
d.style("background-color: #eeeeee"); d.style("background-color: #eeeeee");
} }
if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) { if (ToolingExtensions.readBoolExtension(i, "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-optionalDisplay")) {

View File

@ -74,14 +74,16 @@ public abstract class ResourceRenderer extends DataRenderer {
assert r.getContext() == context; assert r.getContext() == context;
XhtmlNode x = new XhtmlNode(NodeType.Element, "div"); XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
boolean hasExtensions = render(x, r); boolean hasExtensions = render(x, r);
r.injectNarrative(x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED); if (r.hasNarrative()) {
r.injectNarrative(x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
}
return x; return x;
} }
public abstract boolean render(XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome; public abstract boolean render(XhtmlNode x, DomainResource r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome;
public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome { public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
throw new NotImplementedException("This is not implemented yet for resources of type "+r.getName()); throw new NotImplementedException("Rendering using the wrapper is not implemented yet for resources of type "+r.getName());
} }
public void describe(XhtmlNode x, DomainResource r) throws UnsupportedEncodingException, IOException { public void describe(XhtmlNode x, DomainResource r) throws UnsupportedEncodingException, IOException {

View File

@ -27,7 +27,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
} }
public boolean render(XhtmlNode x, StructureDefinition sd) throws FHIRFormatError, DefinitionException, IOException { public boolean render(XhtmlNode x, StructureDefinition sd) throws FHIRFormatError, DefinitionException, IOException {
x.getChildNodes().add(context.getProfileUtilities().generateTable(context.getDefinitionsTarget(), sd, true, context.getDestDir(), false, sd.getId(), false, context.getSpecLink(), "", false, false, null, false)); x.getChildNodes().add(context.getProfileUtilities().generateTable(context.getDefinitionsTarget(), sd, true, context.getDestDir(), false, sd.getId(), false, context.getSpecificationLink(), "", false, false, null, false));
return true; return true;
} }

View File

@ -103,7 +103,7 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
for (UsedConceptMap m : maps) { for (UsedConceptMap m : maps) {
XhtmlNode td = tr.td(); XhtmlNode td = tr.td();
XhtmlNode b = td.b(); XhtmlNode b = td.b();
XhtmlNode a = b.ah(getContext().getSpecLink()+m.getLink()); XhtmlNode a = b.ah(getContext().getSpecificationLink()+m.getLink());
a.addText(m.getDetails().getName()); a.addText(m.getDetails().getName());
if (m.getDetails().isDoDescription() && m.getMap().hasDescription()) if (m.getDetails().isDoDescription() && m.getMap().hasDescription())
addMarkdown(td, m.getMap().getDescription()); addMarkdown(td, m.getMap().getDescription());
@ -155,19 +155,22 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
ref = (String) cs.getUserData("filename"); ref = (String) cs.getUserData("filename");
else else
addHtml = false; addHtml = false;
if (Utilities.noString(ref)) if (Utilities.noString(ref)) {
ref = (String) cs.getUserData("path"); ref = (String) cs.getUserData("path");
if (ref != null) {
addHtml = false;
}
}
} }
String spec = getSpecialReference(inc.getSystem()); String spec = getSpecialReference(inc.getSystem());
if (spec != null) { if (spec != null) {
XhtmlNode a = li.ah(spec); XhtmlNode a = li.ah(spec);
a.code(inc.getSystem()); a.code(inc.getSystem());
} else if (cs != null && ref != null) { } else if (cs != null && ref != null) {
if (!Utilities.noString(getContext().getSpecLink()) && ref.startsWith("http://hl7.org/fhir/")) if (addHtml && !ref.contains(".html"))
ref = ref.substring(20)+"/index.html";
else if (addHtml && !ref.contains(".html"))
ref = ref + ".html"; ref = ref + ".html";
XhtmlNode a = li.ah(getContext().getSpecLink()+ref.replace("\\", "/")); ref = context.fixReference(ref);
XhtmlNode a = li.ah(ref.replace("\\", "/"));
a.code(inc.getSystem()); a.code(inc.getSystem());
} else { } else {
li.code(inc.getSystem()); li.code(inc.getSystem());
@ -260,14 +263,14 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
if (vs != null) { if (vs != null) {
String ref = (String) vs.getUserData("path"); String ref = (String) vs.getUserData("path");
ref = adjustForPath(ref); ref = context.fixReference(ref);
XhtmlNode a = li.ah(ref == null ? "?ngen-11?" : ref.replace("\\", "/")); XhtmlNode a = li.ah(ref == null ? "?ngen-11?" : ref.replace("\\", "/"));
a.addText(value); a.addText(value);
} else { } else {
CodeSystem cs = getContext().getWorker().fetchCodeSystem(value); CodeSystem cs = getContext().getWorker().fetchCodeSystem(value);
if (cs != null) { if (cs != null) {
String ref = (String) cs.getUserData("path"); String ref = (String) cs.getUserData("path");
ref = adjustForPath(ref); ref = context.fixReference(ref);
XhtmlNode a = li.ah(ref == null ? "?ngen-12?" : ref.replace("\\", "/")); XhtmlNode a = li.ah(ref == null ? "?ngen-12?" : ref.replace("\\", "/"));
a.addText(value); a.addText(value);
} else if (value.equals("http://snomed.info/sct") || value.equals("http://snomed.info/id")) { } else if (value.equals("http://snomed.info/sct") || value.equals("http://snomed.info/id")) {
@ -282,13 +285,6 @@ public abstract class TerminologyRenderer extends ResourceRenderer {
} }
} }
private String adjustForPath(String ref) {
if (getContext().getSpecLink() == null)
return ref;
else
return getContext().getSpecLink()+ref;
}
protected String getDisplayForConcept(String system, String value) { protected String getDisplayForConcept(String system, String value) {

View File

@ -207,7 +207,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
if (ref == null) if (ref == null)
p.code(vs.getExpansion().getContains().get(0).getSystem()); p.code(vs.getExpansion().getContains().get(0).getSystem());
else else
p.ah(getContext().getSpecLink()+ref).code(vs.getExpansion().getContains().get(0).getSystem()); p.ah(context.fixReference(ref)).code(vs.getExpansion().getContains().get(0).getSystem());
} }
XhtmlNode t = x.table( "codes"); XhtmlNode t = x.table( "codes");
XhtmlNode tr = t.tr(); XhtmlNode tr = t.tr();
@ -638,7 +638,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
} else } else
td.addText(code); td.addText(code);
} else { } else {
String href = getContext().getSpecLink()+getCsRef(e); String href = context.fixReference(getCsRef(e));
if (href.contains("#")) if (href.contains("#"))
href = href + "-"+Utilities.nmtokenize(code); href = href + "-"+Utilities.nmtokenize(code);
else else
@ -662,9 +662,9 @@ public class ValueSetRenderer extends TerminologyRenderer {
String cslink = getCsRef(cs); String cslink = getCsRef(cs);
XhtmlNode a = null; XhtmlNode a = null;
if (cslink != null) if (cslink != null)
a = td.ah(getContext().getSpecLink()+cslink+"#"+cs.getId()+"-"+code); a = td.ah(getContext().getSpecificationLink()+cslink+"#"+cs.getId()+"-"+code);
else else
a = td.ah(getContext().getSpecLink()+vslink+"#"+code); a = td.ah(getContext().getSpecificationLink()+vslink+"#"+code);
a.addText(code); a.addText(code);
} }
@ -796,7 +796,7 @@ public class ValueSetRenderer extends TerminologyRenderer {
} else { } else {
li.tx(f.getProperty()+" "+describe(f.getOp())+" "); li.tx(f.getProperty()+" "+describe(f.getOp())+" ");
if (e != null && codeExistsInValueSet(e, f.getValue())) { if (e != null && codeExistsInValueSet(e, f.getValue())) {
String href = getContext().getSpecLink()+getCsRef(e); String href = getContext().getSpecificationLink()+getCsRef(e);
if (href.contains("#")) if (href.contains("#"))
href = href + "-"+Utilities.nmtokenize(f.getValue()); href = href + "-"+Utilities.nmtokenize(f.getValue());
else else

View File

@ -29,6 +29,7 @@ public class BaseWrappers {
public int getMaxCardinality(); public int getMaxCardinality();
public StructureDefinition getStructure(); public StructureDefinition getStructure();
public BaseWrapper value(); public BaseWrapper value();
public ResourceWrapper getAsResource();
} }
public interface WrapperBase extends RendererWrapper { public interface WrapperBase extends RendererWrapper {
@ -48,6 +49,7 @@ public class BaseWrappers {
public void injectNarrative(XhtmlNode x, NarrativeStatus status) throws IOException; public void injectNarrative(XhtmlNode x, NarrativeStatus status) throws IOException;
public BaseWrapper root(); public BaseWrapper root();
public StructureDefinition getDefinition(); public StructureDefinition getDefinition();
public boolean hasNarrative();
} }
public interface BaseWrapper extends WrapperBase { public interface BaseWrapper extends WrapperBase {

View File

@ -178,6 +178,11 @@ public class DOMWrappers {
return getValues().get(0); return getValues().get(0);
} }
@Override
public ResourceWrapper getAsResource() {
throw new Error("Not implemented yet");
}
} }
public static class ResourceWrapperElement extends WrapperBaseImpl implements ResourceWrapper { public static class ResourceWrapperElement extends WrapperBaseImpl implements ResourceWrapper {
@ -312,6 +317,18 @@ public class DOMWrappers {
public Base getBase() { public Base getBase() {
throw new Error("Not Implemented yet"); throw new Error("Not Implemented yet");
} }
@Override
public boolean hasNarrative() {
StructureDefinition sd = definition;
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
return false;
}
} }
} }

View File

@ -96,6 +96,11 @@ public class DirectWrappers {
public String toString() { public String toString() {
return "#."+wrapped.toString(); return "#."+wrapped.toString();
} }
@Override
public ResourceWrapper getAsResource() {
throw new Error("Not implemented yet");
}
} }
public static class BaseWrapperDirect extends WrapperBaseImpl implements BaseWrapper { public static class BaseWrapperDirect extends WrapperBaseImpl implements BaseWrapper {
@ -219,6 +224,19 @@ public class DirectWrappers {
public Base getBase() { public Base getBase() {
return wrapped; return wrapped;
} }
@Override
public boolean hasNarrative() {
StructureDefinition sd = context.getWorker().fetchTypeDefinition(wrapped.fhirType());
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
return false;
}
} }
} }

View File

@ -48,8 +48,9 @@ public class ElementWrappers {
if (type == null || type.equals("Resource") || type.equals("BackboneElement") || type.equals("Element")) if (type == null || type.equals("Resource") || type.equals("BackboneElement") || type.equals("Element"))
return null; return null;
if (element.hasElementProperty()) if (element.hasElementProperty()) {
return null; return element;
}
ByteArrayOutputStream xml = new ByteArrayOutputStream(); ByteArrayOutputStream xml = new ByteArrayOutputStream();
try { try {
new XmlParser(context.getWorker()).compose(element, xml, OutputStyle.PRETTY, null); new XmlParser(context.getWorker()).compose(element, xml, OutputStyle.PRETTY, null);
@ -57,7 +58,7 @@ public class ElementWrappers {
throw new FHIRException(e.getMessage(), e); throw new FHIRException(e.getMessage(), e);
} }
if (context.getParser() == null) { if (context.getParser() == null) {
System.out.println("huh?"); System.out.println("Noe version specific parser provided");
} }
return context.getParser().parseType(xml.toString(), type); return context.getParser().parseType(xml.toString(), type);
} }
@ -219,6 +220,18 @@ public class ElementWrappers {
public Base getBase() { public Base getBase() {
return wrapped; return wrapped;
} }
@Override
public boolean hasNarrative() {
StructureDefinition sd = definition;
while (sd != null) {
if ("DomainResource".equals(sd.getType())) {
return true;
}
sd = context.getWorker().fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
return false;
}
} }
public static class PropertyWrapperMetaElement extends RendererWrapperImpl implements PropertyWrapper { public static class PropertyWrapperMetaElement extends RendererWrapperImpl implements PropertyWrapper {
@ -287,6 +300,11 @@ public class ElementWrappers {
return getValues().get(0); return getValues().get(0);
} }
@Override
public ResourceWrapper getAsResource() {
return new ElementWrappers.ResourceWrapperMetaElement(context, values.get(0));
}
} }
} }

View File

@ -16,6 +16,7 @@ import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext; import org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext;
import org.hl7.fhir.utilities.MarkDownProcessor; import org.hl7.fhir.utilities.MarkDownProcessor;
import org.hl7.fhir.utilities.MarkDownProcessor.Dialect; import org.hl7.fhir.utilities.MarkDownProcessor.Dialect;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.validation.ValidationOptions;
public class RenderingContext { public class RenderingContext {
@ -71,7 +72,8 @@ public class RenderingContext {
private ITypeParser parser; private ITypeParser parser;
private String lang; private String lang;
private String specLink; private String localPrefix; // relative link within local context
private String specificationLink;
private String selfLink; // absolute link to where the content is to be found (only used in a few circumstances when making external references to tools) private String selfLink; // absolute link to where the content is to be found (only used in a few circumstances when making external references to tools)
private int headerLevelContext; private int headerLevelContext;
private boolean canonicalUrlsAsLinks; private boolean canonicalUrlsAsLinks;
@ -101,12 +103,13 @@ public class RenderingContext {
* @param specLink - path to FHIR specification * @param specLink - path to FHIR specification
* @param lang - langauage to render in * @param lang - langauage to render in
*/ */
public RenderingContext(IWorkerContext worker, MarkDownProcessor markdown, ValidationOptions terminologyServiceOptions, String specLink, String lang, ResourceRendererMode mode) { public RenderingContext(IWorkerContext worker, MarkDownProcessor markdown, ValidationOptions terminologyServiceOptions, String specLink, String localPrefix, String lang, ResourceRendererMode mode) {
super(); super();
this.worker = worker; this.worker = worker;
this.markdown = markdown; this.markdown = markdown;
this.lang = lang; this.lang = lang;
this.specLink = specLink; this.specificationLink = specLink;
this.localPrefix = localPrefix;
this.mode = mode; this.mode = mode;
this.terminologyServiceOptions = terminologyServiceOptions; this.terminologyServiceOptions = terminologyServiceOptions;
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
@ -146,8 +149,12 @@ public class RenderingContext {
return lang; return lang;
} }
public String getSpecLink() { public String getSpecificationLink() {
return specLink; return specificationLink;
}
public String getLocalPrefix() {
return localPrefix;
} }
public ValidationOptions getTerminologyServiceOptions() { public ValidationOptions getTerminologyServiceOptions() {
@ -293,7 +300,7 @@ public class RenderingContext {
} }
public RenderingContext copy() { public RenderingContext copy() {
RenderingContext res = new RenderingContext(worker, markdown, terminologyServiceOptions, specLink, lang, mode); RenderingContext res = new RenderingContext(worker, markdown, terminologyServiceOptions, specificationLink, localPrefix, lang, mode);
res.resolver = resolver; res.resolver = resolver;
res.templateProvider = templateProvider; res.templateProvider = templateProvider;
@ -349,6 +356,16 @@ public class RenderingContext {
public void setSelfLink(String selfLink) { public void setSelfLink(String selfLink) {
this.selfLink = selfLink; this.selfLink = selfLink;
} }
public String fixReference(String ref) {
if (!Utilities.isAbsoluteUrl(ref)) {
return (localPrefix == null ? "" : localPrefix)+ref;
}
if (ref.startsWith("http://hl7.org/fhir") && !ref.substring(20).contains("/")) {
return specificationLink+ref.substring(20);
}
return ref;
}

View File

@ -90,7 +90,7 @@ public class NarrativeGenerationTests {
@ParameterizedTest(name = "{index}: file {0}") @ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data") @MethodSource("data")
public void test(String id, TestDetails test) throws Exception { public void test(String id, TestDetails test) throws Exception {
RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", null, ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setDestDir("C:\\work\\org.hl7.fhir\\packages\\packages\\hl7.fhir.pubpack\\package\\other\\"); rc.setDestDir("C:\\work\\org.hl7.fhir\\packages\\packages\\hl7.fhir.pubpack\\package\\other\\");
rc.setHeader(test.isHeader()); rc.setHeader(test.isHeader());
rc.setDefinitionsTarget("test.html"); rc.setDefinitionsTarget("test.html");

View File

@ -24,7 +24,7 @@ public class NarrativeGeneratorTests {
@BeforeAll @BeforeAll
public static void setUp() throws FHIRException { public static void setUp() throws FHIRException {
rc = new RenderingContext(TestingUtilities.context(), null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
} }
@Test @Test

View File

@ -27,7 +27,7 @@ public class ResourceRoundTripTests {
@Test @Test
public void test() throws IOException, FHIRException, EOperationOutcome { public void test() throws IOException, FHIRException, EOperationOutcome {
DomainResource res = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "unicode.xml")); DomainResource res = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"));
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
RendererFactory.factory(res, rc).render(res); RendererFactory.factory(res, rc).render(res);
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"), new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.xml"))); IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "unicode.xml"), new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.xml")));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.out.xml")), res); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("gen", "unicode.out.xml")), res);

View File

@ -550,7 +550,7 @@ public class SnapShotGenerationTests {
throw e; throw e;
} }
if (output.getDifferential().hasElement()) { if (output.getDifferential().hasElement()) {
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP())); rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP()));
RendererFactory.factory(output, rc).render(output); RendererFactory.factory(output, rc).render(output);
} }

View File

@ -681,6 +681,13 @@ public class XhtmlNode implements IBaseXhtml {
return this; return this;
} }
public XhtmlNode addChildren(XhtmlNode x) {
if (x != null) {
getChildNodes().addAll(x.getChildNodes());
}
return this;
}
public XhtmlNode input(String name, String type, String placeholder, int size) { public XhtmlNode input(String name, String type, String placeholder, int size) {
XhtmlNode p = new XhtmlNode(NodeType.Element, "input"); XhtmlNode p = new XhtmlNode(NodeType.Element, "input");

View File

@ -1171,7 +1171,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
private OperationOutcome exceptionToOutcome(Exception ex) throws IOException, FHIRException, EOperationOutcome { private OperationOutcome exceptionToOutcome(Exception ex) throws IOException, FHIRException, EOperationOutcome {
OperationOutcome op = new OperationOutcome(); OperationOutcome op = new OperationOutcome();
op.addIssue().setCode(org.hl7.fhir.r5.model.OperationOutcome.IssueType.EXCEPTION).setSeverity(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.FATAL).getDetails().setText(ex.getMessage()); op.addIssue().setCode(org.hl7.fhir.r5.model.OperationOutcome.IssueType.EXCEPTION).setSeverity(org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.FATAL).getDetails().setText(ex.getMessage());
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
RendererFactory.factory(op, rc).render(op); RendererFactory.factory(op, rc).render(op);
return op; return op;
} }
@ -1187,7 +1187,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
} }
op.getIssue().add(OperationOutcomeUtilities.convertToIssue(vm, op)); op.getIssue().add(OperationOutcomeUtilities.convertToIssue(vm, op));
} }
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
RendererFactory.factory(op, rc).render(op); RendererFactory.factory(op, rc).render(op);
return op; return op;
} }
@ -1245,7 +1245,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
public DomainResource generate(String source, String version) throws Exception { public DomainResource generate(String source, String version) throws Exception {
Content cnt = loadContent(source, "validate"); Content cnt = loadContent(source, "validate");
Resource res = loadResourceByVersion(version, cnt.focus, source); Resource res = loadResourceByVersion(version, cnt.focus, source);
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
RendererFactory.factory(res, rc).render((DomainResource) res); RendererFactory.factory(res, rc).render((DomainResource) res);
return (DomainResource) res; return (DomainResource) res;
} }
@ -1550,7 +1550,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
} }
private void genScanOutputItem(ScanOutputItem item, String filename) throws IOException, FHIRException, EOperationOutcome { private void genScanOutputItem(ScanOutputItem item, String filename) throws IOException, FHIRException, EOperationOutcome {
RenderingContext rc = new RenderingContext(context, null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setNoSlowLookup(true); rc.setNoSlowLookup(true);
RendererFactory.factory(item.outcome, rc).render(item.outcome); RendererFactory.factory(item.outcome, rc).render(item.outcome);
String s = new XhtmlComposer(XhtmlComposer.HTML).compose(item.outcome.getText().getDiv()); String s = new XhtmlComposer(XhtmlComposer.HTML).compose(item.outcome.getText().getDiv());

View File

@ -520,7 +520,7 @@ public class SnapShotGenerationTestsX {
throw e; throw e;
} }
if (output.getDifferential().hasElement()) { if (output.getDifferential().hasElement()) {
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "", "http://hl7.org/fhir", ResourceRendererMode.RESOURCE); RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.RESOURCE);
rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP())); rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP()));
RendererFactory.factory(output, rc).render(output); RendererFactory.factory(output, rc).render(output);
} }