io.github.linuxforhealth.hl7.expression.specification.ContextMapData 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
package io.github.linuxforhealth.hl7.expression.specification;
import java.util.Map;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.api.Specification;
import io.github.linuxforhealth.core.expression.ContextValueUtils;
import io.github.linuxforhealth.core.expression.EmptyEvaluationResult;
import io.github.linuxforhealth.core.expression.SimpleEvaluationResult;
public class ContextMapData implements InputDataExtractor {
@Override
public EvaluationResult evaluateJexlExpression(String expression,
Map contextValues) {
throw new IllegalStateException("No supported for this input source type");
}
@Override
public String getName() {
return "ContextMap";
}
@Override
public String getId() {
throw new IllegalStateException("No supported for this input source type");
}
@Override
public EvaluationResult extractValueForSpec(Specification spec,
Map contextValues) {
EvaluationResult fetchedValue = this.extractMultipleValuesForSpec(spec, contextValues);
if (fetchedValue != null && !fetchedValue.isEmpty()) {
return new SimpleEvaluationResult<>(ContextValueUtils.getSingleValue(fetchedValue.getValue()));
} else {
return new EmptyEvaluationResult();
}
}
@Override
public EvaluationResult extractMultipleValuesForSpec(Specification spec,
Map contextValues) {
EvaluationResult res;
if (spec instanceof SimpleSpecification) {
SimpleSpecification simpleSpec = (SimpleSpecification) spec;
res = ContextValueUtils.getVariableValueFromVariableContextMap(simpleSpec, contextValues);
} else {
res = null;
}
if (res != null && !res.isEmpty()) {
return res;
} else {
return new EmptyEvaluationResult();
}
}
}