fix test, revert var patch

This commit is contained in:
oliveregger 2024-09-21 18:50:01 +02:00
parent d69a8e3e43
commit 2f165863e7
1 changed files with 3 additions and 28 deletions

View File

@ -1075,16 +1075,19 @@ public class StructureMapUtilities {
if (lexer.hasToken("where")) { if (lexer.hasToken("where")) {
lexer.take(); lexer.take();
ExpressionNode node = fpe.parse(lexer); ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_EXPRESSION, node);
source.setCondition(node.toString()); source.setCondition(node.toString());
} }
if (lexer.hasToken("check")) { if (lexer.hasToken("check")) {
lexer.take(); lexer.take();
ExpressionNode node = fpe.parse(lexer); ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_CHECK, node);
source.setCheck(node.toString()); source.setCheck(node.toString());
} }
if (lexer.hasToken("log")) { if (lexer.hasToken("log")) {
lexer.take(); lexer.take();
ExpressionNode node = fpe.parse(lexer); ExpressionNode node = fpe.parse(lexer);
source.setUserData(MAP_WHERE_LOG, node);
source.setLogMessage(node.toString()); source.setLogMessage(node.toString());
} }
} }
@ -1598,7 +1601,6 @@ public class StructureMapUtilities {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_SEARCH_EXPRESSION); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_SEARCH_EXPRESSION);
if (expr == null) { if (expr == null) {
expr = fpe.parse(src.getElement()); expr = fpe.parse(src.getElement());
patchVariablesInExpression(expr, vars);
src.setUserData(MAP_SEARCH_EXPRESSION, expr); src.setUserData(MAP_SEARCH_EXPRESSION, expr);
} }
String search = fpe.evaluateToString(vars, null, null, new StringType(), expr); // string is a holder of nothing to ensure that variables are processed correctly String search = fpe.evaluateToString(vars, null, null, new StringType(), expr); // string is a holder of nothing to ensure that variables are processed correctly
@ -1632,7 +1634,6 @@ public class StructureMapUtilities {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION);
if (expr == null) { if (expr == null) {
expr = fpe.parse(src.getCondition()); expr = fpe.parse(src.getCondition());
patchVariablesInExpression(expr, vars);
src.setUserData(MAP_WHERE_EXPRESSION, expr); src.setUserData(MAP_WHERE_EXPRESSION, expr);
} }
List<Base> remove = new ArrayList<Base>(); List<Base> remove = new ArrayList<Base>();
@ -1654,7 +1655,6 @@ public class StructureMapUtilities {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_CHECK); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_CHECK);
if (expr == null) { if (expr == null) {
expr = fpe.parse(src.getCheck()); expr = fpe.parse(src.getCheck());
patchVariablesInExpression(expr, vars);
src.setUserData(MAP_WHERE_CHECK, expr); src.setUserData(MAP_WHERE_CHECK, expr);
} }
for (Base item : items) { for (Base item : items) {
@ -1671,7 +1671,6 @@ public class StructureMapUtilities {
ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_LOG); ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_LOG);
if (expr == null) { if (expr == null) {
expr = fpe.parse(src.getLogMessage()); expr = fpe.parse(src.getLogMessage());
patchVariablesInExpression(expr, vars);
src.setUserData(MAP_WHERE_LOG, expr); src.setUserData(MAP_WHERE_LOG, expr);
} }
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
@ -1764,29 +1763,6 @@ public class StructureMapUtilities {
vars.add(VariableMode.OUTPUT, tgt.getVariable(), v); vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
} }
public static void patchVariablesInExpression(ExpressionNode node, Variables vars) {
if (node.isProximal() && node.getKind() == ExpressionNode.Kind.Name && node.getName() !=null && node.getName().length()>0 && !node.getName().startsWith("%")) {
// Check if this name is in the variables
if (vars.get(VariableMode.INPUT, node.getName())!=null)
node.setName("%" + node.getName());
}
// walk into children
var next = node.getOpNext();
if (next != null)
patchVariablesInExpression(next, vars);
var grp = node.getGroup();
if (grp != null)
patchVariablesInExpression(grp, vars);
var inner = node.getInner();
if (inner != null)
patchVariablesInExpression(inner, vars);
if (node.parameterCount() > 0) {
for(ExpressionNode p : node.getParameters()) {
patchVariablesInExpression(p, vars);
}
}
}
private Base runTransform(String rulePath, TransformContext context, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, Variables vars, Base dest, String element, String srcVar, boolean root) throws FHIRException { private Base runTransform(String rulePath, TransformContext context, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, Variables vars, Base dest, String element, String srcVar, boolean root) throws FHIRException {
try { try {
switch (tgt.getTransform()) { switch (tgt.getTransform()) {
@ -1826,7 +1802,6 @@ public class StructureMapUtilities {
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION); ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) { if (expr == null) {
expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(tgt.getParameter().size() - 1), tgt.toString())); expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(tgt.getParameter().size() - 1), tgt.toString()));
patchVariablesInExpression(expr, vars);
tgt.setUserData(MAP_EXPRESSION, expr); tgt.setUserData(MAP_EXPRESSION, expr);
} }
List<Base> v = fpe.evaluate(vars, null, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr); List<Base> v = fpe.evaluate(vars, null, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr);