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

The following examples show how to use org.hl7.fhir.utilities.xhtml.XhtmlNode#hr() . 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
public XhtmlNode generateDocumentNarrative(Bundle feed) {
  /*
   When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
   * The Composition resource
   * The Subject resource
   * Resources referenced in the section.content
   */
  XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
  Composition comp = (Composition) feed.getEntry().get(0).getResource();
  root.getChildNodes().add(comp.getText().getDiv());
  Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
  if (subject != null && subject instanceof DomainResource) {
    root.hr();
    root.getChildNodes().add(((DomainResource)subject).getText().getDiv());
  }
  List<SectionComponent> sections = comp.getSection();
  renderSections(feed, root, sections, 1);
  return root;
}
 
Example 2
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void renderSections(Bundle feed, XhtmlNode node, List<SectionComponent> sections, int level) {
    for (SectionComponent section : sections) {
      node.hr();
      if (section.hasTitleElement())
        node.addTag("h"+Integer.toString(level)).addText(section.getTitle());
//      else if (section.hasCode())
//        node.addTag("h"+Integer.toString(level)).addText(displayCodeableConcept(section.getCode()));

//      if (section.hasText()) {
//        node.getChildNodes().add(section.getText().getDiv());
//      }
//
//      if (!section.getSection().isEmpty()) {
//        renderSections(feed, node.addTag("blockquote"), section.getSection(), level+1);
//      }
    }
  }
 
Example 3
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public XhtmlNode generateDocumentNarrative(Bundle feed) {
  /*
   When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
   * The Composition resource
   * The Subject resource
   * Resources referenced in the section.content
   */
  XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
  Composition comp = (Composition) feed.getEntry().get(0).getResource();
  root.getChildNodes().add(comp.getText().getDiv());
  Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
  if (subject != null && subject instanceof DomainResource) {
    root.hr();
    root.getChildNodes().add(((DomainResource)subject).getText().getDiv());
  }
  List<SectionComponent> sections = comp.getSection();
  renderSections(feed, root, sections, 1);
  return root;
}
 
Example 4
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void renderSections(Bundle feed, XhtmlNode node, List<SectionComponent> sections, int level) {
    for (SectionComponent section : sections) {
      node.hr();
      if (section.hasTitleElement())
        node.addTag("h"+Integer.toString(level)).addText(section.getTitle());
//      else if (section.hasCode())
//        node.addTag("h"+Integer.toString(level)).addText(displayCodeableConcept(section.getCode()));

//      if (section.hasText()) {
//        node.getChildNodes().add(section.getText().getDiv());
//      }
//
//      if (!section.getSection().isEmpty()) {
//        renderSections(feed, node.addTag("blockquote"), section.getSection(), level+1);
//      }
    }
  }
 
Example 5
Source File: BundleRenderer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
  public boolean render(XhtmlNode x, ResourceWrapper b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome {
    List<BaseWrapper> entries = b.children("entry");
    if ("document".equals(b.get("type").primitiveValue())) {
      if (entries.isEmpty() || (entries.get(0).has("resource") && "Composition".equals(entries.get(0).get("resource").fhirType())))
        throw new FHIRException("Invalid document - first entry is not a Composition");
      ResourceWrapper r = (ResourceWrapper) entries.get(0).getChildByName("resource").getValues().get(0);
      x.addChildren(r.getNarrative());
    } else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) {
      // nothing
    } else {
      XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
      root.para().addText("Bundle "+b.getId()+" of type "+b.get("type").primitiveValue());
      int i = 0;
      for (BaseWrapper be : entries) {
        i++;
        if (be.has("fullUrl")) {
          root.an(makeInternalLink(be.get("fullUrl").primitiveValue()));
        }
        if (be.has("resource") && be.getChildByName("resource").getValues().get(0).has("id")) {
          root.an(be.get("resource").fhirType().toLowerCase() + "_" + be.getChildByName("resource").getValues().get(0).get("id").primitiveValue());
        }
        root.hr();
        root.para().addText("Entry "+Integer.toString(i)+(be.has("fullUrl") ? " - Full URL = " + be.get("fullUrl").primitiveValue() : ""));
//        if (be.hasRequest())
//          renderRequest(root, be.getRequest());
//        if (be.hasSearch())
//          renderSearch(root, be.getSearch());
//        if (be.hasResponse())
//          renderResponse(root, be.getResponse());
        if (be.has("resource")) {
          root.para().addText("Resource "+be.get("resource").fhirType()+":");
          ResourceWrapper rw = be.getChildByName("resource").getAsResource();
          root.blockquote().addChildren(rw.getNarrative());
        }
      }
    }
    return false;
  }
 
Example 6
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.hr();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example 7
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XhtmlNode renderBundle(org.hl7.fhir.r4.elementmodel.Element element) throws FHIRException {
  XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
  for (Base b : element.listChildrenByName("entry")) {
    org.hl7.fhir.r4.elementmodel.Element r = ((org.hl7.fhir.r4.elementmodel.Element) b).getNamedChild("resource");
    if (r!=null) {
      XhtmlNode c = getHtmlForResource(r);
      if (c != null)
        root.getChildNodes().addAll(c.getChildNodes());
      root.hr();
    }
  }
  return root;
}
 
Example 8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) {
  if (!x.hasAttribute("xmlns"))
    x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");
  if (!r.hasText() || !r.getText().hasDiv() || r.getText().getDiv().getChildNodes().isEmpty()) {
    r.setText(new Narrative());
    r.getText().setDiv(x);
    r.getText().setStatus(status);
  } else {
    XhtmlNode n = r.getText().getDiv();
    n.hr();
    n.getChildNodes().addAll(x.getChildNodes());
  }
}
 
Example 9
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XhtmlNode renderBundle(org.hl7.fhir.dstu3.elementmodel.Element element) throws FHIRException {
  XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
  for (Base b : element.listChildrenByName("entry")) {
    XhtmlNode c = getHtmlForResource(((org.hl7.fhir.dstu3.elementmodel.Element) b).getNamedChild("resource"));
    if (c != null)
      root.getChildNodes().addAll(c.getChildNodes());
    root.hr();
  }
  return root;
}