001package org.hl7.fhir.r5.renderers; 002 003import java.io.IOException; 004import java.io.UnsupportedEncodingException; 005 006import org.hl7.fhir.exceptions.DefinitionException; 007import org.hl7.fhir.exceptions.FHIRFormatError; 008import org.hl7.fhir.r5.model.DomainResource; 009import org.hl7.fhir.r5.model.Resource; 010import org.hl7.fhir.r5.model.StructureDefinition; 011import org.hl7.fhir.r5.renderers.utils.RenderingContext; 012import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper; 013import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext; 014import org.hl7.fhir.utilities.xhtml.XhtmlNode; 015 016public class StructureDefinitionRenderer extends ResourceRenderer { 017 018 public StructureDefinitionRenderer(RenderingContext context) { 019 super(context); 020 } 021 022 public StructureDefinitionRenderer(RenderingContext context, ResourceContext rcontext) { 023 super(context, rcontext); 024 } 025 026 public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException { 027 return render(x, (StructureDefinition) dr); 028 } 029 030 public boolean render(XhtmlNode x, StructureDefinition sd) throws FHIRFormatError, DefinitionException, IOException { 031 x.getChildNodes().add(context.getProfileUtilities().generateTable(context.getDefinitionsTarget(), sd, true, context.getDestDir(), false, sd.getId(), false, context.getSpecificationLink(), "", false, false, null, false, false)); 032 return true; 033 } 034 035 public void describe(XhtmlNode x, StructureDefinition sd) { 036 x.tx(display(sd)); 037 } 038 039 public String display(StructureDefinition sd) { 040 return sd.present(); 041 } 042 043 @Override 044 public String display(Resource r) throws UnsupportedEncodingException, IOException { 045 return ((StructureDefinition) r).present(); 046 } 047 048 public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException { 049 if (r.has("title")) { 050 return r.children("title").get(0).getBase().primitiveValue(); 051 } 052 if (r.has("name")) { 053 return r.children("name").get(0).getBase().primitiveValue(); 054 } 055 return "??"; 056 } 057 058}