Search in sources :

Example 21 with StructureMapGroupRuleDependentComponent

use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent 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 22 with StructureMapGroupRuleDependentComponent

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