This commit is contained in:
Grahame Grieve 2020-01-11 06:25:03 +11:00
commit 377aaed23c
10 changed files with 117 additions and 87 deletions

View File

@ -52,15 +52,13 @@ package org.hl7.fhir.r5.model;
*/
import org.hl7.fhir.instance.model.api.IBaseIntegerDatatype;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
/**
* Primitive type "integer" in FHIR: A signed 32-bit integer
* Primitive type "integer" in FHIR: A signed 64-bit integer
*/
@DatatypeDef(name = "integer")
public class Integer64Type extends PrimitiveType<Long> /* implements IBaseInteger64Datatype */ {
@DatatypeDef(name = "integer64")
public class Integer64Type extends PrimitiveType<Long> {
private static final long serialVersionUID = 3L;
@ -97,12 +95,8 @@ public class Integer64Type extends PrimitiveType<Long> /* implements IBaseIntege
* @throws IllegalArgumentException If the value is too large to fit in a signed integer
*/
public Integer64Type(Long theValue) {
if (theValue < java.lang.Long.MIN_VALUE || theValue > java.lang.Long.MAX_VALUE) {
throw new IllegalArgumentException
(theValue + " cannot be cast to int without changing its value.");
}
if(theValue!=null) {
setValue((long)theValue.longValue());
setValue(theValue);
}
}

View File

@ -209,7 +209,7 @@ public class Narrative extends BaseNarrative implements INarrative {
/**
* The actual narrative content, a stripped down version of XHTML.
*/
@Child(name = "div", type = {XhtmlType.class}, order=1, min=1, max=1, modifier=false, summary=false)
@Child(name = "div", type = {}, order=1, min=1, max=1, modifier=false, summary=false)
@Description(shortDefinition="Limited xhtml content", formalDefinition="The actual narrative content, a stripped down version of XHTML." )
protected XhtmlNode div;

View File

@ -37,9 +37,9 @@ package org.hl7.fhir.r5.model;
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -49,45 +49,48 @@ package org.hl7.fhir.r5.model;
*/
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import java.net.URI;
@DatatypeDef(name = "uuid", profileOf = UriType.class)
public class UuidType extends UriType {
private static final long serialVersionUID = 3L;
private static final long serialVersionUID = 3L;
/**
* Constructor
*/
public UuidType() {
super();
}
/**
* Constructor
*/
public UuidType() {
super();
}
/**
* Constructor
*/
public UuidType(String theValue) {
super(theValue);
}
/**
* Constructor
*/
public UuidType(String theValue) {
super(theValue);
}
/**
* Constructor
*/
public UuidType(URI theValue) {
super(theValue);
}
/**
* Constructor
*/
public UuidType(URI theValue) {
super(theValue);
}
/**
* Constructor
*/
@Override
public UuidType copy() {
UuidType ret = new UuidType(getValue());
copyValues(ret);
/**
* Constructor
*/
@Override
public UuidType copy() {
UuidType ret = new UuidType(getValue());
copyValues(ret);
return ret;
}
public String fhirType() {
return "uuid";
}
}
public String fhirType() {
return "uuid";
}
}

View File

@ -24,12 +24,14 @@ package org.hl7.fhir.r5.model;
import java.io.IOException;
import java.util.List;
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class XhtmlType extends Element {
private Narrative place;

View File

@ -1922,7 +1922,7 @@ public class StructureMapUtilities {
id = UUID.randomUUID().toString().toLowerCase();
b.setIdBase(id);
}
return new Reference().setReference(b.fhirType()+"/"+id);
return new StringType(b.fhirType()+"/"+id);
}
case DATEOP :
throw new Error("Rule \""+ruleId+"\": Transform "+tgt.getTransform().toCode()+" not supported yet");

View File

@ -1,16 +0,0 @@
<configuration scan="true" scanPeriod="30 seconds">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -394,13 +394,16 @@ public class XhtmlNode implements IBaseXhtml {
val = XhtmlDt.preprocessXhtmlNamespaceDeclaration(val);
try {
// TODO: this is ugly
XhtmlNode fragment = new XhtmlParser().parseFragment(val);
this.attributes = fragment.attributes;
this.childNodes = fragment.childNodes;
this.content = fragment.content;
this.name = fragment.name;
this.nodeType= fragment.nodeType;
XhtmlDocument fragment = new XhtmlParser().parse(val, "div");
this.attributes = fragment.getAttributes();
this.childNodes = fragment.getChildNodes();
// Strip the <? .. ?> declaration if one was present
if (childNodes.size() > 0 && childNodes.get(0) != null && childNodes.get(0).getNodeType() == NodeType.Instruction) {
childNodes.remove(0);
}
this.content = fragment.getContent();
this.name = fragment.getName();
this.nodeType= fragment.getNodeType();
} catch (Exception e) {
// TODO: composer shouldn't throw exception like this
throw new RuntimeException(e);

View File

@ -54,6 +54,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -446,7 +447,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
}
public XhtmlDocument parse(InputStream input, String entryName) throws FHIRFormatError, IOException {
rdr = new InputStreamReader(input, "UTF-8");
rdr = new InputStreamReader(input, StandardCharsets.UTF_8);
return parse(entryName);
}
@ -472,7 +473,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
readChar();
} else {
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(root, p, nsm, true);
}
return result;
@ -488,9 +489,6 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
// what we do here is strip out any stated namespace attributes, putting them in the namesapce map
// then we figure out what the namespace of this element is, and state it explicitly if it's not the default
// but we don't bother with any of this if we're not validating
if (!validatorMode)
return null;
NSMap result = new NSMap(nsm);
List<String> nsattrs = new ArrayList<String>();
for (String an : node.getAttributes().keySet()) {
@ -1176,7 +1174,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
String n = readName().toLowerCase();
readToTagEnd();
XhtmlNode result = new XhtmlNode(NodeType.Element);
int colonIndex = n.indexOf(':');
if (colonIndex != -1) {
n = n.substring(colonIndex + 1);
@ -1184,7 +1182,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
result.setName(n);
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<XhtmlNode>();
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(result, p, null, true);
return result;

View File

@ -1,13 +1,16 @@
package org.hl7.fhir.utilities.tests;
import org.junit.Test;
import static org.junit.Assert.*;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
public class XhtmlNodeTest {
private static final Logger ourLog = LoggerFactory.getLogger(XhtmlNodeTest.class);
/**
* See https://github.com/jamesagnew/hapi-fhir/issues/1488
*/
@ -26,5 +29,46 @@ public class XhtmlNodeTest {
}
/**
* See https://github.com/jamesagnew/hapi-fhir/issues/1658
*/
@Test
public void testLangAttributePreserved() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testParseRsquo() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("It&rsquo;s January again");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">Its January again</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@Test
public void testProcessingInstructionNotPreserved() {
XhtmlNode dt = new XhtmlNode();
dt.setValueAsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>");
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>", dt.getValueAsString());
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">help i'm a bug</div>", new XhtmlNode().setValue(dt.getValue()).getValueAsString());
}
@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);
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);
}
}

View File

@ -864,7 +864,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private void checkElementUsage(List<ValidationMessage> errors, Element element, NodeStack stack) {
String elementUsage = element.getUserString("elementSupported");
hint(errors, IssueType.INFORMATIONAL, element.line(),element.col(), stack.getLiteralPath(), elementUsage==null || elementUsage.equals("Y"),
String.format("The element %s is not marked as 'mustSupport' in the profile %s. Consider not using the element, or marking the element as must-Support in the profile", element.getName(), element.getProperty().getStructure().getUrl()));
"The element " + element.getName() + " is not marked as 'mustSupport' in the profile " + element.getProperty().getStructure().getUrl() + ". Consider not using the element, or marking the element as must-Support in the profile");
if (element.hasChildren()) {
String prevName = "";
@ -1496,14 +1496,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
} else if (binding.getStrength() == BindingStrength.PREFERRED)
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "Could not confirm that the codes provided are in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code is recommended to come from this value set)");
} else if (binding.getStrength() == BindingStrength.REQUIRED)
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code is required from this value set)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code is required from this value set)"+getErrorMessage(vr.getMessage()));
else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), c, stack);
else
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code should come from this value set unless it has no suitable code)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code should come from this value set unless it has no suitable code)"+getErrorMessage(vr.getMessage()));
} else if (binding.getStrength() == BindingStrength.PREFERRED)
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code is recommended to come from this value set)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The Coding provided is not in the value set " + describeReference(binding.getValueSet()) + " (" + valueset.getUrl() + ", and a code is recommended to come from this value set)"+getErrorMessage(vr.getMessage()));
}
} catch (Exception e) {
warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, false, "Error "+e.getMessage()+" validating Coding");
@ -2160,14 +2160,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (vr.IsNoService())
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') could not be validated in the absence of a terminology server");
else if (binding.getStrength() == BindingStrength.REQUIRED)
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code is required from this value set)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code is required from this value set)"+getErrorMessage(vr.getMessage()));
else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), value, stack);
else if (!noExtensibleWarnings)
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code should come from this value set unless it has no suitable code)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txWarning(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code should come from this value set unless it has no suitable code)"+getErrorMessage(vr.getMessage()));
} else if (binding.getStrength() == BindingStrength.PREFERRED)
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code is recommended to come from this value set)"+(vr.getMessage() != null ? " (error message = "+vr.getMessage()+")" : ""));
txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, "The value provided ('"+value+"') is not in the value set " + describeReference(binding.getValueSet()) + " (" + vs.getUrl() + ", and a code is recommended to come from this value set)"+getErrorMessage(vr.getMessage()));
}
}
} else if (!noBindingMsgSuppressed)
@ -2784,7 +2784,9 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
}
private String getErrorMessage(String message) {
return message != null ? " (error message = " + message + ")" : "";
}
public boolean isSuppressLoincSnomedMessages() {
return suppressLoincSnomedMessages;