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.Enumeration; 009import org.hl7.fhir.r5.model.Enumerations.SearchComparator; 010import org.hl7.fhir.r5.model.Enumerations.SearchModifierCode; 011import org.hl7.fhir.r5.model.Library; 012import org.hl7.fhir.r5.model.MarkdownType; 013import org.hl7.fhir.r5.model.Requirements; 014import org.hl7.fhir.r5.model.Resource; 015import org.hl7.fhir.r5.model.StringType; 016import org.hl7.fhir.r5.model.SubscriptionTopic; 017import org.hl7.fhir.r5.model.SubscriptionTopic.InteractionTrigger; 018import org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicCanFilterByComponent; 019import org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicEventTriggerComponent; 020import org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicNotificationShapeComponent; 021import org.hl7.fhir.r5.model.SubscriptionTopic.SubscriptionTopicResourceTriggerComponent; 022import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper; 023import org.hl7.fhir.r5.renderers.utils.RenderingContext; 024import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext; 025import org.hl7.fhir.utilities.xhtml.XhtmlNode; 026 027public class SubscriptionTopicRenderer extends ResourceRenderer { 028 029 public SubscriptionTopicRenderer(RenderingContext context) { 030 super(context); 031 } 032 033 public SubscriptionTopicRenderer(RenderingContext context, ResourceContext rcontext) { 034 super(context, rcontext); 035 } 036 037 public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException { 038 return render(x, (SubscriptionTopic) dr); 039 } 040 041 public boolean render(XhtmlNode x, SubscriptionTopic st) throws FHIRFormatError, DefinitionException, IOException { 042 043 if (context.isHeader()) { 044 XhtmlNode h = x.h2(); 045 h.addText(st.hasTitle() ? st.getTitle() : st.getName()); 046 addMarkdown(x, st.getDescription()); 047 if (st.hasCopyright()) 048 generateCopyright(x, st); 049 } 050 051 if (st.hasResourceTrigger()) { 052 TableData td = new TableData("Resource Triggers"); 053 for (SubscriptionTopicResourceTriggerComponent rt : st.getResourceTrigger()) { 054 TableRowData tr = td.addRow(); 055 if (rt.hasResource()) { 056 tr.value("Resource", rt.getResourceElement()); 057 } 058 for (Enumeration<InteractionTrigger> t : rt.getSupportedInteraction()) { 059 tr.value("Interactions", t); 060 } 061 if (rt.hasQueryCriteria()) { 062 StringBuilder md = new StringBuilder(); 063 if (rt.getQueryCriteria().hasPrevious()) { 064 md.append("* previous = "+rt.getQueryCriteria().getPrevious()+"\r\n"); 065 } 066 if (rt.getQueryCriteria().hasResultForCreate()) { 067 md.append("* create result = "+rt.getQueryCriteria().getResultForCreate()+"\r\n"); 068 } 069 if (rt.getQueryCriteria().hasCurrent()) { 070 md.append("* create result = "+rt.getQueryCriteria().getCurrent()+"\r\n"); 071 } 072 if (rt.getQueryCriteria().hasPrevious()) { 073 md.append("* delete result = "+rt.getQueryCriteria().getResultForDelete()+"\r\n"); 074 } 075 if (rt.getQueryCriteria().hasRequireBoth()) { 076 md.append("* require both = "+rt.getQueryCriteria().getRequireBoth()+"\r\n"); 077 } 078 tr.value("Criteria", new MarkdownType(md.toString())); 079 } 080 if (rt.hasFhirPathCriteriaElement()) { 081 tr.value("FHIR Path", rt.getFhirPathCriteriaElement()); 082 } 083 if (rt.hasDescription()) { 084 tr.value("Description", rt.getDescriptionElement()); 085 } 086 } 087 renderTable(td, x); 088 } 089 090 if (st.hasEventTrigger()) { 091 TableData td = new TableData("Event Triggers"); 092 for (SubscriptionTopicEventTriggerComponent rt : st.getEventTrigger()) { 093 TableRowData tr = td.addRow(); 094 if (rt.hasResource()) { 095 tr.value("Resource", rt.getResourceElement()); 096 } 097 if (rt.hasEvent()) { 098 tr.value("Event", rt.getEvent()); 099 } 100 if (rt.hasDescription()) { 101 tr.value("Description", rt.getDescriptionElement()); 102 } 103 } 104 renderTable(td, x); 105 } 106 107 if (st.hasCanFilterBy()) { 108 TableData td = new TableData("Can Filter By"); 109 for (SubscriptionTopicCanFilterByComponent rt : st.getCanFilterBy()) { 110 TableRowData tr = td.addRow(); 111 if (rt.hasResource()) { 112 tr.value("Resource", rt.getResourceElement()); 113 } 114 if (rt.hasFilterParameter()) { 115 tr.value("Filter Parameter", rt.getFilterParameterElement()); 116 } 117 if (rt.hasFilterDefinition()) { 118 tr.value("Filter Definition", rt.getFilterDefinitionElement()); 119 } 120 for (Enumeration<SearchComparator> t : rt.getComparator()) { 121 tr.value("Comparators", t); 122 } 123 for (Enumeration<SearchModifierCode> t : rt.getModifier()) { 124 tr.value("Modifiers", t); 125 } 126 } 127 renderTable(td, x); 128 } 129 130 if (st.hasNotificationShape()) { 131 TableData td = new TableData("Notification Shapes"); 132 for (SubscriptionTopicNotificationShapeComponent rt : st.getNotificationShape()) { 133 TableRowData tr = td.addRow(); 134 if (rt.hasResource()) { 135 tr.value("Resource", rt.getResourceElement()); 136 } 137 for (StringType t : rt.getInclude()) { 138 tr.value("Includes", t); 139 } 140 for (StringType t : rt.getRevInclude()) { 141 tr.value("Reverse Includes", t); 142 } 143 } 144 renderTable(td, x); 145 } 146 147 return false; 148 } 149 150 public void describe(XhtmlNode x, Library lib) { 151 x.tx(display(lib)); 152 } 153 154 public String display(Library lib) { 155 return lib.present(); 156 } 157 158 @Override 159 public String display(Resource r) throws UnsupportedEncodingException, IOException { 160 return ((Library) r).present(); 161 } 162 163 @Override 164 public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException { 165 if (r.has("title")) { 166 return r.children("title").get(0).getBase().primitiveValue(); 167 } 168 return "??"; 169 } 170 171}