use of org.hl7.fhir.dstu2016may.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);
}
}
}
}
}
use of org.hl7.fhir.dstu2016may.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");
}
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 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