Add hl7.terminology to shared worker contexts in tests
This commit is contained in:
parent
7c6e7b278a
commit
927bdffd2e
|
@ -1,20 +1,11 @@
|
||||||
package org.hl7.fhir.r5.context;
|
package org.hl7.fhir.r5.context;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
|
||||||
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
||||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||||
import org.hl7.fhir.r5.model.CodeSystem;
|
import org.hl7.fhir.r5.model.CodeSystem;
|
||||||
import org.hl7.fhir.r5.model.DomainResource;
|
|
||||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
||||||
import org.hl7.fhir.utilities.VersionUtilities;
|
import org.hl7.fhir.utilities.VersionUtilities;
|
||||||
|
|
||||||
|
@ -28,6 +19,12 @@ import org.hl7.fhir.utilities.VersionUtilities;
|
||||||
|
|
||||||
public class CanonicalResourceManager<T extends CanonicalResource> {
|
public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||||
|
|
||||||
|
private final String[] INVALID_TERMINOLOGY_URLS = {
|
||||||
|
"http://terminology.hl7.org/CodeSystem/v3-NullFlavor",
|
||||||
|
"http://snomed.info/sct",
|
||||||
|
"http://nucc.org/provider-taxonomy"
|
||||||
|
};
|
||||||
|
|
||||||
public static abstract class CanonicalResourceProxy {
|
public static abstract class CanonicalResourceProxy {
|
||||||
private String type;
|
private String type;
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -219,7 +216,11 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
||||||
|
|
||||||
public void see(CachedCanonicalResource<T> cr) {
|
public void see(CachedCanonicalResource<T> cr) {
|
||||||
// ignore UTG NUCC erroneous code system
|
// ignore UTG NUCC erroneous code system
|
||||||
if (cr.getPackageInfo() != null && cr.getPackageInfo().getId() != null && cr.getPackageInfo().getId().startsWith("hl7.terminology") && "http://nucc.org/provider-taxonomy".equals(cr.getUrl())) {
|
if (cr.getPackageInfo() != null
|
||||||
|
&& cr.getPackageInfo().getId() != null
|
||||||
|
&& cr.getPackageInfo().getId().startsWith("hl7.terminology")
|
||||||
|
&& Arrays.stream(INVALID_TERMINOLOGY_URLS).anyMatch((it)->it.equals(cr.getUrl()))
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hl7.fhir.r5.context;
|
package org.hl7.fhir.r5.test.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
|
@ -114,6 +114,11 @@ public class TestingUtilities extends BaseTestingUtilities {
|
||||||
IWorkerContext fcontext = getWorkerContext(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.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
|
||||||
fcontext.setExpansionProfile(new Parameters());
|
fcontext.setExpansionProfile(new Parameters());
|
||||||
|
if (!fcontext.hasPackage("hl7.terminology", null)) {
|
||||||
|
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
|
||||||
|
System.out.println("Loading THO: "+utg.name()+"#"+utg.version());
|
||||||
|
fcontext.loadFromPackage(utg, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet"}));
|
||||||
|
}
|
||||||
return fcontext;
|
return fcontext;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -132,24 +132,24 @@ public class NarrativeGenerationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
XhtmlNode x = RendererFactory.factory(source, rc).build(source);
|
XhtmlNode x = RendererFactory.factory(source, rc).build(source);
|
||||||
String target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
|
String expected = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".html"));
|
||||||
String output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
String actual = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
||||||
String tfn = TestingUtilities.tempFile("narrative", test.getId() + ".target.html");
|
String expectedFileName = TestingUtilities.tempFile("narrative", test.getId() + ".expected.html");
|
||||||
String ofn = TestingUtilities.tempFile("narrative", test.getId() + ".output.html");
|
String actualFileName = TestingUtilities.tempFile("narrative", test.getId() + ".actual.html");
|
||||||
TextFile.stringToFile(target, tfn);
|
TextFile.stringToFile(expected, expectedFileName);
|
||||||
TextFile.stringToFile(output, ofn);
|
TextFile.stringToFile(actual, actualFileName);
|
||||||
String msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
|
String msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
|
||||||
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||||
|
|
||||||
if (test.isMeta()) {
|
if (test.isMeta()) {
|
||||||
org.hl7.fhir.r5.elementmodel.Element e = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".xml"), FhirFormat.XML);
|
org.hl7.fhir.r5.elementmodel.Element e = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + ".xml"), FhirFormat.XML);
|
||||||
x = RendererFactory.factory(source, rc).render(new ElementWrappers.ResourceWrapperMetaElement(rc, e));
|
x = RendererFactory.factory(source, rc).render(new ElementWrappers.ResourceWrapperMetaElement(rc, e));
|
||||||
|
|
||||||
target = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
|
expected = TextFile.streamToString(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-meta.html"));
|
||||||
output = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
actual = HEADER+new XhtmlComposer(true, true).compose(x)+FOOTER;
|
||||||
ofn = TestingUtilities.tempFile("narrative", test.getId() + "-meta.output.html");
|
actualFileName = TestingUtilities.tempFile("narrative", test.getId() + "-meta.actual.html");
|
||||||
TextFile.stringToFile(output, ofn);
|
TextFile.stringToFile(actual, actualFileName);
|
||||||
msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
|
msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
|
||||||
Assertions.assertTrue(msg == null, "Meta output does not match expected: "+msg);
|
Assertions.assertTrue(msg == null, "Meta output does not match expected: "+msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
import org.hl7.fhir.exceptions.PathEngineException;
|
import org.hl7.fhir.exceptions.PathEngineException;
|
||||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||||
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
|
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
|
||||||
import org.hl7.fhir.r5.context.TestPackageLoader;
|
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
|
||||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||||
import org.hl7.fhir.r5.formats.JsonParser;
|
import org.hl7.fhir.r5.formats.JsonParser;
|
||||||
import org.hl7.fhir.r5.formats.XmlParser;
|
import org.hl7.fhir.r5.formats.XmlParser;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.hl7.fhir.r5.test;
|
package org.hl7.fhir.r5.test;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -13,7 +12,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||||
import org.hl7.fhir.r5.context.TestPackageLoader;
|
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
|
||||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||||
import org.hl7.fhir.r5.formats.JsonParser;
|
import org.hl7.fhir.r5.formats.JsonParser;
|
||||||
import org.hl7.fhir.r5.formats.XmlParser;
|
import org.hl7.fhir.r5.formats.XmlParser;
|
||||||
|
@ -109,13 +108,8 @@ public class VocabTests {
|
||||||
/* Do NOT get a shared worker context from Testing Utilities or else the terminology package loaded below
|
/* Do NOT get a shared worker context from Testing Utilities or else the terminology package loaded below
|
||||||
will appear in tests where it causes failures.
|
will appear in tests where it causes failures.
|
||||||
*/
|
*/
|
||||||
context = TestingUtilities.getWorkerContext(VersionUtilities.getMajMin(TestingUtilities.DEFAULT_CONTEXT_VERSION));
|
context = TestingUtilities.getSharedWorkerContext(VersionUtilities.getMajMin(TestingUtilities.DEFAULT_CONTEXT_VERSION));
|
||||||
if (!context.hasPackage("hl7.terminology", null)) {
|
|
||||||
|
|
||||||
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
|
|
||||||
System.out.println("Loading THO: "+utg.name()+"#"+utg.version());
|
|
||||||
context.loadFromPackage(utg, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet"}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest(name = "{index}: file {0}")
|
@ParameterizedTest(name = "{index}: file {0}")
|
||||||
|
@ -150,13 +144,13 @@ public class VocabTests {
|
||||||
if (outcome.isOk()) {
|
if (outcome.isOk()) {
|
||||||
outcome.getValueset().getExpansion().setIdentifier(null);
|
outcome.getValueset().getExpansion().setIdentifier(null);
|
||||||
outcome.getValueset().getExpansion().setTimestamp(null);
|
outcome.getValueset().getExpansion().setTimestamp(null);
|
||||||
String target = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(targetVS);
|
String expected = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(targetVS);
|
||||||
String output = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(outcome.getValueset());
|
String actual = new XmlParser().setOutputStyle(OutputStyle.PRETTY).composeString(outcome.getValueset());
|
||||||
String tfn = TestingUtilities.tempFile("vocab", test.getId() + ".target.html");
|
String expectedFileName = TestingUtilities.tempFile("vocab", test.getId() + ".expected.html");
|
||||||
String ofn = TestingUtilities.tempFile("vocab", test.getId() + ".output.html");
|
String actualFileName = TestingUtilities.tempFile("vocab", test.getId() + ".actual.html");
|
||||||
TextFile.stringToFile(target, tfn);
|
TextFile.stringToFile(expected, expectedFileName);
|
||||||
TextFile.stringToFile(output, ofn);
|
TextFile.stringToFile(actual, actualFileName);
|
||||||
String msg = TestingUtilities.checkXMLIsSame(ofn, tfn);
|
String msg = TestingUtilities.checkXMLIsSame(actualFileName, expectedFileName);
|
||||||
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
Assertions.assertTrue(msg == null, "Output does not match expected: "+msg);
|
||||||
} else {
|
} else {
|
||||||
Assertions.fail("Expansion Failed: "+outcome.getError());
|
Assertions.fail("Expansion Failed: "+outcome.getError());
|
||||||
|
|
Loading…
Reference in New Issue