Search in sources :

Example 1 with StructureMapGroupComponent

use of org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseGroup.

private void parseGroup(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("group");
    StructureMapGroupComponent group = result.addGroup();
    group.setName(lexer.take());
    if (lexer.hasToken("extends")) {
        lexer.next();
        group.setExtends(lexer.take());
    }
    lexer.skipComments();
    while (lexer.hasToken("input")) parseInput(group, lexer);
    while (!lexer.hasToken("endgroup")) {
        if (lexer.done())
            throw lexer.error("premature termination expecting 'endgroup'");
        parseRule(group.getRule(), lexer);
    }
    lexer.next();
    lexer.skipComments();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent)

Example 2 with StructureMapGroupComponent

use of org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method render.

public String render(StructureMap map) throws FHIRException {
    StringBuilder b = new StringBuilder();
    b.append("map \"");
    b.append(map.getUrl());
    b.append("\" = \"");
    b.append(Utilities.escapeJava(map.getName()));
    b.append("\"\r\n\r\n");
    renderUses(b, map);
    renderImports(b, map);
    for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g);
    return b.toString();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent)

Example 3 with StructureMapGroupComponent

use of org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent 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 4 with StructureMapGroupComponent

use of org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent 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 5 with StructureMapGroupComponent

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

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)34 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)12 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 StructureMapGroupComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent)7 StructureMapGroupComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent)7 IOException (java.io.IOException)5 StructureMapGroupInputComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupInputComponent)5 StructureMapGroupRuleComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 StructureMapGroupInputComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent)5 StructureMapGroupRuleComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleComponent)5 Base (org.hl7.fhir.dstu3.model.Base)4 UriType (org.hl7.fhir.dstu3.model.UriType)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 Base (org.hl7.fhir.r4.model.Base)4 UriType (org.hl7.fhir.r4.model.UriType)4 StructureMap (org.hl7.fhir.r4b.model.StructureMap)4 StructureMap (org.hl7.fhir.r5.model.StructureMap)4 StructureMapGroupComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent)3