All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.linuxforhealth.hl7.expression.variable.ExpressionVariable Maven / Gradle / Ivy

Go to download

FHIR converter is a Java based library that enables converting Hl7v2 messages to FHIR resources

There is a newer version: 1.0.19
Show newest version
/*
 * (C) Copyright IBM Corp. 2020
 *
 * SPDX-License-Identifier: Apache-2.0
 */
package io.github.linuxforhealth.hl7.expression.variable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.core.expression.EmptyEvaluationResult;


/**
 * Defines Variable object that can be used during the expression evaluation.
 * 
 *
 * @author pbhallam
 */
public class ExpressionVariable extends SimpleVariable {

  private String expression;

  /**
   * Constructor for Variable with default type: Object
   * 
   * @param name
   * @param spec
   */
  public ExpressionVariable(String name, String expression, List spec,
      boolean extractMultiple) {
    super(name, spec, extractMultiple);
    this.expression = expression;
  }




  // resolve variable value
  @Override
  public EvaluationResult extractVariableValue(Map 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 localContextValues = new HashMap<>(contextValues);

        localContextValues.put(this.getName(), result);

      result = dataSource.evaluateJexlExpression(expression, localContextValues);
    }
    return result;

  }




}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy