Java Code Examples for org.hl7.fhir.utilities.xhtml.NodeType#Element

The following examples show how to use org.hl7.fhir.utilities.xhtml.NodeType#Element . 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
public String generate(ResourceContext rcontext, org.hl7.fhir.dstu3.elementmodel.Element er, boolean showCodeDetails) throws IOException, DefinitionException {
  if (rcontext == null)
    rcontext = new ResourceContext(null, er);
  
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    ResurceWrapperMetaElement resw = new ResurceWrapperMetaElement(er);
    BaseWrapperMetaElement base = new BaseWrapperMetaElement(er, null, er.getProperty().getStructure(), er.getProperty().getDefinition());
    base.children();
    generateByProfile(resw, er.getProperty().getStructure(), base, er.getProperty().getStructure().getSnapshot().getElement(), er.getProperty().getDefinition(), base.children, x, er.fhirType(), showCodeDetails);

  } catch (Exception e) {
    e.printStackTrace();
    x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: "+e.getMessage());
  }
  inject(er, x,  NarrativeStatus.GENERATED);
  return new XhtmlComposer(XhtmlComposer.XML).compose(x);
}
 
Example 3
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void generate(ValueSet vs, ValueSet src, boolean header) {
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    if (vs.hasExpansion()) {
      // for now, we just accept an expansion if there is one
      generateExpansion(x, vs, src, header);
//      if (!vs.hasCodeSystem() && !vs.hasCompose())
//        generateExpansion(x, vs, src, header);
//      else
//        throw new DefinitionException("Error: should not encounter value set expansion at this point");
    }

    boolean hasExtensions = false;
    if (vs.hasCodeSystem())
      hasExtensions = generateDefinition(x, vs, header);
    if (vs.hasCompose())
      hasExtensions = generateComposition(x, vs, header) || hasExtensions;
    inject(vs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
  }
 
Example 4
Source File: Narrative.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.)
 */
public XhtmlNode getDiv() { 
  if (this.div == null)
    if (Configuration.errorOnAutoCreate())
      throw new Error("Attempt to auto-create Narrative.div");
    else if (Configuration.doAutoCreate())
      this.div = new XhtmlNode(NodeType.Element, "div"); // cc 
  return this.div;
}
 
Example 5
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
   XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
   x.h2().addText(opd.getName());
   x.para().addText(Utilities.capitalize(opd.getKind().toString())+": "+opd.getName());
   x.para().tx("The official URL for this operation definition is: ");
   x.pre().tx(opd.getUrl());
   addMarkdown(x, opd.getDescription());

   if (opd.getSystem())
     x.para().tx("URL: [base]/$"+opd.getCode());
   for (CodeType c : opd.getResource()) {
     if (opd.getType())
       x.para().tx("URL: [base]/"+c.getValue()+"/$"+opd.getCode());
     if (opd.getInstance())
       x.para().tx("URL: [base]/"+c.getValue()+"/[id]/$"+opd.getCode());
   }

   x.para().tx("Parameters");
   XhtmlNode tbl = x.table( "grid");
   XhtmlNode tr = tbl.tr();
   tr.td().b().tx("Use");
   tr.td().b().tx("Name");
   tr.td().b().tx("Cardinality");
   tr.td().b().tx("Type");
   tr.td().b().tx("Binding");
   tr.td().b().tx("Documentation");
   for (OperationDefinitionParameterComponent p : opd.getParameter()) {
     genOpParam(rcontext, tbl, "", p);
   }
   addMarkdown(x, opd.getComment());
   inject(opd, x, NarrativeStatus.GENERATED);
   return true;
}
 
Example 6
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, StructureDefinition sd, Set<String> outputTracker) throws EOperationOutcome, FHIRException, IOException {
  ProfileUtilities pu = new ProfileUtilities(context, null, pkp);
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.getChildNodes().add(pu.generateTable(definitionsTarget, sd, true, destDir, false, sd.getId(), false, corePath, "", false, false, outputTracker));
  inject(sd, x, NarrativeStatus.GENERATED);
  return true;
}
 
Example 7
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void generate(ResourceContext rcontext, ValueSet vs, ValueSet src, boolean header) throws FHIRException, IOException {
  List<UsedConceptMap> maps = findReleventMaps(vs);
  
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions;
  if (vs.hasExpansion()) {
    // for now, we just accept an expansion if there is one
    hasExtensions = generateExpansion(x, vs, src, header, maps);
  } else {
    hasExtensions = generateComposition(rcontext, x, vs, header, maps);
  }
  inject(vs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
}
 
Example 8
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, OperationDefinition opd) throws EOperationOutcome, FHIRException, IOException {
   XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
   x.h2().addText(opd.getName());
   x.para().addText(Utilities.capitalize(opd.getKind().toString())+": "+opd.getName());
   x.para().tx("The official URL for this operation definition is: ");
   x.pre().tx(opd.getUrl());
   addMarkdown(x, opd.getDescription());

   if (opd.getSystem())
     x.para().tx("URL: [base]/$"+opd.getCode());
   for (CodeType c : opd.getResource()) {
     if (opd.getType())
       x.para().tx("URL: [base]/"+c.getValue()+"/$"+opd.getCode());
     if (opd.getInstance())
       x.para().tx("URL: [base]/"+c.getValue()+"/[id]/$"+opd.getCode());
   }

   x.para().tx("Parameters");
   XhtmlNode tbl = x.table( "grid");
   XhtmlNode tr = tbl.tr();
   tr.td().b().tx("Use");
   tr.td().b().tx("Name");
   tr.td().b().tx("Cardinality");
   tr.td().b().tx("Type");
   tr.td().b().tx("Binding");
   tr.td().b().tx("Documentation");
   for (OperationDefinitionParameterComponent p : opd.getParameter()) {
     genOpParam(rcontext, tbl, "", p);
   }
   addMarkdown(x, opd.getComment());
   inject(opd, x, NarrativeStatus.GENERATED);
   return true;
}
 
Example 9
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void generateByProfile(DomainResource r, StructureDefinition profile, boolean showCodeDetails) {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.addTag("p").addTag("b").addText("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    generateByProfile(r, profile, r, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), r.getResourceType().toString()), x, r.getResourceType().toString(), showCodeDetails);
  } catch (Exception e) {
    e.printStackTrace();
    x.addTag("p").addTag("b").setAttribute("style", "color: maroon").addText("Exception generating Narrative: "+e.getMessage());
  }
  inject(r, x,  NarrativeStatus.GENERATED);
}
 
Example 10
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public boolean generate(ResourceContext rcontext, ImplementationGuide ig) throws EOperationOutcome, FHIRException, IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.h2().addText(ig.getName());
  x.para().tx("The official URL for this implementation guide is: ");
  x.pre().tx(ig.getUrl());
  addMarkdown(x, ig.getDescription());
  inject(ig, x, NarrativeStatus.GENERATED);
  return true;
}
 
Example 11
Source File: ProfileDrivenRenderer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean generateByProfile(StructureDefinition profile, boolean showCodeDetails) {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    generateByProfile(rcontext.getResourceResource(), profile, rcontext.getResourceResource(), profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), rcontext.getResourceResource().getResourceType().toString()), x, rcontext.getResourceResource().getResourceType().toString(), showCodeDetails);
  } catch (Exception e) {
    e.printStackTrace();
    x.para().b().style("color: maroon").tx("Exception generating Narrative: "+e.getMessage());
  }
  inject(rcontext.getResourceResource(), x,  NarrativeStatus.GENERATED);
  return true;
}
 
Example 12
Source File: Narrative.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * @return {@link #div} (The actual narrative content, a stripped down version of XHTML.)
 */
public XhtmlNode getDiv() { 
  if (this.div == null)
    if (Configuration.errorOnAutoCreate())
      throw new Error("Attempt to auto-create Narrative.div");
    else if (Configuration.doAutoCreate())
      this.div = new XhtmlNode(NodeType.Element, "div"); // cc.1
  return this.div;
}
 
Example 13
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String generateByProfile(Element er, StructureDefinition profile, boolean showCodeDetails) throws IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.addTag("p").addTag("b").addText("Generated Narrative"+(showCodeDetails ? " with Details" : ""));
  try {
    generateByProfile(er, profile, er, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), er.getLocalName()), x, er.getLocalName(), showCodeDetails);
  } catch (Exception e) {
    e.printStackTrace();
    x.addTag("p").addTag("b").setAttribute("style", "color: maroon").addText("Exception generating Narrative: "+e.getMessage());
  }
  inject(er, x,  NarrativeStatus.GENERATED);
  return new XhtmlComposer(true, pretty).compose(x);
}
 
Example 14
Source File: CapabilityStatementUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private XhtmlNode same(String text, boolean test) {
  XhtmlNode span = new XhtmlNode(NodeType.Element, "span");
  if (test)
    span.style("background-color: #bbff99; border: 1px solid #44cc00; margin-width: 10px");
  span.tx(text);
  return span;
}
 
Example 15
Source File: ResourceComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XhtmlNode renderErrors(ResourceComparison csc) {
  XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
  XhtmlNode tbl = div.table("grid");
  for (ValidationMessage vm : csc.messages) {
    XhtmlNode tr = tbl.tr();
    tr.style("background-color: "+colorForLevel(vm.getLevel()));
    tr.td().tx(vm.getLocation());
    tr.td().tx(vm.getMessage());
    tr.td().tx(vm.getLevel().getDisplay());
  }
  return div;
}
 
Example 16
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public void generate(Conformance conf) {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  x.addTag("h2").addText(conf.getName());
  smartAddText(x.addTag("p"), conf.getDescription());
  ConformanceRestComponent rest = conf.getRest().get(0);
  XhtmlNode t = x.addTag("table");
  addTableRow(t, "Mode", rest.getMode().toString());
  addTableRow(t, "Description", rest.getDocumentation());

  addTableRow(t, "Transaction", showOp(rest, SystemRestfulInteraction.TRANSACTION));
  addTableRow(t, "System History", showOp(rest, SystemRestfulInteraction.HISTORYSYSTEM));
  addTableRow(t, "System Search", showOp(rest, SystemRestfulInteraction.SEARCHSYSTEM));

  t = x.addTag("table");
  XhtmlNode tr = t.addTag("tr");
  tr.addTag("th").addTag("b").addText("Resource Type");
  tr.addTag("th").addTag("b").addText("Profile");
  tr.addTag("th").addTag("b").addText("Read");
  tr.addTag("th").addTag("b").addText("V-Read");
  tr.addTag("th").addTag("b").addText("Search");
  tr.addTag("th").addTag("b").addText("Update");
  tr.addTag("th").addTag("b").addText("Updates");
  tr.addTag("th").addTag("b").addText("Create");
  tr.addTag("th").addTag("b").addText("Delete");
  tr.addTag("th").addTag("b").addText("History");

  for (ConformanceRestResourceComponent r : rest.getResource()) {
    tr = t.addTag("tr");
    tr.addTag("td").addText(r.getType());
    if (r.hasProfile()) {
    	XhtmlNode a = tr.addTag("td").addTag("a");
    	a.addText(r.getProfile().getReference());
    	a.setAttribute("href", prefix+r.getProfile().getReference());
    }
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.READ));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.VREAD));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.SEARCHTYPE));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.UPDATE));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.HISTORYINSTANCE));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.CREATE));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.DELETE));
    tr.addTag("td").addText(showOp(r, TypeRestfulInteraction.HISTORYTYPE));
  }

  inject(conf, x, NarrativeStatus.GENERATED);
}
 
Example 17
Source File: SpecDifferenceEvaluator.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private void start() {
  tbl = new XhtmlNode(NodeType.Element, "table");
  tbl.setAttribute("class", "grid");
  
}
 
Example 18
Source File: XhtmlType.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public XhtmlNode getValue() {
  return place == null ? new XhtmlNode(NodeType.Element, "div") : place.getDiv();
}
 
Example 19
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * This generate is optimised for the FHIR build process itself in as much as it
 * generates hyperlinks in the narrative that are only going to be correct for
 * the purposes of the build. This is to be reviewed in the future.
 *
 * @param vs
 * @param codeSystems
 * @throws IOException
 * @throws DefinitionException
 * @throws FHIRFormatError
 * @throws Exception
 */
public boolean generate(ResourceContext rcontext, CodeSystem cs, boolean header) throws FHIRFormatError, DefinitionException, IOException {
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions = false;
  hasExtensions = generateDefinition(x, cs, header);
  inject(cs, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
  return true;
}
 
Example 20
Source File: ResourceRenderer.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * given a resource, update it's narrative with the best rendering available
 * 
 * @param r - the domain resource in question
 * 
 * @throws IOException
 * @throws EOperationOutcome 
 * @throws FHIRException 
 */

public void render(DomainResource r) throws IOException, FHIRException, EOperationOutcome {  
  XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
  boolean hasExtensions = render(x, r);
  inject(r, x, hasExtensions ? NarrativeStatus.EXTENSIONS :  NarrativeStatus.GENERATED);
}