use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromFileJson.
private void loadFromFileJson(InputStream stream, String name, IContextResourceLoader loader, ILoadFilter filter, PackageVersion pi) throws IOException, FHIRException {
Bundle f = null;
try {
if (loader != null)
f = loader.loadBundle(stream, true);
else {
JsonParser json = new JsonParser();
Resource r = json.parse(stream);
if (r instanceof Bundle)
f = (Bundle) r;
else if (filter == null || filter.isOkToLoad(f)) {
cacheResourceFromPackage(r, pi);
}
}
} catch (FHIRFormatError e1) {
throw new org.hl7.fhir.exceptions.FHIRFormatError(e1.getMessage(), e1);
}
if (f != null)
for (BundleEntryComponent e : f.getEntry()) {
if (filter == null || filter.isOkToLoad(e.getResource())) {
String path = loader != null ? loader.getResourcePath(e.getResource()) : null;
if (path != null) {
e.getResource().setUserData("path", path);
}
cacheResourceFromPackage(e.getResource(), pi);
}
}
}
use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromPackageInt.
public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws IOException, FHIRException {
int t = 0;
if (progress) {
System.out.println("Load Package " + pi.name() + "#" + pi.version());
}
if (loadedPackages.contains(pi.id() + "#" + pi.version())) {
return 0;
}
loadedPackages.add(pi.id() + "#" + pi.version());
if ((types == null || types.length == 0) && loader != null) {
types = loader.getTypes();
}
if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad()) {
// can't lazy load R2 because of valueset/codesystem implementation
if (types.length == 0) {
types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
}
for (String s : pi.listResources(types)) {
try {
loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
t++;
} catch (Exception e) {
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
}
}
} else {
if (types.length == 0) {
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" };
}
for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
if (!pri.getFilename().contains("ig-r4")) {
try {
registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version(), pi.dateAsDate()));
t++;
} catch (FHIRException e) {
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
}
}
}
}
for (String s : pi.list("other")) {
binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
}
if (version == null) {
version = pi.version();
}
return t;
}
use of org.hl7.fhir.r4b.context.IWorkerContext.PackageVersion in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromFileJson.
private void loadFromFileJson(InputStream stream, String name, IContextResourceLoader loader, ILoadFilter filter, PackageVersion pi) throws IOException, FHIRException {
Bundle f = null;
try {
if (loader != null)
f = loader.loadBundle(stream, true);
else {
JsonParser json = new JsonParser();
Resource r = json.parse(stream);
if (r instanceof Bundle)
f = (Bundle) r;
else if (filter == null || filter.isOkToLoad(f)) {
cacheResourceFromPackage(r, pi);
}
}
} catch (FHIRFormatError e1) {
throw new org.hl7.fhir.exceptions.FHIRFormatError(e1.getMessage(), e1);
}
if (f != null)
for (BundleEntryComponent e : f.getEntry()) {
if (filter == null || filter.isOkToLoad(e.getResource())) {
String path = loader != null ? loader.getResourcePath(e.getResource()) : null;
if (path != null) {
e.getResource().setUserData("path", path);
}
cacheResourceFromPackage(e.getResource(), pi);
}
}
}
Aggregations