use of org.hl7.fhir.r4b.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method getWorkerContext.
public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage, IWorkerContext.IContextResourceLoader loader) throws Exception {
SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage, loader);
TerminologyCache.setCacheErrors(true);
return swc;
}
use of org.hl7.fhir.r4b.context.SimpleWorkerContext 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");
}
use of org.hl7.fhir.r4b.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.
the class IgLoaderTests method testFailIfInvalidFHIRVersion.
@Test
public void testFailIfInvalidFHIRVersion() throws IOException {
IgLoader igLoader = Mockito.spy(new IgLoader(filesystemPackageCacheManager, simpleWorkerContext, "4.0.1"));
Exception exception = assertThrows(FHIRException.class, () -> {
List<ImplementationGuide> igs = Collections.emptyList();
igLoader.loadIg(igs, Collections.emptyMap(), "[0.1.2]" + DUMMY_PATH, false);
});
assertLinesMatch(Arrays.asList(".*Unsupported FHIR Version.*"), Arrays.asList(exception.getMessage()));
}
use of org.hl7.fhir.r4b.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method context.
public static IWorkerContext context(String version) {
if ("4.5.0".equals(version)) {
// temporary work around
version = "4.4.0";
}
String v = VersionUtilities.getMajMin(version);
if (fcontexts == null) {
fcontexts = new HashMap<>();
}
if (!fcontexts.containsKey(v)) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = SimpleWorkerContext.fromPackage(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);
fcontexts.put(v, fcontext);
} catch (Exception e) {
e.printStackTrace();
throw new Error(e);
}
}
return fcontexts.get(v);
}
use of org.hl7.fhir.r4b.context.SimpleWorkerContext in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method fromClassPath.
public static SimpleWorkerContext fromClassPath(String name) throws IOException, FHIRException {
InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
SimpleWorkerContext res = new SimpleWorkerContext();
res.loadFromStream(s, null);
return res;
}
Aggregations