Search in sources :

Example 11 with StructureMap

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

the class RdfParser method composeStructureMapStructureMapGroupRuleDependentComponent.

protected void composeStructureMapStructureMapGroupRuleDependentComponent(Complex parent, String parentType, String name, StructureMap.StructureMapGroupRuleDependentComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "dependent", name, element, index);
    if (element.hasNameElement())
        composeId(t, "StructureMap", "name", element.getNameElement(), -1);
    for (int i = 0; i < element.getVariable().size(); i++) composeString(t, "StructureMap", "variable", element.getVariable().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 12 with StructureMap

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

the class RdfParser method composeStructureMapStructureMapGroupRuleTargetComponent.

protected void composeStructureMapStructureMapGroupRuleTargetComponent(Complex parent, String parentType, String name, StructureMap.StructureMapGroupRuleTargetComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "target", name, element, index);
    if (element.hasContextElement())
        composeId(t, "StructureMap", "context", element.getContextElement(), -1);
    if (element.hasContextTypeElement())
        composeEnum(t, "StructureMap", "contextType", element.getContextTypeElement(), -1);
    if (element.hasElementElement())
        composeString(t, "StructureMap", "element", element.getElementElement(), -1);
    if (element.hasVariableElement())
        composeId(t, "StructureMap", "variable", element.getVariableElement(), -1);
    for (int i = 0; i < element.getListMode().size(); i++) composeEnum(t, "StructureMap", "listMode", element.getListMode().get(i), i);
    if (element.hasListRuleIdElement())
        composeId(t, "StructureMap", "listRuleId", element.getListRuleIdElement(), -1);
    if (element.hasTransformElement())
        composeEnum(t, "StructureMap", "transform", element.getTransformElement(), -1);
    for (int i = 0; i < element.getParameter().size(); i++) composeStructureMapStructureMapGroupRuleTargetParameterComponent(t, "StructureMap", "parameter", element.getParameter().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 13 with StructureMap

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

the class RdfParser method composeStructureMapStructureMapGroupInputComponent.

protected void composeStructureMapStructureMapGroupInputComponent(Complex parent, String parentType, String name, StructureMap.StructureMapGroupInputComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "input", name, element, index);
    if (element.hasNameElement())
        composeId(t, "StructureMap", "name", element.getNameElement(), -1);
    if (element.hasTypeElement())
        composeString(t, "StructureMap", "type", element.getTypeElement(), -1);
    if (element.hasModeElement())
        composeEnum(t, "StructureMap", "mode", element.getModeElement(), -1);
    if (element.hasDocumentationElement())
        composeString(t, "StructureMap", "documentation", element.getDocumentationElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 14 with StructureMap

use of org.hl7.fhir.dstu2016may.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.dstu2016may.formats.RdfGenerator.Complex)

Example 15 with StructureMap

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

the class StructureMapUtilities method runTransform.

private Base runTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, Variables vars) throws FHIRException {
    switch(tgt.getTransform()) {
        case CREATE:
            return ResourceFactory.createResourceOrType(getParamString(vars, tgt.getParameter().get(0)));
        case COPY:
            return getParam(vars, tgt.getParameter().get(0));
        case EVALUATE:
            ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
            if (expr == null) {
                expr = fpe.parse(getParamString(vars, tgt.getParameter().get(1)));
                tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
            }
            List<Base> v = fpe.evaluate(null, null, getParam(vars, tgt.getParameter().get(0)), expr);
            if (v.size() != 1)
                throw new FHIRException("evaluation of " + expr.toString() + " returned " + Integer.toString(v.size()) + " objects");
            return v.get(0);
        case TRUNCATE:
            String src = getParamString(vars, tgt.getParameter().get(0));
            String len = getParamString(vars, tgt.getParameter().get(1));
            if (Utilities.isInteger(len)) {
                int l = Integer.parseInt(len);
                if (src.length() > l)
                    src = src.substring(0, l);
            }
            return new StringType(src);
        case ESCAPE:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case CAST:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case APPEND:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case TRANSLATE:
            return translate(context, map, vars, tgt.getParameter());
        case REFERENCE:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case DATEOP:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case UUID:
            return new IdType(UUID.randomUUID().toString());
        case POINTER:
            Base b = getParam(vars, tgt.getParameter().get(0));
            if (b instanceof Resource)
                return new UriType("urn:uuid:" + ((Resource) b).getId());
            else
                throw new FHIRException("Transform engine cannot point at an element of type " + b.fhirType());
        default:
            throw new Error("Transform Unknown: " + tgt.getTransform().toCode());
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) Resource(org.hl7.fhir.dstu2016may.model.Resource) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu2016may.model.Base) IdType(org.hl7.fhir.dstu2016may.model.IdType) UriType(org.hl7.fhir.dstu2016may.model.UriType)

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