use of io.github.linuxforhealth.core.expression.EmptyEvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class SimpleExpressionTest method test_variable_no_context.
@Test
void test_variable_no_context() {
ExpressionAttributes attr = new ExpressionAttributes.Builder().withValueOf("$var1").build();
SimpleExpression exp = new SimpleExpression(attr);
Map<String, EvaluationResult> context = new HashMap<>();
EvaluationResult value = exp.evaluate(data, ImmutableMap.copyOf(context), new EmptyEvaluationResult());
assertThat(value).isNull();
}
use of io.github.linuxforhealth.core.expression.EmptyEvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class SimpleExpressionTest method test_constant.
@Test
void test_constant() {
ExpressionAttributes attr = new ExpressionAttributes.Builder().withValue(SOME_VALUE).build();
SimpleExpression exp = new SimpleExpression(attr);
Map<String, EvaluationResult> context = new HashMap<>();
EvaluationResult value = exp.evaluate(data, ImmutableMap.copyOf(context), new EmptyEvaluationResult());
assertThat((String) value.getValue()).isEqualTo(SOME_VALUE);
}
use of io.github.linuxforhealth.core.expression.EmptyEvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ExpressionUtility method evaluate.
/**
* Evaluates map of expression and generates ResourceEvaluationResult object.
*
* @param dataSource The data extractor to be used
* @param context The context in use
* @param baseValue The value to evaluate
* @param expressionMap Map of expressions
* @return {@link ResourceEvaluationResult}
*/
public static ResourceEvaluationResult evaluate(InputDataExtractor dataSource, Map<String, EvaluationResult> context, EvaluationResult baseValue, Map<String, Expression> expressionMap) {
try {
Map<String, Expression> expressionsToEvaluateLater = new HashMap<>();
Map<String, EvaluationResult> localContext = new HashMap<>(context);
localContext.put(Constants.NULL_VAR_NAME, new EmptyEvaluationResult());
// initialize the map and list to collect values
List<ResourceValue> additionalResolveValues = new ArrayList<>();
Map<String, Object> resolveValues = new HashMap<>();
for (Entry<String, Expression> entry : expressionMap.entrySet()) {
Expression exp = entry.getValue();
LOGGER.debug(EVALUATING, entry.getKey(), entry.getValue());
if (exp.isEvaluateLater()) {
expressionsToEvaluateLater.put(entry.getKey(), entry.getValue());
} else {
processExpression(dataSource, baseValue, localContext, additionalResolveValues, resolveValues, entry);
}
}
resolveValues.values().removeIf(Objects::isNull);
return new ResourceEvaluationResult(resolveValues, additionalResolveValues, new PendingExpressionState(expressionsToEvaluateLater, context));
} catch (RequiredConstraintFailureException e) {
LOGGER.warn("Resource Constraint condition not satisfied.");
LOGGER.debug("Resource Constraint condition not satisfied, exception", e);
return null;
} catch (IllegalArgumentException | IllegalStateException | DataExtractionException e) {
LOGGER.error("Exception during resource evaluation");
LOGGER.debug("Exception during resource evaluation reason ", e);
return null;
}
}
use of io.github.linuxforhealth.core.expression.EmptyEvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ExpressionUtility method evaluate.
public static ResourceEvaluationResult evaluate(HL7MessageData dataSource, Map<String, EvaluationResult> context, Map<String, Expression> expressionMap) {
try {
Map<String, EvaluationResult> localContext = new HashMap<>(context);
Map<String, Object> resolveValues = new HashMap<>();
List<ResourceValue> additionalResolveValues = new ArrayList<>();
for (Entry<String, Expression> entry : expressionMap.entrySet()) {
LOGGER.debug(EVALUATING, entry.getKey(), entry.getValue());
processExpression(dataSource, new EmptyEvaluationResult(), localContext, additionalResolveValues, resolveValues, entry);
}
resolveValues.values().removeIf(Objects::isNull);
return new ResourceEvaluationResult(resolveValues, additionalResolveValues);
} catch (RequiredConstraintFailureException e) {
LOGGER.warn("Resource Constraint condition not satisfied.");
LOGGER.debug("Resource Constraint condition not satisfied, exception", e);
return null;
} catch (IllegalArgumentException | IllegalStateException | DataExtractionException e) {
LOGGER.error("Exception during resource evaluation.");
LOGGER.debug("Exception during resource evaluation reason ", e);
return null;
}
}
use of io.github.linuxforhealth.core.expression.EmptyEvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ExpressionVariable method extractVariableValue.
// resolve variable value
@Override
public EvaluationResult extractVariableValue(Map<String, EvaluationResult> contextValues, InputDataExtractor dataSource) {
EvaluationResult result = null;
if (!this.getSpec().isEmpty()) {
result = getValueFromSpecs(contextValues, dataSource);
}
if (result == null) {
result = new EmptyEvaluationResult();
}
if (this.expression != null) {
// resolve expression
Map<String, EvaluationResult> localContextValues = new HashMap<>(contextValues);
localContextValues.put(this.getName(), result);
result = dataSource.evaluateJexlExpression(expression, localContextValues);
}
return result;
}
Aggregations