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");
}
}
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);
}
Aggregations