use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent 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.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method parseTarget.
private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
StructureMapGroupRuleTargetComponent target = rule.addTarget();
String start = lexer.take();
if (lexer.hasToken(".")) {
target.setContext(start);
target.setContextType(StructureMapContextType.VARIABLE);
start = null;
lexer.token(".");
target.setElement(lexer.take());
}
String name;
boolean isConstant = false;
if (lexer.hasToken("=")) {
if (start != null)
target.setContext(start);
lexer.token("=");
isConstant = lexer.isConstant(true);
name = lexer.take();
} else
name = start;
if ("(".equals(name)) {
// inline fluentpath expression
target.setTransform(StructureMapTransform.EVALUATE);
ExpressionNode node = fpe.parse(lexer);
target.setUserData(MAP_EXPRESSION, node);
target.addParameter().setValue(new StringType(node.toString()));
lexer.token(")");
} else if (lexer.hasToken("(")) {
target.setTransform(StructureMapTransform.fromCode(name));
lexer.token("(");
if (target.getTransform() == StructureMapTransform.EVALUATE) {
parseParameter(target, lexer);
lexer.token(",");
ExpressionNode node = fpe.parse(lexer);
target.setUserData(MAP_EXPRESSION, node);
target.addParameter().setValue(new StringType(node.toString()));
} else {
while (!lexer.hasToken(")")) {
parseParameter(target, lexer);
if (!lexer.hasToken(")"))
lexer.token(",");
}
}
lexer.token(")");
} else if (name != null) {
target.setTransform(StructureMapTransform.COPY);
if (!isConstant) {
String id = name;
while (lexer.hasToken(".")) {
id = id + lexer.take() + lexer.take();
}
target.addParameter().setValue(new IdType(id));
} else
target.addParameter().setValue(readConstant(name, lexer));
}
if (lexer.hasToken("as")) {
lexer.take();
target.setVariable(lexer.take());
}
while (Utilities.existsInList(lexer.getCurrent(), "first", "last", "share", "collate")) {
if (lexer.getCurrent().equals("share")) {
target.addListMode(StructureMapTargetListMode.SHARE);
lexer.next();
target.setListRuleId(lexer.take());
} else if (lexer.getCurrent().equals("first"))
target.addListMode(StructureMapTargetListMode.FIRST);
else
target.addListMode(StructureMapTargetListMode.LAST);
lexer.next();
}
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method executeGroup.
private void executeGroup(String indent, TransformContext context, StructureMap map, Variables vars, StructureMapGroupComponent group) throws FHIRException {
log(indent + "Group : " + group.getName());
// todo: check inputs
if (group.hasExtends()) {
ResolvedGroup rg = resolveGroupReference(map, group, group.getExtends());
executeGroup(indent + " ", context, rg.targetMap, vars, rg.target);
}
for (StructureMapGroupRuleComponent r : group.getRule()) {
executeRule(indent + " ", context, map, vars, group, r);
}
}
use of org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent 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.r4b.model.StructureMap.StructureMapGroupRuleComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseGroup.
private void analyseGroup(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapAnalysis result) throws Exception {
log(indent + "Analyse Group : " + group.getName());
// todo: extends
// todo: check inputs
XhtmlNode tr = result.summary.addTag("tr").setAttribute("class", "diff-title");
XhtmlNode xs = tr.addTag("td");
XhtmlNode xt = tr.addTag("td");
for (StructureMapGroupInputComponent inp : group.getInput()) {
if (inp.getMode() == StructureMapInputMode.SOURCE)
noteInput(vars, inp, VariableMode.INPUT, xs);
if (inp.getMode() == StructureMapInputMode.TARGET)
noteInput(vars, inp, VariableMode.OUTPUT, xt);
}
for (StructureMapGroupRuleComponent r : group.getRule()) {
analyseRule(indent + " ", context, map, vars, group, r, result);
}
}
Aggregations