Merge pull request #1026 from hapifhir/gg-202212-xhtml

Gg 202212 xhtml
This commit is contained in:
Grahame Grieve 2022-12-05 17:48:09 +11:00 committed by GitHub
commit 943ffdbf79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 213 additions and 47 deletions

View File

@ -151,4 +151,10 @@ public class R2016MayToR5Loader extends BaseLoaderR5 {
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -122,9 +122,6 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
r2 = new XmlParser().parse(stream);
org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2, advisor);
setPath(r5);
if (!advisor.getCslist().isEmpty()) {
throw new FHIRException("Error: Cannot have included code systems");
}
if (killPrimitives) {
throw new FHIRException("Cannot kill primitives when using deferred loading");
}
@ -152,4 +149,15 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
List<CodeSystem> list = new ArrayList<>();
if (!advisor.getCslist().isEmpty()) {
list.addAll(advisor.getCslist());
advisor.getCslist().clear();
}
return list;
}
}

View File

@ -153,4 +153,10 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -160,4 +160,11 @@ public class R4BToR5Loader extends BaseLoaderR5 implements IContextResourceLoade
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -160,4 +160,11 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -151,4 +151,11 @@ public class R5ToR5Loader extends BaseLoaderR5 {
}
}
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -27,6 +27,10 @@ import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.r5.model.Enumeration;
import org.hl7.fhir.r5.model.Enumerations.FHIRVersionEnumFactory;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.json.model.JsonArray;
@ -99,9 +103,10 @@ public class NpmPackageVersionConverter {
Map<String, byte[]> output = new HashMap<>();
output.put("package/package.json", convertPackage(content.get("package/package.json")));
output.put("package/other/spec.internals", convertSpec(content.get("package/other/spec.internals")));
for (Entry<String, byte[]> e : content.entrySet()) {
if (!e.getKey().equals("package/package.json")) {
if (!e.getKey().equals("package/package.json") && !e.getKey().equals("package/other/spec.internals")) {
byte[] cnv = e.getValue();
try {
JsonObject json = JsonParser.parseObject(e.getValue());
@ -189,10 +194,17 @@ public class NpmPackageVersionConverter {
return JsonParser.composeBytes(json);
}
private byte[] convertSpec(byte[] cnt) throws IOException {
JsonObject json = JsonParser.parseObject(cnt);
json.set("ig-version", version);
return JsonParser.composeBytes(json, true);
}
private byte[] convertResource(String n, byte[] cnt) {
try {
if (VersionUtilities.isR2Ver(currentVersion)) {
org.hl7.fhir.dstu2.model.Resource res = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt);
convertResourceR2(res);
if (VersionUtilities.isR2Ver(version)) {
return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(res);
} else if (VersionUtilities.isR2BVer(version)) {
@ -206,6 +218,7 @@ public class NpmPackageVersionConverter {
}
} else if (VersionUtilities.isR2BVer(currentVersion)) {
org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt);
convertResourceR2B(res);
if (VersionUtilities.isR2Ver(version)) {
return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(VersionConvertorFactory_10_30.convertResource(VersionConvertorFactory_14_30.convertResource(res)));
} else if (VersionUtilities.isR2BVer(version)) {
@ -219,6 +232,7 @@ public class NpmPackageVersionConverter {
}
} else if (VersionUtilities.isR3Ver(currentVersion)) {
org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt);
convertResourceR3(res);
if (VersionUtilities.isR2Ver(version)) {
return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(VersionConvertorFactory_10_30.convertResource(res));
} else if (VersionUtilities.isR2BVer(version)) {
@ -232,6 +246,7 @@ public class NpmPackageVersionConverter {
}
} else if (VersionUtilities.isR4Ver(currentVersion)) {
org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt);
convertResourceR4(res);
if (VersionUtilities.isR2Ver(version)) {
return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(VersionConvertorFactory_10_40.convertResource(res, new PR2Handler()));
} else if (VersionUtilities.isR2BVer(version)) {
@ -245,6 +260,7 @@ public class NpmPackageVersionConverter {
}
} else if (VersionUtilities.isR5Ver(currentVersion)) {
org.hl7.fhir.r5.model.Resource res = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt);
convertResourceR5(res);
if (VersionUtilities.isR2Ver(version)) {
return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(VersionConvertorFactory_10_50.convertResource(res));
} else if (VersionUtilities.isR2BVer(version)) {
@ -265,4 +281,41 @@ public class NpmPackageVersionConverter {
}
}
private void convertResourceR2(org.hl7.fhir.dstu2.model.Resource res) {
if (res instanceof org.hl7.fhir.dstu2.model.ImplementationGuide) {
org.hl7.fhir.dstu2.model.ImplementationGuide ig = (org.hl7.fhir.dstu2.model.ImplementationGuide) res;
ig.setFhirVersion(version);
}
}
private void convertResourceR2B(org.hl7.fhir.dstu2016may.model.Resource res) {
if (res instanceof org.hl7.fhir.dstu2016may.model.ImplementationGuide) {
org.hl7.fhir.dstu2016may.model.ImplementationGuide ig = (org.hl7.fhir.dstu2016may.model.ImplementationGuide) res;
ig.setFhirVersion(version);
}
}
private void convertResourceR3(org.hl7.fhir.dstu3.model.Resource res) {
if (res instanceof org.hl7.fhir.dstu3.model.ImplementationGuide) {
org.hl7.fhir.dstu3.model.ImplementationGuide ig = (org.hl7.fhir.dstu3.model.ImplementationGuide) res;
ig.setFhirVersion(version);
}
}
private void convertResourceR4(org.hl7.fhir.r4.model.Resource res) {
if (res instanceof org.hl7.fhir.r4.model.ImplementationGuide) {
org.hl7.fhir.r4.model.ImplementationGuide ig = (org.hl7.fhir.r4.model.ImplementationGuide) res;
ig.getFhirVersion().clear();
ig.getFhirVersion().add(new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Enumerations.FHIRVersionEnumFactory(), version));
}
}
private void convertResourceR5(Resource res) {
if (res instanceof ImplementationGuide) {
ImplementationGuide ig = (ImplementationGuide) res;
ig.getFhirVersion().clear();
ig.getFhirVersion().add(new Enumeration<>(new FHIRVersionEnumFactory(), version));
}
}
}

View File

@ -4497,7 +4497,7 @@ public class ProfileUtilities extends TranslatingUtilities {
Piece p = gc.addText(ProfileUtilities.CONSTRAINT_CHAR);
p.setHint(translate("sd.table", "This element has or is affected by constraints ("+listConstraintsAndConditions(element)+")"));
p.addStyle(CONSTRAINT_STYLE);
p.setReference(VersionUtilities.getSpecUrl(context.getVersion())+"conformance-rules.html#constraints");
p.setReference(Utilities.pathURL(VersionUtilities.getSpecUrl(context.getVersion()), "conformance-rules.html#constraints"));
}
if (element != null && element.hasExtension(ToolingExtensions.EXT_STANDARDS_STATUS)) {
StandardsStatus ss = StandardsStatus.fromCode(element.getExtensionString(ToolingExtensions.EXT_STANDARDS_STATUS));

View File

@ -310,7 +310,14 @@ public interface IWorkerContext {
* @throws IOException
* @throws JsonSyntaxException
*/
IContextResourceLoader getNewLoader(NpmPackage npm) throws JsonSyntaxException, IOException;
IContextResourceLoader getNewLoader(NpmPackage npm) throws JsonSyntaxException, IOException;
/**
* called when processing R2 for implicit code systems in ValueSets
*
* @return
*/
List<CodeSystem> getCodeSystems();
}
/**

View File

@ -11547,6 +11547,10 @@ The primary difference between a medicationusage and a medicationadministration
return FHIRTypes.VISIONPRESCRIPTION;
if ("Parameters".equals(codeString))
return FHIRTypes.PARAMETERS;
if ("Any".equals(codeString))
return FHIRTypes.RESOURCE;
if ("CapabilityStatement2".equals(codeString))
return FHIRTypes.CAPABILITYSTATEMENT;
throw new IllegalArgumentException("Unknown FHIRTypes code '"+codeString+"'");
}
public Enumeration<FHIRTypes> fromType(Base code) throws FHIRException {

View File

@ -1574,7 +1574,7 @@ public class DataRenderer extends Renderer {
if (rep.hasOffset()) {
st = Integer.toString(rep.getOffset())+"min ";
}
b.append("Do "+st);
b.append(st);
for (Enumeration<EventTiming> wh : rep.getWhen())
b.append(displayEventCode(wh.getValue()));
} else {
@ -1592,7 +1592,7 @@ public class DataRenderer extends Renderer {
st = st + "-"+rep.getPeriodMax().toPlainString();
st = st + " "+displayTimeUnits(rep.getPeriodUnit());
}
b.append("Do "+st);
b.append(st);
}
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasEnd())
b.append("Until "+displayDateTime(rep.getBoundsPeriod().getEndElement()));

View File

@ -2,12 +2,15 @@ package org.hl7.fhir.r5.test.utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.Bundle;
import org.hl7.fhir.r5.model.CodeSystem;
import org.hl7.fhir.r5.model.Resource;
import org.hl7.fhir.utilities.npm.NpmPackage;
@ -43,4 +46,10 @@ public class TestPackageLoader implements IContextResourceLoader {
public IContextResourceLoader getNewLoader(NpmPackage npm) {
return this;
}
@Override
public List<CodeSystem> getCodeSystems() {
return new ArrayList<>();
}
}

View File

@ -477,6 +477,9 @@ public class Utilities {
}
public static String appendForwardSlash(String definitions) {
if (definitions == null) {
return "/";
}
return definitions.endsWith("/") ? definitions : definitions + "/";
}

View File

@ -75,10 +75,11 @@ public class PackageClient {
}
public List<PackageInfo> getVersions(String id) throws IOException {
String url = Utilities.pathURL(address, id);
List<PackageInfo> res = new ArrayList<>();
JsonObject json;
try {
json = fetchJson(Utilities.pathURL(address, id));
json = fetchJson(url);
JsonObject versions = json.getJsonObject("versions");
boolean hasDates = true;
if (versions != null) {
@ -103,6 +104,7 @@ public class PackageClient {
Collections.sort(res, new PackageInfo.PackageInfoSorter(false));
}
} catch (Exception e) {
System.out.println("Error fetching "+url+": "+e.getMessage());
}
return res;
}

View File

@ -90,40 +90,42 @@ public class XhtmlComposer {
private void composeDoc(XhtmlDocument doc) throws IOException {
// headers....
// dst.append("<html>" + (pretty ? "\r\n" : ""));
for (XhtmlNode c : doc.getChildNodes())
for (XhtmlNode c : doc.getChildNodes()) {
writeNode(" ", c, false);
}
// dst.append("</html>" + (pretty ? "\r\n" : ""));
}
private void writeNode(String indent, XhtmlNode node, boolean noPrettyOverride) throws IOException {
if (node.getNodeType() == NodeType.Comment)
if (node.getNodeType() == NodeType.Comment) {
writeComment(indent, node, noPrettyOverride);
else if (node.getNodeType() == NodeType.DocType)
} else if (node.getNodeType() == NodeType.DocType) {
writeDocType(node);
else if (node.getNodeType() == NodeType.Instruction)
} else if (node.getNodeType() == NodeType.Instruction) {
writeInstruction(node);
else if (node.getNodeType() == NodeType.Element)
} else if (node.getNodeType() == NodeType.Element) {
writeElement(indent, node, noPrettyOverride);
else if (node.getNodeType() == NodeType.Document)
} else if (node.getNodeType() == NodeType.Document) {
writeDocument(indent, node);
else if (node.getNodeType() == NodeType.Text)
} else if (node.getNodeType() == NodeType.Text) {
writeText(node);
else if (node.getNodeType() == null)
} else if (node.getNodeType() == null) {
throw new IOException("Null node type");
else
} else {
throw new IOException("Unknown node type: "+node.getNodeType().toString());
}
}
private void writeText(XhtmlNode node) throws IOException {
for (char c : node.getContent().toCharArray())
{
if (c == '&')
if (c == '&') {
dst.append("&amp;");
else if (c == '<')
} else if (c == '<') {
dst.append("&lt;");
else if (c == '>')
} else if (c == '>') {
dst.append("&gt;");
else if (xml) {
} else if (xml) {
if (c == '"')
dst.append("&quot;");
else
@ -189,26 +191,34 @@ public class XhtmlComposer {
indent = "";
// html self closing tags: http://xahlee.info/js/html5_non-closing_tag.html
if (node.getChildNodes().size() == 0 && (xml || Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr")))
boolean concise = node.getChildNodes().size() == 0;
if (node.hasEmptyExpanded() && node.getEmptyExpanded()) {
concise = false;
}
if (!xml && Utilities.existsInList(node.getName(), "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr")) {
concise = true;
}
if (concise)
dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else {
boolean act = node.allChildrenAreText();
if (act || !pretty || noPrettyOverride)
dst.append(indent + "<" + node.getName() + attributes(node)+">");
else
dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n");
if (node.getName() == "head" && node.getElement("meta") == null)
dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (pretty && !noPrettyOverride ? "\r\n" : ""));
boolean act = node.allChildrenAreText();
if (act || !pretty || noPrettyOverride)
dst.append(indent + "<" + node.getName() + attributes(node)+">");
else
dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n");
if (node.getName() == "head" && node.getElement("meta") == null)
dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (pretty && !noPrettyOverride ? "\r\n" : ""));
for (XhtmlNode c : node.getChildNodes())
writeNode(indent + " ", c, noPrettyOverride || node.isNoPretty());
if (act)
dst.append("</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text)
dst.append((pretty && !noPrettyOverride ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else
dst.append(indent + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
for (XhtmlNode c : node.getChildNodes())
writeNode(indent + " ", c, noPrettyOverride || node.isNoPretty());
if (act)
dst.append("</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text)
dst.append((pretty && !noPrettyOverride ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
else
dst.append(indent + "</" + node.getName() + ">" + (pretty && !noPrettyOverride ? "\r\n" : ""));
}
}

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.utilities.xhtml;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
/*
Copyright (c) 2011+, HL7, Inc.
All rights reserved.
@ -38,21 +40,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.instance.model.api.IBaseXhtml;
import org.hl7.fhir.utilities.MarkDownProcessor;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.MarkDownProcessor.Dialect;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.Utilities;
import ca.uhn.fhir.model.api.annotation.ChildOrder;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@ca.uhn.fhir.model.api.annotation.DatatypeDef(name="xhtml")
public class XhtmlNode implements IBaseXhtml {
private static final long serialVersionUID = -4362547161441436492L;
@ -93,6 +89,7 @@ public class XhtmlNode implements IBaseXhtml {
private boolean inPara;
private boolean inLink;
private boolean seperated;
private Boolean emptyExpanded;
public XhtmlNode() {
super();
@ -416,6 +413,19 @@ public class XhtmlNode implements IBaseXhtml {
}
public Boolean getEmptyExpanded() {
return emptyExpanded;
}
public boolean hasEmptyExpanded() {
return emptyExpanded != null;
}
public void setEmptyExpanded(Boolean emptyExpanded) {
this.emptyExpanded = emptyExpanded;
}
@Override
public String getValueAsString() {
if (isEmpty()) {

View File

@ -506,10 +506,12 @@ public class XhtmlParser {
if (peekChar() != '>')
throw new FHIRFormatError("unexpected non-end of element "+n+" "+descLoc());
readChar();
root.setEmptyExpanded(false);
} else {
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(root, p, nsm, true);
root.setEmptyExpanded(true);
}
return result;
}
@ -671,7 +673,9 @@ public class XhtmlParser {
if (peekChar() != '>')
throw new FHIRFormatError("unexpected non-end of element "+name+" "+descLoc());
readChar();
node.setEmptyExpanded(false);
} else {
node.setEmptyExpanded(true);
parseElementInner(node, newParents, namespaceMap, "script".equals(name.getName()));
}
}

View File

@ -6,6 +6,8 @@ import java.io.ObjectOutputStream;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
import org.junit.jupiter.api.Assertions;
@ -137,4 +139,25 @@ public class XhtmlNodeTest {
Assertions.assertEquals("http://www.w3.org/1999/xlink", x.getChildNodes().get(0).getChildNodes().get(1).getAttributes().get("xmlns:xlink"));
}
@Test
public void testParseSvgElements() throws FHIRFormatError, IOException {
String src = BaseTestingUtilities.loadTestResource("xhtml", "xhtml-empty-elements.xml");
XhtmlNode x = new XhtmlParser().parse(src, "xml");
String xml = new XhtmlComposer(false, false).compose(x);
Assertions.assertEquals(src.trim(), xml.trim());
}
@Test
public void testParseSvgF() throws FHIRFormatError, IOException {
String src = TextFile.fileToString("/Users/grahamegrieve/work/r5/source/fhir-exchanges.svg.html");
XhtmlNode x = new XhtmlParser().parse(src, "svg");
String xml = new XhtmlComposer(false, true).compose(x);
TextFile.stringToFile(xml, "/Users/grahamegrieve/work/r5/source/fhir-exchanges.svg.html");
}
}

View File

@ -260,7 +260,7 @@ public class QuestionnaireValidator extends BaseValidator {
if (questionnaireMode == QuestionnaireMode.REQUIRED) {
qok = rule(errors, NO_RULE_DATE, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);
ok = qok && ok;
} else if (questionnaire.startsWith("http://example.org")) {
} else if (questionnaire.startsWith("http://example.org") || questionnaire.startsWith("https://example.org")) {
qok = hint(errors, NO_RULE_DATE, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);
} else {
qok = warning(errors, NO_RULE_DATE, IssueType.REQUIRED, q.line(), q.col(), stack.getLiteralPath(), qsrc != null, I18nConstants.QUESTIONNAIRE_QR_Q_NOTFOUND, questionnaire);

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>5.4.0</hapi_fhir_version>
<validator_test_case_version>1.1.128</validator_test_case_version>
<validator_test_case_version>1.1.129-SNAPSHOT</validator_test_case_version>
<junit_jupiter_version>5.7.1</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version>