Search in sources :

Example 16 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class JavaEnumerationsGenerator method generate.

public void generate() throws Exception {
    write("package org.hl7.fhir." + jid + ".model;\r\n");
    startMark(version, genDate);
    write("\r\n");
    write("import org.hl7.fhir.instance.model.api.*;\r\n");
    write("import org.hl7.fhir.exceptions.FHIRException;\r\n");
    write("\r\n");
    write("public class Enumerations {\r\n");
    write("\r\n");
    write("// In here: \r\n");
    Map<String, ValueSet> enums = scanForEnums();
    List<String> names = new ArrayList<String>();
    names.addAll(enums.keySet());
    Collections.sort(names);
    for (String n : names) {
        ValueSet vs = enums.get(n);
        write("//   " + n + ": " + vs.getDescription());
        if (vs.hasUserData("usages")) {
            write(vs.getUserData("usages").toString());
        } else {
            write("?null?");
        }
        write("\r\n");
    }
    write("\r\n");
    write("\r\n");
    for (String n : names) {
        ValueSet vs = enums.get(n);
        generateEnum(n, (ValueSet) vs.getUserData("expansion"));
    }
    write("\r\n");
    write("}\r\n");
    write("\r\n");
    flush();
}
Also used : ArrayList(java.util.ArrayList) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 17 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeMedicationMedicationPackageComponent.

protected void composeMedicationMedicationPackageComponent(Complex parent, String parentType, String name, Medication.MedicationPackageComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "package", name, element, index);
    if (element.hasContainer())
        composeCodeableConcept(t, "Medication", "container", element.getContainer(), -1);
    for (int i = 0; i < element.getContent().size(); i++) composeMedicationMedicationPackageContentComponent(t, "Medication", "content", element.getContent().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 18 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class NPMPackageGenerator method buildPackageJson.

private void buildPackageJson(String canonical, PackageType kind, String web, String genDate, ImplementationGuide ig, List<String> fhirVersion) throws FHIRException, IOException {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    if (!ig.hasPackageId())
        b.append("packageId");
    if (!ig.hasVersion())
        b.append("version");
    if (!ig.hasFhirVersion())
        b.append("fhirVersion");
    if (!ig.hasLicense())
        b.append("license");
    for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
        if (!d.hasVersion()) {
            b.append("dependsOn.version(" + d.getUri() + ")");
        }
    }
    JsonObject npm = new JsonObject();
    npm.addProperty("name", ig.getPackageId());
    npm.addProperty("version", ig.getVersion());
    npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
    npm.addProperty("type", kind.getCode());
    if (ig.hasLicense())
        npm.addProperty("license", ig.getLicense().toCode());
    npm.addProperty("canonical", canonical);
    npm.addProperty("url", web);
    if (ig.hasTitle())
        npm.addProperty("title", ig.getTitle());
    if (ig.hasDescription())
        npm.addProperty("description", ig.getDescription() + " (built " + genDate + timezone() + ")");
    if (kind != PackageType.CORE) {
        JsonObject dep = new JsonObject();
        npm.add("dependencies", dep);
        for (String v : fhirVersion) {
            // TODO: fix for multiple versions
            dep.addProperty("hl7.fhir.core", v);
        }
        for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
            dep.addProperty(d.getPackageId(), d.getVersion());
        }
    }
    if (ig.hasPublisher())
        npm.addProperty("author", ig.getPublisher());
    JsonArray m = new JsonArray();
    for (ContactDetail t : ig.getContact()) {
        String email = email(t.getTelecom());
        String url = url(t.getTelecom());
        if (t.hasName() & (email != null || url != null)) {
            JsonObject md = new JsonObject();
            m.add(md);
            md.addProperty("name", t.getName());
            if (email != null)
                md.addProperty("email", email);
            if (url != null)
                md.addProperty("url", url);
        }
    }
    if (m.size() > 0)
        npm.add("maintainers", m);
    if (ig.getManifest().hasRendering())
        npm.addProperty("homepage", ig.getManifest().getRendering());
    JsonObject dir = new JsonObject();
    npm.add("directories", dir);
    dir.addProperty("lib", "package");
    dir.addProperty("example", "example");
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(npm);
    try {
        addFile(Category.RESOURCE, "package.json", json.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
    }
    packageJ = npm;
}
Also used : JsonArray(com.google.gson.JsonArray) ContactDetail(org.hl7.fhir.r4.model.ContactDetail) ImplementationGuideDependsOnComponent(org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent) GsonBuilder(com.google.gson.GsonBuilder) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 19 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class NPMPackageGenerator method loadFiles.

public void loadFiles(String root, File dir, String... noload) throws IOException {
    for (File f : dir.listFiles()) {
        if (!Utilities.existsInList(f.getName(), noload)) {
            if (f.isDirectory()) {
                loadFiles(root, f);
            } else {
                String path = f.getAbsolutePath().substring(root.length() + 1);
                byte[] content = TextFile.fileToBytes(f);
                if (created.contains(path))
                    System.out.println("Duplicate package file " + path);
                else {
                    created.add(path);
                    TarArchiveEntry entry = new TarArchiveEntry(path);
                    entry.setSize(content.length);
                    tar.putArchiveEntry(entry);
                    tar.write(content);
                    tar.closeArchiveEntry();
                }
            }
        }
    }
}
Also used : File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 20 with Package

use of org.hl7.fhir.utilities.graphql.Package 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)

Aggregations

File (java.io.File)25 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 TextFile (org.hl7.fhir.utilities.TextFile)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)15 JsonObject (com.google.gson.JsonObject)12 FileNotFoundException (java.io.FileNotFoundException)11 FileInputStream (java.io.FileInputStream)9 IniFile (org.hl7.fhir.utilities.IniFile)9 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)9 ParseException (java.text.ParseException)8 HashMap (java.util.HashMap)7 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 JsonElement (com.google.gson.JsonElement)5 FileOutputStream (java.io.FileOutputStream)5 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)5 CSFile (org.hl7.fhir.utilities.CSFile)5