Search in sources :

Example 56 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method registerResourceFromPackage.

public void registerResourceFromPackage(CanonicalResourceProxy r, PackageVersion packageInfo) throws FHIRException {
    synchronized (lock) {
        Map<String, ResourceProxy> map = allResourcesById.get(r.getType());
        if (map == null) {
            map = new HashMap<String, ResourceProxy>();
            allResourcesById.put(r.getType(), map);
        }
        if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
            map.put(r.getId(), new ResourceProxy(r));
        }
        String url = r.getUrl();
        if (!allowLoadingDuplicates && hasResource(r.getType(), url)) {
            // spcial workaround for known problems with existing packages
            if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
                return;
            }
            throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
        }
        switch(r.getType()) {
            case "StructureDefinition":
                if ("1.4.0".equals(version)) {
                    StructureDefinition sd = (StructureDefinition) r.getResource();
                    fixOldSD(sd);
                }
                structures.register(r, packageInfo);
                break;
            case "ValueSet":
                valueSets.register(r, packageInfo);
                break;
            case "CodeSystem":
                codeSystems.register(r, packageInfo);
                break;
            case "ImplementationGuide":
                guides.register(r, packageInfo);
                break;
            case "CapabilityStatement":
                capstmts.register(r, packageInfo);
                break;
            case "Measure":
                measures.register(r, packageInfo);
                break;
            case "Library":
                libraries.register(r, packageInfo);
                break;
            case "SearchParameter":
                searchParameters.register(r, packageInfo);
                break;
            case "PlanDefinition":
                plans.register(r, packageInfo);
                break;
            case "OperationDefinition":
                operations.register(r, packageInfo);
                break;
            case "Questionnaire":
                questionnaires.register(r, packageInfo);
                break;
            case "ConceptMap":
                maps.register(r, packageInfo);
                break;
            case "StructureMap":
                transforms.register(r, packageInfo);
                break;
            case "NamingSystem":
                systems.register(r, packageInfo);
                break;
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)

Example 57 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeImplementationGuideImplementationGuideGlobalComponent.

protected void composeImplementationGuideImplementationGuideGlobalComponent(Complex parent, String parentType, String name, ImplementationGuide.ImplementationGuideGlobalComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "global", name, element, index);
    if (element.hasTypeElement())
        composeCode(t, "ImplementationGuide", "type", element.getTypeElement(), -1);
    if (element.hasProfileElement())
        composeCanonical(t, "ImplementationGuide", "profile", element.getProfileElement(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 58 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide 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)

Example 59 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide 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 60 with ImplementationGuide

use of org.hl7.fhir.dstu3.model.ImplementationGuide in project org.hl7.fhir.core by hapifhir.

the class FilesystemPackageCacheManager method fetchTheOldWay.

// ----- the old way, from before package server, while everything gets onto the package server
private InputStreamWithSrc fetchTheOldWay(String id, String v) {
    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 + "#" + v);
    }
    if (url.contains("/ImplementationGuide/")) {
        url = url.substring(0, url.indexOf("/ImplementationGuide/"));
    }
    String pu = Utilities.pathURL(url, "package-list.json");
    String aurl = pu;
    JsonObject json;
    try {
        json = JsonTrackingParser.fetchJson(pu);
    } catch (Exception e) {
        String pv = Utilities.pathURL(url, v, "package.tgz");
        try {
            aurl = pv;
            InputStreamWithSrc src = new InputStreamWithSrc(fetchFromUrlSpecific(pv, false), pv, v);
            return src;
        } catch (Exception e1) {
            throw new FHIRException("Error fetching package directly (" + pv + "), or fetching package list for " + id + " from " + pu + ": " + e1.getMessage(), e1);
        }
    }
    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 (v.equals(JSONUtil.str(vo, "version"))) {
            aurl = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz");
            String u = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz");
            return new InputStreamWithSrc(fetchFromUrlSpecific(u, true), u, v);
        }
    }
    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)

Aggregations

ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)16 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 File (java.io.File)8 JsonObject (com.google.gson.JsonObject)7 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)7 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)6 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 JsonArray (com.google.gson.JsonArray)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)4 ValueSet (org.hl7.fhir.r5.model.ValueSet)4