use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseRuleReference.
private void parseRuleReference(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRLexerException {
StructureMapGroupRuleDependentComponent ref = rule.addDependent();
ref.setName(lexer.take());
lexer.token("(");
boolean done = false;
while (!done) {
ref.addVariable(lexer.take());
done = !lexer.hasToken(",");
if (!done)
lexer.next();
}
lexer.token(")");
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderRule.
private static void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) {
for (int i = 0; i < indent; i++) b.append(' ');
b.append(r.getName());
b.append(" : for ");
boolean canBeAbbreviated = checkisSimple(r);
boolean first = true;
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
if (first)
first = false;
else
b.append(", ");
renderSource(b, rs, canBeAbbreviated);
}
if (r.getTarget().size() > 1) {
b.append(" make ");
first = true;
for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
if (first)
first = false;
else
b.append(", ");
if (RENDER_MULTIPLE_TARGETS_ONELINE)
b.append(' ');
else {
b.append("\r\n");
for (int i = 0; i < indent + 4; i++) b.append(' ');
}
renderTarget(b, rt, false);
}
} else if (r.hasTarget()) {
b.append(" make ");
renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
}
if (!canBeAbbreviated) {
if (r.hasRule()) {
b.append(" then {\r\n");
renderDoco(b, r.getDocumentation());
for (StructureMapGroupRuleComponent ir : r.getRule()) {
renderRule(b, ir, indent + 2);
}
for (int i = 0; i < indent; i++) b.append(' ');
b.append("}\r\n");
} else {
if (r.hasDependent()) {
b.append(" then ");
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(rdp.asStringValue());
}
b.append(")");
}
}
}
}
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 parseRuleReference.
private void parseRuleReference(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRLexerException {
StructureMapGroupRuleDependentComponent ref = rule.addDependent();
ref.setName(lexer.take());
lexer.token("(");
boolean done = false;
while (!done) {
ref.addVariable(lexer.take());
done = !lexer.hasToken(",");
if (!done)
lexer.next();
}
lexer.token(")");
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderRule.
private static void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) {
for (int i = 0; i < indent; i++) b.append(' ');
boolean canBeAbbreviated = checkisSimple(r);
boolean first = true;
for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
if (first)
first = false;
else
b.append(", ");
renderSource(b, rs, canBeAbbreviated);
}
if (r.getTarget().size() > 1) {
b.append(" -> ");
first = true;
for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
if (first)
first = false;
else
b.append(", ");
if (RENDER_MULTIPLE_TARGETS_ONELINE)
b.append(' ');
else {
b.append("\r\n");
for (int i = 0; i < indent + 4; i++) b.append(' ');
}
renderTarget(b, rt, false);
}
} else if (r.hasTarget()) {
b.append(" -> ");
renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
}
if (r.hasRule()) {
b.append(" then {\r\n");
renderDoco(b, r.getDocumentation());
for (StructureMapGroupRuleComponent ir : r.getRule()) {
renderRule(b, ir, indent + 2);
}
for (int i = 0; i < indent; i++) b.append(' ');
b.append("}");
} else {
if (r.hasDependent()) {
b.append(" then ");
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(rdp.asStringValue());
}
b.append(")");
}
}
}
if (r.hasName()) {
String n = ntail(r.getName());
if (!n.startsWith("\""))
n = "\"" + n + "\"";
if (!matchesName(n, r.getSource())) {
b.append(" ");
b.append(n);
}
}
b.append(";");
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 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);
}
}
}
}
}
Aggregations