Fix CDA validation test case

This commit is contained in:
Grahame Grieve 2023-07-21 21:17:51 +10:00
parent 8980df2364
commit 672ebf0348
9 changed files with 164 additions and 6 deletions

View File

@ -0,0 +1,43 @@
package org.hl7.fhir.utilities;
/**
* A few places in the code, we call System.exit(int) to pass on the exit code to
* other tools (for integration in scripts)
*
* But you don't want to do that while running the failing things under JUnit
* This class does two things
*
* * Remember the exit code while shutdown / cleanup happens
* * Allow for a test case to turn exiting off altogther
*
* @author grahamegrieve
*
*/
public class SystemExitManager {
private static int error;
private static boolean noExit;
public static int getError() {
return error;
}
public static void setError(int error) {
SystemExitManager.error = error;
}
public static boolean isNoExit() {
return noExit;
}
public static void setNoExit(boolean noExit) {
SystemExitManager.noExit = noExit;
}
public static void finish() {
if (!noExit && error > 0) {
System.exit(error);
}
}
}

View File

@ -594,7 +594,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
try { try {
loader.load(ref.getCnt()); loader.load(ref.getCnt());
} catch (Throwable t) { } catch (Throwable t) {
System.out.println(t.getMessage()); if (debug) {
System.out.println("Error during round 1 scanning: "+t.getMessage());
}
} }
} }
} }

View File

@ -67,6 +67,7 @@ POSSIBILITY OF SUCH DAMAGE.
import org.apache.commons.text.WordUtils; import org.apache.commons.text.WordUtils;
import org.hl7.fhir.r5.terminologies.JurisdictionUtilities; import org.hl7.fhir.r5.terminologies.JurisdictionUtilities;
import org.hl7.fhir.utilities.FileFormat; import org.hl7.fhir.utilities.FileFormat;
import org.hl7.fhir.utilities.SystemExitManager;
import org.hl7.fhir.utilities.TimeTracker; import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
@ -163,7 +164,8 @@ public class ValidatorCli {
}); });
} else { } else {
displayHelpForDefaultTask(); displayHelpForDefaultTask();
}return; }
return;
} }
readParamsAndExecuteTask(tt, tts, cliContext, args); readParamsAndExecuteTask(tt, tts, cliContext, args);
@ -310,6 +312,7 @@ public class ValidatorCli {
} }
System.out.println("Done. " + tt.report()+". Max Memory = "+Utilities.describeSize(Runtime.getRuntime().maxMemory())); System.out.println("Done. " + tt.report()+". Max Memory = "+Utilities.describeSize(Runtime.getRuntime().maxMemory()));
SystemExitManager.finish();
} }
private CliTask selectCliTask(CliContext cliContext, String[] params) { private CliTask selectCliTask(CliContext cliContext, String[] params) {

View File

@ -48,6 +48,7 @@ import org.hl7.fhir.r5.renderers.spreadsheets.ValueSetSpreadsheetGenerator;
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities; import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.FhirPublication; import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.SystemExitManager;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.TimeTracker; import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
@ -225,7 +226,9 @@ public class ValidationService {
Thread.sleep(watchScanDelay); Thread.sleep(watchScanDelay);
} }
} while (watch != ValidatorWatchMode.NONE); } while (watch != ValidatorWatchMode.NONE);
System.exit(ec > 0 ? 1 : 0); if (ec > 0) {
SystemExitManager.setError(1);
}
} }
private int countErrors(OperationOutcome oo) { private int countErrors(OperationOutcome oo) {

View File

@ -1,5 +1,6 @@
package org.hl7.fhir.validation.cli.tasks; package org.hl7.fhir.validation.cli.tasks;
import org.hl7.fhir.utilities.SystemExitManager;
import org.hl7.fhir.utilities.TimeTracker; import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.validation.cli.model.CliContext; import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.utils.Params; import org.hl7.fhir.validation.cli.utils.Params;
@ -43,6 +44,7 @@ public class TxTestsTask extends StandaloneTask{
final String tx = Params.getParam(args, Params.TERMINOLOGY); final String tx = Params.getParam(args, Params.TERMINOLOGY);
final String filter = Params.getParam(args, Params.FILTER); final String filter = Params.getParam(args, Params.FILTER);
boolean ok = new TxTester(new TxTester.InternalTxLoader(source, output), tx, false).setOutput(output).execute(version, filter); boolean ok = new TxTester(new TxTester.InternalTxLoader(source, output), tx, false).setOutput(output).execute(version, filter);
System.exit(ok ? 1 : 0); SystemExitManager.setError(ok ? 1 : 0);
SystemExitManager.finish();
} }
} }

View File

@ -2,18 +2,22 @@ package org.hl7.fhir.validation.tests;
import org.hl7.fhir.r4.context.SimpleWorkerContext; import org.hl7.fhir.r4.context.SimpleWorkerContext;
import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.SystemExitManager;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.validation.ValidatorCli; import org.hl7.fhir.validation.ValidatorCli;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@Disabled
public class CDAValidationTest { public class CDAValidationTest {
private SimpleWorkerContext context; private SimpleWorkerContext context;
@Test @Test
public void test() throws Exception { public void test() throws Exception {
ValidatorCli.main(new String[] {TestingUtilities.loadTestResource("ccda.xml"), "-ig", "hl7.fhir.cda"}); String fn = TestingUtilities.tempFile("cda", "cda.xml");
TextFile.stringToFile(TestingUtilities.loadTestResource("cda/cda-original.xml"), fn);
SystemExitManager.setNoExit(true);
ValidatorCli.main(new String[] {fn, "-ig", "hl7.cda.uv.core#current"});
} }
} }

View File

@ -126,3 +126,20 @@ v: {
"system" : "urn:ietf:bcp:47" "system" : "urn:ietf:bcp:47"
} }
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
{"code" : {
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
"code" : "001",
"display" : "World"
}, "url": "http://hl7.org/fhir/ValueSet/jurisdiction", "version": "5.0.0", "langs":"[en]", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"NO_MEMBERSHIP_CHECK", "displayWarningMode":"false", "versionFlexible":"false", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "World",
"code" : "001",
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm"
}
-------------------------------------------------------------------------------------

View File

@ -0,0 +1,33 @@
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
"code" : "001"
}, "url": "http://hl7.org/fhir/ValueSet/jurisdiction--2", "version": "5.0.0", "langs":"[en]", "useServer":"true", "useClient":"false", "guessSystem":"false", "valueSetMode":"CHECK_MEMERSHIP_ONLY", "displayWarningMode":"false", "versionFlexible":"false", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "World",
"code" : "001",
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm"
}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm",
"code" : "001"
}, "valueSet" :null, "langs":"[en]", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "displayWarningMode":"false", "versionFlexible":"false", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "World",
"code" : "001",
"system" : "http://unstats.un.org/unsd/methods/m49/m49.htm"
}
-------------------------------------------------------------------------------------

View File

@ -822,3 +822,54 @@ v: {
"version" : "http://snomed.info/sct/900000000000207008/version/20230131" "version" : "http://snomed.info/sct/900000000000207008/version/20230131"
} }
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
{"code" : {
"system" : "http://snomed.info/sct",
"code" : "230993007"
}, "valueSet" :null, "langs":"[en-US, en]", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Worsening",
"code" : "230993007",
"system" : "http://snomed.info/sct",
"version" : "http://snomed.info/sct/900000000000207008/version/20230131"
}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://snomed.info/sct",
"code" : "385633008"
}, "valueSet" :null, "langs":"[en-US, en]", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "Improving (qualifier value)",
"code" : "385633008",
"system" : "http://snomed.info/sct",
"version" : "http://snomed.info/sct/900000000000207008/version/20230131"
}
-------------------------------------------------------------------------------------
{"code" : {
"system" : "http://snomed.info/sct",
"code" : "260388006"
}, "valueSet" :null, "langs":"[en-US, en]", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "displayWarningMode":"false", "versionFlexible":"true", "profile": {
"resourceType" : "Parameters",
"parameter" : [{
"name" : "profile-url",
"valueString" : "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}]
}}####
v: {
"display" : "No status change",
"code" : "260388006",
"system" : "http://snomed.info/sct",
"version" : "http://snomed.info/sct/900000000000207008/version/20230131"
}
-------------------------------------------------------------------------------------