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.ListResource;
010import org.hl7.fhir.r5.renderers.utils.RenderingContext;
011import org.hl7.fhir.r5.renderers.utils.ResourceWrapper;
012import org.hl7.fhir.r5.utils.EOperationOutcome;
013import org.hl7.fhir.utilities.MarkedToMoveToAdjunctPackage;
014import org.hl7.fhir.utilities.xhtml.XhtmlNode; 
015 
016@MarkedToMoveToAdjunctPackage
017public class ListRenderer extends ResourceRenderer { 
018 
019  public ListRenderer(RenderingContext context) { 
020    super(context); 
021  } 
022 
023  @Override
024  public String buildSummary(ResourceWrapper r) throws UnsupportedEncodingException, IOException {
025    ResourceWrapper c = r.child("code");
026    String cd = c == null ? context.formatPhrase(RenderingContext.LIST_UNSPECIFIED_CODE) : displayCodeableConcept(c);
027    ResourceWrapper s = r.child("subject");
028    String sd = s == null ? context.formatPhrase(RenderingContext.LIST_UNSPECIFIED_SUBJECT) : displayReference(s);
029    return context.formatPhrase(RenderingContext.LIST_SUMMARY, cd, sd);
030  }
031
032  @Override
033  public void buildNarrative(RenderingStatus status, XhtmlNode x, ResourceWrapper list) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
034    renderResourceTechDetails(list, x);
035    if (list.has("title")) { 
036      x.h2().tx(list.primitiveValue("title")); 
037    } 
038    XhtmlNode t = x.table("clstu", false); 
039    XhtmlNode tr = t.tr(); 
040    if (list.has("date")) { 
041      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DATE, displayDateTime(list.child("date")))+" "); 
042    }  
043    if (list.has("mode")) { 
044      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_MODE, getTranslatedCode(list.child("mode")))+" "); 
045    } 
046    if (list.has("status")) { 
047      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_STAT, getTranslatedCode(list.child("status")))+" "); 
048    } 
049    if (list.has("code")) { 
050      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_CODE, displayDataType(list.child("code")))+" "); 
051    }     
052    tr = t.tr(); 
053    XhtmlNode td = tr.td(); 
054    if (list.has("subject")) { 
055      td.tx(context.formatPhrase(RenderingContext.LIST_REND_SUB)+" "); 
056      renderReference(status, td, list.child("subject")); 
057    } 
058    if (list.has("encounter")) { 
059      td.tx(context.formatPhrase(RenderingContext.LIST_REND_ENC)+" "); 
060      renderReference(status, td, list.child("encounter")); 
061    } 
062    if (list.has("source")) { 
063      td.tx(context.formatPhrase(RenderingContext.GENERAL_SRC)+" "); 
064      renderReference(status, td, list.child("encounter")); 
065    } 
066    if (list.has("orderedBy")) { 
067      td.tx(context.formatPhrase(RenderingContext.LIST_REND_ORD, displayDataType(list.child("orderedBy")))+" "); 
068    } 
069    for (ResourceWrapper a : list.children("note")) { 
070      renderAnnotation(status, x, a); 
071    } 
072    boolean flag = false; 
073    boolean deleted = false; 
074    boolean date = false; 
075    for (ResourceWrapper e : list.children("entry")) { 
076      flag = flag || e.has("flag"); 
077      deleted = deleted || e.has("deleted"); 
078      date = date || e.has("date"); 
079    } 
080    t = x.table("grid", false); 
081    tr = t.tr().style("backgound-color: #eeeeee"); 
082    tr.td().b().tx(context.formatPhrase(RenderingContext.LIST_REND_ITEM)); 
083    if (date) { 
084      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DAT));       
085    } 
086    if (flag) { 
087      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_FLAG));       
088    } 
089    if (deleted) { 
090      tr.td().tx(context.formatPhrase(RenderingContext.LIST_REND_DEL));       
091    } 
092    for (ResourceWrapper e : list.children("entry")) { 
093      tr = t.tr(); 
094      renderReference(status, tr.td(), e.child("item")); 
095      if (date) { 
096        tr.td().tx(e.has("date") ? displayDateTime(e.child("date")) : "");       
097      } 
098      if (flag) { 
099        tr.td().tx(e.has("flag") ? displayDataType(e.child("flag")) : "");       
100      } 
101      if (deleted) { 
102        tr.td().tx(e.has("deleted") ? e.primitiveValue("deleted") : ""); 
103      } 
104    }     
105    
106    if (list.has("contained") && context.isTechnicalMode()) {
107      x.hr();
108      x.para().b().tx(context.formatMessagePlural(list.children("contained").size(), RenderingContext.PAT_CONTAINED));
109      addContained(status, x, list.children("contained"));
110    }
111  } 
112  
113  public void describe(XhtmlNode x, ListResource list) { 
114    x.tx(display(list)); 
115  } 
116 
117  public String display(ListResource list) { 
118    return list.getTitle(); 
119  } 
120 
121 
122}