use of org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader in project org.hl7.fhir.core by hapifhir.
the class ExtensionDefinitionGenerator method loadSource.
private List<StructureDefinition> loadSource() throws IOException, FHIRException {
List<StructureDefinition> list = new ArrayList<>();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
if (sourceVersion == FHIRVersion._4_0_0)
context = SimpleWorkerContext.fromPackage(npm);
else if (sourceVersion == FHIRVersion._3_0_1)
context = SimpleWorkerContext.fromPackage(npm, new R3ToR4Loader());
else if (sourceVersion == FHIRVersion._1_4_0)
context = SimpleWorkerContext.fromPackage(npm, new R2016MayToR4Loader());
else if (sourceVersion == FHIRVersion._1_0_2)
context = SimpleWorkerContext.fromPackage(npm, new R2ToR4Loader());
pu = new ProfileUtilities(context, null, null);
for (String fn : npm.listResources("StructureDefinition")) {
list.add((StructureDefinition) loadResource(npm.load("package", fn), sourceVersion));
}
for (StructureDefinition sd : list) if (sd.getName().equals("Extension")) {
extbase = sd;
extv = extbase.getSnapshot().getElement().get(extbase.getSnapshot().getElement().size() - 1);
}
return list;
}
use of org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader 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