other code

This commit is contained in:
Grahame Grieve 2023-12-06 17:57:35 +11:00
parent e697ec1c4c
commit 161e92d439
3 changed files with 158 additions and 9 deletions

View File

@ -0,0 +1,100 @@
package org.hl7.fhir.r4.ips;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.r4.ips.IPSRenderer.InternalTemplateEngine;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Composition;
import org.hl7.fhir.r4.model.Composition.SectionComponent;
import org.hl7.fhir.r4.model.DomainResource;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.terminologies.TerminologyClient;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class IPSRenderer {
public class InternalTemplateEngine implements ITemplateImplementer {
@Override
public String buildPage(Map<String, String> headers, String content) {
// TODO Auto-generated method stub
return null;
}
}
private interface ITemplateImplementer {
public String buildPage(Map<String, String> headers, String content);
}
private TerminologyClient tx;
private String folder; // for images etc
private Map<String, byte[]> binaries; // from the pubpack
private ITemplateImplementer templater;
private Map<String, String> headers;
public IPSRenderer(TerminologyClient tx, String folder, Map<String, byte[]> binaries, ITemplateImplementer templater) {
super();
this.tx = tx;
this.folder = folder;
this.binaries = binaries;
this.templater = templater;
}
public IPSRenderer(TerminologyClient tx, String folder, Map<String, byte[]> binaries) {
super();
this.tx = tx;
this.folder = folder;
this.binaries = binaries;
this.templater = new InternalTemplateEngine();
}
public String render(Bundle document) throws IOException {
headers = new HashMap<>();
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
generate(x, document);
return templater.buildPage(headers, new XhtmlComposer(false, true).compose(x));
}
private void generate(XhtmlNode x, Bundle document) {
Composition cmp = (Composition) document.getEntryFirstRep().getResource();
int sectionDepth = findSectionDepth(cmp.getSection());
XhtmlNode table = x.table("grid");
// row 1: header
XhtmlNode tr = table.tr();
XhtmlNode td = tr.td().colspan(1+sectionDepth);
td.b().tx("Provided");
td = tr.td().colspan(1+sectionDepth);
td.b().tx("Generated");
// row 2: Subject
DomainResource subject = findResource(document, cmp.getSubject());
tr = table.tr();
td = tr.td().colspan(1+sectionDepth);
// genNarrative("subject", subject, td);
td = tr.td().colspan(1+sectionDepth);
td.b().tx("Generated");
}
private DomainResource findResource(Bundle document, Reference subject) {
// TODO Auto-generated method stub
return null;
}
private int findSectionDepth(List<SectionComponent> list) {
int i = 1;
for (SectionComponent sect : list) {
i = Integer.max(i, 1+findSectionDepth(sect.getSection()));
}
return i;
}
}

View File

@ -701,8 +701,9 @@ public class RenderingContext {
public GenerationRules getRules() {
return rules;
}
public void setRules(GenerationRules rules) {
public RenderingContext setRules(GenerationRules rules) {
this.rules = rules;
return this;
}
public StandardsStatus getDefaultStandardsStatus() {
return defaultStandardsStatus;

View File

@ -63,6 +63,12 @@ public class CanonicalResourceUtilities {
}
}
/**
* for use in the core build where the context is not fully populated. Only known safe for R6 resources
*
* @param res
* @param code
*/
public static void setHl7WG(org.w3c.dom.Element res, String code) {
String rt = res.getNodeName();
if (VersionUtilities.getExtendedCanonicalResourceNames("5.0.0").contains(rt)) {
@ -82,15 +88,12 @@ public class CanonicalResourceUtilities {
if (wgext == null) {
wgext = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "extension");
wgext.setAttribute("url", ToolingExtensions.EXT_WORKGROUP);
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "modifierExtension", "url", "identifier", "version", "status", "name", "title");
if (after == null) {
after = XMLUtil.getLastChild(res, "id", "meta", "text", "implicitRules", "language", "text", "contained");
org.w3c.dom.Element after = XMLUtil.getLastChild(res, "id", "meta", "text", "implicitRules", "language", "text", "contained");
if (after != null) {
after = XMLUtil.getNextSibling(after);
}
}
res.insertBefore(wgext, after);
res.insertBefore(res.getOwnerDocument().createTextNode("/n "), after);
res.insertBefore(res.getOwnerDocument().createTextNode("\n "), after);
}
XMLUtil.clearChildren(wgext);
org.w3c.dom.Element valueCode = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "valueCode");
@ -100,10 +103,55 @@ public class CanonicalResourceUtilities {
org.w3c.dom.Element pub = XMLUtil.getNamedChild(res, "publisher");
if (pub == null) {
pub = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "publisher");
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "contact", "relatedArtifact", "description", "useContext", "jurisdiction", "purpose", "copyright");
org.w3c.dom.Element after = XMLUtil.getLastChild(res, "id", "meta", "text", "implicitRules", "language", "text", "contained", "extension", "modifierExtension",
"url", "identifier", "version", "versionAlgorithmString", "versionAlgorithmCoding", "name", "title", "status", "experimental", "date", ("EvidenceReport".equals(rt) ? "subject" : "xx"));
if (after != null) {
after = XMLUtil.getNextSibling(after);
}
res.insertBefore(pub, after);
res.insertBefore(res.getOwnerDocument().createTextNode("\n "), after);
}
pub.setAttribute("value", "HL7 International / "+wg.getName());
org.w3c.dom.Element contact = XMLUtil.getNamedChild(res, "contact");
if (contact == null) {
contact = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "contact");
res.insertBefore(contact, XMLUtil.getNextSibling(pub));
res.insertBefore(res.getOwnerDocument().createTextNode("\n "), contact.getNextSibling());
}
org.w3c.dom.Element telecom = XMLUtil.getNamedChild(contact, "telecom");
if (telecom == null) {
contact.appendChild(res.getOwnerDocument().createTextNode("\n "));
telecom = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "telecom");
contact.appendChild(telecom);
contact.appendChild(res.getOwnerDocument().createTextNode("\n "));
}
org.w3c.dom.Element system = XMLUtil.getNamedChild(telecom, "system");
if (system == null) {
system = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "system");
org.w3c.dom.Element after = XMLUtil.getLastChild(telecom, "id", "extension");
if (after != null) {
after = XMLUtil.getNextSibling(after);
}
telecom.insertBefore(system, after);
telecom.insertBefore(res.getOwnerDocument().createTextNode("\n "), after);
}
system.setAttribute("value", "url");
org.w3c.dom.Element value = XMLUtil.getNamedChild(telecom, "value");
if (value == null) {
value = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "value");
org.w3c.dom.Element after = XMLUtil.getLastChild(telecom, "id", "extension", "system");
if (after != null) {
after = XMLUtil.getNextSibling(after);
}
telecom.insertBefore(system, after);
telecom.insertBefore(res.getOwnerDocument().createTextNode("\n "), after);
}
value.setAttribute("value", wg.getLink());
}
}
}