io.github.linuxforhealth.hl7.expression.specification.SimpleSpecification 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.specification;
import java.util.HashMap;
import java.util.Map;
import io.github.linuxforhealth.api.EvaluationResult;
import io.github.linuxforhealth.api.InputDataExtractor;
import io.github.linuxforhealth.api.Specification;
import io.github.linuxforhealth.core.Constants;
import io.github.linuxforhealth.core.expression.EvaluationResultFactory;
/**
* Represents HL7 data specification. It defines segment, field, component and subcomponent
* names/identifiers that can be used for extracting data.
*
*
* @author pbhallam
*/
public class SimpleSpecification implements Specification {
private String variableName;
private boolean isExtractMultiple;
private boolean useGroup;
private InputDataExtractor primaryDataSource = new ContextMapData();
public SimpleSpecification(String variableName,
boolean isMultiple, boolean useGroup) {
this.variableName = variableName;
this.isExtractMultiple = isMultiple;
this.useGroup = useGroup;
}
public boolean isExtractMultiple() {
return isExtractMultiple;
}
public String getVariable() {
return variableName;
}
public Class extends InputDataExtractor> getSourceInputDataClass() {
return this.primaryDataSource.getClass();
}
@Override
public EvaluationResult extractValueForSpec(InputDataExtractor dataSource,
Map contextValues) {
Map localContextValues = new HashMap<>(contextValues);
localContextValues.put(Constants.USE_GROUP,
EvaluationResultFactory.getEvaluationResult(useGroup));
return primaryDataSource.extractValueForSpec(this, localContextValues);
}
@Override
public EvaluationResult extractMultipleValuesForSpec(InputDataExtractor dataSource,
Map contextValues) {
Map localContextValues = new HashMap<>(contextValues);
localContextValues.put(Constants.USE_GROUP,
EvaluationResultFactory.getEvaluationResult(useGroup));
return primaryDataSource.extractMultipleValuesForSpec(this, localContextValues);
}
public boolean isUseGroup() {
return useGroup;
}
public void setUseGroup(boolean useGroup) {
this.useGroup = useGroup;
}
}