Search in sources :

Example 66 with Package

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

the class PackageValidator method execute.

private void execute() throws IOException {
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    CachingPackageClient pc = new CachingPackageClient(PackageClient.PRIMARY_SERVER);
    for (PackageInfo t : pc.search(null, null, null, false)) {
        System.out.println("Check Package " + t.getId());
        List<PackageInfo> vl = pc.getVersions(t.getId());
        PackageInfo v = vl.get(vl.size() - 1);
        System.out.println(" v" + v.getVersion());
        try {
            NpmPackage pi = pcm.loadPackage(v.getId(), v.getVersion());
            if (VersionUtilities.isR4Ver(pi.fhirVersion()) || VersionUtilities.isR3Ver(pi.fhirVersion()) || VersionUtilities.isR2Ver(pi.fhirVersion())) {
                for (String n : pi.list("package")) {
                    if (n.endsWith(".json") && !n.equals("ig-r4.json")) {
                        InputStream s = pi.load("package", n);
                        try {
                            parseResource(s, pi.fhirVersion());
                        } catch (Exception e) {
                            System.out.println("  error parsing " + n + " for " + pi.fhirVersion() + ": " + e.getMessage());
                        }
                    }
                }
            } else {
                System.out.println("  Unsupported FHIR version " + pi.fhirVersion());
            }
        } catch (Exception e) {
            System.out.println("  Error - no FHIR version");
        }
    }
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) PackageInfo(org.hl7.fhir.utilities.npm.PackageInfo) InputStream(java.io.InputStream) CachingPackageClient(org.hl7.fhir.utilities.npm.CachingPackageClient) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 67 with Package

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

the class UtilitiesXTests method loadTestResource.

public static String loadTestResource(String... paths) throws IOException {
    if (new File("../../fhir-test-cases").exists() && isTryToLoadFromFileSystem()) {
        String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
        // ok, we'll resolve this locally
        return TextFile.fileToString(new File(n));
    } else {
        // resolve from the package
        String contents;
        String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
        try (InputStream inputStream = UtilitiesXTests.class.getResourceAsStream(classpath)) {
            if (inputStream == null) {
                throw new IOException("Can't find file on classpath: " + classpath);
            }
            contents = IOUtils.toString(inputStream, java.nio.charset.StandardCharsets.UTF_8);
        }
        return contents;
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 68 with Package

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

the class PackageVisitor method getAllPackages.

private Set<String> getAllPackages() throws IOException, ParserConfigurationException, SAXException {
    Set<String> list = new HashSet<>();
    for (PackageInfo i : pc.search(null, null, null, false)) {
        list.add(i.getId());
    }
    JsonObject json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json");
    for (JsonObject ig : JSONUtil.objects(json, "guides")) {
        list.add(JSONUtil.str(ig, "npm-name"));
    }
    json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/package-feeds.json");
    for (JsonObject feed : JSONUtil.objects(json, "feeds")) {
        processFeed(list, JSONUtil.str(feed, "url"));
    }
    return list;
}
Also used : PackageInfo(org.hl7.fhir.utilities.npm.PackageInfo) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

Example 69 with Package

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

the class PackageVisitor method processPackage.

private void processPackage(String pid, String v) throws IOException {
    NpmPackage npm = null;
    String fv = null;
    try {
        npm = pcm.loadPackage(pid, v);
        fv = npm.fhirVersion();
    } catch (Throwable e) {
        System.out.println("Unable to process: " + pid + "#" + v + ": " + e.getMessage());
    }
    int c = 0;
    if (fv != null && (versions.isEmpty() || versions.contains(fv))) {
        for (String type : resourceTypes) {
            for (String s : npm.listResources(type)) {
                c++;
                processor.processResource(pid + "#" + v, fv, type, TextFile.streamToBytes(npm.load("package", s)));
            }
        }
    }
    System.out.println("Processed: " + pid + "#" + v + ": " + c + " resources");
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 70 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, Date date, ImplementationGuide ig, List<String> fhirVersion, boolean notForPublication) throws FHIRException, IOException {
    String dtHuman = new SimpleDateFormat("EEE, MMM d, yyyy HH:mmZ", new Locale("en", "US")).format(date);
    String dt = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
    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());
    igVersion = ig.getVersion();
    npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
    npm.addProperty("type", kind.getCode());
    npm.addProperty("date", dt);
    if (ig.hasLicense()) {
        npm.addProperty("license", ig.getLicense().toCode());
    }
    npm.addProperty("canonical", canonical);
    if (notForPublication) {
        npm.addProperty("notForPublication", true);
    }
    npm.addProperty("url", web);
    if (ig.hasTitle()) {
        npm.addProperty("title", ig.getTitle());
    }
    if (ig.hasDescription()) {
        npm.addProperty("description", ig.getDescription() + " (built " + dtHuman + timezone() + ")");
    }
    JsonArray vl = new JsonArray();
    npm.add("fhirVersions", vl);
    for (String v : fhirVersion) {
        vl.add(new JsonPrimitive(v));
    }
    if (kind != PackageType.CORE) {
        JsonObject dep = new JsonObject();
        npm.add("dependencies", dep);
        for (String v : fhirVersion) {
            String vp = packageForVersion(v);
            if (vp != null) {
                dep.addProperty(vp, 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;
    packageManifest = new JsonObject();
    packageManifest.addProperty("version", ig.getVersion());
    packageManifest.addProperty("fhirVersion", fhirVersion.toString());
    packageManifest.addProperty("date", dt);
    packageManifest.addProperty("name", ig.getPackageId());
}
Also used : Locale(java.util.Locale) JsonArray(com.google.gson.JsonArray) ContactDetail(org.hl7.fhir.r4b.model.ContactDetail) ImplementationGuideDependsOnComponent(org.hl7.fhir.r4b.model.ImplementationGuide.ImplementationGuideDependsOnComponent) JsonPrimitive(com.google.gson.JsonPrimitive) 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) SimpleDateFormat(java.text.SimpleDateFormat)

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