
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.ActorDefinition; 009import org.hl7.fhir.r5.model.CapabilityStatement; 010import org.hl7.fhir.r5.model.Library; 011import org.hl7.fhir.r5.model.Resource; 012import org.hl7.fhir.r5.model.UrlType; 013import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper; 014import org.hl7.fhir.r5.renderers.utils.RenderingContext; 015import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext; 016import org.hl7.fhir.utilities.xhtml.XhtmlNode; 017 018public class ActorDefinitionRenderer extends ResourceRenderer { 019 020 public ActorDefinitionRenderer(RenderingContext context) { 021 super(context); 022 } 023 024 public ActorDefinitionRenderer(RenderingContext context, ResourceContext rcontext) { 025 super(context, rcontext); 026 } 027 028 public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException { 029 return render(x, (ActorDefinition) dr); 030 } 031 032 033 public boolean render(XhtmlNode x, ActorDefinition acd) throws FHIRFormatError, DefinitionException, IOException { 034 XhtmlNode tbl = x.table("grid"); 035 XhtmlNode tr = tbl.tr(); 036 tr.td().b().tx("Actor: "+acd.getName()); 037 tr.td().tx(acd.getTitle()); 038 tr.td().tx("Type: " + acd.getType().toCode()); 039 XhtmlNode td = tbl.tr().td().colspan("3"); 040 addMarkdown(td, acd.getDocumentation()); 041 if (acd.hasReference()) { 042 tbl.tr().td().tx("References:"); 043 td = tr.td().colspan("2"); 044 boolean first = true; 045 for (UrlType t : acd.getReference()) { 046 if (first) first = false; else x.br(); 047 render(td, t); 048 } 049 } 050 if (acd.hasCapabilities()) { 051 tbl.tr().td().tx("Capabilities:"); 052 td = tr.td().colspan("2"); 053 CapabilityStatement cs = context.getWorker().fetchResource(CapabilityStatement.class, acd.getCapabilities(), acd); 054 if (cs != null) { 055 td.ah(cs.getWebPath()).tx(cs.present()); 056 } else { 057 render(td, acd.getCapabilitiesElement()); 058 } 059 } 060 if (acd.hasDerivedFrom()) { 061 tbl.tr().td().tx("Derived from:"); 062 td = tr.td().colspan("2"); 063 boolean first = true; 064 for (UrlType t : acd.getReference()) { 065 if (first) first = false; else x.br(); 066 ActorDefinition df = context.getWorker().fetchResource(ActorDefinition.class, t.getValue(), acd); 067 if (df != null) { 068 td.ah(df.getWebPath()).tx(df.present()); 069 } else { 070 render(td, t); 071 } 072 } 073 } 074 return false; 075 } 076 077 public void describe(XhtmlNode x, Library lib) { 078 x.tx(display(lib)); 079 } 080 081 public String display(Library lib) { 082 return lib.present(); 083 } 084 085 @Override 086 public String display(Resource r) throws UnsupportedEncodingException, IOException { 087 return ((Library) r).present(); 088 } 089 090 @Override 091 public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException { 092 if (r.has("title")) { 093 return r.children("title").get(0).getBase().primitiveValue(); 094 } 095 return "??"; 096 } 097 098}