From 10af73a27fadf6d3a029c58827f67e30bb2c02fb Mon Sep 17 00:00:00 2001 From: Zylox Date: Mon, 16 Dec 2024 15:07:05 -0600 Subject: [PATCH] Issue1469: Return false when performing 'in' on valueset with null code (#1470) --- .../elm/executing/AnyInValueSetEvaluator.java | 8 +++++- .../elm/executing/InValueSetEvaluator.java | 6 +++-- .../executing/AnyInValueSetEvaluatorTest.java | 25 +++++++++++++++++++ .../executing/InValueSetEvaluatorTest.java | 23 +++++++++++++++++ 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluatorTest.java create mode 100644 Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluatorTest.java diff --git a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluator.java b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluator.java index fb4b4b56e..75a77db55 100644 --- a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluator.java +++ b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluator.java @@ -6,6 +6,10 @@ public class AnyInValueSetEvaluator { public static Object internalEvaluate(Object codes, ValueSetRef valueSetRef, Object valueset, State state) { + if (codes == null) { + return false; + } + Object vs = null; if (valueSetRef != null) { vs = ValueSetRefEvaluator.toValueSet(state, valueSetRef); @@ -13,7 +17,9 @@ public static Object internalEvaluate(Object codes, ValueSetRef valueSetRef, Obj vs = valueset; } - if (codes == null || vs == null) return null; + if (vs == null) { + return null; + } if (codes instanceof Iterable) { Object result; diff --git a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluator.java b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluator.java index 8acb0dacc..df21c0eaa 100644 --- a/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluator.java +++ b/Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluator.java @@ -22,8 +22,10 @@ The in (Valueset) operators determine whether or not a given code is in a partic public class InValueSetEvaluator { public static Object inValueSet(Object code, Object valueset, State state) { - - if (code == null || valueset == null) { + if (code == null) { + return false; + } + if (valueset == null) { return null; } diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluatorTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluatorTest.java new file mode 100644 index 000000000..97b65677c --- /dev/null +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/AnyInValueSetEvaluatorTest.java @@ -0,0 +1,25 @@ +package org.opencds.cqf.cql.engine.elm.executing; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +import org.hl7.elm.r1.ValueSetRef; +import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.engine.execution.Environment; +import org.opencds.cqf.cql.engine.execution.State; +import org.opencds.cqf.cql.engine.runtime.ValueSet; + +public class AnyInValueSetEvaluatorTest { + + @Test + void issue1469FalseOnNullCode() { + var env = new Environment(null); + var state = new State(env); + var valueSet = new ValueSet(); + var valueSetRef = new ValueSetRef(); + + Object actual = AnyInValueSetEvaluator.internalEvaluate(null, valueSetRef, valueSet, state); + assertInstanceOf(Boolean.class, actual); + assertFalse((Boolean) actual); + } +} diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluatorTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluatorTest.java new file mode 100644 index 000000000..c4c22d2e1 --- /dev/null +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/elm/executing/InValueSetEvaluatorTest.java @@ -0,0 +1,23 @@ +package org.opencds.cqf.cql.engine.elm.executing; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; + +import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.engine.execution.Environment; +import org.opencds.cqf.cql.engine.execution.State; +import org.opencds.cqf.cql.engine.runtime.ValueSet; + +public class InValueSetEvaluatorTest { + + @Test + void issue1469FalseOnNullCode() { + var env = new Environment(null); + var state = new State(env); + var valueSet = new ValueSet(); + + Object actual = InValueSetEvaluator.inValueSet(null, valueSet, state); + assertInstanceOf(Boolean.class, actual); + assertFalse((Boolean) actual); + } +}