io.github.linuxforhealth.hl7.expression.Hl7Expression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hl7v2-fhir-converter Show documentation
Show all versions of hl7v2-fhir-converter Show documentation
FHIR converter is a Java based library that enables converting Hl7v2 messages to FHIR resources
/*
* (C) Copyright IBM Corp. 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
package io.github.linuxforhealth.hl7.expression;
import java.util.Map;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.core.expression.EmptyEvaluationResult;
import io.github.linuxforhealth.core.expression.EvaluationResultFactory;
import io.github.linuxforhealth.hl7.data.SimpleDataTypeMapper;
import io.github.linuxforhealth.hl7.data.ValueExtractor;
import io.github.linuxforhealth.hl7.resource.deserializer.TemplateFieldNames;
/**
* Represents the HL7 expression linuxforhealthch can generate the extraction string that HAPI
* terser can evaluate. Supports the following structure
*
*
* @author pbhallam
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Hl7Expression extends AbstractExpression {
public Hl7Expression(String type, String hl7spec) {
this(type, hl7spec, null, false, null, null, null, false);
}
/**
*
* @param type
* @param specs
* @param defaultValue
* @param required
* @param variables
* @param condition
* @param constants
* @param useGroup
*/
@JsonCreator
public Hl7Expression(@JsonProperty(TemplateFieldNames.TYPE) String type,
@JsonProperty(TemplateFieldNames.SPEC) String specs,
@JsonProperty(TemplateFieldNames.DEFAULT_VALUE) String defaultValue,
@JsonProperty(TemplateFieldNames.REQUIRED) boolean required,
@JsonProperty(TemplateFieldNames.VARIABLES) Map variables,
@JsonProperty(TemplateFieldNames.CONDITION) String condition,
@JsonProperty(TemplateFieldNames.CONSTANTS) Map constants,
@JsonProperty(TemplateFieldNames.USE_GROUP) boolean useGroup) {
super(type, defaultValue, required, specs, variables, condition, constants, useGroup);
}
@Override
public EvaluationResult evaluateExpression(InputDataExtractor dataSource,
Map contextValues, EvaluationResult baseValue) {
Preconditions.checkArgument(dataSource != null, "dataSource cannot be null");
Preconditions.checkArgument(contextValues != null, "contextValues cannot be null");
Object hl7Value = baseValue.getValue();
Object resolvedValue = null;
ValueExtractor