io.github.linuxforhealth.hl7.message.HL7MessageData 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.message;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import ca.uhn.hl7v2.model.Segment;
import ca.uhn.hl7v2.model.Type;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.api.Specification;
import io.github.linuxforhealth.core.data.JexlEngineUtil;
import io.github.linuxforhealth.core.exception.DataExtractionException;
import io.github.linuxforhealth.core.expression.EmptyEvaluationResult;
import io.github.linuxforhealth.core.expression.EvaluationResultFactory;
import io.github.linuxforhealth.core.expression.SimpleEvaluationResult;
import io.github.linuxforhealth.hl7.data.Hl7RelatedGeneralUtils;
import io.github.linuxforhealth.hl7.expression.specification.HL7Specification;
import io.github.linuxforhealth.hl7.parsing.HL7DataExtractor;
import io.github.linuxforhealth.hl7.parsing.result.ParsingResult;
public class HL7MessageData implements InputDataExtractor {
private HL7DataExtractor hde;
private static final Logger LOGGER = LoggerFactory.getLogger(HL7MessageData.class);
protected static final Pattern HL7_SPEC_SPLITTER = Pattern.compile(".");
private static final JexlEngineUtil JEXL =
new JexlEngineUtil("GeneralUtils", Hl7RelatedGeneralUtils.class);
public HL7MessageData(HL7DataExtractor hde) {
Preconditions.checkArgument(hde != null, "Hl7DataExtractor cannot be null.");
this.hde = hde;
}
@Override
public EvaluationResult extractMultipleValuesForSpec(Specification spec,
Map 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