org.hl7.fhir.utilities.xhtml.XhtmlNode Java Examples
The following examples show how to use
org.hl7.fhir.utilities.xhtml.XhtmlNode.
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 |
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 |
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 |
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.dstu3.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("http://browser.ihtsdotools.org/?perspective=full&conceptId1="+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 #4
Source File: ProfileDrivenRenderer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
@Override public boolean render(XhtmlNode x, ResourceWrapper r) throws FHIRFormatError, DefinitionException, IOException { x.para().b().tx("Generated Narrative"); try { StructureDefinition sd = r.getDefinition(); ElementDefinition ed = sd.getSnapshot().getElement().get(0); if (sd.getType().equals("NamingSystem") && "icd10".equals(r.getId())) { System.out.println("hah!"); } generateByProfile(r, sd, r.root(), sd.getSnapshot().getElement(), ed, context.getProfileUtilities().getChildList(sd, ed), x, r.getName(), false, 0); } catch (Exception e) { e.printStackTrace(); x.para().b().style("color: maroon").tx("Exception generating Narrative: "+e.getMessage()); } return false; }
Example #5
Source File: CodeSystemComparer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public XhtmlNode renderConcepts(CodeSystemComparison comparison, String id, String prefix) throws FHIRException, IOException { // columns: code, display (left|right), properties (left|right) HierarchicalTableGenerator gen = new HierarchicalTableGenerator(Utilities.path("[tmp]", "compare"), false); TableModel model = gen.new TableModel(id, true); model.setAlternating(true); model.getTitles().add(gen.new Title(null, null, "Code", "The code for the concept", null, 100)); model.getTitles().add(gen.new Title(null, null, "Display", "The display for the concept", null, 200, 2)); for (PropertyComponent p : comparison.getUnion().getProperty()) { model.getTitles().add(gen.new Title(null, null, p.getCode(), p.getDescription(), null, 100, 2)); } model.getTitles().add(gen.new Title(null, null, "Comments", "Additional information about the comparison", null, 200)); for (StructuralMatch<ConceptDefinitionComponent> t : comparison.getCombined().getChildren()) { addRow(gen, model.getRows(), t, comparison); } return gen.generate(model, prefix, 0, null); }
Example #6
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void analyseGroup(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapAnalysis result) throws FHIRException { log(indent+"Analyse Group : "+group.getName()); // todo: extends // todo: check inputs XhtmlNode tr = result.summary.addTag("tr").setAttribute("class", "diff-title"); XhtmlNode xs = tr.addTag("td"); XhtmlNode xt = tr.addTag("td"); for (StructureMapGroupInputComponent inp : group.getInput()) { if (inp.getMode() == StructureMapInputMode.SOURCE) noteInput(vars, inp, VariableMode.INPUT, xs); if (inp.getMode() == StructureMapInputMode.TARGET) noteInput(vars, inp, VariableMode.OUTPUT, xt); } for (StructureMapGroupRuleComponent r : group.getRule()) { analyseRule(indent+" ", context, map, vars, group, r, result); } }
Example #7
Source File: CapabilityStatementUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void error(XhtmlNode x, IssueType type, String path, String message) { output.messages.add(new ValidationMessage(Source.ProfileComparer, type, path, message, IssueSeverity.ERROR)); XhtmlNode ul; if ("ul".equals(x.getName())) { ul = x; } else { ul = null; for (XhtmlNode c : x.getChildNodes()) { if ("ul".equals(c.getName())) { ul = c; } } if (ul == null) { ul = x.ul(); } } ul.li().b().style("color: maroon").addText(message); }
Example #8
Source File: CapabilityStatementUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void information(XhtmlNode x, IssueType type, String path, String message) { if (type != null) output.messages.add(new ValidationMessage(Source.ProfileComparer, type, path, message, IssueSeverity.INFORMATION)); XhtmlNode ul; if ("ul".equals(x.getName())) { ul = x; } else { ul = null; for (XhtmlNode c : x.getChildNodes()) { if ("ul".equals(c.getName())) { ul = c; } } if (ul == null) { ul = x.ul(); } } ul.li().addText(message); }
Example #9
Source File: ResourceRenderer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
public static void inject(DomainResource r, XhtmlNode x, NarrativeStatus status) { if (!x.hasAttribute("xmlns")) x.setAttribute("xmlns", "http://www.w3.org/1999/xhtml"); if (r.hasLanguage()) { // use both - see https://www.w3.org/TR/i18n-html-tech-lang/#langvalues x.setAttribute("lang", r.getLanguage()); x.setAttribute("xml:lang", r.getLanguage()); } 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.clear(); n.getChildNodes().addAll(x.getChildNodes()); } }
Example #10
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean generateByProfile(ResourceContext rc, StructureDefinition profile, boolean showCodeDetails) { XhtmlNode x = new XhtmlNode(NodeType.Element, "div"); x.para().b().tx("Generated Narrative"+(showCodeDetails ? " with Details" : "")); try { generateByProfile(rc.resourceResource, profile, rc.resourceResource, profile.getSnapshot().getElement(), profile.getSnapshot().getElement().get(0), getChildrenForPath(profile.getSnapshot().getElement(), rc.resourceResource.getResourceType().toString()), x, rc.resourceResource.getResourceType().toString(), showCodeDetails, rc); } catch (Exception e) { e.printStackTrace(); x.para().b().setAttribute("style", "color: maroon").tx("Exception generating Narrative: "+e.getMessage()); } inject(rc.resourceResource, x, NarrativeStatus.GENERATED); return true; }
Example #11
Source File: ValueSetRenderer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void expRef(XhtmlNode x, String u, String v) { // TODO Auto-generated method stub if (u.equals("http://snomed.info/sct")) { String[] parts = v.split("\\/"); if (parts.length >= 5) { String m = describeModule(parts[4]); if (parts.length == 7) { x.tx("SNOMED CT "+m+" edition "+formatSCTDate(parts[6])); } else { x.tx("SNOMED CT "+m+" edition"); } } else { x.tx(describeSystem(u)+" version "+v); } } else if (u.equals("http://loinc.org")) { String vd = describeLoincVer(v); if (vd != null) { x.tx("Loinc v"+v+" ("+vd+")"); } else { x.tx("Loinc v"+v); } } else { CanonicalResource cr = (CanonicalResource) getContext().getWorker().fetchResource(Resource.class, u+"|"+v); if (cr != null) { if (cr.hasUserData("path")) { x.ah(cr.getUserString("path")).tx(cr.present()+" v"+v+" ("+cr.fhirType()+")"); } else { x.tx(describeSystem(u)+" v"+v+" ("+cr.fhirType()+")"); } } else { x.tx(describeSystem(u)+" version "+v); } } }
Example #12
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #13
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) { XhtmlNode tr = t.tr(); tr.td().addText(c.getCode()); for (String lang : langs) { ConceptDefinitionDesignationComponent d = null; for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) { if (lang.equals(designation.getLanguage())) d = designation; } tr.td().addText(d == null ? "" : d.getValue()); } }
Example #14
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public XhtmlNode getNarrative() { if (wrapped instanceof DomainResource) { DomainResource dr = (DomainResource) wrapped; if (dr.hasText() && dr.getText().hasDiv()) return dr.getText().getDiv(); } return null; }
Example #15
Source File: CodeSystemRenderer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) { XhtmlNode tr = t.tr(); tr.td().addText(c.getCode()); for (String lang : langs) { ConceptDefinitionDesignationComponent d = null; for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) { if (designation.hasLanguage()) { if (lang.equals(designation.getLanguage())) d = designation; } } tr.td().addText(d == null ? "" : d.getValue()); } }
Example #16
Source File: ConceptMapRenderer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public void renderCSDetailsLink(XhtmlNode tr, String url, boolean span2) { CodeSystem cs; XhtmlNode td; cs = getContext().getWorker().fetchCodeSystem(url); td = tr.td(); if (span2) { td.colspan("2"); } td.b().tx("Code"); td.tx(" from "); if (cs == null) td.tx(url); else td.ah(context.fixReference(cs.getUserString("path"))).attribute("title", url).tx(cs.present()); }
Example #17
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public XhtmlNode getNarrative() throws IOException, FHIRException { org.hl7.fhir.r4.elementmodel.Element txt = wrapped.getNamedChild("text"); if (txt == null) return null; org.hl7.fhir.r4.elementmodel.Element div = txt.getNamedChild("div"); if (div == null) return null; else return div.getXhtml(); }
Example #18
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addTelecom(XhtmlNode p, ContactPoint c) { if (c.getSystem() == ContactPointSystem.PHONE) { p.tx("Phone: "+c.getValue()); } else if (c.getSystem() == ContactPointSystem.FAX) { p.tx("Fax: "+c.getValue()); } else if (c.getSystem() == ContactPointSystem.EMAIL) { p.ah( "mailto:"+c.getValue()).addText(c.getValue()); } else if (c.getSystem() == ContactPointSystem.URL) { if (c.getValue().length() > 30) p.ah(c.getValue()).addText(c.getValue().substring(0, 30)+"..."); else p.ah(c.getValue()).addText(c.getValue()); } }
Example #19
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addLanguageRow(ConceptDefinitionComponent c, XhtmlNode t, List<String> langs) { XhtmlNode tr = t.addTag("tr"); tr.addTag("td").addText(c.getCode()); for (String lang : langs) { ConceptDefinitionDesignationComponent d = null; for (ConceptDefinitionDesignationComponent designation : c.getDesignation()) { if (lang.equals(designation.getLanguage())) d = designation; } tr.addTag("td").addText(d == null ? "" : d.getValue()); } }
Example #20
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void renderRange(Range q, XhtmlNode x) { if (q.hasLow()) x.addText(q.getLow().getValue().toString()); else x.tx("?"); x.tx("-"); if (q.hasHigh()) x.addText(q.getHigh().getValue().toString()); else x.tx("?"); if (q.getLow().hasUnit()) x.tx(" "+q.getLow().getUnit()); }
Example #21
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException { if (!textAlready) { XhtmlNode div = res.getNarrative(); if (div != null) { if (div.allChildrenAreText()) x.getChildNodes().addAll(div.getChildNodes()); if (div.getChildNodes().size() == 1 && div.getChildNodes().get(0).allChildrenAreText()) x.getChildNodes().addAll(div.getChildNodes().get(0).getChildNodes()); } x.addText("Generated Summary: "); } String path = res.getName(); StructureDefinition profile = context.fetchResource(StructureDefinition.class, path); if (profile == null) x.addText("unknown resource " +path); else { boolean firstElement = true; boolean last = false; for (PropertyWrapper p : res.children()) { ElementDefinition child = getElementDefinition(profile.getSnapshot().getElement(), path+"."+p.getName(), p); if (p.getValues().size() > 0 && p.getValues().get(0) != null && child != null && isPrimitive(child) && includeInSummary(child)) { if (firstElement) firstElement = false; else if (last) x.addText("; "); boolean first = true; last = false; for (BaseWrapper v : p.getValues()) { if (first) first = false; else if (last) x.addText(", "); last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails) || last; } } } } }
Example #22
Source File: XmlParserBase.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
protected XhtmlNode parseXhtml(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError { XhtmlParser prsr = new XhtmlParser(); try { return prsr.parseHtmlNode(xpp); } catch (org.hl7.fhir.exceptions.FHIRFormatError e) { throw new FHIRFormatError(e.getMessage(), e); } }
Example #23
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void renderResponse(XhtmlNode root, BundleEntryResponseComponent response) { root.para().addText("Request:"); StringBuilder b = new StringBuilder(); b.append(response.getStatus()+"\r\n"); if (response.hasLocation()) b.append("Location: "+response.getLocation()+"\r\n"); if (response.hasEtag()) b.append("E-Tag: "+response.getEtag()+"\r\n"); if (response.hasLastModified()) b.append("LastModified: "+response.getEtag()+"\r\n"); root.pre().addText(b.toString()); }
Example #24
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 #25
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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.tx(" "+q.getUnit()); else if (q.hasCode()) x.tx(" "+q.getCode()); if (showCodeDetails && q.hasCode()) { x.span("background: LightGoldenRodYellow", null).tx(" (Details: "+describeSystem(q.getSystem())+" code "+q.getCode()+" = '"+lookupCode(q.getSystem(), q.getCode())+"')"); } }
Example #26
Source File: XhtmlNodeTest.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Test public void testParseXhtmlQualified() { XhtmlNode node = new XhtmlNode(); node.setValueAsString("<xhtml:div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">" + "<xhtml:img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>" + "@fhirabend" + "</xhtml:div>"); String output = node.getValueAsString(); ourLog.info(output); Assertions.assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\"><img src=\"http://pbs.twimg.com/profile_images/544507893991485440/r_vo3uj2_bigger.png\" alt=\"Twitter Avatar\"/>@fhirabend</div>", output); }
Example #27
Source File: Base.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static boolean compareDeep(XhtmlNode div1, XhtmlNode div2, boolean allowNull) { if (div1 == null && div2 == null && allowNull) return true; if (div1 == null || div2 == null) return false; return div1.equalsDeep(div2); }
Example #28
Source File: SpecDifferenceEvaluator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void markChanged(String name, String change, boolean item) { XhtmlNode tr = tbl.addTag("tr").setAttribute("class", item ? "diff-item" : "diff-entry"); 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); right.ul().li().addText(change); }
Example #29
Source File: Narrative.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
/** * @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 #30
Source File: NarrativeGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void addLanguageRow(ConceptReferenceComponent c, XhtmlNode t, List<String> langs) { XhtmlNode tr = t.tr(); tr.td().addText(c.getCode()); for (String lang : langs) { String d = null; for (ConceptReferenceDesignationComponent cd : c.getDesignation()) { String l = cd.getLanguage(); if (lang.equals(l)) d = cd.getValue(); } tr.td().addText(d == null ? "" : d); } }