io.github.linuxforhealth.hl7.expression.JEXLExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hl7v2-fhir-converter Show documentation
Show all versions of hl7v2-fhir-converter Show documentation
FHIR converter is a Java based library that enables converting Hl7v2 messages to FHIR resources
/*
* (C) Copyright IBM Corp. 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
package io.github.linuxforhealth.hl7.expression;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.api.Variable;
import io.github.linuxforhealth.core.expression.EmptyEvaluationResult;
@JsonIgnoreProperties(ignoreUnknown = true)
public class JEXLExpression extends AbstractExpression {
private static final Logger LOGGER = LoggerFactory.getLogger(JEXLExpression.class);
@JsonCreator
public JEXLExpression(ExpressionAttributes expAttr) {
super(expAttr);
}
@Override
public EvaluationResult evaluateExpression(InputDataExtractor dataSource,
Map contextValues, EvaluationResult baseValue) {
Map localContextValues = new HashMap<>(contextValues);
for (Variable v : this.getVariables()) {
if (!localContextValues.containsKey(v.getVariableName())) {
localContextValues.put(v.getVariableName(), new EmptyEvaluationResult());
}
}
LOGGER.info("Evaluating expression");
return dataSource.evaluateJexlExpression(this.getExpressionAttr().getValueOf(), contextValues);
}
}