Search in sources :

Example 26 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();
    source.setContext(lexer.take());
    if (source.getContext().equals("search") && lexer.hasToken("(")) {
        source.setContext("@search");
        lexer.take();
        ExpressionNode node = fpe.parse(lexer);
        source.setUserData(MAP_SEARCH_EXPRESSION, node);
        source.setElement(node.toString());
        lexer.token(")");
    } else if (lexer.hasToken(".")) {
        lexer.token(".");
        source.setElement(lexer.take());
    }
    if (lexer.hasToken(":")) {
        // type and cardinality
        lexer.token(":");
        source.setType(lexer.takeDottedToken());
        if (!lexer.hasToken("as", "first", "last", "not_first", "not_last", "only_one", "default")) {
            source.setMin(lexer.takeInt());
            lexer.token("..");
            source.setMax(lexer.take());
        }
    }
    if (lexer.hasToken("default")) {
        lexer.token("default");
        source.setDefaultValue(new StringType(lexer.readConstant("default value")));
    }
    if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "not_first", "not_last", "only_one"))
        source.setListMode(StructureMapSourceListMode.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 : StringType(org.hl7.fhir.dstu3.model.StringType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleSourceComponent)

Example 27 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 static void renderGroup(StringBuilder b, StructureMapGroupComponent g) {
    b.append("group ");
    b.append(g.getName());
    b.append("(");
    boolean first = true;
    for (StructureMapGroupInputComponent gi : g.getInput()) {
        if (first)
            first = false;
        else
            b.append(", ");
        b.append(gi.getMode().toCode());
        b.append(" ");
        b.append(gi.getName());
        if (gi.hasType()) {
            b.append(" : ");
            b.append(gi.getType());
        }
    }
    b.append(")");
    if (g.hasExtends()) {
        b.append(" extends ");
        b.append(g.getExtends());
    }
    if (g.hasTypeMode()) {
        switch(g.getTypeMode()) {
            case TYPES:
                b.append(" <<types>>");
                break;
            case TYPEANDTYPES:
                b.append(" <<type+>>");
                break;
            // NONE, NULL
            default:
        }
    }
    b.append(" {\r\n");
    for (StructureMapGroupRuleComponent r : g.getRule()) {
        renderRule(b, r, 2);
    }
    b.append("}\r\n\r\n");
}
Also used : StructureMapGroupInputComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)

Example 28 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 29 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();
    source.setContext(lexer.take());
    if (source.getContext().equals("search") && lexer.hasToken("(")) {
        source.setContext("@search");
        lexer.take();
        ExpressionNode node = fpe.parse(lexer);
        source.setUserData(MAP_SEARCH_EXPRESSION, node);
        source.setElement(node.toString());
        lexer.token(")");
    } else if (lexer.hasToken(".")) {
        lexer.token(".");
        source.setElement(lexer.take());
    }
    if (lexer.hasToken(":")) {
        // type and cardinality
        lexer.token(":");
        source.setType(lexer.takeDottedToken());
        if (!lexer.hasToken("as", "first", "last", "not_first", "not_last", "only_one", "default")) {
            source.setMin(lexer.takeInt());
            lexer.token("..");
            source.setMax(lexer.take());
        }
    }
    if (lexer.hasToken("default")) {
        lexer.token("default");
        source.setDefaultValue(new StringType(lexer.readConstant("default value")));
    }
    if (Utilities.existsInList(lexer.getCurrent(), "first", "last", "not_first", "not_last", "only_one"))
        source.setListMode(StructureMapSourceListMode.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());
    }
    if (lexer.hasToken("log")) {
        lexer.take();
        ExpressionNode node = fpe.parse(lexer);
        source.setUserData(MAP_WHERE_CHECK, node);
        source.setLogMessage(node.toString());
    }
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent)

Example 30 with StructureMapGroupRuleComponent

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

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