Merge pull request #1087 from hapifhir/gg-202301-sm-errors

Gg 202301 sm errors
This commit is contained in:
Grahame Grieve 2023-01-20 21:25:11 +11:00 committed by GitHub
commit 4a68fac9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 338 additions and 42 deletions

View File

@ -1,7 +1,10 @@
## Validator Changes
* no changes
* update FHIRPath implementation for corrections to 'as' (R5 only in validator)
## Other code changes
* update to latest FHIRPath for older versions
* clean up error handling when parsing structure maps
* go-publish related changes
* FTP Client upload and logging improvements

View File

@ -1786,6 +1786,12 @@ public class FHIRPathEngine {
return result;
} else {
String tn = convertToString(right);
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (left.size() > 1) {
throw new PathEngineException("Attempt to use as on more than one item ("+left.size()+")");
}
for (Base nextLeft : left) {
if (tn.equals(nextLeft.fhirType())) {
result.add(nextLeft);
@ -1796,6 +1802,31 @@ public class FHIRPathEngine {
}
private boolean isKnownType(String tn) {
if (!tn.contains(".")) {
try {
return worker.fetchTypeDefinition(tn) != null;
} catch (Exception e) {
return false;
}
}
String[] t = tn.split("\\.");
if (t.length != 2) {
return false;
}
if ("System".equals(t[0])) {
return Utilities.existsInList(t[1], "String", "Boolean", "Integer", "Decimal", "Quantity", "DateTime", "Time", "SimpleTypeInfo", "ClassInfo");
} else if ("FHIR".equals(t[0])) {
try {
return worker.fetchTypeDefinition(t[1]) != null;
} catch (Exception e) {
return false;
}
} else {
return false;
}
}
private List<Base> opIs(List<Base> left, List<Base> right, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
if (left.size() == 0 || right.size() == 0) {
@ -3520,7 +3551,7 @@ public class FHIRPathEngine {
case Aggregate : return funcAggregate(context, focus, exp);
case Item : return funcItem(context, focus, exp);
case As : return funcAs(context, focus, exp);
case OfType : return funcAs(context, focus, exp);
case OfType : return funcOfType(context, focus, exp);
case Type : return funcType(context, focus, exp);
case Is : return funcIs(context, focus, exp);
case Single : return funcSingle(context, focus, exp);
@ -4550,6 +4581,13 @@ public class FHIRPathEngine {
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (focus.size() > 1) {
throw new PathEngineException("Attempt to use as() on more than one item ("+focus.size()+")");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
@ -4569,7 +4607,48 @@ public class FHIRPathEngine {
result.add(b);
break;
}
sd = worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
}
}
}
return result;
}
private List<Base> funcOfType(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
String tn;
if (expr.getParameters().get(0).getInner() != null) {
tn = expr.getParameters().get(0).getName()+"."+expr.getParameters().get(0).getInner().getName();
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
if (b.hasType(tn.substring(7))) {
result.add(b);
}
}
} else if (tn.startsWith("FHIR.")) {
String tnp = tn.substring(5);
if (b.fhirType().equals(tnp)) {
result.add(b);
} else {
StructureDefinition sd = worker.fetchTypeDefinition(b.fhirType());
while (sd != null) {
if (tnp.equals(sd.getType())) {
result.add(b);
break;
}
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
}
}
}

View File

@ -1782,6 +1782,12 @@ public class FHIRPathEngine {
return result;
} else {
String tn = convertToString(right);
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (left.size() > 1) {
throw new PathEngineException("Attempt to use as on more than one item ("+left.size()+")");
}
for (Base nextLeft : left) {
if (tn.equals(nextLeft.fhirType())) {
result.add(nextLeft);
@ -1792,6 +1798,31 @@ public class FHIRPathEngine {
}
private boolean isKnownType(String tn) {
if (!tn.contains(".")) {
try {
return worker.fetchTypeDefinition(tn) != null;
} catch (Exception e) {
return false;
}
}
String[] t = tn.split("\\.");
if (t.length != 2) {
return false;
}
if ("System".equals(t[0])) {
return Utilities.existsInList(t[1], "String", "Boolean", "Integer", "Decimal", "Quantity", "DateTime", "Time", "SimpleTypeInfo", "ClassInfo");
} else if ("FHIR".equals(t[0])) {
try {
return worker.fetchTypeDefinition(t[1]) != null;
} catch (Exception e) {
return false;
}
} else {
return false;
}
}
private List<Base> opIs(List<Base> left, List<Base> right, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
if (left.size() == 0 || right.size() == 0) {
@ -3516,7 +3547,7 @@ public class FHIRPathEngine {
case Aggregate : return funcAggregate(context, focus, exp);
case Item : return funcItem(context, focus, exp);
case As : return funcAs(context, focus, exp);
case OfType : return funcAs(context, focus, exp);
case OfType : return funcOfType(context, focus, exp);
case Type : return funcType(context, focus, exp);
case Is : return funcIs(context, focus, exp);
case Single : return funcSingle(context, focus, exp);
@ -4546,6 +4577,13 @@ public class FHIRPathEngine {
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (focus.size() > 1) {
throw new PathEngineException("Attempt to use as() on more than one item ("+focus.size()+")");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
@ -4565,7 +4603,48 @@ public class FHIRPathEngine {
result.add(b);
break;
}
sd = worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
}
}
}
return result;
}
private List<Base> funcOfType(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
String tn;
if (expr.getParameters().get(0).getInner() != null) {
tn = expr.getParameters().get(0).getName()+"."+expr.getParameters().get(0).getInner().getName();
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
if (b.hasType(tn.substring(7))) {
result.add(b);
}
}
} else if (tn.startsWith("FHIR.")) {
String tnp = tn.substring(5);
if (b.fhirType().equals(tnp)) {
result.add(b);
} else {
StructureDefinition sd = worker.fetchTypeDefinition(b.fhirType());
while (sd != null) {
if (tnp.equals(sd.getType())) {
result.add(b);
break;
}
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
}
}

View File

@ -50,20 +50,31 @@ import org.hl7.fhir.utilities.Utilities;
public class FHIRLexer {
public class FHIRLexerException extends FHIRException {
public FHIRLexerException() {
super();
}
private SourceLocation location;
public FHIRLexerException(String message, Throwable cause) {
super(message, cause);
}
// public FHIRLexerException() {
// super();
// }
//
// public FHIRLexerException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public FHIRLexerException(String message) {
// super(message);
// }
//
// public FHIRLexerException(Throwable cause) {
// super(cause);
// }
public FHIRLexerException(String message) {
public FHIRLexerException(String message, SourceLocation location) {
super(message);
this.location = location;
}
public FHIRLexerException(Throwable cause) {
super(cause);
public SourceLocation getLocation() {
return location;
}
}
@ -145,11 +156,11 @@ public class FHIRLexer {
}
public FHIRLexerException error(String msg) {
return error(msg, currentLocation.toString());
return error(msg, currentLocation.toString(), currentLocation);
}
public FHIRLexerException error(String msg, String location) {
return new FHIRLexerException("Error @"+location+": "+msg);
public FHIRLexerException error(String msg, String location, SourceLocation loc) {
return new FHIRLexerException("Error @"+location+": "+msg, loc);
}
public void next() throws FHIRLexerException {
@ -450,7 +461,7 @@ public class FHIRLexer {
i = i + 4;
break;
default:
throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i));
throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i), currentLocation);
}
} else {
b.append(ch);
@ -499,7 +510,7 @@ public class FHIRLexer {
i = i + 4;
break;
default:
throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i));
throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i), currentLocation);
}
} else {
b.append(ch);

View File

@ -263,6 +263,7 @@ public class FHIRPathEngine {
private boolean allowPolymorphicNames;
private boolean doImplicitStringConversion;
private boolean liquidMode; // in liquid mode, || terminates the expression and hands the parser back to the host
private boolean doNotEnforceAsSingletonRule;
// if the fhir path expressions are allowed to use constants beyond those defined in the specification
// the application can implement them by providing a constant resolver
@ -456,6 +457,14 @@ public class FHIRPathEngine {
this.doImplicitStringConversion = doImplicitStringConversion;
}
public boolean isDoNotEnforceAsSingletonRule() {
return doNotEnforceAsSingletonRule;
}
public void setDoNotEnforceAsSingletonRule(boolean doNotEnforceAsSingletonRule) {
this.doNotEnforceAsSingletonRule = doNotEnforceAsSingletonRule;
}
// --- public API -------------------------------------------------------
/**
* Parse a path for later use using execute
@ -1296,14 +1305,14 @@ public class FHIRPathEngine {
private boolean checkParamCount(FHIRLexer lexer, SourceLocation location, ExpressionNode exp, int count) throws FHIRLexerException {
if (exp.getParameters().size() != count) {
throw lexer.error("The function \""+exp.getName()+"\" requires "+Integer.toString(count)+" parameters", location.toString());
throw lexer.error("The function \""+exp.getName()+"\" requires "+Integer.toString(count)+" parameters", location.toString(), location);
}
return true;
}
private boolean checkParamCount(FHIRLexer lexer, SourceLocation location, ExpressionNode exp, int countMin, int countMax) throws FHIRLexerException {
if (exp.getParameters().size() < countMin || exp.getParameters().size() > countMax) {
throw lexer.error("The function \""+exp.getName()+"\" requires between "+Integer.toString(countMin)+" and "+Integer.toString(countMax)+" parameters", location.toString());
throw lexer.error("The function \""+exp.getName()+"\" requires between "+Integer.toString(countMin)+" and "+Integer.toString(countMax)+" parameters", location.toString(), location);
}
return true;
}
@ -1788,6 +1797,12 @@ public class FHIRPathEngine {
return result;
} else {
String tn = convertToString(right);
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (!doNotEnforceAsSingletonRule && left.size() > 1) {
throw new PathEngineException("Attempt to use as on more than one item ("+left.size()+")");
}
for (Base nextLeft : left) {
if (tn.equals(nextLeft.fhirType())) {
result.add(nextLeft);
@ -1798,6 +1813,34 @@ public class FHIRPathEngine {
}
private boolean isKnownType(String tn) {
if (!tn.contains(".")) {
if (Utilities.existsInList(tn, "String", "Boolean", "Integer", "Decimal", "Quantity", "DateTime", "Time", "SimpleTypeInfo", "ClassInfo")) {
return true;
}
try {
return worker.fetchTypeDefinition(tn) != null;
} catch (Exception e) {
return false;
}
}
String[] t = tn.split("\\.");
if (t.length != 2) {
return false;
}
if ("System".equals(t[0])) {
return Utilities.existsInList(t[1], "String", "Boolean", "Integer", "Decimal", "Quantity", "DateTime", "Time", "SimpleTypeInfo", "ClassInfo");
} else if ("FHIR".equals(t[0])) {
try {
return worker.fetchTypeDefinition(t[1]) != null;
} catch (Exception e) {
return false;
}
} else {
return false;
}
}
private List<Base> opIs(List<Base> left, List<Base> right, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
if (left.size() == 0 || right.size() == 0) {
@ -3522,7 +3565,7 @@ public class FHIRPathEngine {
case Aggregate : return funcAggregate(context, focus, exp);
case Item : return funcItem(context, focus, exp);
case As : return funcAs(context, focus, exp);
case OfType : return funcAs(context, focus, exp);
case OfType : return funcOfType(context, focus, exp);
case Type : return funcType(context, focus, exp);
case Is : return funcIs(context, focus, exp);
case Single : return funcSingle(context, focus, exp);
@ -4552,6 +4595,13 @@ public class FHIRPathEngine {
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
if (!doNotEnforceAsSingletonRule && focus.size() > 1) {
throw new PathEngineException("Attempt to use as() on more than one item ("+focus.size()+")");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
@ -4571,7 +4621,48 @@ public class FHIRPathEngine {
result.add(b);
break;
}
sd = worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
}
}
}
return result;
}
private List<Base> funcOfType(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
List<Base> result = new ArrayList<Base>();
String tn;
if (expr.getParameters().get(0).getInner() != null) {
tn = expr.getParameters().get(0).getName()+"."+expr.getParameters().get(0).getInner().getName();
} else {
tn = "FHIR."+expr.getParameters().get(0).getName();
}
if (!isKnownType(tn)) {
throw new PathEngineException("The type "+tn+" is not valid");
}
for (Base b : focus) {
if (tn.startsWith("System.")) {
if (b instanceof Element &&((Element) b).isDisallowExtensions()) {
if (b.hasType(tn.substring(7))) {
result.add(b);
}
}
} else if (tn.startsWith("FHIR.")) {
String tnp = tn.substring(5);
if (b.fhirType().equals(tnp)) {
result.add(b);
} else {
StructureDefinition sd = worker.fetchTypeDefinition(b.fhirType());
while (sd != null) {
if (tnp.equals(sd.getType())) {
result.add(b);
break;
}
sd = sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE ? null : worker.fetchResource(StructureDefinition.class, sd.getBaseDefinition(), sd);
}
}
}

View File

@ -72,6 +72,9 @@ import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.SourceLocation;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType;
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
import org.hl7.fhir.utilities.validation.ValidationOptions;
import org.hl7.fhir.utilities.xhtml.NodeType;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
@ -640,12 +643,13 @@ public class StructureMapUtilities {
return result;
}
public Element parseEM(String text, String srcName) throws FHIRException {
public Element parseEM(String text, String srcName, List<ValidationMessage> list) throws FHIRException {
FHIRLexer lexer = new FHIRLexer(text, srcName);
if (lexer.done())
throw lexer.error("Map Input cannot be empty");
lexer.token("map");
Element result = Manager.build(worker, worker.fetchTypeDefinition("StructureMap"));
try {
result.makeElement("url").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("url"));
lexer.token("=");
result.makeElement("name").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("name"));
@ -661,6 +665,11 @@ public class StructureMapUtilities {
while (!lexer.done()) {
parseGroupEM(result, lexer);
}
} catch (FHIRLexerException e) {
list.add(new ValidationMessage(Source.InstanceValidator, IssueType.INVALID, e.getLocation().getLine(), e.getLocation().getColumn(), null, e.getMessage(), IssueSeverity.FATAL));
} catch (Exception e) {
list.add(new ValidationMessage(Source.InstanceValidator, IssueType.INVALID, null, e.getMessage(), IssueSeverity.FATAL));
}
return result;
}
@ -3076,8 +3085,4 @@ public class StructureMapUtilities {
this.terminologyServiceOptions = terminologyServiceOptions;
}
public Element parseForValidation(ByteArrayInputStream byteArrayInputStream, String version, List<ValidationMessage> errors) {
return null;
}
}

View File

@ -98,7 +98,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map");
System.out.println(fileMap);
Element structureMap = scu.parseEM(fileMap, "Syntax");
Element structureMap = scu.parseEM(fileMap, "Syntax", null);
// assertSerializeDeserialize(structureMap);
//
// String renderedMap = StructureMapUtilities.render(structureMap);

View File

@ -128,6 +128,33 @@ public class PackageList {
public Instant instant() throws ParseException {
return json.asInstant("date");
}
/**
* only used for a technical correction. tcPath is the name of archive file (web reference) containing the content before correction
*
* @param asString
* @param webpath
* @param asString2
* @param asString3
* @param fhirVersion
* @param tcName
*/
public void update(String version, String path, String status, String sequence, FhirPublication fhirVersion, String tcPath, String date) {
JsonObject tc = new JsonObject();
json.forceArray("corrections").add(tc);
tc.set("version", json.asString("version"));
tc.set("path", tcPath);
tc.set("date", date);
json.set("version", version);
json.set("path", path);
json.set("status", status);
json.set("sequence", sequence);
if (fhirVersion != null) {
json.set("fhirversion", fhirVersion.toCode());
}
setDate(date);
}
}
private String source;

View File

@ -480,6 +480,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (theContext.getVersion().startsWith("3.0") || theContext.getVersion().startsWith("1.0"))
fpe.setLegacyMode(true);
source = Source.InstanceValidator;
fpe.setDoNotEnforceAsSingletonRule(!VersionUtilities.isR5VerOrLater(theContext.getVersion()));
}
@Override

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>6.2.1</hapi_fhir_version>
<validator_test_case_version>1.2.8</validator_test_case_version>
<validator_test_case_version>1.2.9-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>