Search in sources :

Example 1 with PackageResourceInformation

use of org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation in project kindling by HL7.

the class BuildWorkerContext method loadFromPackageInt.

public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
    int t = 0;
    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();
    }
    for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
        try {
            registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version()));
            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) PackageResourceLoader(org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader) PackageVersion(org.hl7.fhir.r5.context.IWorkerContext.PackageVersion) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with PackageResourceInformation

use of org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method loadFromPackageInt.

public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, 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()));
                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)) {
            try {
                registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version()));
                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 3 with PackageResourceInformation

use of org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR3.

private Map<String, CanonicalResource> loadPackageR3(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_30_50.convertResource(new org.hl7.fhir.dstu3.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 4 with PackageResourceInformation

use of org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR4.

private Map<String, CanonicalResource> loadPackageR4(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_40_50.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 5 with PackageResourceInformation

use of org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR2.

private Map<String, CanonicalResource> loadPackageR2(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_10_50.convertResource(new org.hl7.fhir.dstu2.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Aggregations

PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)3 NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 PackageVersion (org.hl7.fhir.r5.context.IWorkerContext.PackageVersion)1 PackageResourceLoader (org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader)1