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 {
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);
RendererFactory.factory(vs, rc).render(vs);
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 {
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);
RendererFactory.factory(vs, rc).render(vs);
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.Composition;
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.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.Resolver.ResourceContext;
import org.hl7.fhir.r5.utils.EOperationOutcome;
@ -42,13 +45,54 @@ public class BundleRenderer extends ResourceRenderer {
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 {
if (b.getType() == BundleType.DOCUMENT) {
if (!b.hasEntry() || !(b.getEntryFirstRep().hasResource() && b.getEntryFirstRep().getResource() instanceof Composition))
throw new FHIRException("Invalid document - first entry is not a Composition");
Composition dr = (Composition) b.getEntryFirstRep().getResource();
return dr.getText().getDiv();
} else if ((b.getType() == BundleType.DOCUMENT && allEntresAreHistoryProvenance(b))) {
} else if ((b.getType() == BundleType.COLLECTION && allEntresAreHistoryProvenance(b))) {
return null;
} else {
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) {
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) {

View File

@ -82,7 +82,7 @@ public class CapabilityStatementRenderer extends ResourceRenderer {
tr = t.tr();
tr.td().addText(r.getType());
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));
if (hasVRead)

View File

@ -414,7 +414,7 @@ public class CodeSystemRenderer extends TerminologyRenderer {
first = false;
XhtmlNode span = td.span(null, mapping.comp.hasRelationship() ? mapping.comp.getRelationship().toCode() : "");
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());
if (!Utilities.noString(mapping.comp.getComment()))
td.i().tx("("+mapping.comp.getComment()+")");

View File

@ -375,7 +375,7 @@ public class ConceptMapRenderer extends TerminologyRenderer {
if (cs == null)
td.tx(url);
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) {

View File

@ -61,7 +61,7 @@ public class DataRenderer {
public DataRenderer(IWorkerContext worker) {
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 -------------------------------------------------------
@ -218,7 +218,7 @@ public class DataRenderer {
// -- 5. Data type Rendering ----------------------------------------------
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) {

View File

@ -105,7 +105,7 @@ public class OperationDefinitionRenderer extends TerminologyRenderer {
if (p.hasSearchType()) {
td.br();
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 = tr.td();

View File

@ -59,8 +59,8 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
TableModel model = gen.new TableModel("qtree="+q.getId(), true);
model.setAlternating(true);
model.setDocoImg(context.getSpecLink() +"help16.png");
model.setDocoRef(context.getSpecLink()+"formats.html#table");
model.setDocoImg(context.getSpecificationLink() +"help16.png");
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", "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));
@ -87,19 +87,19 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
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, (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:
Cell flags = gen.new Cell();
r.getCells().add(flags);
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")) {
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")) {
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")) {
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);
TableModel model = gen.new TableModel("qtree="+q.getId(), true);
model.setAlternating(true);
model.setDocoImg(context.getSpecLink() +"help16.png");
model.setDocoRef(context.getSpecLink()+"formats.html#table");
model.setDocoImg(context.getSpecificationLink() +"help16.png");
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", "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")) {
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");
}
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;
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
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;
}
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 {
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 {

View File

@ -27,7 +27,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
}
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;
}

View File

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

View File

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

View File

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

View File

@ -178,6 +178,11 @@ public class DOMWrappers {
return getValues().get(0);
}
@Override
public ResourceWrapper getAsResource() {
throw new Error("Not implemented yet");
}
}
public static class ResourceWrapperElement extends WrapperBaseImpl implements ResourceWrapper {
@ -312,6 +317,18 @@ public class DOMWrappers {
public Base getBase() {
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() {
return "#."+wrapped.toString();
}
@Override
public ResourceWrapper getAsResource() {
throw new Error("Not implemented yet");
}
}
public static class BaseWrapperDirect extends WrapperBaseImpl implements BaseWrapper {
@ -219,6 +224,19 @@ public class DirectWrappers {
public Base getBase() {
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"))
return null;
if (element.hasElementProperty())
return null;
if (element.hasElementProperty()) {
return element;
}
ByteArrayOutputStream xml = new ByteArrayOutputStream();
try {
new XmlParser(context.getWorker()).compose(element, xml, OutputStyle.PRETTY, null);
@ -57,7 +58,7 @@ public class ElementWrappers {
throw new FHIRException(e.getMessage(), e);
}
if (context.getParser() == null) {
System.out.println("huh?");
System.out.println("Noe version specific parser provided");
}
return context.getParser().parseType(xml.toString(), type);
}
@ -219,6 +220,18 @@ public class ElementWrappers {
public Base getBase() {
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 {
@ -287,6 +300,11 @@ public class ElementWrappers {
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.utilities.MarkDownProcessor;
import org.hl7.fhir.utilities.MarkDownProcessor.Dialect;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationOptions;
public class RenderingContext {
@ -71,7 +72,8 @@ public class RenderingContext {
private ITypeParser parser;
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 int headerLevelContext;
private boolean canonicalUrlsAsLinks;
@ -101,12 +103,13 @@ public class RenderingContext {
* @param specLink - path to FHIR specification
* @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();
this.worker = worker;
this.markdown = markdown;
this.lang = lang;
this.specLink = specLink;
this.specificationLink = specLink;
this.localPrefix = localPrefix;
this.mode = mode;
this.terminologyServiceOptions = terminologyServiceOptions;
profileUtilities = new ProfileUtilities(worker, null, null);
@ -146,8 +149,12 @@ public class RenderingContext {
return lang;
}
public String getSpecLink() {
return specLink;
public String getSpecificationLink() {
return specificationLink;
}
public String getLocalPrefix() {
return localPrefix;
}
public ValidationOptions getTerminologyServiceOptions() {
@ -293,7 +300,7 @@ public class RenderingContext {
}
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.templateProvider = templateProvider;
@ -349,6 +356,16 @@ public class RenderingContext {
public void setSelfLink(String 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}")
@MethodSource("data")
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.setHeader(test.isHeader());
rc.setDefinitionsTarget("test.html");

View File

@ -24,7 +24,7 @@ public class NarrativeGeneratorTests {
@BeforeAll
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

View File

@ -27,7 +27,7 @@ public class ResourceRoundTripTests {
@Test
public void test() throws IOException, FHIRException, EOperationOutcome {
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);
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);

View File

@ -550,7 +550,7 @@ public class SnapShotGenerationTests {
throw e;
}
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()));
RendererFactory.factory(output, rc).render(output);
}

View File

@ -681,6 +681,13 @@ public class XhtmlNode implements IBaseXhtml {
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) {
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 {
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());
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);
return op;
}
@ -1187,7 +1187,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
}
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);
return op;
}
@ -1245,7 +1245,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
public DomainResource generate(String source, String version) throws Exception {
Content cnt = loadContent(source, "validate");
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);
return (DomainResource) res;
}
@ -1550,7 +1550,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
}
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);
RendererFactory.factory(item.outcome, rc).render(item.outcome);
String s = new XhtmlComposer(XhtmlComposer.HTML).compose(item.outcome.getText().getDiv());

View File

@ -520,7 +520,7 @@ public class SnapShotGenerationTestsX {
throw e;
}
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()));
RendererFactory.factory(output, rc).render(output);
}