Search in sources :

Example 1 with FilesystemPackageCacheManager

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

the class PageProcessor method setDefinitions.

public void setDefinitions(Definitions definitions) throws Exception {
    this.definitions = definitions;
    breadCrumbManager.setDefinitions(definitions);
    TerminologyClient client;
    try {
        client = new TerminologyClientR5(tsServer);
        client.setTimeout(60000);
    } catch (Exception e) {
        System.out.println("Warning @ PageProcessor client initialize: " + e.getLocalizedMessage());
        client = null;
    }
    workerContext = new BuildWorkerContext(definitions, client, definitions.getCodeSystems(), definitions.getValuesets(), conceptMaps, profiles, guides, folders.rootDir);
    workerContext.setDefinitions(definitions);
    workerContext.setLogger(this);
    workerContext.setAllowLoadingDuplicates(true);
    log("Load UTG Terminology", LogMessageType.Process);
    NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
    workerContext.loadFromPackage(utg, new R4ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new UTGLoader(utg.version())));
    log("Load Terminology Cache from " + Utilities.path(folders.rootDir, "vscache"), LogMessageType.Process);
    workerContext.initTS(Utilities.path(folders.rootDir, "vscache"));
    log("  .. loaded", LogMessageType.Process);
    vsValidator = new ValueSetValidator(workerContext, definitions.getVsFixups(), definitions.getStyleExemptions());
    breadCrumbManager.setContext(workerContext);
}
Also used : TerminologyClientR5(org.hl7.fhir.convertors.txClient.TerminologyClientR5) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R4ToR5Loader(org.hl7.fhir.convertors.loaders.R4ToR5Loader) TerminologyClient(org.hl7.fhir.r5.terminologies.TerminologyClient) ValueSetValidator(org.hl7.fhir.definitions.validation.ValueSetValidator) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 2 with FilesystemPackageCacheManager

use of org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager 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;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R2ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2ToR4Loader) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) R2016MayToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2016MayToR4Loader)

Example 3 with FilesystemPackageCacheManager

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

the class PackageVisitor method visitPackages.

public void visitPackages() throws IOException, ParserConfigurationException, SAXException {
    System.out.println("Finding packages");
    pc = new PackageClient(PackageClient.PRIMARY_SERVER);
    pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    Set<String> pidList = getAllPackages();
    System.out.println("Go: " + pidList.size() + " packages");
    for (String pid : pidList) {
        List<String> vList = listVersions(pid);
        if (oldVersions) {
            for (String v : vList) {
                processPackage(pid, v);
            }
        } else if (vList.isEmpty()) {
            System.out.println("No Packages for " + pid);
        } else {
            processPackage(pid, vList.get(vList.size() - 1));
        }
    }
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageClient(org.hl7.fhir.utilities.npm.PackageClient)

Example 4 with FilesystemPackageCacheManager

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

the class Convertor_Factory_40_50Test method setUp.

@BeforeAll
public static void setUp() throws Exception {
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with FilesystemPackageCacheManager

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

the class JavaCoreGenerator method generate.

private void generate(String version, String src, String dest) throws Exception {
    long start = System.currentTimeMillis();
    Date date = new Date();
    String ap = Utilities.path(src);
    System.out.println("Load Configuration from " + ap);
    Configuration config = new Configuration(ap);
    String pid = VersionUtilities.isR4BVer(version) ? "r4b" : "r5";
    String jid = VersionUtilities.isR4BVer(version) ? "r4b" : "r5";
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    System.out.println("Cache: " + pcm.getFolder());
    System.out.println("Load hl7.fhir." + pid + ".core");
    NpmPackage npm = pcm.loadPackage("hl7.fhir." + pid + ".core", version);
    Definitions master = VersionUtilities.isR4BVer(version) ? DefinitionsLoaderR4B.load(npm) : DefinitionsLoaderR5.load(npm);
    master.fix();
    markValueSets(master, config);
    System.out.println("Load hl7.fhir." + pid + ".expansions");
    Definitions expansions = DefinitionsLoaderR5.load(pcm.loadPackage("hl7.fhir." + pid + ".expansions", version));
    System.out.println("Process Expansions");
    updateExpansions(master, expansions);
    System.out.println("Generate Model");
    System.out.println(" .. Constants");
    JavaConstantsGenerator cgen = new JavaConstantsGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "Constants.java")), master, config, date, npm.version(), jid);
    cgen.generate();
    cgen.close();
    System.out.println(" .. Enumerations");
    JavaEnumerationsGenerator egen = new JavaEnumerationsGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "Enumerations.java")), master, config, date, npm.version(), jid);
    egen.generate();
    egen.close();
    JavaFactoryGenerator fgen = new JavaFactoryGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "ResourceFactory.java")), master, config, date, npm.version(), jid);
    JavaTypeGenerator tgen = new JavaTypeGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", "ResourceType.java")), master, config, date, npm.version(), jid);
    JavaParserJsonGenerator jgen = new JavaParserJsonGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "JsonParser.java")), master, config, date, npm.version(), jid);
    JavaParserXmlGenerator xgen = new JavaParserXmlGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "XmlParser.java")), master, config, date, npm.version(), jid);
    JavaParserRdfGenerator rgen = new JavaParserRdfGenerator(new FileOutputStream(Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "formats", "RdfParser.java")), master, config, date, npm.version(), jid);
    if (VersionUtilities.isR4BVer(version)) {
        StructureDefinition sd = master.getStructures().get("http://hl7.org/fhir/StructureDefinition/Element");
        genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && !sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    if (VersionUtilities.isR4BVer(version)) {
        StructureDefinition sd = master.getStructures().get("http://hl7.org/fhir/StructureDefinition/Resource");
        genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.RESOURCE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    for (StructureDefinition sd : master.getStructures().getList()) {
        if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.RESOURCE) {
            if (!Utilities.existsInList(sd.getName(), "Base", "PrimitiveType") && !sd.getName().contains(".") && !sd.getAbstract()) {
                genClass(version, dest, date, config, jid, npm, master, jgen, xgen, rgen, sd);
            }
        }
    }
    System.out.println(" .. Factory");
    fgen.generate();
    fgen.close();
    System.out.println(" .. Types");
    tgen.generate();
    tgen.close();
    System.out.println(" .. JsonParser");
    jgen.generate();
    jgen.close();
    System.out.println(" .. XmlParser");
    xgen.generate();
    xgen.close();
    System.out.println(" .. RdfParser");
    rgen.generate();
    rgen.close();
    System.out.println("Done (" + Long.toString(System.currentTimeMillis() - start) + "ms)");
}
Also used : JavaEnumerationsGenerator(org.hl7.fhir.core.generator.codegen.JavaEnumerationsGenerator) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) JavaTypeGenerator(org.hl7.fhir.core.generator.codegen.JavaTypeGenerator) Configuration(org.hl7.fhir.core.generator.codegen.Configuration) JavaParserRdfGenerator(org.hl7.fhir.core.generator.codegen.JavaParserRdfGenerator) JavaParserJsonGenerator(org.hl7.fhir.core.generator.codegen.JavaParserJsonGenerator) JavaParserXmlGenerator(org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator) Date(java.util.Date) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) JavaFactoryGenerator(org.hl7.fhir.core.generator.codegen.JavaFactoryGenerator) FileOutputStream(java.io.FileOutputStream) JavaConstantsGenerator(org.hl7.fhir.core.generator.codegen.JavaConstantsGenerator)

Aggregations

FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)34 NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)13 IOException (java.io.IOException)9 BeforeAll (org.junit.jupiter.api.BeforeAll)8 FileNotFoundException (java.io.FileNotFoundException)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 Test (org.junit.jupiter.api.Test)5 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 ArrayList (java.util.ArrayList)4 UcumEssenceService (org.fhir.ucum.UcumEssenceService)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)3 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)3 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 R3ToR4Loader (org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader)2