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