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;
}
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;
}
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;
}
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());
}
}
}
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;
}
Aggregations