Merge pull request #104 from ahdis/oliveregger_fmltests

FML updates for tests and validator
This commit is contained in:
Grahame Grieve 2020-01-22 06:17:10 +11:00 committed by GitHub
commit 9b64f03a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 22 deletions

View File

@ -389,7 +389,9 @@ public class ExpressionNode {
b.append(")"); b.append(")");
} }
if (inner != null) { if (inner != null) {
b.append("."); if (!((ExpressionNode.Kind.Function == inner.getKind()) && (ExpressionNode.Function.Item == inner.getFunction()))) {
b.append(".");
}
b.append(inner.toString()); b.append(inner.toString());
} }
if (operation != null) { if (operation != null) {

View File

@ -248,11 +248,13 @@ public class FHIRPathEngine {
public FHIRPathEngine(IWorkerContext worker) { public FHIRPathEngine(IWorkerContext worker) {
super(); super();
this.worker = worker; this.worker = worker;
for (StructureDefinition sd : worker.allStructures()) { if (this.worker!=null) {
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL) for (StructureDefinition sd : worker.allStructures()) {
allTypes.put(sd.getName(), sd); if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() != StructureDefinitionKind.LOGICAL)
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) { allTypes.put(sd.getName(), sd);
primitiveTypes.add(sd.getName()); if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
primitiveTypes.add(sd.getName());
}
} }
} }
} }
@ -1078,6 +1080,7 @@ public class FHIRPathEngine {
case Lower: return checkParamCount(lexer, location, exp, 0); case Lower: return checkParamCount(lexer, location, exp, 0);
case Upper: return checkParamCount(lexer, location, exp, 0); case Upper: return checkParamCount(lexer, location, exp, 0);
case ToChars: return checkParamCount(lexer, location, exp, 0); case ToChars: return checkParamCount(lexer, location, exp, 0);
case IndexOf : return checkParamCount(lexer, location, exp, 1);
case Substring: return checkParamCount(lexer, location, exp, 1, 2); case Substring: return checkParamCount(lexer, location, exp, 1, 2);
case StartsWith: return checkParamCount(lexer, location, exp, 1); case StartsWith: return checkParamCount(lexer, location, exp, 1);
case EndsWith: return checkParamCount(lexer, location, exp, 1); case EndsWith: return checkParamCount(lexer, location, exp, 1);

View File

@ -390,7 +390,9 @@ public class ExpressionNode {
b.append(")"); b.append(")");
} }
if (inner != null) { if (inner != null) {
b.append("."); if (!((ExpressionNode.Kind.Function == inner.getKind()) && (ExpressionNode.Function.Item == inner.getFunction()))) {
b.append(".");
}
b.append(inner.toString()); b.append(inner.toString());
} }
if (operation != null) { if (operation != null) {

View File

@ -82,7 +82,7 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
static public void setUp() throws Exception { static public void setUp() throws Exception {
if (context == null) { if (context == null) {
PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION); PackageCacheManager pcm = new PackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0")); context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.1"));
jsonParser = new JsonParser(); jsonParser = new JsonParser();
jsonParser.setOutputStyle(OutputStyle.PRETTY); jsonParser.setOutputStyle(OutputStyle.PRETTY);
} }
@ -93,7 +93,7 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
InputStream fileSource = TestingUtilities.loadTestResourceStream("r5", "fml", source); InputStream fileSource = TestingUtilities.loadTestResourceStream("r5", "fml", source);
InputStream fileMap = TestingUtilities.loadTestResourceStream("r5", "fml", map); InputStream fileMap = TestingUtilities.loadTestResourceStream("r5", "fml", map);
String fileOutput = TestingUtilities.tempFile("fml", output); String outputJson = TestingUtilities.loadTestResource("r5","fml", output);
String fileOutputRes = TestingUtilities.tempFile("fml", output)+".out"; String fileOutputRes = TestingUtilities.tempFile("fml", output)+".out";
outputs.clear(); outputs.clear();
@ -117,9 +117,10 @@ public class FHIRMappingLanguageTests implements ITransformerServices {
if (ok) { if (ok) {
ByteArrayOutputStream boas = new ByteArrayOutputStream(); ByteArrayOutputStream boas = new ByteArrayOutputStream();
jsonParser.compose(boas, resource); jsonParser.compose(boas, resource);
log(boas.toString()); String result = boas.toString();
log(result);
TextFile.bytesToFile(boas.toByteArray(), fileOutputRes); TextFile.bytesToFile(boas.toByteArray(), fileOutputRes);
msg = TestingUtilities.checkJsonIsSame(fileOutputRes,fileOutput); msg = TestingUtilities.checkJsonSrcIsSame(result, outputJson);
assertTrue(msg, Utilities.noString(msg)); assertTrue(msg, Utilities.noString(msg));
} else } else
assertTrue("Error, but proper output was expected (" + msg + ")", output.equals("$error")); assertTrue("Error, but proper output was expected (" + msg + ")", output.equals("$error"));

View File

@ -754,7 +754,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
return FhirFormat.TEXT; return FhirFormat.TEXT;
return checkIsResource(TextFile.fileToBytes(path), path); return checkIsResource(TextFile.fileToBytes(path), path);
} }
public void connectToTSServer(String url, String log, FhirPublication version) throws URISyntaxException, FHIRException { public void connectToTSServer(String url, String log, FhirPublication version) throws URISyntaxException, FHIRException {
context.setTlogging(false); context.setTlogging(false);
@ -770,7 +770,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
throw e; throw e;
} }
} }
} }
public void loadProfile(String src) throws Exception { public void loadProfile(String src) throws Exception {
if (context.hasResource(StructureDefinition.class, src)) if (context.hasResource(StructureDefinition.class, src))
@ -809,10 +809,10 @@ public class ValidationEngine implements IValidatorResourceFetcher {
} }
} }
} }
} }
if (canonical != null) if (canonical != null)
grabNatives(source, canonical); grabNatives(source, canonical);
} }
public Resource loadFileWithErrorChecking(String version, Entry<String, byte[]> t, String fn) { public Resource loadFileWithErrorChecking(String version, Entry<String, byte[]> t, String fn) {
if (debug) if (debug)
@ -908,10 +908,10 @@ public class ValidationEngine implements IValidatorResourceFetcher {
if (e.getKey().endsWith(".zip")) if (e.getKey().endsWith(".zip"))
binaries.put(prefix+"#"+e.getKey(), e.getValue()); binaries.put(prefix+"#"+e.getKey(), e.getValue());
} }
} }
public void setQuestionnaires(List<String> questionnaires) { public void setQuestionnaires(List<String> questionnaires) {
} }
public void setNative(boolean doNative) { public void setNative(boolean doNative) {
this.doNative = doNative; this.doNative = doNative;
@ -1168,12 +1168,12 @@ public class ValidationEngine implements IValidatorResourceFetcher {
private void validateSHEX(String location, List<ValidationMessage> messages) { private void validateSHEX(String location, List<ValidationMessage> messages) {
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "SHEX Validation is not done yet", IssueSeverity.INFORMATION)); messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "SHEX Validation is not done yet", IssueSeverity.INFORMATION));
} }
private void validateXmlSchema(String location, List<ValidationMessage> messages) throws FileNotFoundException, IOException, SAXException { private void validateXmlSchema(String location, List<ValidationMessage> messages) throws FileNotFoundException, IOException, SAXException {
XmlValidator xml = new XmlValidator(messages, loadSchemas(), loadTransforms()); XmlValidator xml = new XmlValidator(messages, loadSchemas(), loadTransforms());
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "XML Schema Validation is not done yet", IssueSeverity.INFORMATION)); messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "XML Schema Validation is not done yet", IssueSeverity.INFORMATION));
} }
private Map<String, byte[]> loadSchemas() throws IOException { private Map<String, byte[]> loadSchemas() throws IOException {
Map<String, byte[]> res = new HashMap<String, byte[]>(); Map<String, byte[]> res = new HashMap<String, byte[]>();
@ -1197,7 +1197,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
private void validateJsonSchema(String location, List<ValidationMessage> messages) { private void validateJsonSchema(String location, List<ValidationMessage> messages) {
messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "JSON Schema Validation is not done yet", IssueSeverity.INFORMATION)); messages.add(new ValidationMessage(Source.InstanceValidator, IssueType.INFORMATIONAL, location, "JSON Schema Validation is not done yet", IssueSeverity.INFORMATION));
} }
private List<ValidationMessage> filterMessages(List<ValidationMessage> messages) { private List<ValidationMessage> filterMessages(List<ValidationMessage> messages) {
List<ValidationMessage> filteredValidation = new ArrayList<ValidationMessage>(); List<ValidationMessage> filteredValidation = new ArrayList<ValidationMessage>();
@ -1229,7 +1229,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
} }
new NarrativeGenerator("", "", context).generate(null, op); new NarrativeGenerator("", "", context).generate(null, op);
return op; return op;
} }
public static String issueSummary (OperationOutcomeIssueComponent issue) { public static String issueSummary (OperationOutcomeIssueComponent issue) {
String source = ToolingExtensions.readStringExtension(issue, ToolingExtensions.EXT_ISSUE_SOURCE); String source = ToolingExtensions.readStringExtension(issue, ToolingExtensions.EXT_ISSUE_SOURCE);