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.DomainResource;
009import org.hl7.fhir.r5.model.ImplementationGuide;
010import org.hl7.fhir.r5.model.Resource;
011import org.hl7.fhir.r5.renderers.utils.RenderingContext;
012import org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper;
013import org.hl7.fhir.r5.renderers.utils.Resolver.ResourceContext;
014import org.hl7.fhir.utilities.xhtml.XhtmlNode;
015
016public class ImplementationGuideRenderer extends ResourceRenderer {
017
018  public ImplementationGuideRenderer(RenderingContext context) {
019    super(context);
020  }
021
022  public ImplementationGuideRenderer(RenderingContext context, ResourceContext rcontext) {
023    super(context, rcontext);
024  }
025  
026  public boolean render(XhtmlNode x, Resource dr) throws FHIRFormatError, DefinitionException, IOException {
027    return render(x, (ImplementationGuide) dr);
028  }
029
030  public boolean render(XhtmlNode x, ImplementationGuide ig) throws FHIRFormatError, DefinitionException, IOException {
031    x.h2().addText(ig.getName());
032    x.para().tx("The official URL for this implementation guide is: ");
033    x.pre().tx(ig.getUrl());
034    addMarkdown(x, ig.getDescription());
035    return true;
036  }
037
038  public void describe(XhtmlNode x, ImplementationGuide ig) {
039    x.tx(display(ig));
040  }
041
042  public String display(ImplementationGuide ig) {
043    return ig.present();
044  }
045
046  @Override
047  public String display(Resource r) throws UnsupportedEncodingException, IOException {
048    return ((ImplementationGuide) r).present();
049  }
050
051  public String display(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
052    if (r.has("title")) {
053      return r.children("title").get(0).getBase().primitiveValue();
054    }
055    if (r.has("name")) {
056      return r.children("name").get(0).getBase().primitiveValue();
057    }
058    return "??";
059  }
060
061}