use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.
the class SnapShotGenerationTests method testGen.
private void testGen(boolean fail, TestDetails test, SnapShotGenerationTestsContext context) throws Exception {
if (!Utilities.noString(test.register)) {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages, null);
pu.setNewSlicingProcessing(true);
for (StructureDefinition sd : test.included) {
pu.setIds(sd, false);
}
for (StructureDefinition sd : test.included) {
if (!TestingUtilities.context().hasResource(StructureDefinition.class, sd.getUrl())) {
TestingUtilities.context().cacheResource(sd);
}
}
StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, test.included.get(0).getBaseDefinition());
if (base != null) {
pu.generateSnapshot(base, test.included.get(0), test.included.get(0).getUrl(), "http://test.org/profile", test.included.get(0).getName());
}
int ec = 0;
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
System.out.println(vm.summary());
ec++;
}
}
if (ec > 0)
throw new FHIRException("register gen failed: " + messages.toString());
}
StructureDefinition base = getSD(test.getSource().getBaseDefinition(), context);
if (!base.getUrl().equals(test.getSource().getBaseDefinition()))
throw new Exception("URL mismatch on base: " + base.getUrl() + " wanting " + test.getSource().getBaseDefinition());
StructureDefinition output = test.getSource().copy();
ProfileUtilities pu = new ProfileUtilities(TestingUtilities.context(), messages, new TestPKP());
pu.setNewSlicingProcessing(test.isNewSliceProcessing());
pu.setThrowException(false);
pu.setDebug(test.isDebug());
pu.setIds(test.getSource(), false);
if (!TestingUtilities.context().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) {
NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
TestingUtilities.context().loadFromPackage(npm, new TestLoader(new String[] { "StructureDefinition" }), new String[] { "StructureDefinition" });
}
pu.setXver(new XVerExtensionManager(TestingUtilities.context()));
if (test.isSort()) {
List<String> errors = new ArrayList<String>();
int lastCount = output.getDifferential().getElement().size();
pu.sortDifferential(base, output, test.getSource().getName(), errors, false);
if (errors.size() > 0)
throw new FHIRException("Sort failed: " + errors.toString());
}
try {
messages.clear();
pu.generateSnapshot(base, output, test.getSource().getUrl(), "http://test.org/profile", test.getSource().getName());
List<ValidationMessage> ml = new ArrayList<>();
for (ValidationMessage vm : messages) {
if (vm.getLevel() == IssueSeverity.ERROR) {
ml.add(vm);
}
}
if (ml.size() > 0) {
throw new FHIRException("Snapshot Generation failed: " + ml.toString());
}
} catch (Throwable e) {
System.out.println("\r\nException: " + e.getMessage());
throw e;
}
if (output.getDifferential().hasElement()) {
RenderingContext rc = new RenderingContext(TestingUtilities.context(), null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER);
rc.setDestDir(Utilities.path("[tmp]", "snapshot"));
rc.setProfileUtilities(new ProfileUtilities(TestingUtilities.context(), null, new TestPKP()));
RendererFactory.factory(output, rc).render(output);
}
if (!fail) {
test.output = output;
TestingUtilities.context().cacheResource(output);
File dst = new File(TestingUtilities.tempFile("snapshot", test.getId() + "-expected.xml"));
if (dst.exists())
dst.delete();
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "snapshot-generation", test.getId() + "-expected.xml"), new FileOutputStream(dst));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("snapshot", test.getId() + "-actual.xml")), output);
StructureDefinition t1 = test.expected.copy();
t1.setText(null);
StructureDefinition t2 = test.output.copy();
t2.setText(null);
Assertions.assertTrue(t1.equalsDeep(t2), "Output does not match expected");
}
}
use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilitiesTest method setUp.
@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"));
}
use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.
the class XmlParserTests method setUp.
@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"));
fp = new FHIRPathEngine(context);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cd.xml"), "cd.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ce.xml"), "ce.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ed.xml"), "ed.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "st.xml"), "st.xml", null);
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "cda.xml"), "cda.xml", null);
for (StructureDefinition sd : context.getStructures()) {
if (!sd.hasSnapshot()) {
System.out.println("generate snapshot for " + sd.getUrl());
context.generateSnapshot(sd, true);
}
}
}
use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method getWorkerContext.
public static IWorkerContext getWorkerContext(String version) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
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;
} catch (Exception e) {
e.printStackTrace();
throw new Error(e);
}
}
use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager in project org.hl7.fhir.core by hapifhir.
the class R3R4ConversionTests method checkLoad.
/*
* Supporting multiple versions at once is a little tricky. We're going to have
* 2 contexts: - an R3 context which is used to read/write R3 instances - an R4
* context which is used to perform the transforms
*
* R3 structure definitions are cloned into R3 context with a modified URL (as
* 3.0/)
*
*/
private void checkLoad() throws IOException, FHIRException, Exception {
if (contextR3 != null)
return;
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
System.out.println("loading R3");
contextR3 = new SimpleWorkerContext();
contextR3.setAllowLoadingDuplicates(true);
contextR3.setOverrideVersionNs("http://hl7.org/fhir/3.0/StructureDefinition");
contextR3.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "3.0.1"), ldr, new String[] {});
System.out.println("loading R4");
contextR4 = new SimpleWorkerContext();
contextR4 = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
contextR4.setCanRunWithoutTerminology(true);
for (StructureDefinition sd : contextR3.allStructures()) {
StructureDefinition sdn = sd.copy();
sdn.getExtension().clear();
contextR4.cacheResource(sdn);
}
for (StructureDefinition sd : contextR4.allStructures()) {
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
contextR3.cacheResource(sd);
StructureDefinition sdn = sd.copy();
sdn.setUrl(sdn.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
sdn.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
contextR3.cacheResource(sdn);
contextR4.cacheResource(sdn);
}
}
contextR3.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
contextR4.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
contextR3.setName("R3");
contextR4.setName("R4");
// contextR4.setValidatorFactory(new InstanceValidatorFactory());
// TODO: this has to be R% now... contextR4.setValidatorFactory(new InstanceValidatorFactory());
System.out.println("loading Maps");
loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R4toR3"));
loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R3toR4"));
System.out.println("loaded");
}
Aggregations