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  protected static final String RENDER_BUNDLE_DOCUMENT_CONTENT = "RENDER_BUNDLE_DOCUMENT_CONTENT";
057  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_URD = "RENDER_BUNDLE_HEADER_DOC_ENTRY_URD";
058  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_U = "RENDER_BUNDLE_HEADER_DOC_ENTRY_U";
059  protected static final String RENDER_BUNDLE_HEADER_DOC_ENTRY_RD = "RENDER_BUNDLE_HEADER_DOC_ENTRY_RD";
060
061  /** the plan here is to make this have it's own implementation of messages, rather than using the 
062   * validator messages, for better alignment with publisher I18n strategy
063   * 
064   * @param theMessage
065   * @param theMessageArguments
066   * @return
067   */
068  protected String formatMessage(String theMessage, Object... theMessageArguments) {
069    return context.getWorker().formatMessage(theMessage, theMessageArguments);
070  }
071
072}