use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class AbstractExpression method getSpecValues.
protected static List<Object> getSpecValues(InputDataExtractor dataSource, Map<String, EvaluationResult> contextValues, EvaluationResult baseinputValue, List<Specification> specs) {
List<Object> baseHl7Specvalues = new ArrayList<>();
EvaluationResult specValues;
if (specs == null || specs.isEmpty()) {
specValues = baseinputValue;
} else {
specValues = SpecificationUtil.extractMultipleValuesForSpec(specs, dataSource, ImmutableMap.copyOf(contextValues));
}
if (specValues != null && specValues.getValue() instanceof List) {
baseHl7Specvalues.addAll((List<Object>) specValues.getValue());
} else if (specValues != null) {
baseHl7Specvalues.add(specValues.getValue());
}
return baseHl7Specvalues;
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ReferenceExpression method evaluateExpression.
@Override
public EvaluationResult evaluateExpression(InputDataExtractor dataSource, Map<String, EvaluationResult> contextValues, EvaluationResult baseValue) {
Preconditions.checkArgument(dataSource != null, "dataSource cannot be null");
Preconditions.checkArgument(contextValues != null, "contextValues cannot be null");
LOGGER.debug("Evaluating expression {}", this.reference);
EvaluationResult resourceReferenceResult = null;
// Evaluate the resource first and add it to the list of additional resources generated
ResourceResult primaryResourceResult = evaluateResource(dataSource, contextValues, baseValue);
// If the primary resource is generated then create the reference
if (primaryResourceResult != null && primaryResourceResult.getValue() != null) {
List<ResourceValue> additionalResources = new ArrayList<>();
additionalResources.addAll(primaryResourceResult.getAdditionalResources());
additionalResources.add(primaryResourceResult.getValue());
EvaluationResult genBaseValue = EvaluationResultFactory.getEvaluationResult(primaryResourceResult.getValue().getResource());
Map<String, EvaluationResult> localContextValues = new HashMap<>(contextValues);
ResourceResult result = this.referenceModel.evaluate(dataSource, ImmutableMap.copyOf(localContextValues), genBaseValue);
if (result != null && result.getValue() != null) {
ResourceValue resolvedvalues = result.getValue();
LOGGER.debug("Evaluated expression {}, returning {} ", this.reference, resolvedvalues);
if (resolvedvalues != null) {
resourceReferenceResult = EvaluationResultFactory.getEvaluationResult(resolvedvalues.getResource(), additionalResources);
}
}
}
return resourceReferenceResult;
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ResourceExpression method evaluateExpression.
@Override
public EvaluationResult evaluateExpression(InputDataExtractor dataSource, Map<String, EvaluationResult> contextValues, EvaluationResult baseValue) {
Preconditions.checkArgument(dataSource != null, "dataSource cannot be null");
Preconditions.checkArgument(contextValues != null, "contextValues cannot be null");
LOGGER.debug("Evaluating expression {}", this.resourceToGenerate);
EvaluationResult evaluationResult = null;
ResourceResult result = this.data.evaluate(dataSource, ImmutableMap.copyOf(contextValues), baseValue);
if (result != null && result.getValue() != null) {
ResourceValue resolvedvalues = result.getValue();
LOGGER.debug("Evaluated expression {}, returning {} ", this.resourceToGenerate, resolvedvalues);
if (resolvedvalues != null) {
evaluationResult = EvaluationResultFactory.getEvaluationResult(resolvedvalues.getResource(), result.getAdditionalResources());
}
}
return evaluationResult;
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class SimpleExpression method evaluateExpression.
@Override
public EvaluationResult evaluateExpression(InputDataExtractor dataSource, Map<String, EvaluationResult> contextValues, EvaluationResult baseValue) {
Preconditions.checkArgument(contextValues != null, "contextValues cannot be null");
Map<String, EvaluationResult> localContextValues = new HashMap<>(contextValues);
if (baseValue != null && !baseValue.isEmpty()) {
localContextValues.put(baseValue.getIdentifier(), baseValue);
localContextValues.put(Constants.BASE_VALUE_NAME, baseValue);
}
/**
* If the expression has fetch pair populated then use that for evaluation.
*/
if (this.fetch != null) {
return evaluateExpressionForFetch(localContextValues, baseValue);
}
Object resolvedValue = null;
if (VariableUtils.isVar(value)) {
boolean fuzzyMatch = VariableUtils.isFuzzyMatch(value);
EvaluationResult obj = ContextValueUtils.getVariableValuesFromVariableContextMap(value, ImmutableMap.copyOf(localContextValues), this.getExpressionAttr().isUseGroup(), fuzzyMatch);
if (obj != null && !obj.isEmpty()) {
resolvedValue = obj.getValue();
}
} else {
LOGGER.debug("Evaluated {} returning value enclosed as GenericResult.", this.value);
resolvedValue = this.value;
}
LOGGER.debug("Evaluated value {} to {} ", this.value, resolvedValue);
if (resolvedValue != null) {
return getValueOfSpecifiedType(resolvedValue);
} else {
LOGGER.debug("Evaluated {} returning null", this.value);
return null;
}
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7MessageData method extractMultipleValuesForSpec.
@Override
public EvaluationResult extractMultipleValuesForSpec(Specification spec, Map<String, EvaluationResult> contextValues) {
HL7Specification hl7spec = (HL7Specification) spec;
EvaluationResult valuefromVariables;
if (StringUtils.isNotBlank(hl7spec.getSegment())) {
valuefromVariables = contextValues.get(hl7spec.getSegment());
} else if (StringUtils.isNotBlank(hl7spec.getField())) {
valuefromVariables = contextValues.get(hl7spec.getField());
} else {
valuefromVariables = null;
}
Object hl7object = null;
if (valuefromVariables != null) {
hl7object = valuefromVariables.getValue();
}
if (hl7object instanceof List) {
List<Object> extractedValues = new ArrayList<>();
for (Object hl7objectFromList : (List) hl7object) {
Object result = extractValue(hl7spec, hl7objectFromList);
if (result instanceof List) {
extractedValues.addAll((List) result);
} else if (result != null) {
extractedValues.add(result);
} else if (result == null && hl7spec.getRetainEmptyFields()) {
// In this case, we need to preserve empty / blank fields. This is specified by '&' in the config.
// so add an empty string to the result array to achieve this.
extractedValues.add("");
}
}
return EvaluationResultFactory.getEvaluationResult(extractedValues);
} else {
return EvaluationResultFactory.getEvaluationResult(extractValue(hl7spec, hl7object));
}
}
Aggregations