Search in sources :

Example 6 with StructureMapGroupRuleComponent

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

Example 7 with StructureMapGroupRuleComponent

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

the class MappingSheetParser method getStructureMap.

public StructureMap getStructureMap() throws FHIRException {
    StructureMap map = new StructureMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    StructureMapGroupComponent grp = map.addGroup();
    for (MappingRow row : rows) {
        StructureMapGroupRuleComponent rule = grp.addRule();
        rule.setName(row.getSequence());
        StructureMapGroupRuleSourceComponent src = rule.getSourceFirstRep();
        src.setContext("src");
        src.setElement(row.getIdentifier());
        src.setMin(row.getCardinalityMin());
        src.setMax(row.getCardinalityMax());
        src.setType(row.getDataType());
        src.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        if (row.getCondition() != null) {
            src.setCheck(processCondition(row.getCondition()));
        }
        StructureMapGroupRuleTargetComponent tgt = rule.getTargetFirstRep();
        tgt.setContext("tgt");
        tgt.setElement(row.getAttribute());
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
        if (row.getDtMapping() != null) {
            src.setVariable("s");
            tgt.setVariable("t");
            tgt.setTransform(StructureMapTransform.CREATE);
            StructureMapGroupRuleDependentComponent dep = rule.addDependent();
            dep.setName(row.getDtMapping());
            dep.addVariable("s");
            dep.addVariable("t");
        } else if (row.getVocabMapping() != null) {
            tgt.setTransform(StructureMapTransform.TRANSLATE);
            tgt.addParameter().setValue(new StringType(row.getVocabMapping()));
            tgt.addParameter().setValue(new IdType("src"));
        } else {
            tgt.setTransform(StructureMapTransform.COPY);
        }
        rule.setDocumentation(row.getComments());
        if (row.getDerived() != null) {
            tgt = rule.addTarget();
            tgt.setContext("tgt");
            tgt.setElement(row.getDerived());
            tgt.setTransform(StructureMapTransform.COPY);
            tgt.addParameter().setValue(new StringType(row.getDerivedMapping()));
        }
    }
    return map;
}
Also used : StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureMapGroupComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent) StringType(org.hl7.fhir.r4b.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.r4b.model.IdType)

Example 8 with StructureMapGroupRuleComponent

use of org.hl7.fhir.r4.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) throws FHIRException {
    log(indent + "rule : " + rule.getName());
    if (rule.getName().contains("CarePlan.participant-unlink"))
        System.out.println("debug");
    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));
    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);
            }
            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);
                }
            } 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
                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);
            }
        }
    }
}
Also used : StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) Base(org.hl7.fhir.dstu3.model.Base)

Example 9 with StructureMapGroupRuleComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent 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 Exception {
    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 Exception("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 : FHIRLexerException(org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 10 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(StructureMap map, 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(map, 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());
    }
    if (isSimpleSyntax(rule)) {
        rule.getSourceFirstRep().setVariable(AUTO_VAR_NAME);
        rule.getTargetFirstRep().setVariable(AUTO_VAR_NAME);
        // with no parameter - e.g. imply what is to be created
        rule.getTargetFirstRep().setTransform(StructureMapTransform.CREATE);
    // no dependencies - imply what is to be done based on types
    }
    lexer.skipComments();
}
Also used : StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.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