Search in sources :

Example 11 with PackageVersion

use of org.hl7.fhir.r5.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);
            }
        }
}
Also used : BundleEntryComponent(org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4b.model.Bundle) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) JsonParser(org.hl7.fhir.r4b.formats.JsonParser)

Example 12 with PackageVersion

use of org.hl7.fhir.r5.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;
}
Also used : PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 13 with PackageVersion

use of org.hl7.fhir.r5.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);
            }
        }
}
Also used : BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 PackageVersion (org.hl7.fhir.r5.context.IWorkerContext.PackageVersion)3 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)2 ResourceProxy (org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)2 CanonicalResourceProxy (org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy)2 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2 ValueSet (org.hl7.fhir.r4b.model.ValueSet)2 CanonicalResourceProxy (org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy)2 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 ValueSet (org.hl7.fhir.r5.model.ValueSet)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1