8
8
9
9
#nullable enable
10
10
using Hl7 . Cql . Abstractions ;
11
- using Hl7 . Cql . CodeGeneration . NET ;
12
11
using Hl7 . Cql . CodeGeneration . NET . Toolkit ;
13
12
using Hl7 . Cql . CodeGeneration . NET . Toolkit . Extensions ;
14
13
using Hl7 . Cql . CqlToElm ;
15
14
using Hl7 . Cql . CqlToElm . Toolkit ;
16
15
using Hl7 . Cql . CqlToElm . Toolkit . Extensions ;
17
16
using Hl7 . Cql . Elm ;
18
17
using Hl7 . Cql . Fhir ;
19
- using Hl7 . Cql . Invocation . Toolkit ;
20
18
using Hl7 . Cql . Invocation . Toolkit . Extensions ;
21
19
using Hl7 . Cql . Runtime ;
22
20
@@ -26,28 +24,46 @@ namespace CoreTests;
26
24
public class ToolkitTests
27
25
{
28
26
[ TestMethod ]
29
- public void TestRuntimeScopeAgainstLibraryDefinitionResults ( )
27
+ public void TestNestedTupleResult_ToString_MatchesExpectedFormat ( )
30
28
{
31
29
// Arrange
32
- var filePath = new DirectoryInfo ( Directory . GetCurrentDirectory ( ) )
33
- . SelfAndParents ( )
34
- . Select ( dir => Path . GetFullPath ( Path . Combine ( dir . FullName , "Dlls" , "CqlNestedTupleTest-1.0.0.dll" ) ) )
35
- . First ( File . Exists ) ;
30
+ var cqlNestedTuples =
31
+ ( CqlLibraryString ) """
32
+ library CqlNestedTupleTest version '1.0.0'
33
+
34
+ define "Result":
35
+ Tuple{
36
+ status: 'success',
37
+ result: Tuple{
38
+ result1: 'some first result',
39
+ result2: 'some second result'
40
+ }
41
+ }
42
+ """ ;
43
+
36
44
var ctx = FhirCqlContext . ForBundle ( ) ;
37
- using var librarySetInvoker = new InvocationToolkit ( )
38
- . AddAssemblyBinaries ( AssemblyBinary . Default . LoadFromFile ( new FileInfo ( filePath ) ) )
39
- . CreateLibrarySetInvoker ( ) ;
45
+ using var librarySetInvoker =
46
+ new CqlToolkit ( )
47
+ . AddCqlLibraries ( cqlNestedTuples )
48
+ . CreateLibrarySetInvoker ( ) ;
40
49
41
50
// Act
42
- var result = librarySetInvoker
51
+ var results = librarySetInvoker
43
52
. SelectExpressionsForLibrary ( CqlVersionedLibraryIdentifier . Parse ( "CqlNestedTupleTest-1.0.0" ) )
44
53
. SelectResults ( ctx )
45
54
. ToDictionary ( t => t . definitionInvoker . DefinitionName ) ;
46
55
47
56
// Assert
48
- Assert . IsNotNull ( result ) ;
49
- result . TryGetValue ( "Result" , out var obj ) ;
57
+ Assert . IsNotNull ( results ) ;
58
+ results . TryGetValue ( "Result" , out var obj ) ;
50
59
Assert . IsNotNull ( obj ) ;
60
+ Assert . IsNotNull ( obj . invocationResult ) ;
61
+ Assert . AreEqual (
62
+ // NOTE: This is the raw ToString() output of the value tuple returned from the CQL library.
63
+ // It is not a JSON string, but a C# value tuple string representation.
64
+ """
65
+ (["result", "status"], (["result1", "result2"], some first result, some second result), success)
66
+ """ , obj . invocationResult . ToString ( ) ) ;
51
67
}
52
68
53
69
[ TestMethod ]
@@ -220,8 +236,8 @@ context Patient
220
236
221
237
// Act: Get expressions and functions using the new method
222
238
var expressionsAndFunctions = libraryInvoker . SelectExpressions ( DefinitionPredicates . ExpressionsAndFunctions )
223
- . Where ( d => d . DefinitionName != "Patient" ) // Filter out the automatic Patient context definition
224
- . ToList ( ) ;
239
+ . Where ( d => d . DefinitionName != "Patient" ) // Filter out the automatic Patient context definition
240
+ . ToList ( ) ;
225
241
226
242
// Assert: Should include both expressions and functions
227
243
expressionsAndFunctions . Should ( ) . HaveCount ( 5 , "Should include 2 expressions and 3 functions" ) ;
@@ -337,8 +353,8 @@ public void DefinitionInvokerParameters_Tests()
337
353
338
354
// Act: Generate C# code and compile to assembly using ElmToolkit
339
355
var elmToolkit = new ElmToolkit ( )
340
- . AddElmLibraries ( [ elmLibrary ] )
341
- . CompileToAssemblies ( ) ;
356
+ . AddElmLibraries ( [ elmLibrary ] )
357
+ . CompileToAssemblies ( ) ;
342
358
343
359
var assemblyResult = elmToolkit . GetElmToAssemblyResults ( ) . First ( ) ;
344
360
var assemblyBinary = assemblyResult . assemblyBinary ;
@@ -376,5 +392,4 @@ public void DefinitionInvokerParameters_Tests()
376
392
keywordTestInvoker . Parameters [ 1 ] . Name . Should ( ) . Be ( "ref" , "Second parameter should preserve original CQL name even if it's a C# keyword" ) ;
377
393
keywordTestInvoker . Parameters [ 2 ] . Name . Should ( ) . Be ( "class" , "Third parameter should preserve original CQL name even if it's a C# keyword" ) ;
378
394
}
379
-
380
- }
395
+ }
0 commit comments