Search in sources :

Example 1 with ResourceResult

use of io.github.linuxforhealth.core.resource.ResourceResult in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7DataBasedResourceModel method evaluate.

@Override
public ResourceResult evaluate(InputDataExtractor dataSource, Map<String, EvaluationResult> context, EvaluationResult baseValue) {
    ResourceResult resources = null;
    try {
        ResourceEvaluationResult result = ExpressionUtility.evaluate(dataSource, context, baseValue, this.expressions);
        if (result != null && !result.getResolveValues().isEmpty()) {
            String groupId = getGroupId(context);
            resources = new ResourceResult(new SimpleResourceValue(result.getResolveValues(), this.name), result.getAdditionalResolveValues(), groupId, result.getPendingExpressions());
        }
    } catch (RequiredConstraintFailureException e) {
        LOGGER.warn("Resource Constraint condition not satisfied for {}.", this.name);
        LOGGER.debug("Resource Constraint condition not satisfied for {}, exception {}", this.name, e.toString());
        return null;
    } catch (IllegalArgumentException | IllegalStateException | DataExtractionException e) {
        LOGGER.error("Exception during resource {} evaluation reason", this.name);
        LOGGER.debug("Exception during resource {} evaluation reason {}", this.name, e.toString());
        return null;
    }
    return resources;
}
Also used : RequiredConstraintFailureException(io.github.linuxforhealth.core.exception.RequiredConstraintFailureException) ResourceResult(io.github.linuxforhealth.core.resource.ResourceResult) SimpleResourceValue(io.github.linuxforhealth.core.resource.SimpleResourceValue) DataExtractionException(io.github.linuxforhealth.core.exception.DataExtractionException)

Example 2 with ResourceResult

use of io.github.linuxforhealth.core.resource.ResourceResult 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 3 with ResourceResult

use of io.github.linuxforhealth.core.resource.ResourceResult 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 4 with ResourceResult

use of io.github.linuxforhealth.core.resource.ResourceResult in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7MessageEngine method addResourceToBundle.

private void addResourceToBundle(Bundle bundle, List<ResourceResult> resourceResults) {
    if (resourceResults != null && !resourceResults.isEmpty()) {
        for (ResourceResult resReult : resourceResults) {
            addToBundle(bundle, Lists.newArrayList(resReult.getValue()));
            addToBundle(bundle, resReult.getAdditionalResources());
        }
    }
}
Also used : ResourceResult(io.github.linuxforhealth.core.resource.ResourceResult)

Example 5 with ResourceResult

use of io.github.linuxforhealth.core.resource.ResourceResult in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7MessageEngine method generateResources.

private List<ResourceResult> generateResources(HL7MessageData hl7DataInput, HL7FHIRResourceTemplate template, Map<String, EvaluationResult> contextValues) {
    ResourceModel resourceModel = template.getResource();
    List<String> segmentGroup = template.getAttributes().getSegment().getGroup();
    String segment = template.getAttributes().getSegment().getSegment();
    List<ResourceResult> resourceResults = null;
    List<SegmentGroup> multipleSegments = getMultipleSegments(hl7DataInput, template, segmentGroup, segment);
    if (!multipleSegments.isEmpty()) {
        resourceResults = generateMultipleResources(hl7DataInput, resourceModel, contextValues, multipleSegments, template.isGenerateMultiple());
    }
    return resourceResults;
}
Also used : ResourceResult(io.github.linuxforhealth.core.resource.ResourceResult) ResourceModel(io.github.linuxforhealth.api.ResourceModel) SegmentGroup(io.github.linuxforhealth.hl7.message.util.SegmentGroup)

Aggregations

ResourceResult (io.github.linuxforhealth.core.resource.ResourceResult)7 EvaluationResult (io.github.linuxforhealth.api.EvaluationResult)4 ResourceValue (io.github.linuxforhealth.api.ResourceValue)3 RequiredConstraintFailureException (io.github.linuxforhealth.core.exception.RequiredConstraintFailureException)3 SegmentGroup (io.github.linuxforhealth.hl7.message.util.SegmentGroup)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ResourceModel (io.github.linuxforhealth.api.ResourceModel)2 SimpleEvaluationResult (io.github.linuxforhealth.core.expression.SimpleEvaluationResult)2 SimpleResourceValue (io.github.linuxforhealth.core.resource.SimpleResourceValue)2 ResourceEvaluationResult (io.github.linuxforhealth.hl7.resource.ResourceEvaluationResult)2 Structure (ca.uhn.hl7v2.model.Structure)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 FHIRResourceTemplate (io.github.linuxforhealth.api.FHIRResourceTemplate)1 InputDataExtractor (io.github.linuxforhealth.api.InputDataExtractor)1 MessageEngine (io.github.linuxforhealth.api.MessageEngine)1