Search in sources :

Example 31 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method renderRule.

private static void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) {
    for (int i = 0; i < indent; i++) b.append(' ');
    boolean canBeAbbreviated = checkisSimple(r);
    boolean first = true;
    for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
        if (first)
            first = false;
        else
            b.append(", ");
        renderSource(b, rs, canBeAbbreviated);
    }
    if (r.getTarget().size() > 1) {
        b.append(" -> ");
        first = true;
        for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
            if (first)
                first = false;
            else
                b.append(", ");
            if (RENDER_MULTIPLE_TARGETS_ONELINE)
                b.append(' ');
            else {
                b.append("\r\n");
                for (int i = 0; i < indent + 4; i++) b.append(' ');
            }
            renderTarget(b, rt, false);
        }
    } else if (r.hasTarget()) {
        b.append(" -> ");
        renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
    }
    if (r.hasRule()) {
        b.append(" then {\r\n");
        renderDoco(b, r.getDocumentation());
        for (StructureMapGroupRuleComponent ir : r.getRule()) {
            renderRule(b, ir, indent + 2);
        }
        for (int i = 0; i < indent; i++) b.append(' ');
        b.append("}");
    } else {
        if (r.hasDependent()) {
            b.append(" then ");
            first = true;
            for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(rd.getName());
                b.append("(");
                boolean ifirst = true;
                for (StringType rdp : rd.getVariable()) {
                    if (ifirst)
                        ifirst = false;
                    else
                        b.append(", ");
                    b.append(rdp.asStringValue());
                }
                b.append(")");
            }
        }
    }
    if (r.hasName()) {
        String n = ntail(r.getName());
        if (!n.startsWith("\""))
            n = "\"" + n + "\"";
        if (!matchesName(n, r.getSource())) {
            b.append(" ");
            b.append(n);
        }
    }
    b.append(";");
    renderDoco(b, r.getDocumentation());
    b.append("\r\n");
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)

Example 32 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method parseTarget.

private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
    StructureMapGroupRuleTargetComponent target = rule.addTarget();
    String start = lexer.take();
    if (lexer.hasToken(".")) {
        target.setContext(start);
        target.setContextType(StructureMapContextType.VARIABLE);
        start = null;
        lexer.token(".");
        target.setElement(lexer.take());
    }
    String name;
    boolean isConstant = false;
    if (lexer.hasToken("=")) {
        if (start != null)
            target.setContext(start);
        lexer.token("=");
        isConstant = lexer.isConstant();
        name = lexer.take();
    } else
        name = start;
    if ("(".equals(name)) {
        // inline fluentpath expression
        target.setTransform(StructureMapTransform.EVALUATE);
        ExpressionNode node = fpe.parse(lexer);
        target.setUserData(MAP_EXPRESSION, node);
        target.addParameter().setValue(new StringType(node.toString()));
        lexer.token(")");
    } else if (lexer.hasToken("(")) {
        target.setTransform(StructureMapTransform.fromCode(name));
        lexer.token("(");
        if (target.getTransform() == StructureMapTransform.EVALUATE) {
            parseParameter(target, lexer);
            lexer.token(",");
            ExpressionNode node = fpe.parse(lexer);
            target.setUserData(MAP_EXPRESSION, node);
            target.addParameter().setValue(new StringType(node.toString()));
        } else {
            while (!lexer.hasToken(")")) {
                parseParameter(target, lexer);
                if (!lexer.hasToken(")"))
                    lexer.token(",");
            }
        }
        lexer.token(")");
    } else if (name != null) {
        target.setTransform(StructureMapTransform.COPY);
        if (!isConstant) {
            String id = name;
            while (lexer.hasToken(".")) {
                id = id + lexer.take() + lexer.take();
            }
            target.addParameter().setValue(new IdType(id));
        } else
            target.addParameter().setValue(readConstant(name, lexer));
    }
    if (lexer.hasToken("as")) {
        lexer.take();
        target.setVariable(lexer.take());
    }
    while (Utilities.existsInList(lexer.getCurrent(), "first", "last", "share", "collate")) {
        if (lexer.getCurrent().equals("share")) {
            target.addListMode(StructureMapTargetListMode.SHARE);
            lexer.next();
            target.setListRuleId(lexer.take());
        } else {
            if (lexer.getCurrent().equals("first"))
                target.addListMode(StructureMapTargetListMode.FIRST);
            else
                target.addListMode(StructureMapTargetListMode.LAST);
            lexer.next();
        }
    }
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.r4.model.IdType)

Example 33 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method ruleToString.

public static String ruleToString(StructureMapGroupRuleComponent r) {
    StringBuilder b = new StringBuilder();
    renderRule(b, r, 0);
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 34 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method executeRule.

private void executeRule(String indent, TransformContext context, StructureMap map, Variables vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule) throws Exception {
    log(indent + "rule : " + rule.getName());
    Variables srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new Exception("not handled yet");
    List<Variables> source = analyseSource(context, srcVars, rule.getSource().get(0));
    if (source != null) {
        for (Variables v : source) {
            for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
                processTarget(context, v, map, t);
            }
            if (rule.hasRule()) {
                for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
                    executeRule(indent + "  ", context, map, v, group, childrule);
                }
            } else if (rule.hasDependent()) {
                for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
                    executeDependency(indent + "  ", context, map, v, group, dependent);
                }
            }
        }
    }
}
Also used : StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent) FHIRLexerException(org.hl7.fhir.dstu2016may.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)

Example 35 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method renderRule.

private void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) throws FHIRException {
    for (int i = 0; i < indent; i++) b.append(' ');
    b.append(r.getName());
    b.append(": for ");
    boolean first = true;
    for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
        if (first)
            first = false;
        else
            b.append(", ");
        renderSource(b, rs);
    }
    if (r.getTarget().size() > 1) {
        b.append(" make ");
        first = true;
        for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append("\r\n");
            for (int i = 0; i < indent + 4; i++) b.append(' ');
            renderTarget(b, rt);
        }
    } else if (r.hasTarget()) {
        b.append(" make ");
        renderTarget(b, r.getTarget().get(0));
    }
    if (r.hasRule()) {
        b.append(" then {");
        renderDoco(b, r.getDocumentation());
        for (int i = 0; i < indent; i++) b.append(' ');
        b.append("}\r\n");
    } else {
        if (r.hasDependent()) {
            first = true;
            for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                b.append(rd.getName());
                b.append("(");
                boolean ifirst = true;
                for (StringType rdp : rd.getVariable()) {
                    if (ifirst)
                        ifirst = false;
                    else
                        b.append(", ");
                    b.append(rd.getVariable());
                }
            }
        }
        renderDoco(b, r.getDocumentation());
        b.append("\r\n");
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)9 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)7 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)7 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent)4 StructureMapGroupRuleTargetComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 StructureMapGroupRuleComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)3 StringType (org.hl7.fhir.dstu3.model.StringType)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StringType (org.hl7.fhir.r4.model.StringType)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent)3 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)2 StringType (org.hl7.fhir.dstu2016may.model.StringType)2 StructureMapGroupRuleSourceComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent)2 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)2 StructureMapGroupInputComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent)2 StructureMapGroupRuleSourceComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleSourceComponent)2