Search in sources :

Example 71 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 72 with Package

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

the class RdfParser method composeMedication.

protected void composeMedication(Complex parent, String parentType, String name, Medication element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Medication", name, element, index);
    if (element.hasCode())
        composeCodeableConcept(t, "Medication", "code", element.getCode(), -1);
    if (element.hasIsBrandElement())
        composeBoolean(t, "Medication", "isBrand", element.getIsBrandElement(), -1);
    if (element.hasManufacturer())
        composeReference(t, "Medication", "manufacturer", element.getManufacturer(), -1);
    if (element.hasProduct())
        composeMedicationMedicationProductComponent(t, "Medication", "product", element.getProduct(), -1);
    if (element.hasPackage())
        composeMedicationMedicationPackageComponent(t, "Medication", "package", element.getPackage(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 73 with Package

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

the class RdfParser method composeImplementationGuide.

protected void composeImplementationGuide(Complex parent, String parentType, String name, ImplementationGuide element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "ImplementationGuide", name, element, index);
    if (element.hasUrlElement())
        composeUri(t, "ImplementationGuide", "url", element.getUrlElement(), -1);
    if (element.hasVersionElement())
        composeString(t, "ImplementationGuide", "version", element.getVersionElement(), -1);
    if (element.hasNameElement())
        composeString(t, "ImplementationGuide", "name", element.getNameElement(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "ImplementationGuide", "status", element.getStatusElement(), -1);
    if (element.hasExperimentalElement())
        composeBoolean(t, "ImplementationGuide", "experimental", element.getExperimentalElement(), -1);
    if (element.hasPublisherElement())
        composeString(t, "ImplementationGuide", "publisher", element.getPublisherElement(), -1);
    for (int i = 0; i < element.getContact().size(); i++) composeImplementationGuideImplementationGuideContactComponent(t, "ImplementationGuide", "contact", element.getContact().get(i), i);
    if (element.hasDateElement())
        composeDateTime(t, "ImplementationGuide", "date", element.getDateElement(), -1);
    if (element.hasDescriptionElement())
        composeString(t, "ImplementationGuide", "description", element.getDescriptionElement(), -1);
    for (int i = 0; i < element.getUseContext().size(); i++) composeCodeableConcept(t, "ImplementationGuide", "useContext", element.getUseContext().get(i), i);
    if (element.hasCopyrightElement())
        composeString(t, "ImplementationGuide", "copyright", element.getCopyrightElement(), -1);
    if (element.hasFhirVersionElement())
        composeId(t, "ImplementationGuide", "fhirVersion", element.getFhirVersionElement(), -1);
    for (int i = 0; i < element.getDependency().size(); i++) composeImplementationGuideImplementationGuideDependencyComponent(t, "ImplementationGuide", "dependency", element.getDependency().get(i), i);
    for (int i = 0; i < element.getPackage().size(); i++) composeImplementationGuideImplementationGuidePackageComponent(t, "ImplementationGuide", "package", element.getPackage().get(i), i);
    for (int i = 0; i < element.getGlobal().size(); i++) composeImplementationGuideImplementationGuideGlobalComponent(t, "ImplementationGuide", "global", element.getGlobal().get(i), i);
    for (int i = 0; i < element.getBinary().size(); i++) composeUri(t, "ImplementationGuide", "binary", element.getBinary().get(i), i);
    if (element.hasPage())
        composeImplementationGuideImplementationGuidePageComponent(t, "ImplementationGuide", "page", element.getPage(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 74 with Package

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

the class FilesystemPackageCacheManager method fetchVersionTheOldWay.

// ---------- Current Build SubSystem --------------------------------------------------------------------------------------
private String fetchVersionTheOldWay(String id) throws IOException {
    String url = getUrlForPackage(id);
    if (url == null) {
        try {
            url = getPackageUrlFromBuildList(id);
        } catch (Exception e) {
            url = null;
        }
    }
    if (url == null) {
        throw new FHIRException("Unable to resolve package id " + id);
    }
    String pu = Utilities.pathURL(url, "package-list.json");
    JsonObject json = JsonTrackingParser.fetchJson(pu);
    if (!id.equals(JSONUtil.str(json, "package-id")))
        throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JSONUtil.str(json, "package-id"));
    for (JsonElement e : json.getAsJsonArray("list")) {
        JsonObject vo = (JsonObject) e;
        if (JSONUtil.bool(vo, "current")) {
            return JSONUtil.str(vo, "version");
        }
    }
    return null;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 75 with Package

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

the class FilesystemPackageCacheManager method removePackage.

// ========================= Utilities ============================================================================
/**
 * Remove a particular package from the cache
 *
 * @param id
 * @param ver
 * @throws IOException
 */
public void removePackage(String id, String ver) throws IOException {
    new CacheLock(id + "#" + ver).doWithLock(() -> {
        String f = Utilities.path(cacheFolder, id + "#" + ver);
        File ff = new File(f);
        if (ff.exists()) {
            Utilities.clearDirectory(f);
            IniFile ini = new IniFile(Utilities.path(cacheFolder, "packages.ini"));
            ini.removeProperty("packages", id + "#" + ver);
            ini.save();
            ff.delete();
        }
        return null;
    });
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) RandomAccessFile(java.io.RandomAccessFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

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