Search in sources :

Example 1 with StructureMapGroupRuleDependentComponent

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

Example 2 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeDependency.

private void executeDependency(String indent, TransformContext context, StructureMap map, Variables vin, StructureMapGroupComponent group, StructureMapGroupRuleDependentComponent dependent) throws FHIRException {
    ResolvedGroup rg = resolveGroupReference(map, group, dependent.getName());
    if (rg.target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(rg.target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StringType rdp = dependent.getVariable().get(i);
        String var = rdp.asStringValue();
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var);
        if (// * once source, always source. but target can be treated as source at user convenient
        vv == null && mode == VariableMode.INPUT)
            vv = vin.get(VariableMode.OUTPUT, var);
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' named as '" + var + "' has no value");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, rg.targetMap, v, rg.target);
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) StructureMapGroupInputComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Base(org.hl7.fhir.dstu3.model.Base)

Example 3 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method executeDependency.

private void executeDependency(String indent, TransformContext context, StructureMap map, Variables vin, StructureMapGroupComponent group, StructureMapGroupRuleDependentComponent dependent) throws FHIRException {
    ResolvedGroup rg = resolveGroupReference(map, group, dependent.getName());
    if (rg.target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(rg.target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < rg.target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = rg.target.getInput().get(i);
        StringType rdp = dependent.getVariable().get(i);
        String var = rdp.asStringValue();
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var);
        if (// * once source, always source. but target can be treated as source at user convenient
        vv == null && mode == VariableMode.INPUT)
            vv = vin.get(VariableMode.OUTPUT, var);
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' named as '" + var + "' has no value (vars = " + vin.summary() + ")");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, rg.targetMap, v, rg.target, false);
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.dstu3.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, 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 StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseRule.

private void analyseRule(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, StructureMapAnalysis result) throws FHIRException {
    log(indent + "Analyse rule : " + rule.getName());
    XhtmlNode tr = result.summary.addTag("tr");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    VariablesForProfiling srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new FHIRException("Rule \"" + rule.getName() + "\": not handled yet");
    VariablesForProfiling source = analyseSource(rule.getName(), context, srcVars, rule.getSourceFirstRep(), xs);
    TargetWriter tw = new TargetWriter();
    for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
        analyseTarget(rule.getName(), context, source, map, t, rule.getSourceFirstRep().getVariable(), tw, result.profiles, rule.getName());
    }
    tw.commit(xt);
    for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
        analyseRule(indent + "  ", context, map, source, group, childrule, result);
    }
// for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
// executeDependency(indent+"  ", context, map, v, group, dependent); // do we need group here?
// }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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