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.CanonicalResource;
010import org.hl7.fhir.r5.model.MarkdownType;
011import org.hl7.fhir.r5.renderers.utils.RenderingContext;
012import org.hl7.fhir.r5.renderers.utils.ResourceWrapper;
013import org.hl7.fhir.r5.utils.EOperationOutcome;
014import org.hl7.fhir.utilities.xhtml.XhtmlNode;
015
016public class SubscriptionTopicRenderer extends ResourceRenderer {
017
018  public SubscriptionTopicRenderer(RenderingContext context) { 
019    super(context); 
020  } 
021  
022  @Override
023  public String buildSummary(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
024    return canonicalTitle(r);
025  }
026
027  @Override
028  public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper st) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
029    renderResourceTechDetails(st, x);
030    genSummaryTable(status, x, (CanonicalResource) st.getResourceNative());
031
032    XhtmlNode tbl = x.table("grid");
033    XhtmlNode ttr = tbl.tr();
034    ttr.td().b().tx("SubscriptionTopic");
035    ttr.td().tx(context.getTranslated(st.has("title") ? st.child("title") : st.child("name")));
036    if (st.has("description")) {
037      ttr = tbl.tr();
038      ttr.td().b().tx("Description");
039      addMarkdown(ttr.td(), st.primitiveValue("description"));
040    }
041    if (st.has("copyright")) {
042      generateCopyrightTableRow(tbl, st);
043    }
044
045    
046    if (st.has("resourceTrigger")) {
047      TableData td = new TableData(context.formatPhrase(RenderingContext.SUB_TOPIC_RES_TRIG));
048      for (ResourceWrapper rt : st.children("resourceTrigger")) {
049        TableRowData tr = td.addRow();
050        if (rt.has("resource")) {
051          tr.value(context.formatPhrase(RenderingContext.GENERAL_RESOURCE), rt.child("resource"));
052        }
053        for (ResourceWrapper t : rt.children("supportedInteraction")) {          
054          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_INT), t);
055        }
056        if (rt.has("queryCriteria")) {
057          StringBuilder md = new StringBuilder(); 
058          ResourceWrapper qc = rt.child("queryCriteria");
059          if (qc.has("previous")) {
060            md.append(context.formatPhrase(RenderingContext.SUB_TOPIC_PREV, qc.primitiveValue("previous")+"\r\n")+" ");
061          }
062          if (qc.has("resultForCreate")) {
063            md.append(context.formatPhrase(RenderingContext.SUB_TOPIC_CREATE, qc.primitiveValue("resultForCreate")+"\r\n")+" ");
064          }
065          if (qc.has("current")) {
066            md.append(context.formatPhrase(RenderingContext.SUB_TOPIC_CREATE, qc.primitiveValue("current")+"\r\n")+" ");
067          }
068          if (qc.has("previous")) {
069            md.append(context.formatPhrase(RenderingContext.SUB_TOPIC_DELETE, qc.primitiveValue("resultForDelete")+"\r\n")+" ");
070          }
071          if (qc.has("requireBoth")) {
072            md.append(context.formatPhrase(RenderingContext.SUB_TOPIC_REQ, qc.primitiveValue("requireBoth")+"\r\n")+" ");
073          }
074          tr.value(context.formatPhrase(RenderingContext.GENERAL_CRIT), wrapNC(new MarkdownType(md.toString())));          
075        }
076        if (rt.has("fhirPathCriteria")) {
077          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_FHIR_PATH), rt.child("fhirPathCriteria"));
078        }
079        if (rt.has("description")) {
080          tr.value(context.formatPhrase(RenderingContext.GENERAL_DESC), rt.child("description"));
081        }
082      }
083      renderTable(status, td, x);
084    }
085
086    if (st.has("eventTrigger")) {
087      TableData td = new TableData("Event Triggers");
088      for (ResourceWrapper rt : st.children("eventTrigger")) {
089        TableRowData tr = td.addRow();
090        if (rt.has("resource")) {
091          tr.value(context.formatPhrase(RenderingContext.GENERAL_RESOURCE), rt.child("resource"));
092        }
093        if (rt.has("event(")) {
094          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_EVENT), rt.child("event"));
095        }
096        if (rt.has("description")) {
097          tr.value(context.formatPhrase(RenderingContext.GENERAL_DESC), rt.child("description"));
098        }
099      }
100      renderTable(status, td, x);
101    }
102
103    if (st.has("canFilterBy")) {
104      TableData td = new TableData("Can Filter By");
105      for (ResourceWrapper rt : st.children("canFilterBy")) {
106        TableRowData tr = td.addRow();
107        if (rt.has("resource")) {
108          tr.value(context.formatPhrase(RenderingContext.GENERAL_RESOURCE), rt.child("resource"));
109        }
110        if (rt.has("filterParameter")) {
111          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_FILT_PAR), rt.child("filterParameter"));
112        }
113        if (rt.has("filterDefinition")) {
114          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_FILT_DEF), rt.child("filterDefinition"));
115        }
116        for (ResourceWrapper t : rt.children("comparator")) {
117          tr.value(context.formatPhrase(RenderingContext.GENERAL_COMPARATORS), t);
118        }
119        for (ResourceWrapper t : rt.children("modifier")) {
120          tr.value(context.formatPhrase(RenderingContext.GENERAL_MODIFIERS), t);
121        }
122      }
123      renderTable(status, td, x);
124    }
125
126    if (st.has("notificationShape")) {
127      TableData td = new TableData("Notification Shapes");
128      for (ResourceWrapper rt : st.children("notificationShape")) {
129        TableRowData tr = td.addRow();
130        if (rt.has("resource")) {
131          tr.value(context.formatPhrase(RenderingContext.GENERAL_RESOURCE), rt.child("resource"));
132        }
133        for (ResourceWrapper t : rt.children("include")) {
134          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_INCL), t);
135        }
136        for (ResourceWrapper t : rt.children("revInclude")) {
137          tr.value(context.formatPhrase(RenderingContext.SUB_TOPIC_REV_INCL), t);
138        }
139      }
140      renderTable(status, td, x);
141    }
142  }
143
144}