Search in sources :

Example 16 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent 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 17 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent 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 18 with StructureMapGroupRuleDependentComponent

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

Example 19 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent 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 20 with StructureMapGroupRuleDependentComponent

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

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)14 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)4 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent)3 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)3 StructureMapGroupRuleDependentComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent)3 StringType (org.hl7.fhir.dstu2016may.model.StringType)2 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)2 Base (org.hl7.fhir.dstu3.model.Base)2 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)2 StringType (org.hl7.fhir.dstu3.model.StringType)2 Base (org.hl7.fhir.r4.model.Base)2 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)2 StringType (org.hl7.fhir.r4.model.StringType)2 IOException (java.io.IOException)1 Base (org.hl7.fhir.dstu2016may.model.Base)1 StructureMap (org.hl7.fhir.dstu2016may.model.StructureMap)1