Skip to content

Commit baf7796

Browse files
authored
Merge branch 'master' into engine-coverage
2 parents a02ecc3 + 01788ab commit baf7796

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Src/java/engine/src/main/kotlin/org/opencds/cqf/cql/engine/exception/Backtrace.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.hl7.elm.r1.Expression
88
import org.hl7.elm.r1.ExpressionDef
99
import org.hl7.elm.r1.FunctionDef
1010
import org.hl7.elm.r1.OperandDef
11+
import org.hl7.elm.r1.VersionedIdentifier
1112
import org.opencds.cqf.cql.engine.execution.State.ActivationFrame
1213
import org.opencds.cqf.cql.engine.execution.Variable
1314

@@ -40,6 +41,7 @@ class Backtrace {
4041
* function or expression definition, function arguments, local variables as well as the name
4142
* and value of the CQL context.
4243
*/
44+
@Suppress("LongParameterList")
4345
class FunctionoidFrame(
4446
expression: Expression?,
4547
/**
@@ -69,6 +71,13 @@ class Backtrace {
6971
* @return A list of the [Variable]s that correspond to local variable bindings.
7072
*/
7173
val localVariables: MutableList<Variable?>?,
74+
/**
75+
* Returns the name of the Library that was current during the evaluation represented by the
76+
* frame.
77+
*
78+
* @return The name of the Library in context.
79+
*/
80+
val libraryIdentifier: VersionedIdentifier?,
7281
/**
7382
* Returns the name of the CQL context that was current during the evaluation represented by
7483
* the frame.
@@ -91,12 +100,14 @@ class Backtrace {
91100
this.frames.add(frame)
92101
}
93102

103+
@Suppress("LongParameterList")
94104
fun maybeAddFrame(
95105
containingDefinition: ExpressionDef?,
96106
definitionFrame: ActivationFrame?,
97107
stack: Deque<ActivationFrame>,
98108
contextName: String?,
99109
contextValue: Any?,
110+
libraryIdentifier: VersionedIdentifier?,
100111
expression: Expression?,
101112
) {
102113
// When the EvaluationVisitor unwinds through
@@ -169,6 +180,7 @@ class Backtrace {
169180
containingDefinition,
170181
arguments,
171182
localVariables,
183+
libraryIdentifier,
172184
contextName,
173185
contextValue,
174186
)

Src/java/engine/src/main/kotlin/org/opencds/cqf/cql/engine/execution/EvaluationVisitor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class EvaluationVisitor : BaseElmLibraryVisitor<Any?, State?>() {
212212
context.stack,
213213
context.getCurrentContext(),
214214
context.currentContextValue,
215+
context.getCurrentLibrary()?.identifier,
215216
expression,
216217
)
217218
}

Src/java/engine/src/test/kotlin/org/opencds/cqf/cql/engine/execution/BacktraceTest.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.hamcrest.Matchers
66
import org.hamcrest.TypeSafeMatcher
77
import org.hl7.elm.r1.ExpressionDef
88
import org.hl7.elm.r1.FunctionDef
9+
import org.hl7.elm.r1.VersionedIdentifier
910
import org.junit.jupiter.api.Assertions
1011
import org.junit.jupiter.api.Test
1112
import org.opencds.cqf.cql.engine.exception.Backtrace.FunctionoidFrame
@@ -69,6 +70,32 @@ internal class BacktraceTest : CqlTestBase() {
6970
}
7071
}
7172

73+
internal class VersionedIdentifierMatcher(
74+
private val expectedId: String?,
75+
private val expectedVersion: String?,
76+
) : TypeSafeMatcher<VersionedIdentifier>() {
77+
override fun matchesSafely(vi: VersionedIdentifier): Boolean {
78+
return true
79+
}
80+
81+
override fun describeTo(description: Description) {
82+
description
83+
.appendText("a library id")
84+
.appendValue(expectedId)
85+
.appendText("a library version")
86+
.appendValue(expectedVersion)
87+
}
88+
89+
companion object {
90+
fun isVersionedIdentifier(
91+
expectedId: String?,
92+
expectedVersion: String?,
93+
): VersionedIdentifierMatcher {
94+
return VersionedIdentifierMatcher(expectedId, expectedVersion)
95+
}
96+
}
97+
}
98+
7299
internal class ContextMatcher(
73100
private val expectedName: String?,
74101
private val expectedValue: Any?,
@@ -123,6 +150,13 @@ internal class BacktraceTest : CqlTestBase() {
123150
VariableMatcher.isVariable("_", 1),
124151
),
125152
)
153+
MatcherAssert.assertThat(
154+
frame1Functionoid.libraryIdentifier,
155+
VersionedIdentifierMatcher.isVersionedIdentifier(
156+
"BacktraceTest",
157+
expectedVersion = null,
158+
),
159+
)
126160
MatcherAssert.assertThat(
127161
frame1Functionoid,
128162
ContextMatcher.hasContext("Unfiltered", null),
@@ -145,6 +179,13 @@ internal class BacktraceTest : CqlTestBase() {
145179
),
146180
)
147181
MatcherAssert.assertThat(frame2Functionoid.localVariables, Matchers.empty())
182+
MatcherAssert.assertThat(
183+
frame2Functionoid.libraryIdentifier,
184+
VersionedIdentifierMatcher.isVersionedIdentifier(
185+
"BacktraceTest",
186+
expectedVersion = null,
187+
),
188+
)
148189
MatcherAssert.assertThat(
149190
frame2Functionoid,
150191
ContextMatcher.hasContext("Unfiltered", null),
@@ -162,6 +203,13 @@ internal class BacktraceTest : CqlTestBase() {
162203
)
163204
MatcherAssert.assertThat(frame3Functionoid.arguments, Matchers.empty())
164205
MatcherAssert.assertThat(frame3Functionoid.localVariables, Matchers.empty())
206+
MatcherAssert.assertThat(
207+
frame3Functionoid.libraryIdentifier,
208+
VersionedIdentifierMatcher.isVersionedIdentifier(
209+
"BacktraceTest",
210+
expectedVersion = null,
211+
),
212+
)
165213
MatcherAssert.assertThat(
166214
frame3Functionoid,
167215
ContextMatcher.hasContext("Unfiltered", null),

0 commit comments

Comments
 (0)