use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent 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.StructureMapGroupRuleTargetComponent in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method processTarget.
private void processTarget(TransformContext context, Variables vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt) throws Exception {
Base dest = vars.get(VariableMode.OUTPUT, tgt.getContext());
if (dest == null)
throw new Exception("target context not known: " + tgt.getContext());
if (!tgt.hasElement())
throw new Exception("Not supported yet");
Base v = null;
if (tgt.hasTransform()) {
v = runTransform(context, map, tgt, vars);
if (v != null)
dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
} else
v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
if (tgt.hasVariable() && v != null)
vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
}
use of org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent 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();
target.setContext(lexer.take());
if (lexer.hasToken(".")) {
lexer.token(".");
target.setElement(lexer.take());
}
if (lexer.hasToken("=")) {
lexer.token("=");
boolean isConstant = lexer.isConstant(true);
String name = lexer.take();
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 {
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", "only_one")) {
if (lexer.getCurrent().equals("share")) {
target.addListMode(StructureMapListMode.SHARE);
lexer.next();
target.setListRuleId(lexer.take());
} else if (lexer.getCurrent().equals("first"))
target.addListMode(StructureMapListMode.FIRST);
else
target.addListMode(StructureMapListMode.LAST);
lexer.next();
}
}
Aggregations