Search in sources :

Example 1 with StructureMapGroupRuleComponent

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

Example 2 with StructureMapGroupRuleComponent

use of org.hl7.fhir.dstu3.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 ");
    switch(g.getTypeMode()) {
        case TYPES:
            b.append("for types");
        case TYPEANDTYPES:
            b.append("for type+types ");
        // NONE, NULL
        default:
    }
    b.append("for types ");
    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.dstu3.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)

Example 3 with StructureMapGroupRuleComponent

use of org.hl7.fhir.dstu3.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 4 with StructureMapGroupRuleComponent

use of org.hl7.fhir.dstu3.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, boolean atRoot) throws FHIRException {
    log(indent + "rule : " + rule.getName() + "; vars = " + vars.summary());
    Variables srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new FHIRException("Rule \"" + rule.getName() + "\": not handled yet");
    List<Variables> source = processSource(rule.getName(), context, srcVars, rule.getSource().get(0), map.getUrl(), indent);
    if (source != null) {
        for (Variables v : source) {
            for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
                processTarget(rule.getName(), context, v, map, group, t, rule.getSource().size() == 1 ? rule.getSourceFirstRep().getVariable() : null, atRoot, vars);
            }
            if (rule.hasRule()) {
                for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
                    executeRule(indent + "  ", context, map, v, group, childrule, false);
                }
            } else if (rule.hasDependent()) {
                for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
                    executeDependency(indent + "  ", context, map, v, group, dependent);
                }
            } else if (rule.getSource().size() == 1 && rule.getSourceFirstRep().hasVariable() && rule.getTarget().size() == 1 && rule.getTargetFirstRep().hasVariable() && rule.getTargetFirstRep().getTransform() == StructureMapTransform.CREATE && !rule.getTargetFirstRep().hasParameter()) {
                // simple inferred, map by type
                System.out.println(v.summary());
                Base src = v.get(VariableMode.INPUT, rule.getSourceFirstRep().getVariable());
                Base tgt = v.get(VariableMode.OUTPUT, rule.getTargetFirstRep().getVariable());
                String srcType = src.fhirType();
                String tgtType = tgt.fhirType();
                ResolvedGroup defGroup = resolveGroupByTypes(map, rule.getName(), group, srcType, tgtType);
                Variables vdef = new Variables();
                vdef.add(VariableMode.INPUT, defGroup.target.getInput().get(0).getName(), src);
                vdef.add(VariableMode.OUTPUT, defGroup.target.getInput().get(1).getName(), tgt);
                executeGroup(indent + "  ", context, defGroup.targetMap, vdef, defGroup.target, false);
            }
        }
    }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 5 with StructureMapGroupRuleComponent

use of org.hl7.fhir.dstu3.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 FHIRException {
    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 : 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