Search in sources :

Example 51 with StructureMapGroupRuleTargetComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method renderRule.

private void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) throws FHIRException {
    for (int i = 0; i < indent; i++) b.append(' ');
    b.append(r.getName());
    b.append(": for ");
    boolean first = true;
    for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
        if (first)
            first = false;
        else
            b.append(", ");
        renderSource(b, rs);
    }
    if (r.getTarget().size() > 1) {
        b.append(" make ");
        first = true;
        for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
            if (first)
                first = false;
            else
                b.append(", ");
            b.append("\r\n");
            for (int i = 0; i < indent + 4; i++) b.append(' ');
            renderTarget(b, rt);
        }
    } else if (r.hasTarget()) {
        b.append(" make ");
        renderTarget(b, r.getTarget().get(0));
    }
    if (r.hasRule()) {
        b.append(" then {");
        renderDoco(b, r.getDocumentation());
        for (int i = 0; i < indent; i++) b.append(' ');
        b.append("}\r\n");
    } else {
        if (r.hasDependent()) {
            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(rd.getVariable());
                }
            }
        }
        renderDoco(b, r.getDocumentation());
        b.append("\r\n");
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)

Example 52 with StructureMapGroupRuleTargetComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method processTarget.

private void processTarget(TransformContext context, Variables vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt) throws Exception {
    Base dest = vars.get(VariableMode.OUTPUT, tgt.getContext());
    if (dest == null)
        throw new Exception("target context not known: " + tgt.getContext());
    if (!tgt.hasElement())
        throw new Exception("Not supported yet");
    Base v = null;
    if (tgt.hasTransform()) {
        v = runTransform(context, map, tgt, vars);
        if (v != null)
            dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
    } else
        v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
    if (tgt.hasVariable() && v != null)
        vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
}
Also used : Base(org.hl7.fhir.dstu2016may.model.Base) FHIRLexerException(org.hl7.fhir.dstu2016may.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 53 with StructureMapGroupRuleTargetComponent

use of org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseTarget.

private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
    StructureMapGroupRuleTargetComponent target = rule.addTarget();
    target.setContext(lexer.take());
    if (lexer.hasToken(".")) {
        lexer.token(".");
        target.setElement(lexer.take());
    }
    if (lexer.hasToken("=")) {
        lexer.token("=");
        boolean isConstant = lexer.isConstant(true);
        String name = lexer.take();
        if (lexer.hasToken("(")) {
            target.setTransform(StructureMapTransform.fromCode(name));
            lexer.token("(");
            if (target.getTransform() == StructureMapTransform.EVALUATE) {
                parseParameter(target, lexer);
                lexer.token(",");
                ExpressionNode node = fpe.parse(lexer);
                target.setUserData(MAP_EXPRESSION, node);
                target.addParameter().setValue(new StringType(node.toString()));
            } else {
                while (!lexer.hasToken(")")) {
                    parseParameter(target, lexer);
                    if (!lexer.hasToken(")"))
                        lexer.token(",");
                }
            }
            lexer.token(")");
        } else {
            target.setTransform(StructureMapTransform.COPY);
            if (!isConstant) {
                String id = name;
                while (lexer.hasToken(".")) {
                    id = id + lexer.take() + lexer.take();
                }
                target.addParameter().setValue(new IdType(id));
            } else
                target.addParameter().setValue(readConstant(name, lexer));
        }
    }
    if (lexer.hasToken("as")) {
        lexer.take();
        target.setVariable(lexer.take());
    }
    while (Utilities.existsInList(lexer.getCurrent(), "first", "last", "share", "only_one")) {
        if (lexer.getCurrent().equals("share")) {
            target.addListMode(StructureMapListMode.SHARE);
            lexer.next();
            target.setListRuleId(lexer.take());
        } else if (lexer.getCurrent().equals("first"))
            target.addListMode(StructureMapListMode.FIRST);
        else
            target.addListMode(StructureMapListMode.LAST);
        lexer.next();
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.dstu2016may.model.IdType)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)35 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 IOException (java.io.IOException)6 StringType (org.hl7.fhir.dstu3.model.StringType)6 StringType (org.hl7.fhir.r4.model.StringType)6 IdType (org.hl7.fhir.dstu3.model.IdType)4 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent)4 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 StructureMapGroupRuleTargetComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent)4 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)4 StringType (org.hl7.fhir.dstu2016may.model.StringType)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)3 Base (org.hl7.fhir.dstu3.model.Base)3 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)3 UriType (org.hl7.fhir.dstu3.model.UriType)3 Base (org.hl7.fhir.r4.model.Base)3 IdType (org.hl7.fhir.r4.model.IdType)3