use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class ExpressionVariable method extractVariableValue.
// resolve variable value
@Override
public EvaluationResult extractVariableValue(Map<String, EvaluationResult> contextValues, InputDataExtractor dataSource) {
EvaluationResult result = null;
if (!this.getSpec().isEmpty()) {
result = getValueFromSpecs(contextValues, dataSource);
}
if (result == null) {
result = new EmptyEvaluationResult();
}
if (this.expression != null) {
// resolve expression
Map<String, EvaluationResult> localContextValues = new HashMap<>(contextValues);
localContextValues.put(this.getName(), result);
result = dataSource.evaluateJexlExpression(expression, localContextValues);
}
return result;
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ExpressionTest method test3_field_subcomponent.
@Test
void test3_field_subcomponent() throws IOException {
String message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
Message hl7message = getMessage(message);
HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
Structure s = hl7DTE.getStructure("PID", 0).getValue();
ExpressionAttributes attr = new ExpressionAttributes.Builder().withSpecs("PID.3.1").withType("String").build();
Hl7Expression exp = new Hl7Expression(attr);
Map<String, EvaluationResult> context = new HashMap<>();
// context.put("PID", new SimpleEvaluationResult(s));
EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new SimpleEvaluationResult(s));
assertThat((String) value.getValue()).isEqualTo("000010016");
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ExpressionTest method test3_field.
@Test
void test3_field() throws IOException {
String message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
Message hl7message = getMessage(message);
HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
Structure s = hl7DTE.getStructure("PID", 0).getValue();
Type type = hl7DTE.getType((Segment) s, 3, 0).getValue();
ExpressionAttributes attr = new ExpressionAttributes.Builder().withSpecs("CX.1").withType("String").build();
Hl7Expression exp = new Hl7Expression(attr);
Map<String, EvaluationResult> context = new HashMap<>();
// context.put("PID", new SimpleEvaluationResult(s));
// context.put(type.getName(), new SimpleEvaluationResult(type));
EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new SimpleEvaluationResult(type));
assertThat((String) value.getValue()).isEqualTo("000010016");
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class JELXExpressionTest method test_simple.
@Test
void test_simple() throws IOException {
String message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
Message hl7message = getMessage(message);
HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
ExpressionAttributes attr = new ExpressionAttributes.Builder().withValueOf("String.join(\" \", var1,var2, var3)").build();
JEXLExpression exp = new JEXLExpression(attr);
Map<String, EvaluationResult> context = new HashMap<>();
context.put("var1", new SimpleEvaluationResult(SOME_VALUE_1));
context.put("var2", new SimpleEvaluationResult(SOME_VALUE_2));
context.put("var3", new SimpleEvaluationResult(SOME_VALUE_3));
EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new EmptyEvaluationResult());
assertThat((String) value.getValue()).isEqualTo(SOME_VALUE_1 + " " + SOME_VALUE_2 + " " + SOME_VALUE_3);
}
use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.
the class JELXExpressionTest method test_with_variables.
@Test
void test_with_variables() throws IOException, DataTypeException {
String message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
Message hl7message = getMessage(message);
HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
CX cx = new CX(hl7message);
cx.getCx1_IDNumber().setValue(SOME_VALUE_1);
cx.getCx2_IdentifierCheckDigit().setValue(SOME_VALUE_2);
Map<String, EvaluationResult> context = new HashMap<>();
context.put("CX", new SimpleEvaluationResult(cx));
Map<String, String> var = new HashMap<>();
var.put("var1", "String, CX.1");
var.put("var2", "String, CX.2");
var.put("var3", "String, CX.2");
ExpressionAttributes attr = new ExpressionAttributes.Builder().withValueOf("String.join(\" \", var1,var2, var3)").withVars(var).build();
JEXLExpression exp = new JEXLExpression(attr);
EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new EmptyEvaluationResult());
assertThat((String) value.getValue()).isEqualTo(SOME_VALUE_1 + " " + SOME_VALUE_2 + " " + SOME_VALUE_2);
}
Aggregations