Search in sources :

Example 16 with EvaluationResult

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;
}
Also used : HashMap(java.util.HashMap) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult)

Example 17 with EvaluationResult

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");
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Structure(ca.uhn.hl7v2.model.Structure) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Test(org.junit.jupiter.api.Test)

Example 18 with EvaluationResult

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");
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) Segment(ca.uhn.hl7v2.model.Segment) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Type(ca.uhn.hl7v2.model.Type) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Structure(ca.uhn.hl7v2.model.Structure) Test(org.junit.jupiter.api.Test)

Example 19 with EvaluationResult

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);
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) Test(org.junit.jupiter.api.Test)

Example 20 with EvaluationResult

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);
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult) CX(ca.uhn.hl7v2.model.v26.datatype.CX) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Test(org.junit.jupiter.api.Test)

Aggregations

EvaluationResult (io.github.linuxforhealth.api.EvaluationResult)46 HashMap (java.util.HashMap)36 SimpleEvaluationResult (io.github.linuxforhealth.core.expression.SimpleEvaluationResult)30 Test (org.junit.jupiter.api.Test)26 Message (ca.uhn.hl7v2.model.Message)19 EmptyEvaluationResult (io.github.linuxforhealth.core.expression.EmptyEvaluationResult)19 HL7MessageData (io.github.linuxforhealth.hl7.message.HL7MessageData)19 HL7DataExtractor (io.github.linuxforhealth.hl7.parsing.HL7DataExtractor)19 Structure (ca.uhn.hl7v2.model.Structure)18 List (java.util.List)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 ResourceValue (io.github.linuxforhealth.api.ResourceValue)6 RequiredConstraintFailureException (io.github.linuxforhealth.core.exception.RequiredConstraintFailureException)5 ResourceEvaluationResult (io.github.linuxforhealth.hl7.resource.ResourceEvaluationResult)5 ResourceResult (io.github.linuxforhealth.core.resource.ResourceResult)4 SimpleCode (io.github.linuxforhealth.core.terminology.SimpleCode)4 DataExtractionException (io.github.linuxforhealth.core.exception.DataExtractionException)3 Expression (io.github.linuxforhealth.api.Expression)2