Search in sources :

Example 31 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeStructureMapStructureMapGroupRuleTargetParameterComponent.

protected void composeStructureMapStructureMapGroupRuleTargetParameterComponent(Complex parent, String parentType, String name, StructureMap.StructureMapGroupRuleTargetParameterComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "parameter", name, element, index);
    if (element.hasValue())
        composeType(t, "StructureMap", "value", element.getValue(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 32 with StructureMap

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

Example 33 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method findTransformsforSource.

public List<StructureMap> findTransformsforSource(String url) {
    List<StructureMap> res = new ArrayList<StructureMap>();
    for (StructureMap map : listTransforms()) {
        boolean match = false;
        boolean ok = true;
        for (StructureMapStructureComponent t : map.getStructure()) {
            if (t.getMode() == StructureMapModelMode.SOURCE) {
                match = match || t.getUrl().equals(url);
                ok = ok && t.getUrl().equals(url);
            }
        }
        if (match && ok)
            res.add(map);
    }
    return res;
}
Also used : StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureMapStructureComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapStructureComponent) ArrayList(java.util.ArrayList)

Example 34 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method fetchResourceWithException.

@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(String cls, String uri, CanonicalResource source) throws FHIRException {
    if (uri == null) {
        return null;
    }
    if ("StructureDefinition".equals(cls)) {
        uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
    }
    synchronized (lock) {
        String version = null;
        if (uri.contains("|")) {
            version = uri.substring(uri.lastIndexOf("|") + 1);
            uri = uri.substring(0, uri.lastIndexOf("|"));
        }
        if (uri.contains("#")) {
            uri = uri.substring(0, uri.indexOf("#"));
        }
        if (cls == null || "Resource".equals(cls)) {
            if (structures.has(uri)) {
                return (T) structures.get(uri, version);
            }
            if (guides.has(uri)) {
                return (T) guides.get(uri, version);
            }
            if (capstmts.has(uri)) {
                return (T) capstmts.get(uri, version);
            }
            if (measures.has(uri)) {
                return (T) measures.get(uri, version);
            }
            if (libraries.has(uri)) {
                return (T) libraries.get(uri, version);
            }
            if (valueSets.has(uri)) {
                return (T) valueSets.get(uri, version);
            }
            if (codeSystems.has(uri)) {
                return (T) codeSystems.get(uri, version);
            }
            if (operations.has(uri)) {
                return (T) operations.get(uri, version);
            }
            if (searchParameters.has(uri)) {
                return (T) searchParameters.get(uri, version);
            }
            if (plans.has(uri)) {
                return (T) plans.get(uri, version);
            }
            if (maps.has(uri)) {
                return (T) maps.get(uri, version);
            }
            if (transforms.has(uri)) {
                return (T) transforms.get(uri, version);
            }
            if (questionnaires.has(uri)) {
                return (T) questionnaires.get(uri, version);
            }
            for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
                for (ResourceProxy r : rt.values()) {
                    if (uri.equals(r.getUrl())) {
                        return (T) r.getResource();
                    }
                }
            }
        } else if ("ImplementationGuide".equals(cls)) {
            return (T) guides.get(uri, version);
        } else if ("CapabilityStatement".equals(cls)) {
            return (T) capstmts.get(uri, version);
        } else if ("Measure".equals(cls)) {
            return (T) measures.get(uri, version);
        } else if ("Library".equals(cls)) {
            return (T) libraries.get(uri, version);
        } else if ("StructureDefinition".equals(cls)) {
            return (T) structures.get(uri, version);
        } else if ("StructureMap".equals(cls)) {
            return (T) transforms.get(uri, version);
        } else if ("ValueSet".equals(cls)) {
            return (T) valueSets.get(uri, version);
        } else if ("CodeSystem".equals(cls)) {
            return (T) codeSystems.get(uri, version);
        } else if ("ConceptMap".equals(cls)) {
            return (T) maps.get(uri, version);
        } else if ("PlanDefinition".equals(cls)) {
            return (T) plans.get(uri, version);
        } else if ("OperationDefinition".equals(cls)) {
            OperationDefinition od = operations.get(uri, version);
            return (T) od;
        } else if ("Questionnaire.class".equals(cls)) {
            return (T) questionnaires.get(uri, version);
        } else if ("SearchParameter.class".equals(cls)) {
            SearchParameter res = searchParameters.get(uri, version);
            return (T) res;
        }
        if ("CodeSystem".equals(cls) && codeSystems.has(uri)) {
            return (T) codeSystems.get(uri, version);
        }
        if ("ValueSet".equals(cls) && valueSets.has(uri)) {
            return (T) valueSets.get(uri, version);
        }
        if ("Questionnaire".equals(cls)) {
            return (T) questionnaires.get(uri, version);
        }
        if (cls == null) {
            if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
                return null;
            }
            // it might be a special URL.
            if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
                // findTxValueSet(uri);
                Resource res = null;
                if (res != null) {
                    return (T) res;
                }
            }
            return null;
        }
        if (supportedCodeSystems.contains(uri)) {
            return null;
        }
        throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
    }
}
Also used : CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) SearchParameter(org.hl7.fhir.r4b.model.SearchParameter) OperationDefinition(org.hl7.fhir.r4b.model.OperationDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy)

Example 35 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeDependency.

private void executeDependency(String indent, TransformContext context, StructureMap map, Variables vin, StructureMapGroupComponent group, StructureMapGroupRuleDependentComponent dependent) throws FHIRException {
    ResolvedGroup rg = resolveGroupReference(map, group, dependent.getName());
    if (rg.target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(rg.target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StringType rdp = dependent.getVariable().get(i);
        String var = rdp.asStringValue();
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var);
        if (// * once source, always source. but target can be treated as source at user convenient
        vv == null && mode == VariableMode.INPUT)
            vv = vin.get(VariableMode.OUTPUT, var);
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' named as '" + var + "' has no value (vars = " + vin.summary() + ")");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, rg.targetMap, v, rg.target, false);
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)69 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 StructureMap (org.hl7.fhir.r4b.model.StructureMap)13 StructureMap (org.hl7.fhir.r5.model.StructureMap)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 StructureMap (org.hl7.fhir.r4.model.StructureMap)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)10 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)9 StructureMap (org.hl7.fhir.dstu3.model.StructureMap)8 File (java.io.File)7 UriType (org.hl7.fhir.r4.model.UriType)7 Test (org.junit.jupiter.api.Test)7 Base (org.hl7.fhir.dstu3.model.Base)6 TextFile (org.hl7.fhir.utilities.TextFile)6 FileOutputStream (java.io.FileOutputStream)5