Search in sources :

Example 21 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method parseRuleReference.

private void parseRuleReference(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRLexerException {
    StructureMapGroupRuleDependentComponent ref = rule.addDependent();
    ref.setName(lexer.take());
    lexer.token("(");
    boolean done = false;
    while (!done) {
        ref.addVariable(lexer.take());
        done = !lexer.hasToken(",");
        if (!done)
            lexer.next();
    }
    lexer.token(")");
}
Also used : StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent)

Example 22 with StructureMapGroupRuleComponent

use of org.hl7.fhir.r4b.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(true);
        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.dstu3.model.StringType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 23 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method executeGroup.

private void executeGroup(String indent, TransformContext context, StructureMap map, Variables vars, StructureMapGroupComponent group) throws FHIRException {
    log(indent + "Group : " + group.getName());
    // todo: check inputs
    if (group.hasExtends()) {
        ResolvedGroup rg = resolveGroupReference(map, group, group.getExtends());
        executeGroup(indent + " ", context, rg.targetMap, vars, rg.target);
    }
    for (StructureMapGroupRuleComponent r : group.getRule()) {
        executeRule(indent + "  ", context, map, vars, group, r);
    }
}
Also used : StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)

Example 24 with StructureMapGroupRuleComponent

use of org.hl7.fhir.r4b.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(' ');
    b.append(r.getName());
    b.append(" : for ");
    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(" make ");
        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(" make ");
        renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
    }
    if (!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("}\r\n");
        } 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(")");
                }
            }
        }
    }
    renderDoco(b, r.getDocumentation());
    b.append("\r\n");
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)

Example 25 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method analyseGroup.

private void analyseGroup(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapAnalysis result) throws Exception {
    log(indent + "Analyse Group : " + group.getName());
    // todo: extends
    // todo: check inputs
    XhtmlNode tr = result.summary.addTag("tr").setAttribute("class", "diff-title");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    for (StructureMapGroupInputComponent inp : group.getInput()) {
        if (inp.getMode() == StructureMapInputMode.SOURCE)
            noteInput(vars, inp, VariableMode.INPUT, xs);
        if (inp.getMode() == StructureMapInputMode.TARGET)
            noteInput(vars, inp, VariableMode.OUTPUT, xt);
    }
    for (StructureMapGroupRuleComponent r : group.getRule()) {
        analyseRule(indent + "  ", context, map, vars, group, r, result);
    }
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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