Search in sources :

Example 26 with PackageInfo

use of org.hl7.fhir.utilities.npm.PackageInfo 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 27 with PackageInfo

use of org.hl7.fhir.utilities.npm.PackageInfo 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 28 with PackageInfo

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

the class PackageClient method search.

public List<PackageInfo> search(String name, String canonical, String fhirVersion, boolean preRelease) throws IOException {
    CommaSeparatedStringBuilder params = new CommaSeparatedStringBuilder("&");
    if (!Utilities.noString(name)) {
        params.append("name=" + name);
    }
    if (!Utilities.noString(canonical)) {
        params.append("canonical=" + canonical);
    }
    if (!Utilities.noString(fhirVersion)) {
        params.append("fhirversion=" + fhirVersion);
    }
    if (preRelease) {
        params.append("prerelease=" + preRelease);
    }
    List<PackageInfo> res = new ArrayList<>();
    try {
        JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?") + params.toString());
        for (JsonElement e : json) {
            JsonObject obj = (JsonObject) e;
            res.add(new PackageInfo(JSONUtil.str(obj, "Name", "name"), JSONUtil.str(obj, "Version", "version"), JSONUtil.str(obj, "FhirVersion", "fhirVersion"), JSONUtil.str(obj, "Description", "description"), JSONUtil.str(obj, "url"), JSONUtil.str(obj, "canonical"), address));
        }
    } catch (IOException e1) {
    }
    return res;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 29 with PackageInfo

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

the class CachingPackageClientTests method testVersionsNone.

@Test
public void testVersionsNone() throws IOException {
    CachingPackageClient client = new CachingPackageClient(CachingPackageClientTests.SERVER1);
    List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3X");
    Assertions.assertTrue(matches.size() == 0);
}
Also used : PackageInfo(org.hl7.fhir.utilities.npm.PackageInfo) CachingPackageClient(org.hl7.fhir.utilities.npm.CachingPackageClient) Test(org.junit.jupiter.api.Test)

Example 30 with PackageInfo

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

the class CachingPackageClientTests method testVersions2.

@Test
public void testVersions2() throws IOException {
    CachingPackageClient client = new CachingPackageClient(CachingPackageClientTests.SERVER2);
    List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3");
    for (PackageInfo pi : matches) {
        System.out.println(pi.toString());
    }
    Assertions.assertTrue(matches.size() == 0);
}
Also used : PackageInfo(org.hl7.fhir.utilities.npm.PackageInfo) CachingPackageClient(org.hl7.fhir.utilities.npm.CachingPackageClient) Test(org.junit.jupiter.api.Test)

Aggregations

PackageInfo (org.hl7.fhir.utilities.npm.PackageInfo)12 CachingPackageClient (org.hl7.fhir.utilities.npm.CachingPackageClient)11 CodeType (org.hl7.fhir.r5.model.CodeType)10 Test (org.junit.jupiter.api.Test)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 ArrayList (java.util.ArrayList)6 ValueSetComposeComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent)5 File (java.io.File)4 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)4 FileInputStream (java.io.FileInputStream)3 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 XmlParser (org.hl7.fhir.r5.formats.XmlParser)3 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)3 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2