Search in sources :

Example 11 with EvaluationResult

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult)

Example 12 with EvaluationResult

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;
}
Also used : ResourceResult(io.github.linuxforhealth.core.resource.ResourceResult) HashMap(java.util.HashMap) ResourceValue(io.github.linuxforhealth.api.ResourceValue) ArrayList(java.util.ArrayList) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult)

Example 13 with EvaluationResult

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;
}
Also used : ResourceResult(io.github.linuxforhealth.core.resource.ResourceResult) ResourceValue(io.github.linuxforhealth.api.ResourceValue) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult)

Example 14 with 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;
    }
}
Also used : HashMap(java.util.HashMap) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult)

Example 15 with EvaluationResult

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));
    }
}
Also used : ArrayList(java.util.ArrayList) HL7Specification(io.github.linuxforhealth.hl7.expression.specification.HL7Specification) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult)

Aggregations

EvaluationResult (io.github.linuxforhealth.api.EvaluationResult)46 HashMap (java.util.HashMap)36 SimpleEvaluationResult (io.github.linuxforhealth.core.expression.SimpleEvaluationResult)30 Test (org.junit.jupiter.api.Test)26 Message (ca.uhn.hl7v2.model.Message)19 EmptyEvaluationResult (io.github.linuxforhealth.core.expression.EmptyEvaluationResult)19 HL7MessageData (io.github.linuxforhealth.hl7.message.HL7MessageData)19 HL7DataExtractor (io.github.linuxforhealth.hl7.parsing.HL7DataExtractor)19 Structure (ca.uhn.hl7v2.model.Structure)18 List (java.util.List)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 ResourceValue (io.github.linuxforhealth.api.ResourceValue)6 RequiredConstraintFailureException (io.github.linuxforhealth.core.exception.RequiredConstraintFailureException)5 ResourceEvaluationResult (io.github.linuxforhealth.hl7.resource.ResourceEvaluationResult)5 ResourceResult (io.github.linuxforhealth.core.resource.ResourceResult)4 SimpleCode (io.github.linuxforhealth.core.terminology.SimpleCode)4 DataExtractionException (io.github.linuxforhealth.core.exception.DataExtractionException)3 Expression (io.github.linuxforhealth.api.Expression)2