diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml
index 4c5db9556..42cce980e 100644
--- a/org.hl7.fhir.r5/pom.xml
+++ b/org.hl7.fhir.r5/pom.xml
@@ -114,6 +114,13 @@
true
+
+ org.projectlombok
+ lombok
+ ${lombok_version}
+ provided
+
+
com.fasterxml.jackson.core
diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java
index 7697e403f..b75204ed5 100644
--- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java
+++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java
@@ -45,6 +45,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.fhir.ucum.UcumService;
import org.hl7.fhir.exceptions.DefinitionException;
@@ -203,6 +204,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
protected ILoggingService logger;
protected Parameters expParameters;
private TranslationServices translator = new NullTranslator();
+
+ @Getter
protected TerminologyCache txCache;
protected TimeTracker clock;
private boolean tlogging = true;
@@ -945,14 +948,14 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (options.isGuessSystem()) {
pIn.addParameter().setName("implySystem").setValue(new BooleanType(true));
}
- setTerminologyOptions(options, pIn);
- res = validateOnServer(vs, pIn, options);
+ setTerminologyOptions(options, pIn);res = validateOnServer(vs, pIn, options);
} catch (Exception e) {
res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog == null ? null : txLog.getLastId()).setErrorClass(TerminologyServiceErrorClass.SERVER_ERROR);
}
if (res.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED && !code.hasVersion()) {
unsupportedCodeSystems.add(codeKey);
- } else if (txCache != null) { // we never cache unsuppoted code systems - we always keep trying (but only once per run)
+ }
+ if (txCache != null) { // we never cache unsuppoted code systems - we always keep trying (but only once per run)
txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
}
return res;
@@ -2068,10 +2071,6 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return this;
}
- public String getTxCache() {
- return txCache.getFolder();
- }
-
public TerminologyClient getTxClient() {
return txClient;
}
diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/TerminologyCache.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/TerminologyCache.java
index 50186143c..fbdff6265 100644
--- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/TerminologyCache.java
+++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/TerminologyCache.java
@@ -36,11 +36,10 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
+import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.IWorkerContext.ValidationResult;
@@ -84,10 +83,19 @@ public class TerminologyCache {
private static final String ENTRY_MARKER = "-------------------------------------------------------------------------------------";
private static final String BREAK = "####";
+ @Getter
+ private int requestCount;
+ @Getter
+ private int hitCount;
+ @Getter
+ private int networkCount;
+
public class CacheToken {
private String name;
private String key;
private String request;
+ private boolean hasVersion;
+
public void setName(String n) {
if (name == null)
name = n;
@@ -114,12 +122,21 @@ public class TerminologyCache {
private String folder;
private Map caches = new HashMap();
private static boolean noCaching;
+ private static boolean cacheErrors;
+
+ static {
+ String cacheErrorsProperty = System.getProperty("cacheErrors");
+ cacheErrors = true;//cacheErrorsProperty != null ? "TRUE".equals(cacheErrorsProperty.toUpperCase(Locale.ROOT)) : false;
+ }
// use lock from the context
public TerminologyCache(Object lock, String folder) throws FileNotFoundException, IOException, FHIRException {
super();
this.lock = lock;
this.folder = folder;
+ requestCount = 0;
+ hitCount = 0;
+ networkCount = 0;
if (folder != null)
load();
}
@@ -133,6 +150,7 @@ public class TerminologyCache {
ct.name = getNameForSystem(code.getSystem());
else
ct.name = NAME_FOR_NO_SYSTEM;
+ ct.hasVersion = code.hasVersion();
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
ValueSet vsc = getVSEssense(vs);
@@ -145,15 +163,16 @@ public class TerminologyCache {
return ct;
}
+ private String getValueSetHash(ValueSet vsc) {
+ final String expansionKey = vsc.getExpansion().getContains().stream().map(x -> x.getCode()).collect(Collectors.joining(","));
+ final String composeKey = vsc.getCompose().getIncludeFirstRep().getConcept().stream().map(x -> x.getCode()).collect(Collectors.joining(","));
+ return Integer.toString((expansionKey + "\t" + composeKey).hashCode());
+ }
+
public String extracted(JsonParser json, ValueSet vsc) throws IOException {
String s = null;
if (vsc.getExpansion().getContains().size() > 1000 || vsc.getCompose().getIncludeFirstRep().getConcept().size() > 1000) {
- int hashCode = (vsc.getExpansion().getContains().toString() + vsc.getCompose().getIncludeFirstRep().getConcept().toString()).hashCode();
- StringBuilder sb = new StringBuilder();
- for (ValueSet.ConceptReferenceComponent c : vsc.getCompose().getIncludeFirstRep().getConcept()) {
- sb.append(c.getCode());
- }
- s = Integer.toString((vsc.getExpansion().getContains().toString() + sb.toString()).hashCode()); // turn caching off - hack efficiency optimisation
+ s = getValueSetHash(vsc); // save a hash representation instead of a complete valueset
} else {
s = json.composeString(vsc);
}
@@ -165,7 +184,9 @@ public class TerminologyCache {
for (Coding c : code.getCoding()) {
if (c.hasSystem())
ct.setName(getNameForSystem(c.getSystem()));
+ ct.hasVersion = c.hasVersion();
}
+
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
ValueSet vsc = getVSEssense(vs);
@@ -194,14 +215,20 @@ public class TerminologyCache {
CacheToken ct = new CacheToken();
ValueSet vsc = getVSEssense(vs);
for (ConceptSetComponent inc : vs.getCompose().getInclude())
- if (inc.hasSystem())
+ if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
+ ct.hasVersion = inc.hasVersion();
+ }
for (ConceptSetComponent inc : vs.getCompose().getExclude())
- if (inc.hasSystem())
+ if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
+ ct.hasVersion = inc.hasVersion();
+ }
for (ValueSetExpansionContainsComponent inc : vs.getExpansion().getContains())
- if (inc.hasSystem())
+ if (inc.hasSystem()) {
ct.setName(getNameForSystem(inc.getSystem()));
+ ct.hasVersion = inc.hasVersion();
+ }
JsonParser json = new JsonParser();
json.setOutputStyle(OutputStyle.PRETTY);
try {
@@ -277,6 +304,15 @@ public class TerminologyCache {
if (noCaching) {
return;
}
+
+ if ( !cacheErrors &&
+ ( e.v!= null
+ && e.v.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED
+ && !cacheToken.hasVersion)) {
+ return;
+ }
+
+
boolean n = nc.map.containsKey(cacheToken.key);
nc.map.put(cacheToken.key, e);
if (persistent) {
@@ -293,16 +329,22 @@ public class TerminologyCache {
}
public ValidationResult getValidation(CacheToken cacheToken) {
+
if (cacheToken.key == null) {
return null;
}
+
synchronized (lock) {
+ requestCount++;
NamedCache nc = getNamedCache(cacheToken);
CacheEntry e = nc.map.get(cacheToken.key);
- if (e == null)
+ if (e == null) {
+ networkCount++;
return null;
- else
+ } else {
+ hitCount++;
return e.v;
+ }
}
}
diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestConstants.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestConstants.java
new file mode 100644
index 000000000..5d910ec57
--- /dev/null
+++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestConstants.java
@@ -0,0 +1,5 @@
+package org.hl7.fhir.r5.test.utils;
+
+public class TestConstants {
+ public static final java.lang.String TX_CACHE = "/Users/david.otasek/org.hl7.fhir.core-cache";
+}
diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java
index af854cd8a..d7dec3b4b 100644
--- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java
+++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/test/utils/TestingUtilities.java
@@ -23,6 +23,8 @@ import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
+import org.hl7.fhir.utilities.npm.IPackageCacheManager;
+import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.npm.ToolsVersion;
import org.hl7.fhir.utilities.tests.BaseTestingUtilities;
import org.w3c.dom.Document;
@@ -89,7 +91,7 @@ public class TestingUtilities extends BaseTestingUtilities {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
- IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
+ IWorkerContext fcontext = getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
// ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
@@ -102,6 +104,21 @@ public class TestingUtilities extends BaseTestingUtilities {
return fcontexts.get(v);
}
+ public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage) throws Exception {
+ SimpleWorkerContext swc = SimpleWorkerContext.fromPackage(npmPackage);
+
+ swc.initTS(TestConstants.TX_CACHE+ "/" + swc.getVersion());
+ swc.setUserAgent("fhir/r5-test-cases");
+ return swc;
+ }
+
+ public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage, IWorkerContext.IContextResourceLoader loader) throws Exception {
+ SimpleWorkerContext swc = SimpleWorkerContext.fromPackage(npmPackage, loader);
+ swc.initTS(TestConstants.TX_CACHE+ "/" + swc.getVersion());
+ swc.setUserAgent("fhir/r5-test-cases");
+ return swc;
+ }
+
static public String fixedpath;
static public String contentpath;
diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java
index b39dc90ec..d6480f070 100644
--- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java
+++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/CDARoundTripTests.java
@@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
+import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.elementmodel.Element;
import org.hl7.fhir.r5.elementmodel.Manager;
@@ -27,7 +28,7 @@ public class CDARoundTripTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
- context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
+ context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
fp = new FHIRPathEngine(context);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java
index 8fccee915..65602d1eb 100644
--- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java
+++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java
@@ -25,7 +25,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices {
@BeforeAll
static public void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
- context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
+ context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
}
@Test
diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java
index 4d9b6d97f..e8ba3ec28 100644
--- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java
+++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/XmlParserTests.java
@@ -25,7 +25,8 @@ public class XmlParserTests {
@BeforeAll
public static void setUp() throws Exception {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
- context = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
+ context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
+
fp = new FHIRPathEngine(context);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestingUtilities.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestingUtilities.java
deleted file mode 100644
index 7987e755c..000000000
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestingUtilities.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.hl7.fhir;
-
-import org.hl7.fhir.r5.model.FhirPublication;
-import org.hl7.fhir.validation.ValidationEngine;
-
-public class TestingUtilities {
- public static final ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, java.lang.String vString, java.lang.String userAgent) throws Exception {
- txLog = TestConstants.TX_CACHE + "/tx.log.html";
- final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, version, canRunWithoutTerminologyServer, vString, userAgent);
- validationEngine.getContext().initTS(TestConstants.TX_CACHE + "/" + version.toString());
- validationEngine.getContext().setUserAgent("fhir/test-cases");
- return validationEngine;
- }
-
- public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, java.lang.String vString, java.lang.String userAgent) throws Exception {
- final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, version, vString, userAgent);
- validationEngine.getContext().initTS(TestConstants.TX_CACHE + "/" + version.toString());
- validationEngine.getContext().setUserAgent("fhir/test-cases");
- return validationEngine;
- }
-}
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java
index a0aba6e61..ae907092e 100644
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java
+++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/UtilitiesXTests.java
@@ -55,6 +55,7 @@ import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.IWorkerContext.IContextResourceLoader;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.model.Parameters;
+import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.utilities.CSFile;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities;
@@ -86,7 +87,7 @@ public class UtilitiesXTests {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
- IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
+ IWorkerContext fcontext = TestingUtilities.getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
fcontext.setUcumService(new UcumEssenceService(UtilitiesXTests.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
fcontexts.put(version, fcontext);
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java
index c343d2725..3cb6a9bfb 100644
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java
+++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationEngineTests.java
@@ -3,7 +3,7 @@ package org.hl7.fhir.validation.tests;
import java.util.ArrayList;
import java.util.List;
-import org.hl7.fhir.TestConstants;
+import org.hl7.fhir.validation.tests.utilities.TestConstants;
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
import org.hl7.fhir.r5.model.FhirPublication;
import org.hl7.fhir.r5.model.OperationOutcome;
@@ -27,7 +27,7 @@ public class ValidationEngineTests {
public void testCurrentXml() throws Exception {
if (!TestUtilities.silent)
System.out.println("TestCurrentXml: Validate patient-example.xml in Current version");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient-example.xml"), null);
int e = errors(op);
@@ -48,7 +48,7 @@ public class ValidationEngineTests {
public void testCurrentJson() throws Exception {
if (!TestUtilities.silent)
System.out.println("TestCurrentJson: Validate patient-example.json in Current version");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "patient-example.json"), null);
int e = errors(op);
@@ -69,7 +69,7 @@ public class ValidationEngineTests {
}
if (!TestUtilities.silent)
System.out.println("Test140: Validate patient-example.xml in v1.4.0 version");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, null, FhirPublication.DSTU2016May, "1.4.0", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, null, FhirPublication.DSTU2016May, "1.4.0", "fhir/test-cases");
ve.getContext().initTS(TestConstants.TX_CACHE);
ve.getContext().setUserAgent("fhir/test-cases");
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
@@ -95,7 +95,7 @@ public class ValidationEngineTests {
}
if (!org.hl7.fhir.validation.tests.utilities.TestUtilities.silent)
System.out.println("Test102: Validate patient-example.xml in v1.0.2 version");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
ve.setNoInvariantChecks(true);
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient102.xml"), null);
@@ -121,7 +121,7 @@ public class ValidationEngineTests {
}
if (!TestUtilities.silent)
System.out.println("TestObs102: Validate patient-example.xml in v1.0.2 version");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
ve.setNoInvariantChecks(true);
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "observation102.json"), null);
@@ -144,7 +144,7 @@ public class ValidationEngineTests {
public void test301() throws Exception {
if (!TestUtilities.silent)
System.out.println("Test301: Validate observation301.xml against Core");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
if (!TestUtilities.silent)
System.out.println(" .. load USCore");
@@ -164,7 +164,7 @@ public class ValidationEngineTests {
public void test301USCore() throws Exception {
if (!TestUtilities.silent)
System.out.println("Test301USCore: Validate patient300.xml against US-Core");
- ValidationEngine ve = org.hl7.fhir.TestingUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
+ ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
IgLoader igLoader = new IgLoader(ve.getPcm(), ve.getContext(), ve.getVersion(), true);
if (!TestUtilities.silent)
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java
index 601a56e62..32865320d 100644
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java
+++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/ValidationTests.java
@@ -15,7 +15,7 @@ import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.NotImplementedException;
-import org.hl7.fhir.TestingUtilities;
+import org.hl7.fhir.validation.tests.utilities.TestUtilities;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
@@ -144,15 +144,15 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
version = VersionUtilities.getMajMin(version);
if (!ve.containsKey(version)) {
if (version.startsWith("5.0"))
- ve.put(version, TestingUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0", "fhir/test-cases"));
+ ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0", "fhir/test-cases"));
else if (version.startsWith("3.0"))
- ve.put(version, TestingUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2", "fhir/test-cases"));
+ ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2", "fhir/test-cases"));
else if (version.startsWith("4.0"))
- ve.put(version, TestingUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1", "fhir/test-cases"));
+ ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1", "fhir/test-cases"));
else if (version.startsWith("1.0"))
- ve.put(version, TestingUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2", "fhir/test-cases"));
+ ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2", "fhir/test-cases"));
else if (version.startsWith("1.4"))
- ve.put(version, TestingUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0", "fhir/test-cases"));
+ ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0", "fhir/test-cases"));
else
throw new Exception("unknown version " + version);
}
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestConstants.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestConstants.java
similarity index 72%
rename from org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestConstants.java
rename to org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestConstants.java
index 0a14ccff6..22dc5127a 100644
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/TestConstants.java
+++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestConstants.java
@@ -1,4 +1,4 @@
-package org.hl7.fhir;
+package org.hl7.fhir.validation.tests.utilities;
public class TestConstants {
public static final java.lang.String TX_CACHE = "/Users/david.otasek/org.hl7.fhir.core-cache";
diff --git a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java
index ec20c7b62..d3d8d1397 100644
--- a/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java
+++ b/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/validation/tests/utilities/TestUtilities.java
@@ -1,5 +1,8 @@
package org.hl7.fhir.validation.tests.utilities;
+import org.hl7.fhir.r5.model.FhirPublication;
+import org.hl7.fhir.validation.ValidationEngine;
+
public class TestUtilities {
public static boolean silent = false;
@@ -7,5 +10,18 @@ public class TestUtilities {
// public static String resourceNameToFile(String name) throws IOException {
// return org.hl7.fhir.utilities.Utilities.path(System.getProperty("user.dir"), "src", "test", "resources", name);
// }
+public static final ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, java.lang.String vString, java.lang.String userAgent) throws Exception {
+ txLog = TestConstants.TX_CACHE + "/tx.log.html";
+ final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, version, canRunWithoutTerminologyServer, vString, userAgent);
+ validationEngine.getContext().initTS(TestConstants.TX_CACHE + "/" + vString);
+ validationEngine.getContext().setUserAgent("fhir/test-cases");
+ return validationEngine;
+}
+ public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, java.lang.String vString, java.lang.String userAgent) throws Exception {
+ final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, version, vString, userAgent);
+ validationEngine.getContext().initTS(TestConstants.TX_CACHE + "/" + vString);
+ validationEngine.getContext().setUserAgent("fhir/test-cases");
+ return validationEngine;
+ }
}
\ No newline at end of file