Java Code Examples for org.hl7.fhir.utilities.xhtml.XhtmlNode#addText()

The following examples show how to use org.hl7.fhir.utilities.xhtml.XhtmlNode#addText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private  <T extends Resource> void addCsRef(ConceptSetComponent inc, XhtmlNode li, T cs) {
  String ref = null;
  if (cs != null) {
    ref = (String) cs.getUserData("filename");
    if (Utilities.noString(ref))
      ref = (String) cs.getUserData("path");
  }
  if (cs != null && ref != null) {
    if (!Utilities.noString(prefix) && ref.startsWith("http://hl7.org/fhir/"))
      ref = ref.substring(20)+"/index.html";
    else if (!ref.endsWith(".html"))
        ref = ref + ".html";
    XhtmlNode a = li.addTag("a");
    a.setAttribute("href", prefix+ref.replace("\\", "/"));
    a.addText(inc.getSystem().toString());
  } else
    li.addText(inc.getSystem().toString());
}
 
Example 2
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void addCodeToTable(boolean isAbstract, String system, String code, String display, XhtmlNode td) {
  CodeSystem e = context.fetchCodeSystem(system);
  if (e == null || e.getContent() != org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode.COMPLETE) {
    if (isAbstract)
      td.i().setAttribute("title", ABSTRACT_CODE_HINT).addText(code);
    else if ("http://snomed.info/sct".equals(system)) {
      td.ah(sctLink(code)).addText(code);
    } else if ("http://loinc.org".equals(system)) {
        td.ah("http://details.loinc.org/LOINC/"+code+".html").addText(code);
    } else        
      td.addText(code);
  } else {
    String href = prefix+getCsRef(e);
    if (href.contains("#"))
      href = href + "-"+Utilities.nmtokenize(code);
    else
      href = href + "#"+e.getId()+"-"+Utilities.nmtokenize(code);
    if (isAbstract)
      td.ah(href).setAttribute("title", ABSTRACT_CODE_HINT).i().addText(code);
    else
      td.ah(href).addText(code);
  }
}
 
Example 3
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void renderAnnotation(Annotation a, XhtmlNode x, boolean showCodeDetails) throws FHIRException {
  StringBuilder s = new StringBuilder();
  if (a.hasAuthor()) {
    s.append("Author: ");

    if (a.hasAuthorReference())
      s.append(a.getAuthorReference().getReference());
    else if (a.hasAuthorStringType())
      s.append(a.getAuthorStringType().getValue());
  }


  if (a.hasTimeElement()) {
    if (s.length() > 0)
      s.append("; ");

    s.append("Made: ").append(a.getTimeElement().toHumanDisplay());
  }

  if (a.hasText()) {
    if (s.length() > 0)
      s.append("; ");

    s.append("Annotation: ").append(a.getText());
  }

  x.addText(s.toString());
}
 
Example 4
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addMapHeaders(XhtmlNode tr, Map<ConceptMap, String> mymaps) {
 for (ConceptMap m : mymaps.keySet()) {
 	XhtmlNode td = tr.addTag("td");
 	XhtmlNode b = td.addTag("b");
 	XhtmlNode a = b.addTag("a");
 	a.setAttribute("href", prefix+mymaps.get(m));
 	a.addText(m.hasDescription() ? m.getDescription() : m.getName());
 }
}
 
Example 5
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void renderCoding(Coding c, XhtmlNode x, boolean showCodeDetails) {
  String s = "";
  if (c.hasDisplayElement())
    s = c.getDisplay();
  if (Utilities.noString(s))
    s = lookupCode(c.getSystem(), c.getCode());

  if (Utilities.noString(s))
    s = c.getCode();

  if (showCodeDetails) {
    x.addText(s+" (Details: "+describeSystem(c.getSystem())+" code "+c.getCode()+" = '"+lookupCode(c.getSystem(), c.getCode())+"', stated as '"+c.getDisplay()+"')");
  } else
    x.span(null, "{"+c.getSystem()+" "+c.getCode()+"}").addText(s);
}
 
Example 6
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void renderQuantity(Quantity q, XhtmlNode x, boolean showCodeDetails) {
  if (q.hasComparator())
    x.addText(q.getComparator().toCode());
  x.addText(q.getValue().toString());
  if (q.hasUnit())
    x.addText(" "+q.getUnit());
  else if (q.hasCode())
    x.addText(" "+q.getCode());
  if (showCodeDetails && q.hasCode()) {
    XhtmlNode sp = x.addTag("span");
    sp.setAttribute("style", "background: LightGoldenRodYellow ");
    sp.addText(" (Details: "+describeSystem(q.getSystem())+" code "+q.getCode()+" = '"+lookupCode(q.getSystem(), q.getCode())+"')");
  }
}
 
Example 7
Source File: DataRenderer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected void renderCoding(XhtmlNode x, Coding c, boolean showCodeDetails) {
  String s = "";
  if (c.hasDisplayElement())
    s = c.getDisplay();
  if (Utilities.noString(s))
    s = lookupCode(c.getSystem(), c.getCode());

  if (Utilities.noString(s))
    s = c.getCode();

  if (showCodeDetails) {
    x.addText(s+" (Details: "+TerminologyRenderer.describeSystem(c.getSystem())+" code "+c.getCode()+" = '"+lookupCode(c.getSystem(), c.getCode())+"', stated as '"+c.getDisplay()+"')");
  } else
    x.span(null, "{"+c.getSystem()+" "+c.getCode()+"}").addText(s);
}
 
Example 8
Source File: ResourceRenderer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void renderReference(ResourceWrapper rw, XhtmlNode x, BaseWrapper r) throws UnsupportedEncodingException, IOException {
  XhtmlNode c = x;
  ResourceWithReference tr = null;
  String v;
  if (r.has("reference")) {
    v = r.get("reference").primitiveValue();
    tr = resolveReference(rw, v);

    if (!v.startsWith("#")) {
      if (tr != null && tr.getReference() != null)
        c = x.ah(tr.getReference());
      else
        c = x.ah(v);
    }
  } else {
    v = "";
  }
  // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
  if (r.has("display")) {
    c.addText(r.get("display").primitiveValue());
    if (tr != null && tr.getResource() != null) {
      c.tx(". Generated Summary: ");
      new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), true, v.startsWith("#"));
    }
  } else if (tr != null && tr.getResource() != null) {
    new ProfileDrivenRenderer(context).generateResourceSummary(c, tr.getResource(), v.startsWith("#"), v.startsWith("#"));
  } else {
    c.addText(v);
  }
}
 
Example 9
Source File: SpecDifferenceEvaluator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void markNew(String name, boolean item, boolean res, boolean mand) {
  XhtmlNode tr = tbl.addTag("tr").setAttribute("class", item ? "diff-new-item" : "diff-new");
  XhtmlNode left = tr.addTag("td").setAttribute("class", "diff-left");
  XhtmlNode right = tr.addTag("td").setAttribute("class", "diff-right");
  String link = linker == null ? null : linker.getLink(name);
  if (link!= null)
    left.addTag("a").setAttribute("href", link).addText(name);
  else
    left.addText(name);
  if (!res && mand)
    right.ul().li().b().addText("Added Mandatory Element");    
  else
    right.ul().li().addText(res ? "Added Resource" : !name.contains(".") ? "Added Type" : mand ? "Added Mandatory Element " : "Added Element" );    
}
 
Example 10
Source File: DataRenderer.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public void renderDateTime(XhtmlNode x, Base e) {
  if (e.hasPrimitiveValue())
    x.addText(((DateTimeType) e).toHumanDisplay());
}
 
Example 11
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderHumanName(HumanName name, XhtmlNode x) {
  x.addText(displayHumanName(name));
}
 
Example 12
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderAddress(Address address, XhtmlNode x) {
  x.addText(displayAddress(address));
}
 
Example 13
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints) throws FHIRException, UnsupportedEncodingException, IOException {
  if (ew == null)
    return;

  Base e = ew.getBase();

  if (e instanceof StringType)
    x.addText(((StringType) e).getValue());
  else if (e instanceof CodeType)
    x.addText(((CodeType) e).getValue());
  else if (e instanceof IdType)
    x.addText(((IdType) e).getValue());
  else if (e instanceof Extension)
    x.addText("Extensions: Todo");
  else if (e instanceof InstantType)
    x.addText(((InstantType) e).toHumanDisplay());
  else if (e instanceof DateTimeType)
    x.addText(((DateTimeType) e).toHumanDisplay());
  else if (e instanceof Base64BinaryType)
    x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
  else if (e instanceof org.hl7.fhir.dstu2016may.model.DateType)
    x.addText(((org.hl7.fhir.dstu2016may.model.DateType) e).toHumanDisplay());
  else if (e instanceof Enumeration) {
    Object ev = ((Enumeration<?>) e).getValue();
	x.addText(ev == null ? "" : ev.toString()); // todo: look up a display name if there is one
  } else if (e instanceof BooleanType)
    x.addText(((BooleanType) e).getValue().toString());
  else if (e instanceof CodeableConcept) {
    renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
  } else if (e instanceof Coding) {
    renderCoding((Coding) e, x, showCodeDetails);
  } else if (e instanceof Annotation) {
    renderAnnotation((Annotation) e, x);
  } else if (e instanceof Identifier) {
    renderIdentifier((Identifier) e, x);
  } else if (e instanceof org.hl7.fhir.dstu2016may.model.IntegerType) {
    x.addText(Integer.toString(((org.hl7.fhir.dstu2016may.model.IntegerType) e).getValue()));
  } else if (e instanceof org.hl7.fhir.dstu2016may.model.DecimalType) {
    x.addText(((org.hl7.fhir.dstu2016may.model.DecimalType) e).getValue().toString());
  } else if (e instanceof HumanName) {
    renderHumanName((HumanName) e, x);
  } else if (e instanceof SampledData) {
    renderSampledData((SampledData) e, x);
  } else if (e instanceof Address) {
    renderAddress((Address) e, x);
  } else if (e instanceof ContactPoint) {
    renderContactPoint((ContactPoint) e, x);
  } else if (e instanceof UriType) {
    renderUri((UriType) e, x);
  } else if (e instanceof Timing) {
    renderTiming((Timing) e, x);
  } else if (e instanceof Range) {
    renderRange((Range) e, x);
  } else if (e instanceof Quantity) {
    renderQuantity((Quantity) e, x, showCodeDetails);
  } else if (e instanceof Ratio) {
    renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
    x.addText("/");
    renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
  } else if (e instanceof Period) {
    Period p = (Period) e;
    x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
    x.addText(" --> ");
    x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
  } else if (e instanceof Reference) {
    Reference r = (Reference) e;
    XhtmlNode c = x;
    ResourceWithReference tr = null;
    if (r.hasReferenceElement()) {
      tr = resolveReference(res, r.getReference());
      if (!r.getReference().startsWith("#")) {
        if (tr != null && tr.getReference() != null)
          c = x.addTag("a").attribute("href", tr.getReference());
        else
          c = x.addTag("a").attribute("href", r.getReference());
      }
    }
    // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
    if (r.hasDisplayElement()) {
      c.addText(r.getDisplay());
      if (tr != null) {
        c.addText(". Generated Summary: ");
        generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
      }
    } else if (tr != null) {
      generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
    } else {
      c.addText(r.getReference());
    }
  } else if (e instanceof Resource) {
    return;
  } else if (e instanceof ElementDefinition) {
    x.addText("todo-bundle");
  } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
    throw new NotImplementedException("type "+e.getClass().getName()+" not handled yet");
}
 
Example 14
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private boolean generateComposition(ResourceContext rcontext, XhtmlNode x, ValueSet vs, boolean header) throws FHIRException, IOException {
 boolean hasExtensions = false;
  List<String> langs = new ArrayList<String>();

  if (header) {
    XhtmlNode h = x.h2();
    h.addText(vs.getName());
    addMarkdown(x, vs.getDescription());
    if (vs.hasCopyrightElement())
      generateCopyright(x, vs);
  }
  XhtmlNode p = x.para();
  p.tx("This value set includes codes from the following code systems:");

  XhtmlNode ul = x.ul();
  XhtmlNode li;
  for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
    hasExtensions = genInclude(rcontext, ul, inc, "Include", langs) || hasExtensions;
  }
  for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
    hasExtensions = genInclude(rcontext, ul, exc, "Exclude", langs) || hasExtensions;
  }

  // now, build observed languages

  if (langs.size() > 0) {
    Collections.sort(langs);
    x.para().b().tx("Additional Language Displays");
    XhtmlNode t = x.table( "codes");
    XhtmlNode tr = t.tr();
    tr.td().b().tx("Code");
    for (String lang : langs)
      tr.td().b().addText(describeLang(lang));
    for (ConceptSetComponent c : vs.getCompose().getInclude()) {
      for (ConceptReferenceComponent cc : c.getConcept()) {
        addLanguageRow(cc, t, langs);
      }
    }
  }

  return hasExtensions;
}
 
Example 15
Source File: DataRenderer.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
protected void renderAddress(XhtmlNode x, Address address) {
  x.addText(displayAddress(address));
}
 
Example 16
Source File: DataRenderer.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
protected void renderContactPoint(XhtmlNode x, ContactPoint contact) {
  x.addText(displayContactPoint(contact));
}
 
Example 17
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderAddress(Address address, XhtmlNode x) {
  x.addText(displayAddress(address));
}
 
Example 18
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderTiming(Timing s, XhtmlNode x) throws FHIRException {
  x.addText(displayTiming(s));
}
 
Example 19
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws Exception {
  VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
  if (var == null)
    throw new FHIRException("Rule \""+ruleId+"\": Unknown input variable "+src.getContext());
  PropertyWithType prop = var.getProperty();

  boolean optional = false;
  boolean repeating = false;

  if (src.hasCondition()) {
    optional = true;
  }

  if (src.hasElement()) {
    Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement());
    if (element == null)
      throw new Exception("Rule \""+ruleId+"\": Unknown element name "+src.getElement());
    if (element.getDefinition().getMin() == 0)
      optional = true;
    if (element.getDefinition().getMax().equals("*"))
      repeating = true;
    VariablesForProfiling result = vars.copy(optional, repeating);
    TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
    for (TypeRefComponent tr : element.getDefinition().getType()) {
      if (!tr.hasCode())
        throw new Error("Rule \""+ruleId+"\": Element has no type");
      ProfiledType pt = new ProfiledType(tr.getCode());
      if (tr.hasProfile())
        pt.addProfile(tr.getProfile());
      if (element.getDefinition().hasBinding())
        pt.addBinding(element.getDefinition().getBinding());
      type.addType(pt);
  } 
    td.addText(prop.getPath()+"."+src.getElement()); 
    if (src.hasVariable())
      result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath()+"."+src.getElement(), element, null, type));
  return result;
  } else {
    td.addText(prop.getPath()); // ditto!
    return vars.copy(optional, repeating);
  }
}
 
Example 20
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void renderContactPoint(ContactPoint contact, XhtmlNode x) {
  x.addText(displayContactPoint(contact));
}