Search in sources :

Example 26 with EvaluationResult

use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.

the class ResourceExpressionTest method test1_segment.

@Test
void test1_segment() throws IOException {
    Message hl7message = getMessage(message);
    HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
    Structure s = hl7DTE.getStructure("PID", 0).getValue();
    ExpressionAttributes attr = new ExpressionAttributes.Builder().withSpecs("PID.3").withValueOf("datatype/Identifier").build();
    ResourceExpression exp = new ResourceExpression(attr);
    assertThat(exp.getData()).isNotNull();
    Map<String, EvaluationResult> context = new HashMap<>();
    EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new SimpleEvaluationResult(s));
    Map<String, Object> result = (Map<String, Object>) value.getValue();
    assertThat(result.get("use")).isNull();
    assertThat(result).containsEntry("value", "000010016");
}
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) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) Structure(ca.uhn.hl7v2.model.Structure) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 27 with EvaluationResult

use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.

the class ResourceExpressionTest method test1_segment_rep.

@Test
void test1_segment_rep() throws IOException {
    String message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^SY1^MR~000010017^^^SY2^SS~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").withValueOf("datatype/Identifier").withGenerateList(true).build();
    ResourceExpression exp = new ResourceExpression(attr);
    assertThat(exp.getData()).isNotNull();
    Map<String, EvaluationResult> context = new HashMap<>();
    context.put("code", new SimpleEvaluationResult(hl7DTE.getTypes((Segment) s, 3)));
    EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new SimpleEvaluationResult(s));
    List<Object> results = (List<Object>) value.getValue();
    assertThat(results).hasSize(3);
    Map<String, Object> result = (Map<String, Object>) results.get(0);
    assertThat(result.get("use")).isNull();
    assertThat(result).containsEntry("value", "000010016");
    assertThat(result.get("system")).isNull();
    assertThat(result.get("type")).isNotNull();
}
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) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 28 with EvaluationResult

use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.

the class ResourceExpressionTest method testCodeableConceptFromISTtype.

@Test
void testCodeableConceptFromISTtype() 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|TestPatient^Jane|19700101|female||||||||||\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||\r" + "OBX|1|TX|1234^^SCT||First line: ECHOCARDIOGRAPHIC REPORT|||AA|||F||\r";
    Message hl7message = getMessage(message);
    HL7DataExtractor hl7DTE = new HL7DataExtractor(hl7message);
    Structure s = hl7DTE.getStructure("OBX", 0).getValue();
    ExpressionAttributes attr = new ExpressionAttributes.Builder().withSpecs("OBX.8").withValueOf("datatype/CodeableConcept").withGenerateList(true).build();
    ResourceExpression exp = new ResourceExpression(attr);
    assertThat(exp.getData()).isNotNull();
    Map<String, EvaluationResult> context = new HashMap<>();
    EvaluationResult value = exp.evaluate(new HL7MessageData(hl7DTE), ImmutableMap.copyOf(context), new SimpleEvaluationResult(s));
    List<Map<String, Object>> result = (List<Map<String, Object>>) value.getValue();
    assertThat(result.get(0).get("text")).isNull();
    assertThat(result.get(0).get("coding")).isNotNull();
    List<SimpleCode> scs = (List<SimpleCode>) result.get(0).get("coding");
    SimpleCode sc = scs.get(0);
    assertThat(sc.getCode()).isEqualTo("AA");
    assertThat(sc.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0078");
    assertThat(sc.getDisplay()).isEqualTo("Critically abnormal");
}
Also used : Message(ca.uhn.hl7v2.model.Message) HL7DataExtractor(io.github.linuxforhealth.hl7.parsing.HL7DataExtractor) HashMap(java.util.HashMap) SimpleCode(io.github.linuxforhealth.core.terminology.SimpleCode) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) HL7MessageData(io.github.linuxforhealth.hl7.message.HL7MessageData) SimpleEvaluationResult(io.github.linuxforhealth.core.expression.SimpleEvaluationResult) List(java.util.List) Structure(ca.uhn.hl7v2.model.Structure) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 29 with EvaluationResult

use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.

the class ExpressionUtility method processExpression.

private static void processExpression(InputDataExtractor dataSource, EvaluationResult baseValue, Map<String, EvaluationResult> localContext, List<ResourceValue> additionalResolveValues, Map<String, Object> resolveValues, Entry<String, Expression> entry) {
    EvaluationResult obj = entry.getValue().evaluate(dataSource, localContext, baseValue);
    LOGGER.debug("Evaluated {} {} value returned {} ", entry.getKey(), entry.getValue(), obj);
    if (obj != null && !obj.isEmpty()) {
        String keyNameSuffix = getKeyNameSuffix(localContext);
        // Check if the key already exist in the HashMap, if found append, do not replace
        if (!resolveValues.containsKey(getKeyName(entry.getKey(), keyNameSuffix))) {
            resolveValues.put(getKeyName(entry.getKey(), keyNameSuffix), obj.getValue());
        } else {
            Object existing = resolveValues.get(getKeyName(entry.getKey(), keyNameSuffix));
            if (existing instanceof List) {
                if (obj.getValue() instanceof List) {
                    ((List<Object>) existing).addAll(obj.getValue());
                } else {
                    ((List<Object>) existing).add(obj.getValue());
                }
            }
        }
        if (obj.getAdditionalResources() != null && !obj.getAdditionalResources().isEmpty() && additionalResolveValues != null) {
            additionalResolveValues.addAll(obj.getAdditionalResources());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) EvaluationResult(io.github.linuxforhealth.api.EvaluationResult) ResourceEvaluationResult(io.github.linuxforhealth.hl7.resource.ResourceEvaluationResult) EmptyEvaluationResult(io.github.linuxforhealth.core.expression.EmptyEvaluationResult)

Example 30 with EvaluationResult

use of io.github.linuxforhealth.api.EvaluationResult in project hl7v2-fhir-converter by LinuxForHealth.

the class SimpleExpressionTest method test_variable.

@Test
void test_variable() {
    ExpressionAttributes attr = new ExpressionAttributes.Builder().withValue(SOME_VALUE).build();
    SimpleExpression exp = new SimpleExpression(attr);
    Map<String, EvaluationResult> context = new HashMap<>();
    context.put("var1", new SimpleEvaluationResult(SOME_VALUE));
    EvaluationResult value = exp.evaluate(data, ImmutableMap.copyOf(context), new EmptyEvaluationResult());
    assertThat((String) value.getValue()).isEqualTo(SOME_VALUE);
}
Also used : HashMap(java.util.HashMap) 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)

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