001package org.hl7.fhir.r5.renderers; 002 003import org.hl7.fhir.r5.context.IWorkerContext; 004import org.hl7.fhir.r5.renderers.utils.RenderingContext; 005import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; 006import org.hl7.fhir.utilities.MarkDownProcessor; 007import org.hl7.fhir.utilities.MarkDownProcessor.Dialect; 008import org.hl7.fhir.utilities.validation.ValidationOptions; 009 010/** 011 * Rendering framework: 012 * 013 * * boolean render(DomainResource) : produce an HTML representation suitable for runtime / documentation, and insert it into the resource. Return true of any extensions encountered 014 * * boolean render(XhtmlNode, Resource: produce an HTML representation, and fill out the provided node with it. Return true of any extensions encountered 015 * * XhtmlNode build(DomainResource): same as render(DomainResource) but also return the XHtmlNode 016 * 017 * * String display(Base) : produce a plan text concise representation that serves to describe the resource 018 * * void display(XhtmlNode, Base) : produce a plan text concise representation that serves to describe the resource 019 * 020 * * void describe(XhtmlNode, Resource) : produce a short summary of the resource with key details presented (potentially more verbose than display, but still suitable for a single line) 021 * 022 * if not specific code for rendering a resource has been provided, and there's no liquid script to guide it, a generic rendering based onthe profile will be performed 023 * 024 * @author graha 025 * 026 */ 027public class Renderer { 028 029 protected RenderingContext context; 030 031 public Renderer(RenderingContext context) { 032 this.context = context; 033 } 034 035 public Renderer(IWorkerContext worker) { 036 this.context = new RenderingContext(worker, new MarkDownProcessor(Dialect.COMMON_MARK), ValidationOptions.defaults(), "http://hl7.org/fhir/R5", "", null, ResourceRendererMode.END_USER); 037 } 038 039 040 protected static final String RENDER_BUNDLE_HEADER_ROOT = "RENDER_BUNDLE_HEADER_ROOT"; 041 protected static final String RENDER_BUNDLE_HEADER_ENTRY = "RENDER_BUNDLE_HEADER_ENTRY"; 042 protected static final String RENDER_BUNDLE_HEADER_ENTRY_URL = "RENDER_BUNDLE_HEADER_ENTRY_URL"; 043 protected static final String RENDER_BUNDLE_RESOURCE = "RENDER_BUNDLE_RESOURCE"; 044 protected static final String RENDER_BUNDLE_SEARCH = "RENDER_BUNDLE_SEARCH"; 045 protected static final String RENDER_BUNDLE_SEARCH_MODE = "RENDER_BUNDLE_SEARCH_MODE"; 046 protected static final String RENDER_BUNDLE_SEARCH_SCORE = "RENDER_BUNDLE_SEARCH_SCORE"; 047 protected static final String RENDER_BUNDLE_RESPONSE = "RENDER_BUNDLE_RESPONSE"; 048 protected static final String RENDER_BUNDLE_LOCATION = "RENDER_BUNDLE_LOCATION"; 049 protected static final String RENDER_BUNDLE_ETAG = "RENDER_BUNDLE_ETAG"; 050 protected static final String RENDER_BUNDLE_LAST_MOD = "RENDER_BUNDLE_LAST_MOD"; 051 protected static final String RENDER_BUNDLE_REQUEST = "RENDER_BUNDLE_REQUEST"; 052 protected static final String RENDER_BUNDLE_IF_NON_MATCH = "RENDER_BUNDLE_IF_NON_MATCH"; 053 protected static final String RENDER_BUNDLE_IF_MOD = "RENDER_BUNDLE_IF_MOD"; 054 protected static final String RENDER_BUNDLE_IF_MATCH = "RENDER_BUNDLE_IF_MATCH"; 055 protected static final String RENDER_BUNDLE_IF_NONE = "RENDER_BUNDLE_IF_NONE"; 056 057 058 /** the plan here is to make this have it's own implementation of messages, rather than using the 059 * validator messages, for better alignment with publisher I18n strategy 060 * 061 * @param theMessage 062 * @param theMessageArguments 063 * @return 064 */ 065 protected String formatMessage(String theMessage, Object... theMessageArguments) { 066 return context.getWorker().formatMessage(theMessage, theMessageArguments); 067 } 068 069}