Search in sources :

Example 66 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent 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 Exception {
    log(indent + "rule : " + rule.getName());
    Variables srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new Exception("not handled yet");
    List<Variables> source = analyseSource(context, srcVars, rule.getSource().get(0));
    if (source != null) {
        for (Variables v : source) {
            for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
                processTarget(context, v, map, t);
            }
            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);
                }
            }
        }
    }
}
Also used : StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent) FHIRLexerException(org.hl7.fhir.dstu2016may.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)

Example 67 with StructureMapGroupComponent

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

the class StructureMapUtilities method renderGroup.

private void renderGroup(StringBuilder b, StructureMapGroupComponent g) throws FHIRException {
    b.append("group ");
    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.dstu2016may.model.StructureMap.StructureMapGroupInputComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleComponent)

Example 68 with StructureMapGroupComponent

use of org.hl7.fhir.r4b.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 Exception {
    StructureMap targetMap = null;
    StructureMapGroupComponent target = null;
    for (StructureMapGroupComponent grp : map.getGroup()) {
        if (grp.getName().equals(dependent.getName())) {
            if (targetMap == null) {
                targetMap = map;
                target = grp;
            } else
                throw new FHIRException("Multiple possible matches for rule '" + dependent.getName() + "'");
        }
    }
    for (UriType imp : map.getImport()) {
        StructureMap impMap = library.get(imp.getValue());
        if (impMap == null)
            throw new FHIRException("Unable to find map " + imp.getValue() + " (Known Maps = " + Utilities.listCanonicalUrls(library.keySet()) + ")");
        for (StructureMapGroupComponent grp : impMap.getGroup()) {
            if (grp.getName().equals(dependent.getName())) {
                if (targetMap == null) {
                    targetMap = impMap;
                    target = grp;
                } else
                    throw new FHIRException("Multiple possible matches for rule '" + dependent.getName() + "'");
            }
        }
    }
    if (target == null)
        throw new FHIRException("No matches found for rule '" + dependent.getName() + "'");
    if (target.getInput().size() != dependent.getVariable().size()) {
        throw new FHIRException("Rule '" + dependent.getName() + "' has " + Integer.toString(target.getInput().size()) + " but the invocation has " + Integer.toString(dependent.getVariable().size()) + " variables");
    }
    Variables v = new Variables();
    for (int i = 0; i < target.getInput().size(); i++) {
        StructureMapGroupInputComponent input = target.getInput().get(i);
        StringType var = dependent.getVariable().get(i);
        VariableMode mode = input.getMode() == StructureMapInputMode.SOURCE ? VariableMode.INPUT : VariableMode.OUTPUT;
        Base vv = vin.get(mode, var.getValue());
        if (vv == null)
            throw new FHIRException("Rule '" + dependent.getName() + "' " + mode.toString() + " variable '" + input.getName() + "' has no value");
        v.add(mode, input.getName(), vv);
    }
    executeGroup(indent + "  ", context, targetMap, v, target);
}
Also used : StructureMap(org.hl7.fhir.dstu2016may.model.StructureMap) StructureMapGroupComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupComponent) StringType(org.hl7.fhir.dstu2016may.model.StringType) StructureMapGroupInputComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupInputComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu2016may.model.Base) UriType(org.hl7.fhir.dstu2016may.model.UriType)

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