Skip to content

Commit

Permalink
update kindling to new rendering framework, and fix many bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Aug 4, 2024
1 parent b88bc8b commit 484374d
Show file tree
Hide file tree
Showing 31 changed files with 1,294 additions and 1,367 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "org.hl7.fhir"
version = "1.9.2-SNAPSHOT"
version = "1.9.3-SNAPSHOT"

java {
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fhirCoreVersion = 6.3.2
fhirCoreVersion = 6.3.19
apachePoiVersion = 5.2.1
jacksonVersion = 2.16.0
apacheHttpcomponentsVersion = 4.5.13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.hl7.fhir.definitions.model.ElementDefn;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
import org.hl7.fhir.tools.publisher.PageProcessor;
import org.hl7.fhir.utilities.i18n.RenderingI18nContext;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableGenerationMode;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel;
Expand All @@ -16,7 +17,7 @@ public DataTypeTableGenerator(String dest, PageProcessor page, String pageName,
}

public XhtmlNode generate(ElementDefn e, Set<String> outputTracker, boolean isActive) throws Exception {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(dest, inlineGraphics, false);
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), dest, inlineGraphics, false);
TableModel model = gen.initNormalTable("", false, true, e.getName(), isActive, isActive ? TableGenerationMode.XHTML : TableGenerationMode.XML);

model.getRows().add(genElement(e, gen, false, e.getName(), false, "", RenderMode.DATATYPE, true, e.getStandardsStatus(), null, e.isAbstractType(), false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.conformance.profile.ProfileKnowledgeProvider;
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
import org.hl7.fhir.r5.context.ContextUtilities;
import org.hl7.fhir.r5.formats.FormatUtilities;
import org.hl7.fhir.r5.model.BooleanType;
import org.hl7.fhir.r5.model.Bundle;
Expand Down Expand Up @@ -138,6 +139,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.r5.renderers.OperationDefinitionRenderer;
import org.hl7.fhir.r5.renderers.utils.RenderingContext;
import org.hl7.fhir.r5.renderers.utils.ResourceWrapper;
import org.hl7.fhir.r5.utils.BuildExtensions;
import org.hl7.fhir.r5.utils.CanonicalResourceUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions;
Expand Down Expand Up @@ -2601,7 +2603,7 @@ else if (op.getKind().toLowerCase().equals("query"))
produceOpParam(op.getName(), opd.getParameter(), p, null);
}
OperationDefinitionRenderer opr = new OperationDefinitionRenderer(rc);
opr.render(opd);
opr.renderResource(ResourceWrapper.forResource(new ContextUtilities(context), opd));
return opd;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hl7.fhir.tools.publisher.PageProcessor;
import org.hl7.fhir.utilities.StandardsStatus;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.i18n.RenderingI18nContext;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row;
Expand Down Expand Up @@ -49,7 +50,7 @@ public ResourceDependencyGenerator(String dest, PageProcessor page, String pageN
}

public XhtmlNode generate(ElementDefn e, String prefix) throws Exception {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(dest, inlineGraphics, true);
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), dest, inlineGraphics, true);
RenderMode mode = RenderMode.RESOURCE;
TableModel model = initTable(gen, prefix, mode == RenderMode.LOGICAL, e.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.hl7.fhir.definitions.model.ResourceDefn;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
import org.hl7.fhir.tools.publisher.PageProcessor;
import org.hl7.fhir.utilities.i18n.RenderingI18nContext;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableGenerationMode;
import org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel;
Expand All @@ -16,7 +17,7 @@ public ResourceTableGenerator(String dest, PageProcessor page, String pageName,
}

public XhtmlNode generate(ResourceDefn r, String prefix, boolean isActive) throws Exception {
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(dest, inlineGraphics, true);
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(new RenderingI18nContext(), dest, inlineGraphics, true);
ElementDefn e = r.getRoot();
RenderMode mode = e.typeCode().equals("Logical") && hasLogicalMapping(e) ? RenderMode.LOGICAL : RenderMode.RESOURCE;
TableModel model = gen.initNormalTable(prefix, mode == RenderMode.LOGICAL, true, r.getName(), isActive, isActive ? TableGenerationMode.XHTML : TableGenerationMode.XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ private void process(String name, String path, Element resource) {
}

private void walkChildren(String name, String path, Element element) {
for (Element ex : element.getChildren("extension")) {
see(name, path, ex.getNamedChildValue("url"));
}
for (Element ex : element.getChildren("modifierExtension")) {
see(name, path, ex.getNamedChildValue("url"));
}
for (Element c : element.getChildren()) {
if (c.isResource()) {
process(name, path, c);
} else if (!c.isPrimitive()) {
walkChildren(name, path, c);
if (element.hasChildren()) {
for (Element ex : element.getChildren("extension")) {
see(name, path, ex.getNamedChildValue("url"));
}
for (Element ex : element.getChildren("modifierExtension")) {
see(name, path, ex.getNamedChildValue("url"));
}
for (Element c : element.getChildren()) {
if (c.isResource()) {
process(name, path, c);
} else if (!c.isPrimitive()) {
walkChildren(name, path, c);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.definitions.model.TypeRef;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.tools.publisher.BuildWorkerContext;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.CSFile;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.definitions.model.Definitions;
import org.hl7.fhir.definitions.model.ResourceDefn;
import org.hl7.fhir.tools.publisher.BuildWorkerContext;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.CSFile;

public class SchemaGenerator {

Expand Down
100 changes: 60 additions & 40 deletions src/main/java/org/hl7/fhir/definitions/model/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -39,14 +42,17 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.tools.publisher.PageProcessor;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.CSFileInputStream;
import org.hl7.fhir.utilities.CSVProcessor;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.filesystem.CSFile;
import org.hl7.fhir.utilities.filesystem.CSFileInputStream;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.xml.XMLUtil;
import org.w3c.dom.Document;
Expand All @@ -62,14 +68,16 @@ public class Example {
private String xhtm;
private ExampleType type;
private boolean registered;
private Document xml;
private String resourceName;
private Set<Example> inbounds = new HashSet<Example>();
private String ig;
private String exampleFor;
private Element element;
private List<ValidationMessage> errors = new ArrayList<>();
private Resource resource;
private IWorkerContext context;
private File path;
private boolean noId;


public enum ExampleType {
Expand All @@ -80,35 +88,42 @@ public enum ExampleType {
}


public Example(String name, String id, String title, String description, boolean registered, ExampleType type, Document doc) throws Exception {
public Example(String name, String id, String title, String description, boolean registered, ExampleType type, Element element) throws Exception {
this.name = name;
this.id = id;
this.description = description;
this.type = type;
this.registered = registered;
this.title = title;
this.element = element;

xml = doc;
resourceName = xml.getDocumentElement().getNodeName();
if (XMLUtil.getNamedChild(xml.getDocumentElement(), "id") == null)
resourceName = element.fhirType();
String xid = element.getIdBase();
if (xid == null)
throw new Exception("no id element (looking for '"+id+"' from example "+id);
String xid = XMLUtil.getNamedChild(xml.getDocumentElement(), "id").getAttribute("value");
if (!id.equals(xid)) {
throw new Exception("misidentified resource example "+id+" expected '"+id+"' found '"+xid+"'");
}
}


public Example(String name, String id, String description, File path, boolean registered, ExampleType type, boolean noId) throws Exception {
public Example(IWorkerContext context, String name, String id, String description, File path, boolean registered, ExampleType type, boolean noId) throws Exception {
super();
this.name = name;
this.id = id;
this.description = description;
// this.path = path;
this.path = path;
this.type = type;
this.registered = registered;
this.title = getFileTitle(path);
this.context = context;
this.noId = noId;

}


private void loadExample()
throws FileNotFoundException, IOException, UnsupportedEncodingException, Exception {
if( type == ExampleType.CsvFile ) {
CSVProcessor csv = new CSVProcessor();
csv.setSource(new CSFileInputStream(path));
Expand All @@ -120,23 +135,20 @@ public Example(String name, String id, String description, File path, boolean re
}

if (type == ExampleType.XmlFile || type == ExampleType.CsvFile || type == ExampleType.Container) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
String xs = TextFile.fileToString(new CSFile(path.getAbsolutePath()));
xs = xs.replace("[%test-server%]", PageProcessor.TEST_SERVER_URL);
xml = builder.parse(new ByteArrayInputStream(xs.getBytes(Charsets.UTF_8)));
resourceName = xml.getDocumentElement().getNodeName();
element = Manager.parseSingle(context, new ByteArrayInputStream(xs.getBytes(Charsets.UTF_8)), FhirFormat.XML);
resourceName = element.fhirType();
} catch (Exception e) {
throw new Exception("unable to read "+path.getAbsolutePath()+": "+e.getMessage(), e);
}
}
if (xml != null && !noId) {
if (element != null && !noId) {
if (!Utilities.noString(id)) {
if (XMLUtil.getNamedChild(xml.getDocumentElement(), "id") == null)
String xid = element.getIdBase();
if (xid == null)
throw new Exception("no id element (looking for '"+id+"' from "+path.getName());
String xid = XMLUtil.getNamedChild(xml.getDocumentElement(), "id").getAttribute("value");
if (!id.equals(xid)) {
throw new Exception("misidentified resource "+path+" expected '"+id+"' found '"+xid+"'");
}
Expand Down Expand Up @@ -191,9 +203,6 @@ public String getTitle() {
return title;
}

public Document getXml() {
return xml;
}

public boolean isRegistered() {
return registered;
Expand Down Expand Up @@ -237,7 +246,11 @@ public String getExampleFor() {
}


public Element getElement() {
public Element getElement() throws FileNotFoundException, UnsupportedEncodingException, IOException, Exception {
if (element == null) {
loadExample();
}

return element;
}

Expand All @@ -247,40 +260,42 @@ public void setElement(Element element) {
}


public boolean hasXml() {
return xml != null;
}


public List<ValidationMessage> getErrors() {
return errors;
}


public boolean hasContained() {
if (xml == null) {
return false;
public boolean hasContained() throws FileNotFoundException, UnsupportedEncodingException, IOException, Exception {
if (element == null) {
loadExample();
}
Node n = xml.getDocumentElement().getFirstChild();
while (n != null && !"contained".equals(n.getNodeName())) {
n = n.getNextSibling();

if (element == null) {
return false;
}
return n != null;
return element.hasChildren("contained");
}


public String getURL() {
return xml != null ? XMLUtil.getNamedChildValue(xml.getDocumentElement(), "url") : null;
public String getURL() throws FileNotFoundException, UnsupportedEncodingException, IOException, Exception {
if (element == null) {
loadExample();
}

if (element == null) {
return null;
}
return element.getNamedChildValue("url");
}


public String getOID() {
if (xml == null) {
if (element == null) {
return null;
}
for (org.w3c.dom.Element id : XMLUtil.getNamedChildren(xml.getDocumentElement(), "identifier")) {
String system = XMLUtil.getNamedChildValue(id, "system");
String value = XMLUtil.getNamedChildValue(id, "value");
for (Element id : element.getChildren("identifier")) {
String system = id.getNamedChildValue("system");
String value = id.getNamedChildValue("value");
if ("urn:ietf:rfc:3986".equals(system) && value != null && value.startsWith("urn:oid:")) {
return value.substring(8);
}
Expand All @@ -304,4 +319,9 @@ public String present() {
}


public String fhirType() {
return resourceName;
}


}
Loading

0 comments on commit 484374d

Please sign in to comment.