Search in sources :

Example 36 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();
    target.setContext(lexer.take());
    if (lexer.hasToken(".")) {
        lexer.token(".");
        target.setElement(lexer.take());
    }
    if (lexer.hasToken("=")) {
        lexer.token("=");
        boolean isConstant = lexer.isConstant(true);
        String name = lexer.take();
        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 {
            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", "only_one")) {
        if (lexer.getCurrent().equals("share")) {
            target.addListMode(StructureMapListMode.SHARE);
            lexer.next();
            target.setListRuleId(lexer.take());
        } else if (lexer.getCurrent().equals("first"))
            target.addListMode(StructureMapListMode.FIRST);
        else
            target.addListMode(StructureMapListMode.LAST);
        lexer.next();
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.dstu2016may.model.IdType)

Example 37 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method parseSource.

private void parseSource(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
    StructureMapGroupRuleSourceComponent source = rule.addSource();
    if (lexer.hasToken("optional"))
        lexer.next();
    else
        source.setRequired(true);
    source.setContext(lexer.take());
    if (lexer.hasToken(".")) {
        lexer.token(".");
        source.setElement(lexer.take());
    }
    if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "only_one"))
        if (lexer.getCurrent().equals("only_one")) {
            source.setListMode(StructureMapListMode.SHARE);
            lexer.take();
        } else
            source.setListMode(StructureMapListMode.fromCode(lexer.take()));
    if (lexer.hasToken("as")) {
        lexer.take();
        source.setVariable(lexer.take());
    }
    if (lexer.hasToken("where")) {
        lexer.take();
        ExpressionNode node = fpe.parse(lexer);
        source.setUserData(MAP_WHERE_EXPRESSION, node);
        source.setCondition(node.toString());
    }
    if (lexer.hasToken("check")) {
        lexer.take();
        ExpressionNode node = fpe.parse(lexer);
        source.setUserData(MAP_WHERE_CHECK, node);
        source.setCheck(node.toString());
    }
}
Also used : ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent)

Example 38 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method renderGroup.

private void renderGroup(StringBuilder b, StructureMapGroupComponent g) throws FHIRException {
    b.append("group ");
    b.append(g.getName());
    if (g.hasExtends()) {
        b.append(" extends ");
        b.append(g.getExtends());
    }
    if (g.hasDocumentation())
        renderDoco(b, g.getDocumentation());
    b.append("\r\n");
    for (StructureMapGroupInputComponent gi : g.getInput()) {
        b.append("  input ");
        b.append(gi.getName());
        if (gi.hasType()) {
            b.append(" : ");
            b.append(gi.getType());
        }
        b.append(" as ");
        b.append(gi.getMode().toCode());
        b.append(";\r\n");
    }
    if (g.hasInput())
        b.append("\r\n");
    for (StructureMapGroupRuleComponent r : g.getRule()) {
        renderRule(b, r, 2);
    }
    b.append("\r\nendgroup\r\n");
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)

Example 39 with StructureMapGroupRuleComponent

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

the class StructureMapUtilities method parseRule.

private void parseRule(List<StructureMapGroupRuleComponent> list, FHIRLexer lexer) throws FHIRException {
    StructureMapGroupRuleComponent rule = new StructureMapGroupRuleComponent();
    list.add(rule);
    rule.setName(lexer.takeDottedToken());
    lexer.token(":");
    lexer.token("for");
    boolean done = false;
    while (!done) {
        parseSource(rule, lexer);
        done = !lexer.hasToken(",");
        if (!done)
            lexer.next();
    }
    if (lexer.hasToken("make")) {
        lexer.token("make");
        done = false;
        while (!done) {
            parseTarget(rule, lexer);
            done = !lexer.hasToken(",");
            if (!done)
                lexer.next();
        }
    }
    if (lexer.hasToken("then")) {
        lexer.token("then");
        if (lexer.hasToken("{")) {
            lexer.token("{");
            if (lexer.hasComment()) {
                rule.setDocumentation(lexer.take().substring(2).trim());
            }
            lexer.skipComments();
            while (!lexer.hasToken("}")) {
                if (lexer.done())
                    throw lexer.error("premature termination expecting '}' in nested group");
                parseRule(rule.getRule(), lexer);
            }
            lexer.token("}");
        } else {
            done = false;
            while (!done) {
                parseRuleReference(rule, lexer);
                done = !lexer.hasToken(",");
                if (!done)
                    lexer.next();
            }
        }
    } else if (lexer.hasComment()) {
        rule.setDocumentation(lexer.take().substring(2).trim());
    }
    lexer.skipComments();
}
Also used : StructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)

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