
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.FHIRException; 008import org.hl7.fhir.exceptions.FHIRFormatError; 009import org.hl7.fhir.r5.model.ActorDefinition; 010import org.hl7.fhir.r5.model.CapabilityStatement; 011import org.hl7.fhir.r5.model.Library; 012import org.hl7.fhir.r5.model.UrlType; 013import org.hl7.fhir.r5.renderers.utils.RenderingContext; 014import org.hl7.fhir.r5.renderers.utils.ResourceWrapper; 015import org.hl7.fhir.r5.utils.EOperationOutcome; 016import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage; 017import org.hl7.fhir.utilities.xhtml.XhtmlNode; 018 019@MarkedToMoveToAdjunctPackage 020public class ActorDefinitionRenderer extends ResourceRenderer { 021 022 023 public ActorDefinitionRenderer(RenderingContext context) { 024 super(context); 025 } 026 027 @Override 028 public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome { 029 renderResourceTechDetails(r, x); 030 boolean summ = genSummaryTable(status, x, r); 031 render(status, x, r, summ); 032 } 033 034 @Override 035 public String buildSummary(ResourceWrapper r) throws UnsupportedEncodingException, IOException { 036 return canonicalTitle(r); 037 } 038 039 public void render(RenderingStatus status, XhtmlNode x, ResourceWrapper acd, boolean summ) throws FHIRFormatError, DefinitionException, IOException { 040 XhtmlNode tbl = x.table("grid", false); 041 XhtmlNode tr = tbl.tr(); 042 043 XhtmlNode td = null; 044 045 // if there's no summary table, then the first 3 rows of the table are 046 // * name, title, type 047 // * documentation 048 // * baseDefinition 049 // otherwise, the first row of the table is 050 // * type, baseDefinition 051 // 052 // after that 053 // * reference 054 if (!summ) { 055 // first row, if there's no summary table: 056 xlinkNarrative(tr.td(), acd.child("name")).b().tx(context.formatPhrase(RenderingContext.ACTOR_DEF_ACT, context.getTranslated(acd.child("name"))) + " "); 057 xlinkNarrative(tr.td(), acd.child("title")).tx(context.getTranslated(acd.child("title"))); 058 xlinkNarrative(tr.td(), acd.child("type")).tx(context.formatPhrase(RenderingContext.ACTOR_DEF_TYP, acd.primitiveValue("type")) + " "); 059 tr = tbl.tr(); 060 td = tr.td().colspan("3"); 061 xlinkNarrative(td, acd.child("documentation")); 062 addMarkdown(td, context.getTranslated(acd.child("documentation"))); 063 if (acd.has("baseDefinition")) { 064 markBoilerplate(tr.td()).tx(context.formatPhrase(RenderingContext.ACTOR_DERIVED_FROM)); 065 td = tr.td().colspan("2"); 066 boolean first = true; 067 for (ResourceWrapper t : acd.children("reference")) { 068 if (first) first = false; else x.br(); 069 renderUri(status, spanIfTracking(td, t), t); 070 } 071 } 072 } else { 073 xlinkNarrative(tr.td(), acd.child("type")).tx(context.formatPhrase(RenderingContext.ACTOR_DEF_TYP, acd.primitiveValue("type")) + " "); 074 markBoilerplate(tr.td()).tx(context.formatPhrase(RenderingContext.ACTOR_DERIVED_FROM)); 075 td = tr.td(); 076 if (acd.has("baseDefinition")) { 077 boolean first = true; 078 for (ResourceWrapper t : acd.children("reference")) { 079 if (first) first = false; else x.br(); 080 renderUri(status, spanIfTracking(td, t), t); 081 } 082 } else { 083 markGenerated(td).style("opaque: 0.6").tx(context.formatPhrase(RenderingContext.ACTOR_DERIVED_FROM_NONE)); 084 } 085 } 086 if (acd.has("reference")) { 087 tr = tbl.tr(); 088 markBoilerplate(tr.td()).tx(context.formatPhrase(RenderingContext.GENERAL_REFS)); 089 td = tr.td().colspan("2"); 090 boolean first = true; 091 for (ResourceWrapper t : acd.children("reference")) { 092 if (first) first = false; else x.br(); 093 renderUri(status, spanIfTracking(td, t), t); 094 } 095 } 096 if (acd.has("capabilities")) { 097 tr = tbl.tr(); 098 markBoilerplate(tr.td()).tx(context.formatPhrase(RenderingContext.ACTOR_DEF_CAP)); 099 td = tr.td().colspan("2"); 100 renderCanonical(status, xlinkNarrative(td, acd.child("capabilities")), acd.child("capabilities")); 101 } 102 if (acd.has("derivedFrom")) { 103 tr = tbl.tr(); 104 markBoilerplate(tr.td()).tx(context.formatPhrase(RenderingContext.ACTOR_DEF_DER)); 105 td = tr.td().colspan("2"); 106 boolean first = true; 107 for (ResourceWrapper t : acd.children("derivedFrom")) { 108 if (first) first = false; else x.br(); 109 renderUri(status, spanIfTracking(td, t), t); 110 } 111 } 112 } 113 114 public void describe(XhtmlNode x, Library lib) { 115 x.tx(display(lib)); 116 } 117 118 public String display(Library lib) { 119 return lib.present(); 120 } 121 122}